String transmission/Reception

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

String transmission/Reception

888件の閲覧回数
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 返信

752件の閲覧回数
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 件の賞賛
返信