This is my first project with a ST mcu, I use a STM8S207K8, and the environment tool IAR. I use the internal oscillator, HSI at 16Mhz. One request is to output the CLK on an external pin. I noticed that pin PD0, has the CLK_CCO functionality, but I don't kow how to remap it.
Could you help me please?
In a recent project I used the following code to set the STM8S to do exactly what you are trying to do and I used the following code:
//--------------------------------------------------------------------------------//// Setup the system clock to run at 16MHz using the internal oscillator.//void InitialiseSystemClock(){ CLK_ICKR = 0; // Reset the Internal Clock Register. CLK_ICKR_HSIEN = 1; // Enable the HSI. CLK_ECKR = 0; // Disable the external clock. while (CLK_ICKR_HSIRDY == 0); // Wait for the HSI to be ready for use. CLK_CKDIVR = 0; // Ensure the clocks are running at full speed. CLK_PCKENR1 = 0xff; // Enable all peripheral clocks. CLK_PCKENR2 = 0xff; // Ditto. CLK_CCOR = 1; // Turn on CCO. CLK_HSITRIMR = 0; // Turn off any HSIU trimming. CLK_SWIMCCR = 0; // Set SWIM to run at clock / 2. CLK_SWR = 0xe1; // Use HSI as the clock source. CLK_SWCR = 0; // Reset the clock switch control register. CLK_SWCR_SWEN = 1; // Enable switching. while (CLK_SWCR_SWBSY != 0); // Pause while the clock switch is busy.}
One thing you will have to check is the output of the CCO pin. I found that I get a reasonable square-ish wave when operating a lower frequencies (i.e. 2 MHz) but when you get to 16 MHz the output is not very good. The clock signal oscilates between about 1.5 and 3V at 16 MHz.. I have found that by feeding the output through a logic gate (I used an AND gate with one input tied high) you can get a usable clock signal out of the CCO pin.
BTW, the only reason I used an AND gate was because I had some single AND gates in stock from a previous project.
Hope this helps,
Mark