cancel
Showing results for 
Search instead for 
Did you mean: 

Communication between UART DMA and ESP8266 hangs after first response

Lars Beiderbecke
Senior III
Posted on May 26, 2018 at 16:04

I'm going crazy with this. I want to send some commands to an ESP8266, and search the response for 'OK'. Since the response is of arbitrary length, I'm receiving 400 bytes, and see if there's an 'OK' in there. If there isn't within a given timeout, the operation fails.

clearBuffer(buffer);

HAL_UART_Receive_DMA(&huart7, rxbuffer, 400);

HAL_UART_Transmit_DMA(&huart7, 'OK' CRLF, 4);

buf = waitOK(buffer, 3);  // wait 3 secs for 'OK'

HAL_UART_Transmit_DMA(&huart7, 'OK' CRLF, 4);

buf = waitOK(buf, 3);  // wait 3 secs for 'OK'

// ...

static uint8_t *waitOK(uint8_t *buf, int timeout) {

  uint8_t *found = 0;

  int count = 0;

  while (count++ < 2 * timeout) {

    found = strfind(buf, 'OK');  // search for 'OK' in remaining buffer

    if (found)

      break;

    HAL_Delay(500);

  }

  return found + 1;

}

Unfortunately, I can only get the first OK.  Subsequent commands don't receive ANY response, i.e., the buffer remains empty.

I configured UART7 with two DMA channels, but no interrupt. No callbacks have been defined.

What am I doing wrong here?  I've tried multiple variations, with IR or polling, but they all showed the same issue.

18 REPLIES 18
Posted on May 27, 2018 at 09:51

I also finally did as you suggested. I connected RX of the ESP8266 to a different console, and had your Forward() process the responses send by TX of the ESP8266.

That worked beautifully, I could see the echo and the response of each command.

But what does this mean?

Posted on May 27, 2018 at 09:51

That is correct. 

Posted on May 27, 2018 at 09:53

Cool.  Would you mind sharing the UART bits for the F7 with me?

Posted on May 27, 2018 at 10:18

I did about 5 hours ago

still under moderation

:(

Posted on May 27, 2018 at 10:38

And I use CubeMX 4.25, and both are linear buffers. I didn't write any callbacks, I'm just using the generated code.

Posted on May 27, 2018 at 10:40

me too

Posted on May 27, 2018 at 10:42

I only setup the RxDMA on startup.

I use peek() to check a pending byte in the buffer

I use readable() to check the length of the received packet, before I go get it.

Posted on May 27, 2018 at 11:24

Thanks to both of you for digging into this mystery!

Posted on May 27, 2018 at 12:24

Thanks!