Skip to main content
David Pekin
Senior
May 10, 2019
Solved

external clock

  • May 10, 2019
  • 3 replies
  • 1111 views

..

This topic has been closed for replies.
Best answer by Tesla DeLorean

#define HSE_VALUE 20000000

3 replies

David Pekin
Senior
May 10, 2019

Sorry, that got away from me!

Anyway, I've modified the SystemClock_Config funciton as shown below to handle an external 20MHz clock coming into PF0. Besides modifying the solder bridges on the Nucleo board, the code modifications are simple as shown. Am I missing anything? Is that all that needs to be done to switch from the 8M Nucleo oscillator to a 20M external? That seems too simple.

The applicationon the Nucleo starts up by printing something to the serial port. I do get output on the serial port but it appears the baud rate is compromised since the string received is jibberish. Almost the correct number of characters. I believe this indicates that the external clock is driving the PLL and system but it's probably not clean enough. Is this a valid assumption?

My suspicion is that the 20MHz clock just needs to be cleaned up for it to work correctly, Currently I just have an external oscillator on a bread board and a 8" wire connecting the oscillator output to PF0. Time to get the EE to give a little help on signal conditioning.

Appreciate any input if I'm missing something and hope this helps the next guy wondering about external clocks.

void SystemClock_Config(void)

{

  RCC_ClkInitTypeDef RCC_ClkInitStruct;

  RCC_OscInitTypeDef RCC_OscInitStruct;

  /* HSI Oscillator already ON after system reset, activate PLL with HSI as source */

  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_NONE;

  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;

#if EXTERNAL_CLOCK

RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS;

RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;

RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;

RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV5;  //20M div 5 = 4M

#else

  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; 

  RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV2;  //8M div 2 = 4M

#endif

  RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL16; // 16 x 4m = 64m

  RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;

  if (HAL_RCC_OscConfig(&RCC_OscInitStruct)!= HAL_OK)

  {

    /* Initialization Error */

    while(1);

  }

.

.

.

}

Tesla DeLorean
Tesla DeLoreanBest answer
Guru
May 10, 2019

#define HSE_VALUE 20000000

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
David Pekin
Senior
May 13, 2019

That did it! Thanks for the help!