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
Fork of Amaldi_1_Exercise_PC-Comm by
Revision 3:788597ccf179, committed 2018-05-07
- Comitter:
- pinofal
- Date:
- Mon May 07 07:08:30 2018 +0000
- Parent:
- 2:eeab69a684ad
- Commit message:
- Amaldi 1 Exercise
Changed in this revision
| PC-Comm-Polling.cpp | Show annotated file Show diff for this revision Revisions of this file |
| main.cpp | Show diff for this revision Revisions of this file |
diff -r eeab69a684ad -r 788597ccf179 PC-Comm-Polling.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/PC-Comm-Polling.cpp Mon May 07 07:08:30 2018 +0000
@@ -0,0 +1,74 @@
+// Tested: NUCLEO-L476RG
+// Tested: NUCLEO-F207ZG
+#include "mbed.h"
+
+// genera un oggetto serial collegato al PC
+Serial pc(USBTX, USBRX);
+
+// genera un oggetto DigitalOut collegato al Led
+DigitalOut MyLed1(LED1); // verde
+DigitalOut MyLed2(LED2); // blu
+DigitalOut MyLed3(LED3); // rosso
+
+
+// indice per i cicli
+int nIndex;
+
+// carattere ricevuto dal PC
+char cReadChar;
+// carattere inviato al PC
+char cWriteChar;
+
+
+/********/
+/* MAIN */
+/********/
+int main()
+{
+ // configura velocità della comunicazione seriale su USB-VirtualCom e invia messaggio di benvenuto
+ pc.baud(921600); //921600 bps
+
+ // inizializza variabili
+ cReadChar = '\0';
+ MyLed1=0; // spegni il Led1
+ MyLed2=0; // spegni il Led2
+ MyLed3=0; // spegni il Led3
+
+
+ pc.printf("\r\n> Hallo Amaldi Students - Start Exercise 1 \r\n");
+
+/******* INIZIO ESEMPIO CON POLLING ***/
+ // ciclo infinito
+ while(true)
+ {
+ // spegne il Led per 0.5 sec
+ MyLed1 = 0;
+ MyLed2 = 0;
+ MyLed3 = 0;
+ wait_ms(500);
+
+ // verifica se è arrivato un carattere dal PC
+ if(pc.readable())
+ {
+ // cattura il carattere ricevuto
+ cReadChar = pc.getc();
+
+ //accendi il Led per 500ms
+ // Accende il Led solo se invio carattere corretto
+ if(cReadChar == 'p')
+ {
+ MyLed1 = 1;
+ MyLed2 = 1;
+ MyLed3 = 1;
+ wait_ms(500);
+ }
+
+ // restituisci messaggio al PC su carattere ricevuto
+ cWriteChar = cReadChar+1;
+ pc.printf("Rx Char= %c; Tx Char = %c\n\r", cReadChar, cWriteChar);
+ }
+ }
+
+/******* FINE ESEMPIO CON POLLING ***** */
+
+}
\ No newline at end of file
diff -r eeab69a684ad -r 788597ccf179 main.cpp
--- a/main.cpp Tue Jan 23 10:14:58 2018 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,57 +0,0 @@
-#include "mbed.h"
-
-// dimensione del pacchetto di comunicazione tra PC e uC
-#define PACKETDIM 33
-
-DigitalOut led(LED1);
-Serial pc(SERIAL_TX, SERIAL_RX);
-
-// indice per i cicli
-int nIndex;
-
-// indice dell'array caRxPacket[]
-volatile int nRxIndex;
-// carattere in arrivo dal PC
-volatile char caReadChar;
-
-// paccchetto ricevuto dal PC
-char caRxPacket[PACKETDIM];
-int nRxPacketSize;
-
-void RxInterrupt(void)
-{
- // reset pacchetto ricevuto
- nIndex=0;
- for(nIndex=0;nIndex<PACKETDIM;nIndex++)
- {
- caRxPacket[nIndex]='\0';
- }
-
- // ricevi caratteri su seriale, se disponibili
- while((pc.readable()))
- {
- pc.gets(caRxPacket,sizeof(caRxPacket));
- nRxPacketSize = strlen(caRxPacket);
- //pc.printf("*** pc.readable = %2d \n\r",nRxPacketSize);
- //pc.scanf("%s", &caRxPacket);
- //+++pc.putc(pc.getc()); // read data from UART
-
- }
- //+++pc.printf("%s",caRxPacket);
- pc.printf("You also say goodbye to yours tk");
-}
-
-int main()
-{
- // configura velocità della comunicazione seriale su USB-VirtualCom e invia messaggio di benvenuto
- //pc.baud(921600); //921600 bps
- pc.baud(256000); //9600 bps
- //pc.printf("*** SineWave Generation ***\n\r");
-
- pc.attach(&RxInterrupt,Serial::RxIrq);
-
- while(true)
- {
- led = !led; // Toggle LED
- }
-}
\ No newline at end of file
