CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

receiving 32 bit integer through RS232

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
sk
Guest







receiving 32 bit integer through RS232
PostPosted: Tue Feb 08, 2005 6:25 pm     Reply with quote

Hi everyone,
I would like to know, is there any way to receive 32bit integers through RS232. I used printf to send the 32 bit integer in hexadecimal format. When I tried to use scanf to receive the 32bit integer, the compiler shows error"UNDEFINED IDENTIFIER SCANF". I could not find the scanf statement in the reference manual also. Is there anyway to receive it.
Thanks for any help
sk
John P



Joined: 17 Sep 2003
Posts: 331

View user's profile Send private message

PostPosted: Tue Feb 08, 2005 8:48 pm     Reply with quote

In my humble opinion, you'd do better to break the integer up into 4 bytes and send it that way. It'll send faster, and be much easier to reconstuct the quantity in the processor.
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Tue Feb 08, 2005 9:45 pm     Reply with quote

For the most part, RS232 is an 8-bit kinda thing unless you start bit banging by hand.

4 bytes is the way to go.

-Ben
Charlie U



Joined: 09 Sep 2003
Posts: 183
Location: Somewhere under water in the Great Lakes

View user's profile Send private message

PostPosted: Tue Feb 08, 2005 10:06 pm     Reply with quote

When you send the int32 with printf, it is sent as 8 ascii characters. These should be received at the other end in a buffer. These characters could then be copied to a string where the first 2 characters are '0', 'x', followed by the 8 ascii characters of the int32, and terminated with a 0 (null or zero). Next, use atoi32() to convert the string to an int32.
jds-pic



Joined: 17 Sep 2003
Posts: 205

View user's profile Send private message

PostPosted: Wed Feb 09, 2005 10:22 am     Reply with quote

as you've already figured out, you can't send a 32bit value directly -- the value has to be parsed into 8 bit chunks suitable for transmission over RS232. let me give you an analogy... suppose you needed to send an extremely large crate via Fed Ex -- but the 747's that Fed Ex uses can only take a crate of such and such a size, which is smaller than your huge crate. so you need to break your big crate into several pieces that do fit on the 747, transport them via multiple Fed Ex planes, and then reassemble them on the other side once all the planes are in.

algorithmically in pseudo-code, the sender end could look like

Code:

int32 someval
int8 i, temp
someval=MEASUREMENT_32BIT
printf("send 32bit value=%d\n\r",someval)
for i = 0 to 3, i++ {
temp=int(someval>>(8*i))  // send LSB first
fprintf(stream_RS232,temp)
}

on the receiving end, you invert the process and rebuild the int32
int32 someval=0
int8 i, temp
for i = 3 to 0, i-- {
getchar(temp)
someval=(someval<<(8*i) & temp)
}
printf("recd 32bit value=%d\n\r",someval)


jds-pic
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group