Disabling atmega103 compatibility mode for atmega128

Go To Last Post
24 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hello

i'm trying to use both of the UART in atmega128a but only UART0 is working and read about it and i found out that i should disable compatibility mode of atmega 103 as I need both serial communications, external oscillator, and so on. To do this I need to program the fuse bits, and I need help in this issue.

and also  i'm using external 16MHZ crystal can anyone tell me the values i should use in the lfuse , hfuse & efuse

thanks in advance

Last Edited: Fri. Apr 20, 2018 - 10:22 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I would recommend using the fuse calculator at:

http://www.engbedded.com/fusecalc/

 

Depending on your requirements for Brown-Out-Detection, bootloader size and any other particular settings, the following should give you an idea:

David (aka frog_jr)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thanks a lot that's really helpful but UART1 still not working after disabling compatibility mode can you please tell me what i'm missing here

void USART1_Init( unsigned int ubrr )
{
    /* Set baud rate */
    UBRR1H = (unsigned char)(ubrr>>8);
    UBRR1L = (unsigned char)ubrr;
    /* Enable receiver and transmitter */
    UCSR1B = (1<<RXEN1)|(1<<TXEN1);
    /* Set frame format: 8data, 2stop bit */
    UCSR1C = (1<<USBS1)|(1<<UCSZ11)|(1<<UCSZ10);
}

void USART1_Transmit( unsigned char data )
{
    /* Wait for empty transmit buffer */
    while ( !( UCSR1A & (1<<UDRE1)) )
    ;
    /* Put data into buffer, sends the data */
    UDR1 = data;
}

unsigned char USART1_Receive( void )
{
    /* Wait for data to be received */
    while ( !(UCSR1A & (1<<RXC1)) )
    ;
    /* Get and return received data from buffer */
    return UDR1;
}

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I used the Arduino add-on "MegaCore" and it's "Burn Bootloader" to set fuses, and I never even noticed that particular gotcha...
(although there were some worrisome pin behaviors before I did this, that are now explained!)

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

amrbadr wrote:

thanks a lot that's really helpful but UART1 still not working after disabling compatibility mode can you please tell me what i'm missing here

void USART1_Init( unsigned int ubrr )
{
    /* Set baud rate */
    UBRR1H = (unsigned char)(ubrr>>8);
    UBRR1L = (unsigned char)ubrr;
    /* Enable receiver and transmitter */
    UCSR1B = (1<<RXEN1)|(1<<TXEN1);
    /* Set frame format: 8data, 2stop bit */
    UCSR1C = (1<<USBS1)|(1<<UCSZ11)|(1<<UCSZ10);
}

void USART1_Transmit( unsigned char data )
{
    /* Wait for empty transmit buffer */
    while ( !( UCSR1A & (1<<UDRE1)) )
    ;
    /* Put data into buffer, sends the data */
    UDR1 = data;
}

unsigned char USART1_Receive( void )
{
    /* Wait for data to be received */
    while ( !(UCSR1A & (1<<RXC1)) )
    ;
    /* Get and return received data from buffer */
    return UDR1;
}

 

 

 

Your functions look fine, what is missing is a main that calls them and demos the problem your seeing.

A small COMPLETE program that one of us can compile and test is missing.

 

Jim

 

Click Link: Get Free Stock: Retire early!

share.robinhood.com/jamesc3274

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

void USART1_Init( unsigned int ubrr );
void USART1_Transmit( unsigned char data );
unsigned char USART1_Receive( void );

int main ()
{    DDRA=0xFF;
    DDRD|=0xff;
    
    USART1_Init(MYUBRR);
    char y=0;
    while(1)
    {
        
        USART1_Transmit('k');
        y=USART1_Receive();
        if(y=='k'){
        PORTA=0xFF;
        PORTD=0xFF;
        _delay_ms(1000);
        PORTA=0x00;
        PORTD=0x00;
        _delay_ms(1000);}

    }
    return 0;

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

amrbadr wrote:
USART1_Init(MYUBRR);
We still don't know what that ("MYUBRR")  is - though I suppose that if it is the same value as used for the working UART0 it must be right?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

amrbadr wrote:

...UART1 still not working ...

 

How do you know it's not working?

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What two pins are you connecting for your hardware loopback?

 

Jim

 

Click Link: Get Free Stock: Retire early!

share.robinhood.com/jamesc3274

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

sorry i forgot to add the #define in the comment

myubrr=103 according to the equation and i'm using external crystal 16mhz

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

PD2&PD3 , i'm using usb ttl and tera term for serial monitor i can get characters transmitted from the atmega128 but i can't receive any thing on it

ex: i get "k.." on the monitor but if i send the "k" the port is not toggling

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i'm using usb ttl and tera term for serial monitor i can get characters transmitted from the atmega128 but i can't receive any thing on it

ex: i get "k.." on the monitor but if i send the "k" the port is not toggling

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

amrbadr wrote:
i can get characters transmitted from the atmega128 but i can't receive any thing on it

In another thread, awneil wrote:
Due to the different tolerances each end, it is possible that your AVR's baud rate is (just) close enough for the PC to work with what it receives form the AVR, but not in the other direction.

 

https://www.avrfreaks.net/commen...

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i tried to send "k" using atmega328p to atmega128a both are adjusted to UBRR 103 due to using 16MHZ crystal on both but still the atmega128a not toggling the port it only toggles when i wire the TX and the RX to each other in other words it is only toggling when it receives from itself

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Make sure your terminal is set up 8N2, if setup for 8N1, may explain lack of RX.  Why 2 stop bits?  You can comment out the setting of UCSR1C and it defaults to 8N1...

 

 

Jim

 

 

Click Link: Get Free Stock: Retire early!

share.robinhood.com/jamesc3274

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

But a Stop bit is just the same as a line idle - so a terminal set to 8N1 should have no problem receiving from a device set to 8N2 

 

8N2 is effectively just 8N1 with a little inter-character delay.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i changed it to 8N1 but still facing the same problem and i checked my setting on tera term is also set to 8N1

i'm sure my baud rate is fine since its working on transmitting

so i can't tell where is the problem

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've not used a M128, but:

 

How you  read the Fuses back out to make sure you actually set them the way you think you did?

 

Does your board have by-pass caps, 0.1 uF, across Vcc/Ground and AVcc/Ground, mounted very close to the micro?

 

JC

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i'm using usb ttl and tera term for serial monitor ... but i can't receive any thing on it

Do you have things like hardware flow control disabled?  There was a class of PC serial ports that would just NOT transmit anything unless the modem-control pins (DSR, RTS?) from the external device were in the correct state (or you had done "magic" is PC-side software.)

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

westfw wrote:
that would just NOT transmit anything unless the modem-control pins (DSR, RTS?) f
DTR in fact. It has to be asserted to effectively say "there's something out here that wants to talk to you"

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i read the DS and i'm sure that i assigned the right fuse bits because i did the led blink test and usart0 is working well in both receiving and transmitting

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i'm not sure about this PC thing but usart0 is working fine in both receiving and transmitting

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've lost track here, but what does an unshown blink test have to do with fuse settings?  A blink test may well work, even with M103C fuse programmed.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

For reasons I don't wholly understand OP seems to have decided to continue this thread here:

 

https://www.avrfreaks.net/forum/...

 

So this is locked.

Topic locked