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.
Dependencies: mbed
Diff: COMM-RxTx.cpp
- Revision:
- 3:d63922c90649
diff -r eeab69a684ad -r d63922c90649 COMM-RxTx.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/COMM-RxTx.cpp Tue May 03 12:39:29 2022 +0000
@@ -0,0 +1,45 @@
+#include "mbed.h"
+
+DigitalOut led(LED1);
+DigitalOut Din(PB_9);
+Serial pc(USBTX, USBRX, 9600); // seriale di comunicazione con il PC. Associati a PA_11 e PA_12
+
+// carattere in arrivo dal PC
+volatile unsigned char cReadChar;
+
+
+void RxInterrupt(void)
+{
+ // ricevi caratteri su seriale, se disponibili
+ while((pc.readable()))
+ {
+ // leggi carattere e riscrivi carattere su UART
+ cReadChar = pc.getc();
+ pc.printf("\r\nRx [CHAR]: %c\n\r",cReadChar);
+ pc.printf("Rx [HEX]: %#x\n\r", cReadChar);
+ pc.printf("Rx [reverse BIN]: ");
+ for(int i = 0; i< 8; i++)
+ pc.printf("%d",((cReadChar>>i)&0x01));
+ pc.printf("\n\r");
+
+
+ }
+}
+
+//+++++++++
+// MAIN
+//+++++++++
+int main()
+{
+ pc.printf("\n\r*** Welcome TxRx ***\n\r");
+
+ // definisci callback di IRQ
+ pc.attach(&RxInterrupt,Serial::RxIrq);
+
+ // ciclo main
+ while(true)
+ {
+ led = !led; // Toggle LED
+ wait_ms(500);
+ }
+}
\ No newline at end of file