4.2.4 RS-485 Serial Communication Sample Program

The following sample program illustrates the use of the RS-485 serial drivers. The sample program shows a byte being transmitted, and then the RS-485 transceiver waits for a reply.

#define DINBUFSIZE 15 #define DOUTBUFSIZE 15

void main( void ){ int nEcho,nReply; char cChar;

Jr485Init ();// Init RS485 Control (PD5) serDopen ( 9600 );// Open Serial Port D for (;;) {// Forever

for (cChar='a';cChar<='z';++cChar){

//Send Alphabet

Jr485Tx ();// Enable RS485 Transmitter serDputc ( cChar );// Send Byte while ((nEcho = serDgetc ()) == -1);

//Wait for Echo

Jr485Rx ();// Disable RS485 Transmitter while ((nReply = serDgetc ()) == -1); // Wait for Reply

printf ( "%02x -> %02x\n",nEcho,nReply );

}

}

}

NOTE: If your version of Dynamic C is earlier than 6.55, see Technical Note 117, Jack- rabbit (BL1800 Series) RS-485 Bulletin, for information on restrictions on using both DA1 and RS-485 at the same time.

User’s Manual

47

Page 51
Image 51
Digi BL1800 user manual 4 RS-485 Serial Communication Sample Program