question to store data from USART to an array.

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

:?:
hi all,
i'm now working on USART with my ATMEGA32L.
For now i have a VB program and when i click the button it will send a few data such as my servo position and my timer value.

So i would like to say to store the data as an array, am i right?(this is the first doubt).thank you.

 data[]=2;
      
      while ((UCSRA & (1 << RXC)) == 0) {}; 
      for(i=0; i<2; i++)
      {
         data[0] = UDR;
      }
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Check the UCSRA for each character.

Whether you want to store the data in an array or not will depend on what you want to do with it.

And what is this?

data[]=2;

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
         data[0] = UDR;

And this will overwrite the same byte every time. Don't you want:

         data[i] = UDR; 

Regards,
Steve A.

The Board helps those that help themselves.

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

zbaird wrote:
Check the UCSRA for each character.

Whether you want to store the data in an array or not will depend on what you want to do with it.

And what is this?

data[]=2;

oopss..silly mistake.

int data[2];

this line is to initialize my array size.

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

So, what are you going to do with the data?

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