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

dlms_comms.h

Committer:
creatron
Date:
2014-11-11
Revision:
0:044dfba47660
Child:
3:29454cac7930

File content as of revision 0:044dfba47660:

#ifndef DLMS_COMMS_H
#define DLMS_COMMS_H

#include "types.h"

class dlms_comms
{
public:
    dlms_comms                 (void);
    void      initialise       (INT_16         baudrate,     
                                UINT_8         bits,
                                UINT_8         parity,
                                UINT_8         stop_bits); 
public:
    void      send_packet      (const UINT_8 * ptr,
                                const UINT_8   length);
    bool      char_available   (void);
    UINT_8    get_char         (void);
    void      init             (RawSerial    * parent_uart,
                                Timer        * parent_timer);
    bool      get_dir485       (void);
    bool      poll_rs485       (void);
    UINT_64   ret_irq_count    (void);
private:
    void      Rx_interrupt     (void);
    void      Tx_interrupt     (void);
    // parent classes 
    RawSerial * debug_uart;
    Timer     * timer;
    UINT_8      rx_buffer[256];
    UINT_8      rx_head_ptr;
    UINT_64     irq_count;
    UINT_8      rx_tail_ptr;                           
};
#endif