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.
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...