cancel
Showing results for 
Search instead for 
Did you mean: 

problem with UART receiving - IDLE low all time

yabool2001
Associate III

Hi,

I'm developing STM32G031 UARTs using registers and the CMSIS library. I’m using NUCLEO-G031K8 UART2 over an embedded STLINK/V3 on board and UART1 over an external CP210x UAR/USB adapter.  I have a problem receiving data to UART1. No problem to receive data to UART2. Also both UARTs transmissions are working properly. I’m using the same configuration:

 

// USART1_TX = PA9
// USART1_RX = PA10
// USART2_TX = PA2
// USART2_RX = PA3

void my_uart1_conf ( void )
{
	RCC->IOPENR 	|= RCC_IOPENR_GPIOAEN ;		// Activate clock in GPIOA
	GPIOA->MODER 	&= ~GPIO_MODER_MODE9_0 ; 	// Set Alternate Function (AF) for USART1_TX
	GPIOA->MODER 	&= ~GPIO_MODER_MODE10_0 ; 	// Set Alternate Function (AF) for USART1_RX
	GPIOA->AFR[1]	|= GPIO_AFRH_AFSEL9_0 ;  	// AFRH is AFR[1]. Choose AF1
	GPIOA->AFR[1]	|= GPIO_AFRH_AFSEL10_0 ;  	// AFRH is AFR[1]. Choose AF1
	GPIOA->OTYPER	|= GPIO_OTYPER_OT10 ; 		// Choose Open_drain for RX to avoid P-MOS transistors issues
	//GPIOA->PUPDR	|= GPIO_PUPDR_PUPD10_1 ;	// Rx Pull-up
	RCC->IOPENR 	|= RCC_IOPENR_GPIOAEN ;		// Activate clock in GPIOA
	RCC->APBENR2	|= RCC_APBENR2_USART1EN ;
	USART1->BRR 	=  (uint16_t) ( 16000000 / 115200 ) ;			// Activate clock for UART
	USART1->CR1 	|=  USART_CR1_UE ;
	USART1->CR1 	|=  USART_CR1_TE ;
	USART1->CR1 	|=  USART_CR1_RE ;
}

void my_uart2_conf ( void )
{
	RCC->IOPENR 	|= RCC_IOPENR_GPIOAEN ;		// Activate clock in GPIOA
	GPIOA->MODER 	&= ~GPIO_MODER_MODE2_0 ; 	// Set Alternate Function (AF) for USART2_TX
	GPIOA->MODER 	&= ~GPIO_MODER_MODE3_0 ; 	// Set Alternate Function (AF) for USART2_RX
	GPIOA->AFR[0]	|= GPIO_AFRL_AFSEL2_0 ;  	// AFRL is AFR[0]. Choose AF1
	GPIOA->AFR[0]	|= GPIO_AFRL_AFSEL3_0 ;  	// AFRL is AFR[0]. Choose AF1
	GPIOA->OTYPER	|= GPIO_OTYPER_OT3 ; 		// Choose Open_drain for RX to avoid P-MOS transistors issues
	RCC->IOPENR 	|= RCC_IOPENR_GPIOAEN ;		// Activate clock in GPIOA
	RCC->APBENR1	|= RCC_APBENR1_USART2EN ;
	USART2->BRR 	= (uint16_t) ( 16000000 / 115200 ) ;			// Activate clock for UART
	USART2->CR1 	|=  USART_CR1_UE ;
	USART2->CR1 	|=  USART_CR1_TE ;
	USART2->CR1 	|=  USART_CR1_RE ;
}

 

In debug mode I verified GPIOA, UART1 and UART2 configuration and all registers’ values are the same. Exception is an ISR. There are following differences on ISRs register after UARTs configuration:

ISR Register

UART1

UART2

CMF

1

0

RXNE

1 (goes 0 after some time)

0

IDLE

0

1

FE

1

0

I tried also:

  • change UART/USB adapter,
  • different mix of UART1 OTYPER and PUPDR configuration,

without success.

 

Do you have an idea what I should change in GPIOA or USART1 configuration to be able to receive data to UART1?

V/r

yabool2001

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

If FE (frame error) is set, that suggests the signal coming in in USART1_RX is invalid. Can you view it on a scope or logic analyzer?

Have you tried the setup in CubeMX and comparing the configuration of USART and GPIO registers?

 

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

2 REPLIES 2
TDK
Guru

If FE (frame error) is set, that suggests the signal coming in in USART1_RX is invalid. Can you view it on a scope or logic analyzer?

Have you tried the setup in CubeMX and comparing the configuration of USART and GPIO registers?

 

If you feel a post has answered your question, please click "Accept as Solution".

Tried CubeMX setup and differen setting and HAL library without success. But your suggestion to check signal on a scope (I'don't have) goaded me to change pins to PB6-7 and it works! So probably my PA10 pin has been broken.

Thanks for inspiration.