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
COMM-Protocol.cpp
00001 #include "mbed.h" 00002 00003 // dimensione del pacchetto di comunicazione tra PC e uC. esempio di 30 caratteri: 1/0 say goodbye to your sister 00004 #define PACKETDIM 31 00005 00006 DigitalOut led(LED1); 00007 DigitalOut Din(PB_9); 00008 Serial pc(USBTX, USBRX, 9600); // seriale di comunicazione con il PC. Associati a PA_11 e PA_12 00009 00010 // Definizione periferica seriale 00011 //Serial myBLE(PC_1, PC_0, 9600); //Tx, Rx, bps. per la configurazione bps = 38400. Di default HC05 comunica con bps = 9600 00012 00013 // indice per i cicli 00014 int nIndex; 00015 00016 // indice dell'array caRxPacket[] 00017 volatile int nRxIndex; 00018 // carattere in arrivo dal PC 00019 volatile char caReadChar; 00020 00021 // pacchetto ricevuto dal PC 00022 char caRxPacket[PACKETDIM]; 00023 int nRxPacketSize; 00024 00025 void RxInterrupt(void) 00026 { 00027 // reset pacchetto ricevuto 00028 nIndex=0; 00029 for(nIndex=0;nIndex<PACKETDIM;nIndex++) 00030 { 00031 caRxPacket[nIndex]='\0'; 00032 } 00033 00034 // ricevi caratteri su seriale, se disponibili 00035 while((pc.readable())) 00036 { 00037 pc.gets(caRxPacket,sizeof(caRxPacket)); 00038 nRxPacketSize = strlen(caRxPacket); 00039 //pc.printf("*** pc.readable = %2d \n\r",nRxPacketSize); 00040 //pc.scanf("%s", &caRxPacket); 00041 //+++pc.putc(pc.getc()); // read data from UART 00042 00043 } 00044 //pc.printf("%s",caRxPacket); 00045 pc.printf("\n\rYou also say goodbye to yours tk\n\r"); 00046 } 00047 00048 int main() 00049 { 00050 pc.printf("\n\r*** Welcome ***\n\r"); 00051 00052 pc.attach(&RxInterrupt,Serial::RxIrq); 00053 00054 while(true) 00055 { 00056 led = !led; // Toggle LED 00057 wait_ms(500); 00058 } 00059 }
Generated on Wed Jul 13 2022 18:30:17 by
1.7.2