2020-03-14 10:32 AM
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:
Solved! Go to Solution.
2020-03-24 11:01 AM
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.
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.
2020-03-15 04:12 AM
Solved, switch on HSI in the CLock Configuration.
Why do i have problem when use HSE and PLLCLK?
2020-03-23 03:28 AM
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.
2020-03-23 05:35 AM
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.
2020-03-23 06:53 AM
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?
2020-03-23 07:06 AM
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.
2020-03-23 07:21 AM
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).
2020-03-23 07:53 AM
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?
2020-03-23 08:03 AM
>>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
2020-03-23 08:22 AM
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.