String transmission/Reception

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

String transmission/Reception

887 次查看
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.

标签 (1)
0 项奖励
回复
1 回复

751 次查看
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 项奖励
回复