CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

RS485.C - Send Message Question

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
devilfrmheaven



Joined: 09 Feb 2016
Posts: 53

View user's profile Send private message

RS485.C - Send Message Question
PostPosted: Sat Jun 04, 2016 11:49 pm     Reply with quote

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
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jun 05, 2016 7:19 am     Reply with quote

This post explains some of that code.
http://www.ccsinfo.com/forum/viewtopic.php?t=36810&start=3
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group