2018-05-20 04:57 AM
Like many before, I'm trying to receive data with variable length, in particular responses from an ESP8266.
My idea is to look into the stream of received bytes to find an occurrence of 'OK' or 'ERROR'. My first version used polling, but eventually I need to use DMA. This is my (simplified) code now:
// check AT command
HAL_UART_Receive_DMA(&huart7, buffer, 24); // 24 is max response lengthHAL_UART_Transmit_DMA(&huart7, 'AT\r\n', 4);int found = 0, count = 0;while (count++ < 2 * timeout) { // timeout in seconds if (strfind(buffer, 'OK')) { found = 1; break; // found } HAL_Delay(500);}HAL_DMA_Abort(&hdma_uart7_rx); // abort pending receiver// set to station modeHAL_UART_Receive_DMA(&huart7, buffer, 24);
HAL_UART_Transmit_DMA(&huart7, 'AT+CWMODE=1\r\n', 13);
found = count = 0;// while() and so onThis works for the first ESP8266 command (no matter which one I choose), but not for subsequent commands, where the buffer just remains empty.
Why does my program break from one command to the other? The timeout is chosen appropriately. My only explanation would be that HAL_DMA_Abort() doesn't, although the description reads as if it should work.
(The very same thing happened with my polling code, but in that case I assume my code just missed the crucial bytes.)
#uart #dma2018-05-20 04:17 PM
Why use Abort ?
set it to a circular buffer,
you know where the last frame stopped and the new one starts.