AnsweredAssumed Answered

HAL_UART_Transmit_DMA

Question asked by KUMAR.NANDEESH on Oct 21, 2015
Hi,
I am using STM32F746.
It is connected with ST wifi module(SPWF01SC) via UART.

/* Buffer used for transmission */
uint8_t aTxBuffer[] = "AT+S.SOCKD=8825\r\n";

/* Buffer used for reception */
uint8_t aRxBuffer[RXBUFFERSIZE];

In the program I am using HAL_UART_Transmit_DMA to transfer  and HAL_UART_Receive_DMA to receive.
I am transmitting the buffer to start the wifi module and it is working fine.
Now I am sending a string "PIP" from my wifi module.
whenever I receive this string"PIP" the MCU need to transmit back "CIAO".

In my case I am receiving the string CIAO only when I reset the MCU and also it is working fine only for the first time after reset then for the second time i need to send the string twice then i get the response but after that there is no response.
my main loop code :
  UartHandle.Instance        = USARTx;
  UartHandle.Init.BaudRate   = 115200;
  UartHandle.Init.WordLength = UART_WORDLENGTH_8B;
  UartHandle.Init.StopBits   = UART_STOPBITS_1;
  UartHandle.Init.Parity     = UART_PARITY_NONE;
  UartHandle.Init.HwFlowCtl  = UART_HWCONTROL_NONE;
  UartHandle.Init.Mode       = UART_MODE_TX_RX;
  if(HAL_UART_DeInit(&UartHandle) != HAL_OK)
  {
    Error_Handler();
  }  
  if(HAL_UART_Init(&UartHandle) != HAL_OK)
  {
    Error_Handler();
  }
   if(HAL_UART_Transmit_DMA(&UartHandle, (uint8_t*)aTxBuffer, TXBUFFERSIZE)!= HAL_OK)
  {
    Error_Handler();
  }
  
 /*##-3- Wait for the end of the transfer ###################################*/  
  while (UartReady != SET)
  {
  }


 while (1)
  {
      HAL_Delay(100);
    
      if(HAL_UART_Receive_DMA(&UartHandle, (uint8_t *)aRxBuffer, RXBUFFERSIZE) != HAL_OK)
      {
         // Error_Handler();
      }
     
      if(aRxBuffer[0]=='P'&&aRxBuffer[1]=='I'&&aRxBuffer[2]=='P')
      {
          aTxBuffer[0]='C';
          aTxBuffer[1]='I';
          aTxBuffer[2]='A';
          aTxBuffer[3]='O';
          aTxBuffer[4]='\r';
          aTxBuffer[5]='\n';
          
           BSP_LED_On(LED1); 
          txBuf = 5;
        if(HAL_UART_DeInit(&UartHandle) != HAL_OK)
        {
          Error_Handler();
        }  
        if(HAL_UART_Init(&UartHandle) != HAL_OK)
        {
          Error_Handler();
        }
        if(HAL_UART_Transmit_DMA(&UartHandle, (uint8_t*)aTxBuffer, txBuf)!= HAL_OK)
        {
            //Error_Handler();
        }
            
        while (UartReady != SET)
        {
          
        }
          aRxBuffer[0]='a';
          
       }
          
  }

Help me guys with some solution.
my MCU need to reply back CIAO whenever I receive PIP on the UART.
Please have a look at the image.

Attachments

Outcomes