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.
Fork of mbed-os-example-tcp-server by
main.cpp
00001 #include "mbed.h" 00002 #include "EthernetInterface.h" 00003 #include "TCPServer.h" 00004 #include "TCPSocket.h" 00005 #include "ADS1299.h" 00006 //SPI device(SPI_MOSI, SPI_MISO, SPI_SCK); 00007 SPI device(PC_12, PC_11, PC_10); 00008 Serial pc(SERIAL_TX, SERIAL_RX); 00009 DigitalOut CS(D10); 00010 DigitalOut ledG(LED1); 00011 DigitalOut ledR(LED3); 00012 InterruptIn DDRY(D15); 00013 DigitalOut reset(D14); 00014 DigitalOut START(D9); 00015 00016 #define buffe 356 00017 00018 const uint32_t lenght_char=(buffe*3)+3; 00019 unsigned char b1[lenght_char],*b2[lenght_char]; 00020 uint32_t ciclo,_m; 00021 bool a,bandera; 00022 00023 int leer(void) //concatena 24 bits 00024 { 00025 uint32_t rdata; 00026 rdata = device.write(0); 00027 rdata<<=8; 00028 rdata|=device.write(0); 00029 rdata<<=8; 00030 rdata|=device.write(0); 00031 return rdata; 00032 } 00033 00034 int complement(uint32_t ch)// conversion twos complement 00035 { 00036 int32_t sch; 00037 if(ch>0x7FFFFF) { 00038 ch|=0xFF800000; 00039 ch--; 00040 ch=~ch; 00041 sch = -ch; 00042 } else if(ch<=0x7FFFFF) { 00043 sch = ch; 00044 } 00045 sch+= 0x7FFFFF; //offset, solo valores positivos 00046 return sch; 00047 } 00048 00049 int buffy(uint32_t _ch) 00050 { 00051 //_ch+=0x7FFFFF; 00052 uint8_t c1,c2,c3; 00053 c1=_ch>>16; 00054 b1[ciclo]=c1; 00055 ciclo++; 00056 c2=_ch>>8; 00057 b1[ciclo]=c2; 00058 ciclo++; 00059 c3=_ch; 00060 b1[ciclo]=c3; 00061 ciclo++; 00062 return 0; 00063 } 00064 00065 void send_data() 00066 { 00067 if (bandera == 0) { 00068 buffy(0xffffff); 00069 bandera|=1; 00070 } 00071 00072 uint32_t statu,ch1,ch2,ch3,ch4,ch5; 00073 int32_t sch2; 00074 // uint8_t c1,c2,c3; 00075 statu = leer(); 00076 ch1 = leer(); 00077 ch2 = leer(); 00078 ch3 = leer(); 00079 ch4 = leer(); 00080 ch5 = leer(); 00081 00082 // sch2=complement(ch2); 00083 // buffy(sch2); 00084 //sch2=complement(ch3); 00085 // buffy(0); 00086 //sch2=complement(ch4); 00087 //buffy(0); 00088 //sch2=complement(ch5); 00089 //buffy(0); 00090 00091 sch2=complement(ch2); 00092 buffy(sch2); 00093 sch2=complement(ch3); 00094 buffy(sch2); 00095 sch2=complement(ch4); 00096 buffy(sch2); 00097 sch2=complement(ch5); 00098 buffy(sch2); 00099 00100 if(ciclo>=lenght_char) { 00101 bandera&=~bandera; 00102 memcpy(&b2, &b1, lenght_char); 00103 ciclo=0; 00104 a=1; 00105 } 00106 00107 } 00108 00109 int main() 00110 { 00111 00112 pc.printf("hi, "); 00113 ////////////seteo de ethernet 00114 EthernetInterface eth; 00115 eth.connect(); 00116 pc.printf("The Server IP address is '%s' ", eth.get_ip_address()); 00117 TCPServer srv; 00118 TCPSocket client_sock; 00119 SocketAddress client_addr; 00120 srv.open(ð); 00121 srv.bind(eth.get_ip_address(), 8085); 00122 srv.listen(1); 00123 ledG = 1; 00124 srv.accept(&client_sock, &client_addr); 00125 pc.printf("Accepted %s:%d ", client_addr.get_ip_address(), 00126 client_addr.get_port()); 00127 00128 ///////////////////Wake up ADS 00129 // pc.printf("ADS1299- Nucleo -F767ZI \n"); 00130 device.format(8,1); 00131 device.frequency(4000000); 00132 START=0; 00133 reset=1; 00134 wait(0.2); 00135 reset=0; 00136 CS=1; 00137 wait_us(10); 00138 reset = !reset; 00139 wait_us(40); 00140 ///////////////////////////////////// 00141 00142 00143 00144 /////////////SDATAC para escribir sobre registros 00145 CS = 0; 00146 wait_us(1); 00147 device.write(0x11); 00148 wait_us(4);//tsccs = 4 Tclk 00149 CS = 1; 00150 wait_us(2);//tsch = 2 Tclk 00151 ////////////////////////////////////////////////////////// 00152 00153 ////////////leer ID 00154 int _id; 00155 CS = 0; 00156 wait_us(1); 00157 device.write(RREG|ID); //read 00158 device.write(0x00); 00159 _id=device.write(0x00); 00160 wait_us(4); 00161 CS=1; 00162 wait_us(2); 00163 //////////////////////// 00164 pc.printf("ID register: %X\n",_id); 00165 00166 00167 00168 ////////// SETEAR CONFIGURACION (todos los registros) 00169 CS = 0; 00170 wait_us(5); 00171 device.write(WREG|CONFIG1); //write desde config 1 00172 device.write(0x16); // escribir sobre 23 registros 00173 device.write(0x94); //CONFIG1 00174 device.write(0xc0); //CONFIG2 //c0 normal //d0 Test source 00175 device.write(0xe0); //CONFIG3 00176 device.write(0x00); //LOFF 00177 device.write(0x68); //CH1SET //ref channel 00178 device.write(0x60); //CH2SET //65 cuadrada //60 electrodo 00179 device.write(0x60); //CH3SET 00180 device.write(0x60); //CH4SET 00181 device.write(0x60); //CH5SET // si no los uso 81 00182 device.write(0x81); //CH6SET 00183 device.write(0x81); //CH7SET 00184 device.write(0x81); //CH8SET 00185 device.write(0x00); //BIAS_SENSP 00186 device.write(0x00); //BIAS_SENSN 00187 device.write(0x00); //LOFF_SENSP 00188 device.write(0x00); //LOFF_SENSN 00189 device.write(0x00); //LOFF_FLIP 00190 device.write(0x00); //LOFF_STATP 00191 device.write(0x00); //LOFF_STATN 00192 device.write(0x0f); //GPIO 00193 device.write(0x20); //MISC1 00194 device.write(0x00); //MISC2 00195 device.write(0x00);//CONFIG4 00196 wait_us(4); 00197 CS=1; 00198 wait_us(2); 00199 /////////////////////////////////////// 00200 00201 ////////////////INICIO A _RDATAC 00202 CS = 0; 00203 wait_us(1); 00204 device.write(_RDATAC); 00205 wait_us(4); 00206 CS=1; 00207 wait_us(2); 00208 START=1; 00209 CS = 0; 00210 wait_ms(10);//tsettle 00211 ////////////////////////// 00212 // int _by=0; 00213 // client_sock.recv(reading, 8); 00214 // client_sock.set_blocking(false); 00215 // DDRY.mode(PullUp); 00216 //NVIC_SetPriority(TIMER3_IRQn, 200); 00217 send_data(); 00218 DDRY.fall(&send_data); 00219 // DDRY.disable_irq(); 00220 wait_ms(buffe); 00221 // restart.attach(&send_data, 0.001); 00222 while(1) { 00223 while (a==1) { 00224 client_sock.send(&b2, lenght_char); 00225 a=0; 00226 } 00227 // fflush(); 00228 __wfi(); 00229 } 00230 client_sock.close(); 00231 }
Generated on Tue Aug 2 2022 12:53:13 by
1.7.2
