Tool/software: TI C/C++ Compiler
Hey guys,
I use sensor/collector example (newest SDK) and I am trying to make the collector read a cmd via UART. Note, that I was able to make the uartecho example work fine, also with callback mode.
I use my PC to write a cmd like "1\r\n" via UART to the launchpad which is connected via USB. I do then cause a HWI, which sets a collector event. In the collector event, I do the following:
/* Perfom a HWI triggered factory reset */ if(Collector_events & COLLECTOR_HWI_FACTORY_RESET) { if(allow_hwi_factoryReset) { UART_read(hUart, &rx_input, 1); } /* Clear the event */ Util_clearEvent(&Collector_events, COLLECTOR_HWI_FACTORY_RESET); }
In the callback function I parse the message and I force the system to read until \n is found:
void readCmdCallback(UART_Handle handle, void *buffer, size_t size) { uint8_t index = 0; uint16_t cmd = 0; bool EOL_found; uint8_t buffer_length = 8; char tx_output[buffer_length]; if (rx_input == '\n') { EOL_found = true; tx_output[index] = '\n'; //UART_write(hUart, &tx_output, index++); index = 0; /* convert msg into integer cmd */ cmd = UARTmsgToInt(tx_output); /* execute the cmd */ executeUartCmd(cmd); /* reset tx_output buffer */ for (uint8_t i = 0; i < buffer_length; i++) { tx_output[i]= 0; } } else if(rx_input == '\r') { tx_output[index] = '\r'; index++; EOL_found = false; } else { tx_output[index] = rx_input; index++; EOL_found = false; } if (EOL_found) { /* read until end of line has been found */ UART_read(hUart, &rx_input, 1); } }
I rebuild the message and then do some other stuff with it. However, I never enter the callback function. Here are my UART settings in main.c
uartParams.baudRate = 115200; uartParams.readDataMode = UART_DATA_BINARY; uartParams.readMode = UART_MODE_CALLBACK; uartParams.readCallback = readCmdCallback; uartParams.readEcho = UART_ECHO_OFF;
- Any idea why the system is not entering the callback function? Do you think, that the uart buffer is somehow erased and when UART_read is called in the collector event, there are no bytes to read?!
- Is using UART_read within the callback function a proper way, to make sure all bytes are read? (I dont know the actual length of the message.
Any advice is welcome