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@3:29454cac7930, 2014-11-11 (annotated)
- Committer:
- creatron
- Date:
- Tue Nov 11 16:39:29 2014 +0000
- Revision:
- 3:29454cac7930
- Parent:
- 0:044dfba47660
- Child:
- 5:e00f46d18514
Commit just before attach re put back
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
creatron | 0:044dfba47660 | 1 | #ifndef DLMS_COMMS_H |
creatron | 0:044dfba47660 | 2 | #define DLMS_COMMS_H |
creatron | 0:044dfba47660 | 3 | |
creatron | 0:044dfba47660 | 4 | #include "types.h" |
creatron | 0:044dfba47660 | 5 | |
creatron | 0:044dfba47660 | 6 | class dlms_comms |
creatron | 0:044dfba47660 | 7 | { |
creatron | 0:044dfba47660 | 8 | public: |
creatron | 0:044dfba47660 | 9 | dlms_comms (void); |
creatron | 0:044dfba47660 | 10 | void initialise (INT_16 baudrate, |
creatron | 0:044dfba47660 | 11 | UINT_8 bits, |
creatron | 0:044dfba47660 | 12 | UINT_8 parity, |
creatron | 0:044dfba47660 | 13 | UINT_8 stop_bits); |
creatron | 0:044dfba47660 | 14 | public: |
creatron | 0:044dfba47660 | 15 | void send_packet (const UINT_8 * ptr, |
creatron | 0:044dfba47660 | 16 | const UINT_8 length); |
creatron | 0:044dfba47660 | 17 | bool char_available (void); |
creatron | 0:044dfba47660 | 18 | UINT_8 get_char (void); |
creatron | 0:044dfba47660 | 19 | void init (RawSerial * parent_uart, |
creatron | 0:044dfba47660 | 20 | Timer * parent_timer); |
creatron | 0:044dfba47660 | 21 | bool get_dir485 (void); |
creatron | 0:044dfba47660 | 22 | bool poll_rs485 (void); |
creatron | 3:29454cac7930 | 23 | UINT_64 ret_tx_irq_count (void); |
creatron | 3:29454cac7930 | 24 | UINT_64 ret_rx_irq_count (void); |
creatron | 0:044dfba47660 | 25 | private: |
creatron | 0:044dfba47660 | 26 | void Rx_interrupt (void); |
creatron | 0:044dfba47660 | 27 | void Tx_interrupt (void); |
creatron | 0:044dfba47660 | 28 | // parent classes |
creatron | 0:044dfba47660 | 29 | RawSerial * debug_uart; |
creatron | 0:044dfba47660 | 30 | Timer * timer; |
creatron | 0:044dfba47660 | 31 | UINT_8 rx_buffer[256]; |
creatron | 0:044dfba47660 | 32 | UINT_8 rx_head_ptr; |
creatron | 0:044dfba47660 | 33 | UINT_8 rx_tail_ptr; |
creatron | 3:29454cac7930 | 34 | |
creatron | 3:29454cac7930 | 35 | UINT_64 tx_irq_count; |
creatron | 3:29454cac7930 | 36 | UINT_64 rx_irq_count; |
creatron | 0:044dfba47660 | 37 | }; |
creatron | 0:044dfba47660 | 38 | #endif |