Allows RS485 communication using MAX485 chip

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
NeoBelerophon
Date:
Fri Nov 13 11:08:15 2015 +0000
Child:
1:916e1dd538ce
Commit message:
initial version of a RS485 library for MAX485

Changed in this revision

RS485.cpp Show annotated file Show diff for this revision Revisions of this file
RS485.h Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RS485.cpp	Fri Nov 13 11:08:15 2015 +0000
@@ -0,0 +1,17 @@
+#include "RS485.h"
+
+RS485::RS485(PinName tx, PinName rx, PinName mode, const char *name) : Serial( tx, rx, name), m_modePin(mode)
+{   
+}
+
+int RS485::_getc() { 
+    return _base_getc();
+}
+
+int RS485::_putc(int c) {
+    m_modePin = 1;
+    int ret = _base_putc(c);
+    m_modePin = 0;
+    return ret;
+}
+   
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RS485.h	Fri Nov 13 11:08:15 2015 +0000
@@ -0,0 +1,23 @@
+#include <mbed.h>
+class RS485 : public Serial
+{
+public:
+    /** Create a RS485 Serial port using MAX485, connected to the specified transmit and receive pins
+     *
+     *  @param tx Transmit pin
+     *  @param rx Receive pin
+     *  @param mode Rx TX Mode pin
+     *
+     *  @note
+     *    Either tx or rx may be specified as NC if unused
+     */
+    RS485(PinName tx, PinName rx, PinName mode, const char *name=NULL);
+    
+protected:    
+    virtual int _putc(int c);
+    virtual int _getc();
+
+private:
+    DigitalOut m_modePin;
+         
+};
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Nov 13 11:08:15 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/34e6b704fe68
\ No newline at end of file