cancel
Showing results for 
Search instead for 
Did you mean: 

how to configure stm8s microcontroller's internal oscillator clock in STVD evironment?

GURUMOORTHI KANDASAMY
Associate II
Posted on March 22, 2017 at 12:40

microcontroller :stm8s003f3p6

when I am trying to upload the code it shows following error

Error : Cannot communicate with the device !

so I was thinking this error is shown because the internal oscillator is not configured.

then I have used following internal clock configuration in STVD but it is showing error following error

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 = 0; // Turn off 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.

}

&sharperror cpstm8 main.c:13(17) invalid lvalue

&sharperror cpstm8 main.c:22(16) invalid lvalue

&sharperror cpstm8 main.c:21(0+8) CLK_SWCR undefined

&sharperror cpstm8 main.c:20(0+7) CLK_SWR undefined

&sharperror cpstm8 main.c:19(0+11) CLK_SWIMCCR undefined

&sharperror cpstm8 main.c:18(0+12) CLK_HSITRIMR undefined

&sharperror cpstm8 main.c:17(0+11) CLK_PCKENR2 undefined

&sharperror cpstm8 main.c:16(0+11) CLK_PCKENR1 undefined

&sharperror cpstm8 main.c:15(0+10) CLK_CKDIVR undefined

&sharperror cpstm8 main.c:14(0+8) CLK_ECKR undefined

&sharperror cpstm8 main.c:12(0+8) CLK_ICKR undefined

&sharperror cpstm8 main.c:41(7) missing prototype

#stvd #internal-oscillator #stm8
1 REPLY 1
Ian Legg
Senior
Posted on March 23, 2017 at 10:19

Hello,

Presuming you are using an ST-link v2, have you got it connected correctly, are the drivers installed, is STVD configured to use it etc?

The second error is because CLK_SWR (and the others) are not defined. The respective register address is unknown. These should be available in a header file from your compiler.

Also the HSI clock is enabled by default.

Thanks,

Ian