AnsweredAssumed Answered

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

Question asked by Dev Chandil on Mar 17, 2018
Latest reply on Mar 18, 2018 by T J

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

Outcomes