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.

Dependencies:   mbed

Revision:
3:29454cac7930
Parent:
1:7091401482c5
Child:
5:e00f46d18514
diff -r c99c596be3d1 -r 29454cac7930 dlms_comms.cpp
--- a/dlms_comms.cpp	Tue Nov 11 16:16:34 2014 +0000
+++ b/dlms_comms.cpp	Tue Nov 11 16:39:29 2014 +0000
@@ -25,9 +25,9 @@
 
 //    // attach the receiver input to 'run' a method
 //    // when characters received
-//    rs485.attach(this,
-//                 &dlms_comms::Rx_interrupt,
-//                 RawSerial::RxIrq);
+    rs485.attach(this,
+                 &dlms_comms::Rx_interrupt,
+                 RawSerial::RxIrq);
     // transmit empty flag .. need to set buffer
     // in receive mode again after we have transmitted
     // all data characters
@@ -36,6 +36,8 @@
 //                 RawSerial::TxIrq);
     timer = NULL;
     debug_uart = NULL;
+    tx_irq_count = 0l;
+    rx_irq_count = 0l;
 }
 /** ---------------------------------------------------------------------------
  * @brief bq34z110::init_port_expander Put all ports in INPUT mode
@@ -67,7 +69,8 @@
 {
     // default comms parameters
     SerialBase::Parity my_parity = SerialBase::None;
-    irq_count = 0;
+    tx_irq_count = 0l;
+    rx_irq_count = 0l;
     // set the class baudrate
     rs485.baud(baudrate);
     // enable the receiver on the tranceiver buffer chip
@@ -114,7 +117,7 @@
  */
 void dlms_comms::Tx_interrupt(void)
 {
-    irq_count++;
+    tx_irq_count++;
     // enable the receiver, we are finito with the transmission of characters
     // this changes the direction on the transceiver buffer
     if (dir_485 == 1)
@@ -128,6 +131,7 @@
 void dlms_comms::Rx_interrupt(void)
 {
     UINT_8 value;
+    rx_irq_count++;
     // read the uart and place character in ring buffer
     value = rs485.getc();
     rx_buffer[rx_head_ptr++] = value;
@@ -181,9 +185,13 @@
         rs485.putc (*tmp_ptr++);
     }
 }
-UINT_64 dlms_comms::ret_irq_count (void)
+UINT_64 dlms_comms::ret_rx_irq_count (void)
 {
-    return irq_count;
+    return rx_irq_count;
+}
+UINT_64 dlms_comms::ret_tx_irq_count (void)
+{
+    return tx_irq_count;
 }
 bool dlms_comms::poll_rs485(void)
 {