cancel
Showing results for 
Search instead for 
Did you mean: 

Switching MSI to HSI on STM32L1

JFELI.13
Associate III

Hi,

I have a problem: in my soft, initial setup is for MSI mode (this because, in "stop mode" it will return in this mode) but I want to choose STM32L1 mode, in MSI mode (2.097Mhz) or in HSI (16Mhz) mode

When I select HSI mode (after initial MSI setup) everything seem ok (timer 100ms is accurate) ... except when I'm using a delay function: delay become very short ( perhaps 1/3)

I did a register comparison (RCC_CR, RCC_CFGR, RCC_APB1RSTR,RCC_APB1ENR...) between initial HSI or MSI setup but I can't see the problem.

Any suggestion ?

Thanks for help

void STM32L151_HSI()

{

  unsigned int TimeOut=0xFFFF;

   

  RCC_CR.HSION=1;

  while(!RCC_CR.HSIRDY && TimeOut--);

  RCC_CFGR.SW0=1;

  while(!RCC_CFGR.SWS0);

  RCC_CR.MSION=0;

   

}

13 REPLIES 13
TDK
Guru

> It appear delay_ms function is not updated when clock change. Is it the problem ?

Sure seems like that would be a problem to me.

I would also use a delay function based on systick or other fixed timer interval rather than one that requires the CPU to be utilized 100% for the duration. With the latter, interrupts during the delay will cause the delay to be longer than intended.

If you feel a post has answered your question, please click "Accept as Solution".
JFELI.13
Associate III

If this is the problem I will have to do my own delay function (using timer)

JFELI.13
Associate III

OK, thanks a lot.

I use a 100ms timer and will add a function in it (I don't need exact delay)

Regards

JFELI.13
Associate III

But I also need to control if serial port speed is OK too................... perhaps I will have the same problem.......