cancel
Showing results for 
Search instead for 
Did you mean: 

Use ADC and USARt1 in STM8L151C6

ninjas005
Associate

I am a newbie into the world of embedded systems.

is it possible to enable clock for ADC and TIM4 overflow update.

```

       CLK_DeInit();
 
        CLK_LSICmd(DISABLE);	// Use internal clock.
	CLK_HSICmd(ENABLE);
	while(CLK_GetFlagStatus(CLK_FLAG_HSIRDY) == FALSE);	// Wait for clock to stabilize
 
	CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_HSI);
	
	CLK_PeripheralClockConfig(CLK_Peripheral_ADC1, ENABLE);
        CLK_PeripheralClockConfig(CLK_Peripheral_TIM4, ENABLE);

```

Last 2 lines are confusing me. I guess this code make TIM4 working and not ADC.

pls help me.

2 REPLIES 2
Artur IWANICKI
ST Employee

Hello,

Last two lines are enabling clock from the data bus to the peripheral registers. It should be done before any write/read attempt to those peripherals registers. In STM8L devices most of the peripherals has been disconnected from the bus clock to limit the current consumption. Then it is up to the user to connect clock to the peripheral prior its configuration. This technique is called 'Peripheral clock gating". You can find more information within application note AN3147, point 4.4:

https://www.st.com/resource/en/application_note/an3147-power-management-in-stm8l-and-stm8al-stmicroelectronics.pdf

Additionally you can have a look at point 9.7 within reference manual RM0031:

https://www.st.com/resource/en/reference_manual/rm0031-stm8l050j3-stm8l051f3-stm8l052c6-stm8l052r8-mcus-and-stm8l151l152-stm8l162-stm8al31-stm8al3l-lines-stmicroelectronics.pdf

Best Regards,

Artur Iwanicki,

/STMicroelectronics/

ninjas005
Associate

Hello,

Really thank you very much @Artur IWANICKI​ . I was in a confusion that only one peripheral should only be connected to the clock at a time. Now the confusion is over, I really need a time counter of 2ms and ADC to work simultaneously.

Your answer helped me a lot.

Regards,

Vivek