cancel
Showing results for 
Search instead for 
Did you mean: 

Board: NUCLEO F103RB I have this problem with UART, the serial monitor show: x⸮x⸮x⸮x⸮... Why i have this beaheviour? I use UART2 (PA2 - PA3 board pin) and I connect the board at the PC trought USB cable.

Francesco_
Associate II

This is the code:

 /* USER CODE BEGIN WHILE */

 while (1)

 {

HAL_GPIO_WritePin(GPIOA , LED_Pin, GPIO_PIN_SET);

HAL_Delay(10);

HAL_GPIO_WritePin(GPIOA , LED_Pin, GPIO_PIN_RESET);

HAL_Delay(10);

char p[] = "128";

HAL_UART_Transmit(&huart2, (uint8_t*)p , sizeof(p), HAL_MAX_DELAY);

HAL_Delay(200);

 }

This is the UART config:

/* USER CODE END USART2_Init 1 */

 huart2.Instance = USART2;

 huart2.Init.BaudRate = 9600;

 huart2.Init.WordLength = UART_WORDLENGTH_8B;

 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;

 if (HAL_UART_Init(&huart2) != HAL_OK)

 {

  Error_Handler();

 }

The attachment show the clock configuration:0693W000000TwCNQA0.png

1 ACCEPTED SOLUTION

Accepted Solutions

You are hard to help. You have no test equipment, you don't post a complete compilable project.

Check that the solder bridges (SB) for the MCO / HSE are present. This may depend on board version in uses, and most of the HAL examples for the NUCLEO-F103RB use HSI to clock at 64 MHz. Boards MB1136 C-01 don't have HSE connected.

https://www.st.com/resource/en/user_manual/dm00105823-stm32-nucleo64-boards-mb1136-stmicroelectronics.pdf

Check

SB54 ON

SB55 OFF

SB16 ON

SB50 ON

>>HAL_UART_Transmit(&huart2, (uint8_t*)p , sizeof(p), HAL_MAX_DELAY);

Use strlen() or sizeof()-1 so you don't transmit the NUL characters

This uses USART1 via PA9 / PA10, clocks the board at 64 MHz, you could modify this

STM32Cube_FW_F1_V1.8.0\Projects\STM32F103RB-Nucleo\Examples\UART\UART_Printf

Would be usable with a USB-to-CMOS Serial type adapter from SiLabs, etc.

In the days prior to having a scope, I used a Logic Probe to identify High, Low, and Clocking signals.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

13 REPLIES 13
Francesco_
Associate II

Solved, switch on HSI in the CLock Configuration.

Why do i have problem when use HSE and PLLCLK?

Francesco_
Associate II

Can someone help me?

UART2 works correctly only if PCLK1 = 8 MHz with HSI source at 8 MHz. I want UART2 works correctly with the same of clock configuration on the picture.

TDK
Guru

Take a look at "6.7.1 OSC clock supply" in the user manual UM1724.

Set up the HSE clock in BYPASS mode and it should work.

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

Hi TDK,

thanks for your attention.

I have change HSE in BYPASS mode: RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS, however the UART print: x⸮

I think that there is a problem in BRR register. Why if PCLK1 = 36 MHz at 9600 boud the value of BRR is 0x00000068?

I think that should be 0x00000EA6 (36.000.000/9600). It is correct?

TDK
Guru

You have a clock problem somewhere. Note that 0x68 * 9600 = 1MHz so the system might be set at that rate for some reason. You should verify your system clock is getting set correctly. Or it could be a CubeMX bug.

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

This is the Clock Configuration:

void SystemClock_Config(void)

{

 RCC_OscInitTypeDef RCC_OscInitStruct = {0};

 RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

 /** Initializes the CPU, AHB and APB busses clocks 

 */

 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;

 RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS;

 RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;

 RCC_OscInitStruct.HSIState = RCC_HSI_ON;

 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;

 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;

 RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;

 if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)

 {

  Error_Handler();

 }

 /** Initializes the CPU, AHB and APB busses clocks 

 */

 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK

               |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;

 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;

 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;

 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;

 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

 if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)

 {

  Error_Handler();

 }

}

Where could be the problem? The clock configuration is consistent with the picture ( CubeMX).

0693W000000UWDvQAO.png

Francesco_
Associate II

Also RCC_CFGR = 0x001D3F00 is wrong! Because APB1 and APB2 prescaler are set on "HCLK divided by 16", but should be set on "HCLK divided by 2" and "HCLK not divided" rispectivly.

Why I have this issue?

>>Why I have this issue?

Going to have to debug and examine registers and code. Hard to troubleshoot remotely with random code fragments.

Make sure HSE_VALUE is defined correctly. Use a scope, check the clock sources, and bit rates.

Perhaps try using the HAL examples, rather than use CubeMX

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Francesco_
Associate II

Thanks clive1,

"Going to have to debug and examine registers and code" -> I check that RCC_CR = 0x01074983, HSE source is enabled. I search HSE_VALUE, i think that is ok.

#if !defined (HSE_VALUE) 

 #define HSE_VALUE        8000000U /*!< Default value of the External oscillator in Hz.

                        This value can be provided and adapted by the user application. */

#endif /* HSE_VALUE */

"Use a scope, check the clock sources, and bit rates." -> I don't have an instrument.