String transmission/Reception

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

String transmission/Reception

582 Views
vishaka_maithil
Contributor I

Hi friends,

  I am using 12Xs128 controller for one of my applications. Here,

 I should accept a string serially via RS232 , ultimately the string shall be (string of 8 characters) converted to hexadecimal format and transmitted onto some network. Also, the received string shall be transmitted onto the serial port. Since my string is of 8 characters (in decimal/hex) there will be 32 bits . How can I do this? Any help please...

Thanks in advance.

Labels (1)
0 Kudos
Reply
1 Reply

446 Views
kef
Specialist I

Mmm. Certainly you need some string buffer

 

#define buflen 20

char strbuf[buflen];

 

and string index variable, which is 0 before reception of string. On RX interrupt you read byte from data register, put it to

strbuf[index] and increment the index. Then you check if you received desired number of chars, also if index is stil valid and is lower than buflen.

 

  

Above simple approach would work if you had no noise, connect/disconnect issues etc. For real life app your protocol may need to include handsheaking, start-of-message (re)synchronization, maybe some checksum. You may also need FIFO buffer to let your ISR routine accepting new messages, while you are analysing and processing commands received earlier...

 

0 Kudos
Reply