2018-03-16 11:25 PM
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-f072rb2018-03-17 05:51 AM
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.
2018-03-17 04:50 PM
Why would you use UART_WORDLENGTH_7B, it is not common..