cancel
Showing results for 
Search instead for 
Did you mean: 

STM8S - SPI not working after power-on reset (yes, it strange)

oleg239955_st
Associate II
Posted on March 19, 2012 at 19:01

I trying to develop device using STM8S105K6 MCU and found something very strange.

If I press reset button (connecting NRST to GND) all if working fine.

But If I just turn off/on device power, MCU is starting (timer is working, LED is flashing, and so on), but SPI is not working (to be more exact, it not clears TXE flag).

This is my code for init:

     SPI_CR1_bit.BR = 1;

     SPI_CR1_bit.MSTR = 1;

     SPI_CR1_bit.CPOL = 0;

     SPI_CR1_bit.SPE = 1;

This is a little bit later in main:

         SPI_DR = 0x55; // test

         while (!SPI_SR_bit.TXE) { // here we got infinite loop :(

               PB_ODR_bit.ODR5 = 1;

               PB_ODR_bit.ODR5 = 0;

          }

 

If I do manual reset, all is starting to work fine. But If I just turn power off/on, it goes to infinite loop inside WHILE (and I can see this by oscilloscope by changing voltage on PB5 pin).

Another fact: If I will heat MCU by soldering iron or soldering station - it starting to work, but then it makes cold, and not working again.

Where is my problem (I hope not in my DNA :)?

What I should do to get stable working of MCU?

Thanks in advance!

#problem #reset #spi #stm8s
4 REPLIES 4
oleg239955_st
Associate II
Posted on March 19, 2012 at 20:08

Hmm..

I have tried to add ~5ms delay between initialization of MCU and SPI, and all started to work even in power-on sequence!

I still not understand what happened and why.

What is right workaround for this?
Stm32User
Associate II
Posted on April 24, 2012 at 14:20

Strange behaviour like this is often power supply related.  If the problem occurs only when you cycle the power and is 'fixed' with a delay then the problem is related to the rise time of the power supply and/or power on reset of the device 

espectro
Associate
Posted on May 08, 2012 at 11:43

Just try to connect 10kOm resistor between ground and SCK pin.

rossihwang
Associate
Posted on February 10, 2013 at 11:02