go_away

Author Topic: [SOLVED] Sending integers through UART  (Read 2214 times)

0 Members and 1 Guest are viewing this topic.

Offline mstachoTopic starter

  • Supreme Robot
  • *****
  • Posts: 375
  • Helpful? 10
[SOLVED] Sending integers through UART
« on: July 07, 2011, 08:19:26 AM »
Hi all,

I need to set up a connection between the Axon and my PC that sends integers, not just Bytes (or...chars, as C would call them?)  Is there any particularly easy way to do this without breaking the integer into several Bytes and reconstructing the integer at the PC?

MIKE
« Last Edit: July 13, 2011, 07:43:28 AM by mstacho »
Current project: tactile sensing systems for multifingered robot hands

Offline waltr

  • Supreme Robot
  • *****
  • Posts: 1,944
  • Helpful? 98
Re: Sending integers through UART
« Reply #1 on: July 07, 2011, 10:25:57 AM »
No, the UART only sends 8 bits at a time.

Now the way to do this is to create a char array (or buffer) and fill the array with the bytes for the integer. Then pass a pointer and count to a function that sends the array out the UART.
This does require breaking the integer into bytes and then reconstructing at the PC. But you only need to write these two functions once.

Offline mstachoTopic starter

  • Supreme Robot
  • *****
  • Posts: 375
  • Helpful? 10
Re: Sending integers through UART
« Reply #2 on: July 07, 2011, 10:47:53 AM »
Hm...that's unfortunate.  Alrighty, I guess it's time to start writing those functions :-P

Thanks
Current project: tactile sensing systems for multifingered robot hands

Offline mstachoTopic starter

  • Supreme Robot
  • *****
  • Posts: 375
  • Helpful? 10
Sending integers through UART
« Reply #3 on: July 13, 2011, 07:43:00 AM »
For the curious, here's my solution to this problem (that requires quite a bit of computational overhead on the PC side):

Instead of worrying about sending Bytes and putting the integer back together (which would be faster, but would cause issues if I ever wanted to send something that isn't an int anyway), I just used rprintf attached to the UART, and sent the values as a string.  On the PC side, I just parsed the string -- I used C#, which has a really nice function to do this, but string parsing is a first year programming exercise anyway.

Keep in mind that if you're trying to communicate between two uC's, this is probably not an optimal solution, but it works :-P

MIKE
Current project: tactile sensing systems for multifingered robot hands

 


Get Your Ad Here

data_list