cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L072RB LPUART not working

brunoeagle
Associate II

Hi, I'm not being able to make LPUART work.

What I tried:

  • Use HAL drivers.
  • Clock LPUART with LSE.
  • Use different board.

I also configured PB11 as output and it toggles normally.

PB11: TX(output)

PB10: RX(input)

This is my code:

LL_IOP_GRP1_EnableClock( LL_IOP_GRP1_PERIPH_GPIOB );
 
	// uC Tx ( PB11 / AF7 )
	LL_GPIO_SetPinMode( GPIOB, LL_GPIO_PIN_11, LL_GPIO_MODE_ALTERNATE );
	LL_GPIO_SetAFPin_0_7( GPIOB, LL_GPIO_PIN_11, LL_GPIO_AF_7 );
	LL_GPIO_SetPinSpeed( GPIOB, LL_GPIO_PIN_11, LL_GPIO_SPEED_FREQ_VERY_HIGH );
	LL_GPIO_SetPinOutputType( GPIOB, LL_GPIO_PIN_11, LL_GPIO_OUTPUT_PUSHPULL );
	LL_GPIO_SetPinPull( GPIOB, LL_GPIO_PIN_11, LL_GPIO_PULL_NO );
	// uC Rx ( PB10 / AF7 )
	LL_GPIO_SetPinMode( GPIOB, LL_GPIO_PIN_10, LL_GPIO_MODE_ALTERNATE );
	LL_GPIO_SetAFPin_0_7( GPIOB, LL_GPIO_PIN_10, LL_GPIO_AF_7 );
	LL_GPIO_SetPinSpeed( GPIOB, LL_GPIO_PIN_10, LL_GPIO_SPEED_FREQ_VERY_HIGH );
	LL_GPIO_SetPinOutputType( GPIOB, LL_GPIO_PIN_10, LL_GPIO_OUTPUT_PUSHPULL );
	LL_GPIO_SetPinPull( GPIOB, LL_GPIO_PIN_10, LL_GPIO_PULL_NO );
 
	LL_APB1_GRP1_EnableClock( LL_APB1_GRP1_PERIPH_LPUART1 );
	LL_RCC_SetLPUARTClockSource( LL_RCC_LPUART1_CLKSOURCE_HSI );
 
	NVIC_SetPriority( LPUART1_IRQn, 0 );
	NVIC_EnableIRQ( LPUART1_IRQn );
 
	LL_APB1_GRP1_EnableClock( LL_APB1_GRP1_PERIPH_LPUART1 );
	LL_RCC_SetLPUARTClockSource( LL_RCC_LPUART1_CLKSOURCE_HSI );
 
	LL_LPUART_SetTransferDirection( LPUART1, LL_LPUART_DIRECTION_TX_RX );
	LL_LPUART_ConfigCharacter( LPUART1, LL_LPUART_DATAWIDTH_8B, LL_LPUART_PARITY_NONE, LL_LPUART_STOPBITS_1 );
	LL_LPUART_SetHWFlowCtrl( LPUART1, LL_LPUART_HWCONTROL_NONE );
	LL_LPUART_SetBaudRate( LPUART1, HSI_VALUE, 9600);
	LL_LPUART_Enable( LPUART1 );
 
	while( !LL_LPUART_IsActiveFlag_TXE( LPUART1 ) );
	LL_LPUART_TransmitData8( LPUART1, 0x55 );
	while( !LL_LPUART_IsActiveFlag_TC( LPUART1 ) );

Thank you in advance!

4 REPLIES 4

Read out and check/post the LPTIM and relevant RCC and GPIO registers content.

JW

TDK
Guru

Also describe what "not working" means. Have you looked at the lines with a scope or logic analyzer?

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

Thanks JW,

The problem was that I was using LL_GPIO_SetAFPin_0_7 instead of LL_GPIO_SetAFPin_8_15...

Best Regards!

Sorry, forgot to describe it precisely. I was trying to send a byte, and nothing was appearing on the pin...