devilfrmheaven
Joined: 09 Feb 2016 Posts: 53
|
RS485.C - Send Message Question |
Posted: Sat Jun 04, 2016 11:49 pm |
|
|
Hi All,
First of all I am sorry I got to ask such a silly question. But can anybody help me understand the following code? I have extracted it from the RS485.c driver file.
I am not so strong in C hence I am not sure if I drew the right picture in my mind about this code.
I would like to implement the same code for my PC which would be sending the messages as Master.
Code: |
int1 rs485_send_message(int8 to, int8 len, int8* data) {
int8 try, i, cs;
int1 ret = FALSE;
RCV_OFF();
#if RS485_USE_EXT_INT
disable_interrupts(GLOBAL);
#endif
for(try=0; try<5; ++try) { //tries to send the message, retries 5 times if collision detected.
rs485_collision = 0;
fputc((int16)0x100|rs485_id, RS485_CD);
fputc((int16)0x100|to, RS485_CD);
fputc(len, RS485_CD);
for(i=0, cs=rs485_id^to^len; i<len; ++i) { //please help me understand the logic please
cs ^= *data; //Please help me understand the logic please.
fputc(*data, RS485_CD);
++data;
}
fputc(cs, RS485_CD);
if(!rs485_collision) {
ret = TRUE;
break;
}
delay_ms(RS485_ID);
}
|
Thanks in Advance. _________________ Regards,
Devil |
|