2025-06-20 4:45 AM
No Data Received on MCU.
We have connected MAX3232 RS-232 IC on UART2 (PA2 - Tx & PA3 - Rx) of STM32F0303RCT6.
When UART2 is Configured in Loopback, we are receiving the data that is being transmitted by MCU - on both MCU Loopback & MAX3232 Loopback.
But when we are using CP2102 USB to TTL with MCU or USB to Rs-232 Convertor with MAX3232 IC Interface, we are not receiving any data on the MCU.
We have check USB to TTL (CP2102) with UART4, we are receiving the Data.
We have checked waveform on Oscilloscope, when using USB-TTL or USB-RS-232 data on Rx is observed on every 2-3 send from Laptop, but no data is received on MCU.
Find the Schematic & Layout in Attachment
2025-06-20 4:51 AM - edited 2025-06-20 4:56 AM
Hello @Deepak_0202 and welcome to the ST community,
Since CP2102 USB to TTL is working with UART4 and not with UART2, probably it's an UART config.
Are you sure you have the same config for UART2 as for UART4?
Are you sure you configured the correct pin for UART2_Tx i.e. PA3?
2025-06-20 5:53 AM - last edited on 2025-06-20 5:55 AM by mƎALLEm
Yes, we have initalized the same.
Code for the reference:
void HAL_UART_MspInit(UART_HandleTypeDef* huart)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
if(huart->Instance==USART1)
{
/* USER CODE BEGIN USART1_MspInit 0 */
/* USER CODE END USART1_MspInit 0 */
/* Peripheral clock enable */
__HAL_RCC_USART1_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
/**USART1 GPIO Configuration
PA9 ------> USART1_TX
PA10 ------> USART1_RX
*/
GPIO_InitStruct.Pin = GPIO_PIN_9|GPIO_PIN_10;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF1_USART1;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/* USART1 interrupt Init */
HAL_NVIC_SetPriority(USART1_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(USART1_IRQn);
/* USER CODE BEGIN USART1_MspInit 1 */
/* USER CODE END USART1_MspInit 1 */
}
else if(huart->Instance==USART2)
{
/* USER CODE BEGIN USART2_MspInit 0 */
/* USER CODE END USART2_MspInit 0 */
/* Peripheral clock enable */
__HAL_RCC_USART2_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
/**USART2 GPIO Configuration
PA2 ------> USART2_TX
PA3 ------> USART2_RX
*/
GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_3;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF1_USART2;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/* USART2 interrupt Init */
HAL_NVIC_SetPriority(USART2_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(USART2_IRQn);
/* USER CODE BEGIN USART2_MspInit 1 */
/* USER CODE END USART2_MspInit 1 */
}
else if(huart->Instance==USART4)
{
/* USER CODE BEGIN USART4_MspInit 0 */
/* USER CODE END USART4_MspInit 0 */
/* Peripheral clock enable */
__HAL_RCC_USART4_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
/**USART4 GPIO Configuration
PA0 ------> USART4_TX
PA1 ------> USART4_RX
*/
GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF4_USART4;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/* USART4 interrupt Init */
HAL_NVIC_SetPriority(USART3_6_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(USART3_6_IRQn);
/* USER CODE BEGIN USART4_MspInit 1 */
/* USER CODE END USART4_MspInit 1 */
}
}
2025-06-20 5:57 AM
Hello,
First, please use </> to share your code. See this post on How to insert source code
Second, this is only for the GPIOs what about the UART conffig itsetf? do you have the same config as well?
2025-06-20 9:45 AM
Tx from STM32 to PC works?
Isn't there a physical short between Tx and Rx? This would e.g. result in loopback working even without externally shorting the pins.
Read out and check/post content of UART and relevant GPIO registers.
JW