This is a RS485 class that uses the second UART and was tested on a Nucleo F030R8. A main demo program howto use the class is included. This class control the direction pin on the transceiver buffer automatically, and used transmit and receive interrupts. Ring buffers (256 bytes) are implemented on both transmission and reception. It assumes a ADM3485 'type' buffer where pins 2 ans 3 are connected and seen as direction. This test program could easily be adapted as base for other programs.
Diff: dlms_comms.cpp
- Revision:
- 6:70460dcbc43c
- Parent:
- 5:e00f46d18514
- Child:
- 7:cfe1e0eafb7e
diff -r e00f46d18514 -r 70460dcbc43c dlms_comms.cpp --- a/dlms_comms.cpp Tue Nov 11 17:53:16 2014 +0000 +++ b/dlms_comms.cpp Tue Nov 11 18:17:52 2014 +0000 @@ -34,7 +34,7 @@ // rs485.attach(this, // &dlms_comms::Tx_interrupt, // RawSerial::TxIrq); - timer = NULL; +// timer = NULL; debug_uart = NULL; tx_irq_count = 0l; rx_irq_count = 0l; @@ -103,6 +103,8 @@ # endif // dummy send packet to rs485 //send_packet ("\r\nHello cruel world\r\n",12); + if ( rs485.readable()) + rs485.getc(); } /** --------------------------------------------------------------------------- * @brief dlms_comms::get_dir485 . This method returns the state of the rs485 @@ -193,4 +195,8 @@ { return tx_irq_count; } +bool dlms_comms::ret_dir_485 (void) +{ + return dir_485; +} //----[ the end ]--------------------------------------------------------------