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 circularBuff
main.cpp
00001 #include "mbed.h" 00002 #include "circularBuff.h" 00003 00004 00005 // RECEPCIÓN Y TRANSMISIÓN DE DATSO A TRAVES DE DOS DISPOSITIVOS 00006 00007 00008 00009 # define BUFFER_SIZE 300 // DECLARAMOS EL TAMAÑO DEL BUFFER 00010 00011 Serial pc (USBTX,USBRX); // TX RX 00012 Serial Placa2(p13 , p14); // conexion serial puertos UART PLACA DOS 00013 00014 circ_buf_t BUFFER1; // Estrucura buffer 1 00015 circ_buf_t BUFFER2; // Estructura buffer 2 00016 00017 00018 // Declaración de variables volátiles 00019 volatile bool BUFFER1CHECK = false; 00020 volatile bool BUFFER2CHECK = false; //volátil: el campo puede ser modificado por varios subprocesos que se ejecutan al mismo tiempo 00021 00022 // Función de interrupción recepción de datos por serial pc 00023 void pcRXInterrup(){ 00024 uint8_t data = pc.getc(); 00025 if(data != NULL){ 00026 circ_buf_put(&BUFFER1, data); 00027 00028 } 00029 else 00030 { 00031 circ_buf_put(&BUFFER1, data); 00032 BUFFER1CHECK = true; 00033 } 00034 } 00035 00036 00037 // subRUT transmisión puerto serial pc 00038 void pcTXInterrup(){ 00039 uint8_t dato = 0; 00040 circ_buf_get(&BUFFER1, &dato); 00041 pc.putc(dato); 00042 } 00043 00044 00045 // subRUT recepcion 2Mbed serial placa 2 00046 00047 void Placa2RXInterrup(){ 00048 uint8_t data = Placa2.getc(); 00049 if(data != NULL) 00050 circ_buf_put(&BUFFER2, data); // Se guarda en el buffer el dato que llegan de la otra mbed 00051 else 00052 { 00053 circ_buf_put(&BUFFER2, data); 00054 BUFFER2CHECK = true; 00055 } 00056 00057 uint8_t dato2 = 0; // Visualizar en la pantalla el dato recibido de la otra mbed 00058 circ_buf_get(&BUFFER2, &dato2); 00059 pc.putc(dato2); 00060 00061 00062 } 00063 00064 00065 00066 // subRUT trasnmision 2MBed serial placa 2 00067 00068 void Placa2TXInterrup(){ 00069 uint8_t dato = Placa2.putc(pc.getc()); 00070 circ_buf_put(&BUFFER2, dato); 00071 } 00072 00073 00074 00075 00076 int main() { 00077 00078 00079 pc.baud(115200); // velocidad baudios 00080 00081 BUFFER1.buffer = (uint8_t*)malloc(BUFFER_SIZE); // espacio de memoria para el buffer1 00082 BUFFER2.buffer = (uint8_t*)malloc(BUFFER_SIZE); // espacio de memoria para el buffer2 00083 00084 BUFFER1.size=BUFFER_SIZE; // inicializado buffer 1 00085 BUFFER2.size=BUFFER_SIZE; // inicializado buffer 2 00086 00087 00088 // interrupciones pc 00089 pc.attach(&pcRXInterrup,Serial::RxIrq); 00090 pc.attach(&pcTXInterrup,Serial::TxIrq); 00091 00092 // interrupciones segunda placa 00093 Placa2.attach(Placa2RXInterrup,Serial::RxIrq); 00094 Placa2.attach(Placa2TXInterrup,Serial::TxIrq); 00095 00096 00097 00098 00099 while(1) { 00100 00101 if(BUFFER1CHECK == true) // revision buffer preparado 00102 { 00103 uint8_t Z = NULL; 00104 do{ // do while, primero ejecuta y luego revisa la condicion del while 00105 circ_buf_get(&BUFFER1, &Z); // Para visualizar en el CoolTerm 00106 pc.putc(Z); 00107 }while(Z!=NULL); 00108 BUFFER1CHECK = false; 00109 00110 } 00111 00112 } 00113 }
Generated on Tue Jul 19 2022 12:34:55 by
