App to configure a DDS (AD9854) using a K64F. USB an Ethernet were used as interface.
Dependencies: jro mbed AD9854 mbed-rtos I2CLCD k64f_EthLink SerialDriver FreescaleIAP EthernetInterface
Revision 5:6b81db65f419, committed 2019-09-04
- Comitter:
- miguelcordero191
- Date:
- Wed Sep 04 22:26:36 2019 +0000
- Parent:
- 4:3883bfcdfb63
- Child:
- 6:99a56e714791
- Commit message:
- 04/09/2019
Changed in this revision
--- a/AD9854.lib Tue Feb 24 20:14:16 2015 +0000 +++ b/AD9854.lib Wed Sep 04 22:26:36 2019 +0000 @@ -1,1 +1,1 @@ -http://developer.mbed.org/users/miguelcordero191/code/AD9854/#156a9e15919e +http://developer.mbed.org/users/miguelcordero191/code/AD9854/#d81fca2297fb
--- a/jro.lib Tue Feb 24 20:14:16 2015 +0000 +++ b/jro.lib Wed Sep 04 22:26:36 2019 +0000 @@ -1,1 +1,1 @@ -http://developer.mbed.org/users/miguelcordero191/code/jro/#6500be930b36 +http://developer.mbed.org/users/miguelcordero191/code/jro/#dd61acd77e2c
--- a/main.cpp Tue Feb 24 20:14:16 2015 +0000 +++ b/main.cpp Wed Sep 04 22:26:36 2019 +0000 @@ -48,10 +48,12 @@ //const char LCD_WELCOME[] = " JICAMARCA - DDS "; const char LCD_IP_INI[] = "IP : checking... "; const char LCD_IP_NC[] = "IP : Not connected "; -//const char LCD_IP_NI[] = "IP : Not initialized"; +const char LCD_IP_NI[] = "IP : Not initialized"; +const char LCD_IP_RST[] = "IP : Connect&Restart"; const char LCD_DAC_INI[] = "DAC: checking... "; -const char LCD_DAC_NC[] = "DAC: Not detected "; +const char LCD_DAC_NC[] = "DAC: No detected "; +const char LCD_DAC_NO_CLK[] = "DAC: Verify CLK_IN "; const char LCD_DAC_ENA[] = " RF Enabled "; const char LCD_DAC_DIS[] = " RF Disabled "; @@ -65,6 +67,8 @@ EthernetInterface eth; TCPSocketServer server; +int ethIni = 0; + //DDS SPI spi_device(D11, D12, D13); @@ -78,9 +82,9 @@ DDS dds_device(&spi_device, &dds_mreset, &dds_outramp, &dds_sp_mode, &dds_cs, &dds_io_reset, &dds_updclk); //LEDS -DigitalOut LedR(LED1); -DigitalOut LedG(LED2); -DigitalOut LedB(LED3); +DigitalOut LedADC(PTB11); +DigitalOut LedUART(PTB10); +DigitalOut LedIP(PTB3); DigitalIn IPResetButton(PTB2, PullUp); @@ -121,6 +125,8 @@ //Wait until button will be released while(!IPResetButton){ + LedADC = 0; + LedIP = 0; Thread::wait(50); } @@ -135,12 +141,12 @@ //Thread::signal_wait(0x1); - LedG = 1; + LedUART = 0; uart.baud(SERIAL_BAUDRATE); while(1){ - LedG = 0; + LedUART = 1; successful = false; if (uart.isRxBufferEmpty()){ @@ -153,7 +159,7 @@ //******************** BLINK LED ***************************** for (int i=0; i<n; i++){ - LedG = !LedG; + LedUART = !LedUART; Thread::wait(10); } lcd.printf("Serial command received", 0, 1); @@ -169,7 +175,7 @@ //********************* SUCCESSFUL DATA ********************** if (n == 40) - if (dds_device.setAllDevice(rx_buffer) == 1) + if (dds_device.writeAllDevice(rx_buffer) == 1) successful = true; //******************** REPLY UART***************************** @@ -197,8 +203,8 @@ eth_mutex.lock(); readIpConfig(_ip, _mask, _gateway); - - LedB = 1; + ethIni = 0; + LedIP = 0; if (eth.init(_ip, _mask, _gateway) != 0){ //mbed_reset(); @@ -217,12 +223,12 @@ server.bind(ECHO_SERVER_PORT); server.listen(1); + + ethIni = 1; - LedB = 0; - while(1) { - LedB = 0; + LedIP = 1; n = 0; totalSize = 0; @@ -231,14 +237,14 @@ client.set_blocking(false, 500); // Timeout after (0.5)s while (true) { - LedR = !LedR; + LedIP = !LedIP; n = client.receive(rx_buffer, sizeof(rx_buffer)); if (n <= 0) break; totalSize += n; Thread::wait(10); } - LedB = 1; + LedIP = 1; if (totalSize < 1){ client.close(); @@ -252,14 +258,28 @@ } lcd.printf("Eth command received", 0, 1); //******************** DDS NOT INITIALIZED ******************* + if (!dds_device.wasInitialized()){ client.send(ipData.getNIData(ipData.getCmd()), ipData.getNIDataLen()); + Thread::wait(10); client.close(); continue; } + //******************** REPLY REQ ***************************** + //********* ECHO **** + if (ipData.getCmd() == CMD_ECHO){ + + //Sending data + client.send(ipData.getOKData(ipData.getCmd()), ipData.getOKDataLen()); + Thread::wait(10); + client.close(); + + continue; + } + //********* IP CONFIG **** if (ipData.getCmd() == CMD_CHANGE_IP){ @@ -283,7 +303,7 @@ } } - //Lock dds_device before execute any command + //Lock dds_device before of execute any other command dds_mutex.lock(); // ********** OTHER COMMANDS @@ -296,6 +316,7 @@ dds_mutex.unlock(); } + } void lcdView_thread(void const *args){ @@ -342,14 +363,22 @@ } } else{ - lcd.printf(LCD_DAC_NC, 0, 0); + if (c==0){ + lcd.printf(LCD_DAC_NC, 0, 0); + } + if (c==3){ + lcd.printf(LCD_DAC_NO_CLK, 0, 0); + } lcd_status[0] = lcd_status[0] ^ 0xFF; lcd.printf(lcd_status, 19, 0); } - //Verify if ethernet resource is free + //Verifying if ethernet resource is free if (eth_mutex.trylock()){ if (eth_link.GetELink() == 0){ + //Eth connected + LedIP = 1; + if (c==0){ lcd.printf("IP : ", 0, 1); lcd.printf(eth.getIPAddress(), 5, 1); @@ -364,7 +393,23 @@ } } else{ - lcd.printf(LCD_IP_NC, 0, 1); + + LedIP = 0; + + if (ethIni==0){ + //IP not initialized + if (c==0){ + lcd.printf(LCD_IP_NI, 0, 1); + } + if (c==3){ + lcd.printf(LCD_IP_RST, 0, 1); + } + } + else{ + //IP initialized but unconnected + lcd.printf(LCD_IP_NC, 0, 1); + } + } eth_mutex.unlock(); } @@ -381,6 +426,8 @@ int main() { + LedADC = 0; + screen.baud(9600); screen.putc(0x0A); @@ -392,8 +439,6 @@ eth_thread_ptr = new Thread(&waitEthData_thread); lcd_thread_ptr = new Thread(&lcdView_thread); - LedR = 1; - screen.putc(0x33); screen.putc(0x32); @@ -401,7 +446,7 @@ if (dds_device.init()) break; - LedR = !LedR; + LedADC = !LedADC; Thread::wait(250); if (wasIPResetPressed()){ @@ -410,15 +455,12 @@ } } - LedR = 0; /* screen.putc(0x33); screen.putc(0x31); */ - LedR = 1; dds_device.defaultSettings(); - LedR = 0; /* screen.putc(0x33); screen.putc(0x30); @@ -429,10 +471,10 @@ while(true){ if (dds_device.isRFEnabled()){ - LedR = 0; + LedADC = 1; } else{ - LedR = 1; + LedADC = 0; } if (wasIPResetPressed()){