Richard Ellingworth / Mbed 2 deprecated RS485Test

Dependencies:   mbed

Fork of RS485Test by Richard Ellingworth

Files at this revision

API Documentation at this revision

Comitter:
RichardE
Date:
Mon Nov 05 20:57:14 2012 +0000
Parent:
0:0db8165396ae
Commit message:
Transmits message at roughly 1 second intervals and other end receives OK.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Mon Nov 05 12:27:11 2012 +0000
+++ b/main.cpp	Mon Nov 05 20:57:14 2012 +0000
@@ -3,8 +3,9 @@
  *
  * Test program to see if a 485 communications link is working.
  * This is designed to run on the LPC11U24 which only has a single
- * serial port which uses pin 9 for TX and pin 10 for RX. Note that
- * this is the same serial port that transmits over the USB cable to the PC.
+ * serial port. This program uses pin 9 for TX and pin 10 for RX.
+ * There is only one serial port on the LPC11U24 so you cannot use
+ * the USB serial port to the development PC at the same time.
  *
  */
  
@@ -20,13 +21,13 @@
     // and simultaneously disable the received.
     DigitalOut txEnable( p11 );
     txEnable = 0;
-    // Serial port to PC and also to pins 9 and 10.
-    Serial pc( USBTX, USBRX );
+    // Serial port on pins 9 (TX) and 10 (RX).
+    Serial port485( p9, p10 );
     // Set baud rate and protocol.
-    pc.baud( 38400 );
-    pc.format( 8, Serial::None, 1 );
+    port485.baud( 38400 );
+    port485.format( 8, Serial::None, 1 );
     // Message to send.
-    char message[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n";
+    char message[] = " ABCDEFGHIJKLMNOPQRSTUVWXYZ";
     // Do following until power goes off.
     while( true ) {
         // Toggle state of LED.
@@ -36,12 +37,12 @@
         // Transmit a message.
         char *ptr = message;
         while( *ptr != 0 ) {
-            if( pc.writeable() ) {
-                pc.putc( *ptr++ );
+            if( port485.writeable() ) {
+                port485.putc( *ptr++ );
             }
         }
-        // Wait 300 micro seconds to let last byte transmit.
-        wait_us( 300 );
+        // Wait a bit to let last byte transmit.
+        wait_us( 600 );
         // Turn off the transmitter and enable the receiver.
         txEnable = 0;
         // Wait 1 second.