[TUT] [SOFT] Using the USART - Serial communications

Go To Last Post
490 posts / 0 new

Pages

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

Right thanks. I wil try that later as I just found some other errors on my system.

With my ADC reading, I got nice and expected waveforms on oscilloscope. This is roughly how my code looks like.

]//function for reading data from adc using usart spi
void USARTSPI_ReadADS1252(void)
{
            //declare 8bit WatchDRDY to detect DRDY mode
            unsigned char WatchDRDy;

    			//Watch for Data ready
            WatchDRDy = (PINC & 0x02 );
			//if Data ready occurs, do nothing
			while (WatchDRDy == (PINC & 0x02 ))
			{
                //do nothing
			};


            // make the whole delay to 22us to pass through the DRDY mode
            _delay_us ( 4);

			//PORTC0 = 0
			PORTC ^= (1);

            //Write to data register to initiate data transfer
            
            UDR0= 0;
            //Wait till you've received 8 bits
            //Do nothing  when Receive Complete Flag is ZERO (  means when it has not yet completely received data)
            while ((USART_CSR_A_Receive_Flag  & UCSR0A) == 0)
            {
            }
            //Read the data
            //UDR0 is the 8- bit USART Data Register
            Data[2] = UDR0;

 
            UDR0 = 0;
            while ((USART_CSR_A_Receive_Flag  & UCSR0A) == 0)
            {
            }
            Data[1] = UDR0;

         
            UDR0 = 0;
            while ((USART_CSR_A_Receive_Flag & UCSR0A) == 0)
            {
            }
            Data[0] = UDR0;

This works fine.

But when I include this USART_RS232_interfacing function after the adc reading function, I got waveforms that shows that my ADC is not reading data at the same intervals! (Time intervals between each "sample instant" are different). I don't know what the code has done to my system. Here is the code.

]//interfacing with rs232
void USART_RS232_Interfacing(void)
{

	//formula to mask and count 8 times
	int Loop = (Loop + 1) & 7;

	//at the 8th count, Loop will give 0
	if ( Loop == 0 )
	{
		//get Data[] into another variable ToUsart1[]
		ToUsart1[0] = Data[0];
		ToUsart1[1] = Data[1];
		ToUsart1[2] = Data[2];
	}

	//stream location counter initialisation
	int streamLoc = 0;

	//stream out data from  ToUsart1[0..2]
	while (streamLoc < 3)
	{
		// Do nothing until UDR is ready for more data to be written to it by checking register empty flag
		while ((UCSR1A & USART_CSR_A_Data_Register_Empty_Flag ) == 0) {};

		// Send out the byte value in the variable ToUsart[0..2] to data register of Usart_RS232
		UDR1 = ToUsart1[streamLoc];

		// increment stream location counter 0..2
		streamLoc++;

	}
};

Both these adc read and rs232 functions are included in an infinite loop.

Please advice. Thanks!

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

Quote:

Please advice

Not in a tutorial about the UART - if you have an ADC question ask it in AVR Forum - the discussion in threads here is just to discuss aspects of the tutorial being presented.

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

Hmmm ok sorry. I will start a new thread.

Last Edited: Thu. Apr 16, 2009 - 11:45 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

is there a similar tutorials for using the serial communication on AVR32 (EVK1100)?
Thanks

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

Hi zoro79, the AVR that you are using are very similar to what is on the tutorial. Just read the tutorial carefully and compare all the registers he used with your AVR32 datasheet.

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

Quote:

the AVR that you are using are very similar to what is on the tutorial.

Err...no..it isn't.

Unfortunately there are no tutorials for the AVR32.

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

Hi

I was wondering if you will be able to show me how to implement this USART Example on a AT90USB1287 device ?
Im using code vision.

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

Is there a function simlier to print_dbg_hex to read the USART on the AVR.
I know only usart_getchar function which is able to get one char. from the buffer but I don't know a way to convert a character to number.

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

Hello
Can anybody just have a look in my code to find the bug.
I try to transmit 8 bytes in the shape of a char[9] from one atmega164p to another using usart.
I know the baud settings are correct because one byte works fine to transmit, several bytes not.

Sender side:
char output[9];

void USART_vInit(void)

{

// Set baud rate

UBRR1H = (uint8_t)(USART_UBBR_VALUE>>8);

UBRR1L = (uint8_t)USART_UBBR_VALUE;

// Set frame format to 8 data bits, no parity, 2 stop bit

UCSR1C = (1<<USBS1)|(3<<UCSZ10);

// Enable receiver and transmitter

UCSR1B = (1<<RXEN1)|(1<<TXEN1);
}
void usart_send_string(char * str) {
while (*str) { // keep going until NULL terminator found
usart_send_char(*str++);
}
}

void usart_send_char(uint8_t byte) {
while ((UCSR1A & (1 << UDRE1)) == 0);
UDR1 = byte;
}

int main()
{

USART_vInit();

while(1)
{

output[0] = 2;
output[1] = 4;
output[2] = 6;
output[3] = 8;
output[4] = 10;
output[5] = 12;
output[6] = 14;
output[7] = 16;
usart_send_string(output);
}
}

Receiver side:

char input[9];
void USART_vReceiveByte()
{
int temp = 0;
while (UDR1 != '\0')
{
// Wait until a byte has been received
while((UCSR1A&(1<<RXC1)) == 0) ;
// Return received data
input[temp] =UDR1;
temp ++;
}
return 1;
}
void USART_vInit(void)
{
// Set baud rate
UBRR1H = (uint8_t)(USART_UBBR_VALUE>>8);
UBRR1L = (uint8_t)USART_UBBR_VALUE;
// Set frame format to 8 data bits, no parity, 2 stop bit
UCSR1C = (1<<USBS1)|(3<<UCSZ10);
// Enable receiver and transmitter
UCSR1B = (1<<RXEN1)|(1<<TXEN1);
}

int main(void)
{
DDRB = 0xFF; // port B output
PORTB = 0x00;

// Initialise USART

USART_vInit();

for(;;)
{

USART_vReceiveByte();
PORTB = input[0];
}
}

Using AVRstudio with Gcc and JTAG MKII
Please help :)
/Internetwarrior!

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

hi ABCminiuser,

thumbs up for tutorial!

waiting for your advanced serial comm!!!!!

thank you!

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

Hi

The tutorial above looks very helpful and I am going to attempt it soon. I am a freshbie to USART and I am using ATMEGA8 to establish a 9-bit serial protocol. I am supposed to use UART for my project. What I am confused about is UART being asynchronous, i understand we have to set BAUD rate, 9600bps in my case, do i still need to use a 7372800Hz system clock? Any suggestions? will be of great help thanks very much.

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

Quote:
do i still need to use a 7372800Hz system clock?

It does not need to be that particular value, but you should have something stable for a system clock, and it also needs to be a value that the AVR can use to generate the desired baud rate to within 2%.

Regards,
Steve A.

The Board helps those that help themselves.

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

Hi,

I m doing serial communication from pc to microcontroller.
When i used ATmega16,8 MHz and 1200 Baud Rate it worked perfectly.

When i switched to ATmega32 and 16 MHz ,it is not working with 1200,9600 etc. baud rates.

Any guesses as to why its happening??

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

Furthermore, I did not change the code when i shifted from AVR32 to AVR16 as all the bits positions are same in 16 and 32...Only change that i made was in the baud rate and the clock frequency.
Help please....

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

Are you sure that the AVR is running at 16MHz?

Regards,
Steve A.

The Board helps those that help themselves.

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

im using an external 16MHz crystal oscillator and i believe they are pretty accurate

i cant change the crystal oscillator as i have to make it work with this configuration only

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

Quote:

im using an external 16MHz crystal oscillator and i believe they are pretty accurate

You may have ATTACHED a 16MHz crystal but have you ENABLED it? (that is have you changed CKSEL?)

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

From the day i bought it, i didn't change the fuse bits.
Isn't the default setting corresponds to clock being taken from the external crystal oscillator??

If not, please tell me where are the CKSEL bits located??

I have seen the value of CKSEL required to select the oscillator from the datasheet but where are they located???

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

Quote:

Isn't the default setting corresponds to clock being taken from the external crystal oscillator??

What leads you to believe that? It was true of the very first AVRs but the mega16 runs at 1MHz by default from an internal RC osciallator (actually 900KHz .. 1.1MHz)

The CKSEL bits are in the low fuse byte. If it's 16MHz you are trying to use you'll also need to set CKOPT which is in the high fuse byte.

Be VERY careful when using your ISP to change the fuses as you may find it difficult to contact the AVR again if you get the setting wrong. So always read, modify, write and only change the bits you KNOW must be changed.

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

as you said i should be careful before setting the fuse bits, so i thought it would be better if i first confirm the settings.

i will be doing this for an atmega32 to get its clock from an external 16 MHz oscillator.

CKSEL3..0
1111

CKOPT
1

so my low fuse byte will become XXXX1111.
As CKOPT is already 1 so i dont have to touch the high fuse byte.

is this all correct??
and what is efuse??

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

The CKSEL look right but you should be changing CKOPT from 1 (not enabled) to 0 (enabled).

IOW low=0xEF high=0x89

(mega16 doesn't have efuse does it?)

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

do i have to change the CKOPT bit even for ATmega32??

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

The CKOPT fuse determines whether the Xtal oscillator circuit is driven "full swing" or not. If you read the datasheet for the 32 you'll see it's suggested that you must use this for all Xtal frequencies above 8MHz

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

the usart started wrking on my atmega32....thanx a lot.
this forum is one of the best i have ever been to.

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

ravikiran wrote:
hey which software do you use to recieve the data on the comp...hmm and ya UCSRC and UBRR hav the same memory addr..the first bit wil decide which one is to be written ...i tried simulating it in avr studio..its not working ...any suggestions...??

hey try setting the baud rate before rest of the code coz , since UBRRH and UCSRC share same addres wth a selection bit URSEL so in Dean's code the UCSRC is selected in the whole code cos URSEL is always set as 1.

cheers

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

Hi,

thanks for the tut.

What are the similar commands for the 1280? Where can i find those?

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

Just look at the register descriptions in the datasheet. The biggest (and possibly the only) change will be the addition of a number in the register name (e.g. UCSR0B instead of UCSRB).

Regards,
Steve A.

The Board helps those that help themselves.

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

[NOTE: I originally posted this in AVR-GCC, but then browsing the tutorials found this thread and thought it significantly more relevant. Apologies for the double post]

Hello,

I have been following the sparkfun "Beginning Embedded Electronics" as well as this thread tutorial and have overall been successful. I can read adn write bytes at a time and have no problem receiving/sending from the terminal. Unfortunately, when I output a chunk of data from the AVR rapidly (say 10 bytes) the code continually finds something to read and loops even though I do not send it any data. If however, I place a delay in the putchar function of "5ms" (according to the code - completely uncalibrated obviously) the code works as advertised.

It seems like something is getting out of sync and my send is clobbering my receive.

The question: what is going on and how do I get things to work properly with out the artificial delay?

I am a software engineer by trade trying to learn about microprocessors, so the hardware side is all new to me (read: ripe for newbie errors). Thinking this might have had something to do with buffered IO (i.e. stdio.h) I rewrote printf, etc, but I got the same exact behavior. It seems that when I output a certain amount of data quickly the chip seems to set the flag that there is data available. When I print out the UCSR0A, I see that the DOR0 bit is set. May be relevant?

Anyway, I reverted back to the sparkfun code in order to keep things simple for debugging. For reference, here is the tutorial:

http://www.sparkfun.com/commerce/tutorial_info.php?tutorials_id=105

and here is the link to the tutorial code (my code is below)

http://www.sparkfun.com/tutorial/BeginningEmbedded/5-Compiling/basic-in-atmega168.zip

I am using:
avr-gcc 4.0.2
atmega168
16 Mhz crystal
fuse set correctly ( 0xE6 )
avrdude 5.5
ispmkii programmer
USB BUB for usb->serial communication (also tried a FTDI cable)
Mac OSX with zterm and screen (tried both)
9600 Baud (in code and terminal)

Anything else that would be useful to know?

Here is the code:

/*
    5-10-07
    Copyright Spark Fun Electronics© 2007
    Nathan Seidle
    nathan at sparkfun.com
   
    Example basic printf input/output
*/

#include 
#include 

#define FOSC 16000000
#define BAUD 9600
#define MYUBRR FOSC/16/BAUD-1

#define sbi(var, mask)   ((var) |= (uint8_t)(1 << mask))
#define cbi(var, mask)   ((var) &= (uint8_t)~(1 << mask))

#define STATUS_LED 0

//Define functions
//======================
void ioinit(void);      // initializes IO
static int uart_putchar(char c, FILE *stream);
uint8_t uart_getchar(void);

static FILE mystdout = FDEV_SETUP_STREAM(uart_putchar, NULL, _FDEV_SETUP_WRITE);

void delay_ms(uint16_t x); // general purpose delay
//======================

int main (void)
{
   uint8_t key_press;
   
    ioinit(); //Setup IO pins and defaults

   printf("Waiting for input:\n");

    while(1)
    {
      key_press = uart_getchar();
      
                // [percent] in lieu of the symbol for posting
      printf("I heard : [percent]c\n", key_press);
      
      if(key_press == 'g') printf("  GO!\n");
      if(key_press == 'X') printf("  EXIT\n");
      if(key_press == 13) printf("  RETURN\n");
    }
   
    return(0);
}

void ioinit (void)
{
    //1 = output, 0 = input
  DDRB = 0xEF; //0b11101111; //PB4 = MISO
  DDRC = 0xFF; // 0b11111111; //
  DDRD = 0xFE; // 0b11111110; //PORTD (RX on PD0)

    //USART Baud rate: 9600
    UBRR0H = MYUBRR >> 8;
    UBRR0L = MYUBRR;
    UCSR0B = (1<<RXEN0)|(1<<TXEN0);
   
    stdout = &mystdout; //Required for printf init
}

static int uart_putchar(char c, FILE *stream)
{
    if (c == '\n') uart_putchar('\r', stream);

    // NOTE: This the the delay that makes everything 'work'
    delay_ms(5);
 
    loop_until_bit_is_set(UCSR0A, UDRE0);
    UDR0 = c;
   
    return 0;
}

uint8_t uart_getchar(void)
{
    while( !(UCSR0A & (1<<RXC0)) );
    return(UDR0);
}

//General short delays
void delay_ms(uint16_t x)
{
  uint8_t y, z;
  for ( ; x > 0 ; x--){
    for ( y = 0 ; y < 80 ; y++){
      for ( z = 0 ; z < 40 ; z++){
        asm volatile ("nop");
      }
    }
  }
}

Thanks for any pointers or help!

-stephen

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

Quote:
Thanks for any pointers or help!

Here's a pointer: Don't cross post. This question is already being discussed in the GCC forum.

Regards,
Steve A.

The Board helps those that help themselves.

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

Getting following error:
avrdude -p atmega8 -P com1 -c ponyser -U flash:w:try.hex

avrdude: AVR device not responding
avrdude: initialization failed, rc=-1
Double check connections and try again, or use -F to override
this check.

avrdude done. Thank you.

make: *** [program] Error 1

plz help. thanks..

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

I am guy frm nepal we dont get avr in nepal but i have learnt avr through datasheet and net and i do simulation in prospice I have no idea about SPI in usart mode

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

Hi Dean,

Just wanted to say a big thank you for yet another great tutorial!
It would've probably taken be a while to figure out that i need to calibrate the internal RC oscillator before using it with the USART.

Andrei

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

Hi Everybody!
I am new user of this forum and new user of AVR products.
I want to use the ADC of ATmega168 with a sample frequency equal to 1000Hz and then establish a serial communication (just the transmission).Is the prescaler equal to the sample frequency?
Please I need your help.
Thanks

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

Quote:

Is the prescaler equal to the sample frequency?

Nope. The prescaler sets the ADC clock rate and the datasheet suggests that whatever your F_CPU you should pick a prescale value to get this into the 50kHz to 200kHz range (sometimes lowering F_CPU can actually allow you to get closer to 200kHz by being able to use the next step of prescaler). The datasheet also tells you that the very first conversion will take 26 ADC clocks and all subsequent ones will take 13 clocks. So in general, whatever 50kHz..200kHz clock you are able to configure it for your ADC conversion rate will be 1/13th of this: 3.85kHz .. 15.38kHz. If you only need a conversion every 1ms then you'll easily be able to achieve this and have loads of time for other stuff between conversions.

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

Thanks clawson for your explanation. I should use a timer but I do not really know how to start this program. Thanks

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

Hi!
May I ask a question please? chosen 1000Hz for the sample rate and crystal of 20 MHz, can I use BAUD = 2400 so that I will 0% error?
How can I know and choose the best BAUD for my application?
Thank you

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

I am using ATmega168. Can I use 20 MHz crystal without problem?
Thanks

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

Quote:

crystal of 20 MHz, can I use BAUD = 2400 so that I will 0% error?

Datasheet says that with a UBRR of 520 you will get 0.0% error on 20MHz for 2400 baud.

In fact on all the common baud rates up to 115200 no error is any greater than abs(1.7%) for 76800 baud - so you can use any baud rate you like from the normal selection.

Cliff

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

Good morning,
I want to send via serial transmission the value of the ADC registers. I mean I want to send 10 bits data while the transmission is 8 bits data?The value I should get on the computer have to be my 10bits value.
How am i going to do? Or I do not understand the role of the BAUD?
I need help please. Thanks

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

To send 10 bits (which really means sending 16 bits because everything happens in chunks of 8) you have two options:

1) One would just be to load UDR with ADCH and ADCL separately but this will send the reading in binary form. If the "other end" is another compter then this may be the most efficient way to send the data as it only involves the transmission of 2 bytes whatever the reading.

2) the other would be to use the AVR to first convert the 10 bit reading to a human readable string of digits between "0000" (maybe just "0") and "1023". Then send each digit in turn. This is usually the preferred method if the receiver is a human being and wants to see something they can understand. It could, however, (for readings up to 1023) involve sending as many as four bytes per reading (the number of digits in "1023"). On the other hand a reading of "7" would only require 1 byte to be sent.

As for "baud" - that's just a measure of tranmission speed in bits transmitted per second. All you have to agree is that both ends of the link are agreed about which baud rate is being used and they both try to set their UARTs to work as close to the chosen speed as possible. By tradition the speeds usually chosen are a multiple of 300.

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

Thanks clawson.How dos I use the AVR to convert the 10 bits reading? is this code correct:

int v_num;
v_num = ADC ;//read ADC after conversion

will the value of v_num be between 0 and 1023?

if i want to use the 1st option, can I write:
while (!(UCSR0A & (1<<UDRE0)));
UDR0 = ADCH;
while (!(UCSR0A & (1<<UDRE0)));
UDR0 = ADCL;
while (!(UCSR0A & (1<<UDRE0)));
UDR0 = '\n';

or should I store ADCH and ADCL first, like this:
int v_num1, v_num2;
v_num1 = ADCH ;//read ADC after conversion
v_num2 = ADCL ;//read ADC after conversion

before starting the transmission.

Thank you

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

hi all

i debugged USART register via simulator which integrated AVRstudio.I fould the strange of register like that. i dont know why.

void USART_Init(int port, unsigned int baudrate )
{	
	unsigned int ubrr ;
	ubrr=F_CPU/16/baudrate-1;
	//ubrr=51 with baudrate=19200
	/* Set baud rate */
		UBRR0H = (unsigned char)(ubrr>>8);  
        //UBRR0H=0;
		UBRR0L = (unsigned char)ubrr;
        //UBRR0L=0x33 (51)
	/* Enable receiver and transmitter */
		UCSR0B = (1<<RXEN)|(1<<TXEN);  
	/* Set frame format: 8data, 2stop bit */
		UCSR0C = (0<<USBS)|(3<<UCSZ0);
        /*After above command, UBRR0H is changed,
        UBRR0H=0x06=>ubrr is wrong, but load this 
        code to MCU, it works good. So, why is 
        UBRR0H changed after setup UCSR0C ?
         */
}
when i start debug, UCSR0C=0x06 (i think,it must be UCSROC =0x00 when start debugging
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Which AVR? - some share UBRRH and the C register

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

Look for the URSEL bit in your AVR's datasheet - it should explain your device's odd behaviour.

- Dean :twisted:

Make Atmel Studio better with my free extensions. Open source and feedback welcome!

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

I used atmega128. i searched URSEL bit in datasheet. but, i cant find out it. You mentioned UMSEL in UCSR0C register, didn't you?

  UCSR0C = (0<<USBS)|(3<<UCSZ0); 
        /*After above command, UBRR0H is changed,
        UBRR0H=0x06=>ubrr is wrong, but load this
        code to MCU, it works good. So, why is
        UBRR0H changed after setup UCSR0C ?
         */ 

i thought this problem relate "double speed in asynchronous mode". i calculated like that:
Fosc=16MHz, baud rate 19200, so that
UBRR=0x33 (51) with U2X0=0 and UBRR=103 (<8bit ==>UBRR0H=0 with U2X0=1)//197th page in datasheet
in fact, UBRR0H=0x06, UBRR0L=0X33 after setup UCSR0C

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

Quote:
I used atmega128. i searched URSEL bit in datasheet. but, i cant find out it.

The mega128 doesn't have that bit (UBRR0H and UCSR0C have separate addresses on that model). I would not pay any attention to the values in these registers in the simulator. The value that you set them to is the value that they will have in the actual AVR.

Regards,
Steve A.

The Board helps those that help themselves.

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

From the simulator user manual:

Quote:
Notes for ATmega128
This device is supported by AVR Simulator 2, and we recommend using that to avoid the issues listed below.

When writing to UCSRnC, the value will be copied to UBRRnH unless bit 7 is set. This behaviour should not happen on devices that have separate locations for these registers. A workaround is to write UBRRnH after UCSRnC.


this seems to suggest you were using simulator V1 - but like Steve says - don't put too much faith in simulators - half the time you'll be chasing simulation errors rather than real code errors.

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

NULL

Last Edited: Thu. Sep 10, 2009 - 09:15 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

sscanf() with a % X perhaps?

(but it may be easier to write your own atol() equivalent that can handle base-16)

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

@Dixit. please do not cross post. This question was already answered in the main AVR forum.

Regards,
Steve A.

The Board helps those that help themselves.

Pages

Topic locked