Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of RS485Test by
Diff: main.cpp
- Revision:
- 0:0db8165396ae
- Child:
- 1:0e3453d2d0cc
diff -r 000000000000 -r 0db8165396ae main.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Mon Nov 05 12:27:11 2012 +0000
@@ -0,0 +1,50 @@
+/*
+ * SOURCE FILE : main.cpp
+ *
+ * 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.
+ *
+ */
+
+#include "mbed.h"
+
+/****************/
+/* MAIN PROGRAM */
+/****************/
+int main() {
+ // Digital output connected to on-board LED1.
+ DigitalOut myled(LED1);
+ // Digital output used to enable the 485 transmitter
+ // 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 );
+ // Set baud rate and protocol.
+ pc.baud( 38400 );
+ pc.format( 8, Serial::None, 1 );
+ // Message to send.
+ char message[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n";
+ // Do following until power goes off.
+ while( true ) {
+ // Toggle state of LED.
+ myled = ( myled ? 0 : 1 );
+ // Turn on the transmitter and disable receiver.
+ txEnable = 1;
+ // Transmit a message.
+ char *ptr = message;
+ while( *ptr != 0 ) {
+ if( pc.writeable() ) {
+ pc.putc( *ptr++ );
+ }
+ }
+ // Wait 300 micro seconds to let last byte transmit.
+ wait_us( 300 );
+ // Turn off the transmitter and enable the receiver.
+ txEnable = 0;
+ // Wait 1 second.
+ wait_us( 1000000 );
+ }
+}
