incorrect 2nd data from usart.

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

hi all,
i'm facing problem in getting incorrect data from my usart.

my pc is sending one hex value and one dec value when i press a button. To check is it the correct data has been received, i output the value to my atmega32L PORTB.
eg: PC sending 0x32 and 90(dec).
when i check on the PORTB the value display out for 0x32 is correct but for 90(dec) which is 0101 1010(binary)i get this------> 0010 1101 .

sent: ->0101 1010
received:->0010 1101
--------->00101 101
It seems like shifted to the left once. i try to send other decimal value to confirm this situation i get the same result.it seems like shifted.

Below is my coding.


for(int i=0; i<2; i++)
{
     while ((UCSRA & (1 << RXC)) == 0) {}; 
     	  
        data[i]=UDR;

	first_data = data[0];
	second_data = data[1];	  

	
        PORTB = second_data;
        _delay_ms(1000);
}   
 

thank you.

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

Do you have the same parity settings both for the PC and the AVR?

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

You already have a very similar thread about this - double posting in this forum will fan the ire of several of the people here.

Notice that you have a for loop which executes twice, but after you grab the first character (in pass 1) you're acting like the second is there also. Surely this isn't what you mean to be doing.

It would help here (and in the other thread) if you would tell us what it is you're trying to accomplish.

Chuck Baird

"I wish I were dumber so I could be more certain about my opinions. It looks fun." -- Scott Adams

http://www.cbaird.org

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

Quote:

You already have a very similar thread about this - double posting in this forum will fan the ire of several of the people here.

As such I'm going to lock this one - continue further discussion in the other thread and don't double/cross post in future:

https://www.avrfreaks.net/index.p...

Cliff

Topic locked