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.
dlms_comms.h
- Committer:
- creatron
- Date:
- 2014-11-11
- Revision:
- 7:cfe1e0eafb7e
- Parent:
- 6:70460dcbc43c
File content as of revision 7:cfe1e0eafb7e:
#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); UINT_64 ret_tx_irq_count (void); UINT_64 ret_rx_irq_count (void); bool ret_dir_485 (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_8 rx_tail_ptr; volatile UINT_64 tx_irq_count; volatile UINT_64 rx_irq_count; }; #endif