cancel
Showing results for 
Search instead for 
Did you mean: 

Cannot transmit the string to the system via UART, but can receive the string via the same system

Dev Chandil
Associate
Posted on March 17, 2018 at 07:25

char receivedData[50]='free';

char transmitData[] = 'done';

GPIO_PinState Val;

GPIO_PinState Led_State;

HAL_UART_Receive(&huart2,(uint8_t *)receivedData,50,50);

Val = HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_13);

Led_State = HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_5);

if(strcmp(receivedData, 'busy') == 0)

{

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_SET);

}

else if(Val == GPIO_PIN_RESET && Led_State == GPIO_PIN_SET)

{

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_RESET);

HAL_UART_Transmit(&huart2,(uint8_t  *)transmitData,4,50);

}

I am using the above code on the Nucleo Board F070RB when I send busy string via realterm the on-board LED glows, and after the LED has glown when the user pushes the onboard switch, the LED stops glowing and it sends back an acknowledgment to the system in a form of string which says done. Whole system is working fine but the acknowledgment I am getting is the first letter i.e. d only apart from that I get 2 letters which are garbage. The baudrate, parity, stop bit, flow control is all perfect.

Below is my UART initialization:

huart2.Instance = USART2;

huart2.Init.BaudRate = 9600;

huart2.Init.WordLength = UART_WORDLENGTH_7B;

huart2.Init.StopBits = UART_STOPBITS_1;

huart2.Init.Parity = UART_PARITY_NONE;

huart2.Init.Mode = UART_MODE_TX_RX;

huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;

huart2.Init.OverSampling = UART_OVERSAMPLING_16;

huart2.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;

huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;

Below is my GPIO initialization:

/* GPIO Ports Clock Enable */

__HAL_RCC_GPIOC_CLK_ENABLE();

__HAL_RCC_GPIOA_CLK_ENABLE();

/*Configure GPIO pin Output Level */

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_RESET);

/*Configure GPIO pin : PC13 */

GPIO_InitStruct.Pin = GPIO_PIN_13;

GPIO_InitStruct.Mode = GPIO_MODE_INPUT;

GPIO_InitStruct.Pull = GPIO_PULLUP;

HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

/*Configure GPIO pin : PA5 */

GPIO_InitStruct.Pin = GPIO_PIN_5;

GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;

GPIO_InitStruct.Pull = GPIO_NOPULL;

GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;

HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

#stm32-nucleo #nucleo-f072rb
2 REPLIES 2
Posted on March 17, 2018 at 13:51

Ok, and do you have a debugger or a scope?

Does the signal look correct?

Does the HAL_UART_Transmit return an error code? Might a longer timeout help? Admittedly should take 1ms per char, but trying to cover bases here.

Try using 2 stop bits on the STM32 side.

Try sending the string one character at a time.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
T J
Lead
Posted on March 18, 2018 at 00:50

Why would you use UART_WORDLENGTH_7B, it is not common..