cancel
Showing results for 
Search instead for 
Did you mean: 

UART Tx and Rx problem

Nandy K
Associate II
Posted on October 02, 2015 at 15:16

Hi Guys,

I am working on STM32F746G-Disco Board and I am a fresher on this topic.

I have connected the STM32F746 with a WiFi module(SPWF01SC.11) through UART then it is connected to my mobile phone through wifi.

When I send a AT command from the MCU my wifi module responds for it,so the Tx part is working fine.The problem is withe the Rx part,I would like to explain it with an example

1. If I send a string  Hi from my phone it should reach the MCU via WiFi module. so once the MCU receive the string Hi it should respond back with a string Hello to my phone via Wifi module.

2. for this I would like to receive the string Hi and store it in a buffer and compare the string .

How I can do this ? now I am using an example from STM32F746G-Disco : UART _ComDMA

here is my code 

#include ''main.h''

/

/* Private define ------------------------------------------------------------*/

#define TRANSMITTER_BOARD

/* UART handler declaration */

UART_HandleTypeDef UartHandle;

__IO ITStatus UartReady = RESET;

__IO uint32_t UserButtonStatus = 0;  /* set to 1 after User Button interrupt  */

/* Buffer used for transmission */

uint8_t aTxBuffer[] = ''AT+S.SOCKD=8825\r\n''; wifi module starts listening

/* Buffer used for end test transmission */

uint8_t aEndTestTxBuffer[] = ''\n\r **** TEST ENDED ****\n\r'';

/* Buffer used for reception */

uint8_t aRxBuffer[RXBUFFERSIZE];

void SystemClock_Config(void);

static void Error_Handler(void);

static uint16_t Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength);

static void MPU_Config(void);

static void CPU_CACHE_Enable(void);

int main(void)

{

  /* Configure the MPU attributes as Write Through */

  MPU_Config();

  /* Enable the CPU Cache */

  CPU_CACHE_Enable();

  /* STM32F7xx HAL library initialization:

  HAL_Init();

  /* Configure the system clock to 216 MHz */

  SystemClock_Config();

  

  /* Configure LED1 */

  BSP_LED_Init(LED1);

  /*##-1- Configure the UART peripheral 

  /* Put the USART peripheral in the Asynchronous mode (UART Mode) */

  

 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;

  

//………Transmitting the string AT+S.SOCKD=8825 \r\n and it is working fine…………//

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)

{

    /* Transfer error in transmission process */

   Error_Handler();

}

  /*##-3- Wait for the end of the transfer ###################################*/

   

  while (UartReady != SET)

  {

      

  }

  /* Reset transmission flag */

  UartReady = RESET;

  //………… HOW I CAN RECEIVE THE STRING  & store it in a buffer??????? …………………

  

   if(HAL_UART_Receive_DMA(&UartHandle, (uint8_t*)aRxBuffer, RXBUFFERSIZE)!= HAL_OK)

  {

    Error_Handler();

  }

  

  

   

  // Reset transmission flag //

  //##-6- Compare the sent and received buffers ##############################//

  /*if(Buffercmp((uint8_t*)aTxBuffer,(uint8_t*)aRxBuffer,RXBUFFERSIZE))

  {

    Error_Handler();

  }*/

   

  // Turn on LED1 if test passes then enter infinite loop //

   BSP_LED_On(LED1); 

  // Infinite loop 

  while (1)

  {

      if(RxBuffer== “Hi�?)

{

    uint8_t aTxBuffer[] = “Hello \r\n�?;

     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();

  }

   while (UartReady != SET)

  {

  }

   

  }

  

}

1 REPLY 1
Amel NASRI
ST Employee
Posted on October 07, 2015 at 16:09

Hi kumar.nandeesh,

In reception case, the problem may be in transmitter side not CPU one.

Is it possible to check the data to be received by the STM32F7?

-Mayla-

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.