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
main.cpp
00001 // Goal: Program that receives and send 4 channels of data. 00002 // Receives: 1kHz 00003 // Sends: 70kbits/s 00004 00005 //DONE: 00006 // O programa lê e envia dados da taxa indicada por TIMER_RATE 00007 //TODO: 00008 // Comunicação com bluetooth 00009 // Ver porque o tempo de envio está tão alto. 00010 00011 #include "mbed.h" 00012 00013 /*--------------Signal Definition-----------------*/ 00014 //16bits buffer 00015 #define ECG1 0 00016 #define ECG2 1 00017 #define RESP 2 00018 #define PPG 3 00019 00020 //8bits buffer 00021 #define LSB_ECG1 0 00022 #define MSB_ECG1 1 00023 #define LSB_ECG2 2 00024 #define MSB_ECG2 3 00025 #define LSB_RESP 4 00026 #define MSB_RESP 5 00027 #define LSB_PPG 6 00028 #define MSB_PPG 7 00029 00030 00031 /*---------------- Sample Speed Timer --------------*/ 00032 #define TIMER_RATE 0.01 00033 00034 /*-----READS THE ANALOG SIGNAL FROM THE SENSORS-----*/ 00035 00036 AnalogIn Ecg1(A0); 00037 AnalogIn Ecg2(A1); 00038 AnalogIn Resp(A3); 00039 AnalogIn Ppg(A4); 00040 00041 DigitalOut testSpeed(PTE1); 00042 00043 00044 /*------CONTROLS THE DATA RATE OF THE READING------*/ 00045 Ticker t0; 00046 Serial pc(USBTX,USBRX); 00047 00048 00049 /*---HANDLES THE TIMER AND SERIAL INTERRUPTIONS-----*/ 00050 00051 void t0_handler(void); 00052 void rx_Handler(void); 00053 00054 char test = 0; // Tests the data received from the computer in order to start the reading 00055 00056 00057 /*------------BUFFER TO STORE DATA------------------*/ 00058 00059 uint16_t buffer_16[4] = {0,0,0,0}; 00060 char buffer_8[8] = {0,0,0,0,0,0,0,0}; 00061 00062 00063 int main() { 00064 pc.printf("main"); 00065 pc.attach(&rx_Handler, pc.RxIrq); 00066 00067 00068 while(1){} 00069 00070 //aciona porta 00071 00072 //pc.printf("%i,%i,%i,%i\n",buffer[ECG1],buffer[ECG2],buffer[RESP],buffer[PPG]);//PUTC 00073 00074 00075 } 00076 00077 /*----------------------FUNCTIONS-----------------------*/ 00078 00079 //Reads and send data to the computer 00080 00081 void t0_handler(void){ 00082 00083 //Reads the Analog Ports 00084 buffer_16[ECG1] = Ecg1.read_u16(); 00085 buffer_16[ECG2] = Ecg2.read_u16(); 00086 buffer_16[RESP] = Resp.read_u16(); 00087 buffer_16[PPG] = Ppg.read_u16(); 00088 00089 //Divides de buffer 16 into multiple buffers; 00090 //Falta rotacionar: 00091 //Ver Ser a rotação está correta 00092 00093 buffer_8[LSB_ECG1] = (char)(buffer_16[ECG1]); 00094 buffer_8[MSB_ECG1] = (char)((buffer_16[ECG1]&0xFF)>>8); 00095 00096 buffer_8[LSB_ECG2] = (char)(buffer_16[ECG2]); 00097 buffer_8[LSB_ECG2] = (char)((buffer_16[ECG2]&0xFF)>>8); 00098 00099 buffer_8[LSB_RESP] = (char)(buffer_16[RESP]); 00100 buffer_8[MSB_RESP] = (char)((buffer_16[RESP]&0xFF)>>8); 00101 00102 buffer_8[LSB_PPG] = (char)(buffer_16[PPG]); 00103 buffer_8[MSB_PPG] = (char)((buffer_16[PPG]&0xFF)>>8); 00104 00105 //Sends to the computer 00106 testSpeed = 1; 00107 00108 pc.putc(buffer_8[LSB_ECG1]); //texto se foi bem sucedida 00109 pc.putc(buffer_8[MSB_ECG1]); 00110 pc.putc(buffer_8[LSB_ECG2]); 00111 pc.putc(buffer_8[MSB_ECG2]); 00112 pc.putc(buffer_8[LSB_RESP]); 00113 pc.putc(buffer_8[MSB_RESP]); 00114 pc.putc(buffer_8[LSB_PPG]); 00115 pc.putc(buffer_8[MSB_PPG]); 00116 00117 00118 testSpeed = 0; 00119 00120 00121 } 00122 00123 //This function must 00124 00125 void rx_Handler(void){ 00126 // A programação não estava funcionando poisnão se deve utilizar interrupções para realizar grandes tarefas; 00127 // Elas travam e não funciona mais nada. 00128 // Como fazer para não ficar testando no main?? Sexta feira no globo reporter 00129 00130 test = pc.getc(); // it gets the received character 00131 pc.putc(test);//debug 00132 00133 //--Tests the Receive Character---- 00134 00135 if(test == '2'|| test == '2') 00136 { 00137 t0.attach(&t0_handler,TIMER_RATE); 00138 00139 }else if (test=='3'|| test == '3') 00140 { 00141 t0.detach(); 00142 } 00143 00144 00145 }
Generated on Thu Jul 21 2022 17:45:56 by
1.7.2