Seriale Rx/Tx
Dependencies: mbed
Revision 2:eeab69a684ad, committed 2018-01-23
- Comitter:
- pinofal
- Date:
- Tue Jan 23 10:14:58 2018 +0000
- Parent:
- 1:ce08f1d8140c
- Child:
- 3:d63922c90649
- Commit message:
- Serial Protocol PC-uC
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sat Jul 08 05:01:19 2017 +0000
+++ b/main.cpp Tue Jan 23 10:14:58 2018 +0000
@@ -1,36 +1,57 @@
#include "mbed.h"
-/*------------------------------------------------------------------------------
-Before to use this example, ensure that you an hyperterminal installed on your
-computer. More info here: https://developer.mbed.org/handbook/Terminals
+// dimensione del pacchetto di comunicazione tra PC e uC
+#define PACKETDIM 33
-The default serial comm port uses the SERIAL_TX and SERIAL_RX pins (see their
-definition in the PinNames.h file).
-
-The default serial configuration in this case is 9600 bauds, 8-bit data, no parity
-
-If you want to change the baudrate for example, you have to redeclare the
-serial object in your code:
-
+DigitalOut led(LED1);
Serial pc(SERIAL_TX, SERIAL_RX);
-Then, you can modify the baudrate and print like this:
+// indice per i cicli
+int nIndex;
-pc.baud(115200);
-pc.printf("Hello World !\n");
-------------------------------------------------------------------------------*/
+// indice dell'array caRxPacket[]
+volatile int nRxIndex;
+// carattere in arrivo dal PC
+volatile char caReadChar;
-DigitalOut led(LED1);
+// paccchetto ricevuto dal PC
+char caRxPacket[PACKETDIM];
+int nRxPacketSize;
-int main()
+void RxInterrupt(void)
{
- int i = 1;
-
- printf("Hello World !\n");
+ // 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");
+}
- while(1) {
- wait(1); // 1 second
+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
- printf("This program runs since %d seconds.\n", i++);
- }
-}
+ }
+}
\ No newline at end of file