Society of Robots - Robot Forum

Software => Software => Topic started by: mstacho on July 07, 2011, 08:19:26 AM

Title: [SOLVED] Sending integers through UART
Post by: mstacho 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
Title: Re: Sending integers through UART
Post by: waltr 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.
Title: Re: Sending integers through UART
Post by: mstacho 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
Title: Sending integers through UART
Post by: mstacho 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