Saturday, January 7, 2012

How I re-Invented the wheel with RS485

For the communication part between the PICs, I unknowingly re-invented the wheel with RS-485, which I realised after reading the application AN774 page 8 fig7 "TYPICAL RS-485 FOUR-WIRE CONNECTION" from Microchip in May 2011.  Between November 2010 and May 2011,  in my terms/flavour for the communication setup I would have one device which would be the master and the remaining devices as slaves.  The master in a round robin would query each slave one by one.  The slave would only send back its data if the master was addressing it.  That meant each device would have a unique ID.  In my implementation the master or slaves would send frames of 32 bytes or 256bits length.  Each frame would start with the string ABCXYZ and end with the string ZYXCBA, the remaining 20 bytes in between would contain destination field by device ID, originating device ID field and the rest would be dedicated to 5 data fields.  The ABCXYZ and ZYXCBA strings is placed to ensure that the PIC do not mix the data frames.  The communication module uses the TIMER0 interrupt to prevent the PIC from hanging and detecting timeouts for data transmissions.

The code which I wrote before coming across the RS485 is the same that is working today, I just had to add 4 lines to enable the MAX485 OE pin during receiving mode for the master.

No comments:

Post a Comment