cancel
Showing results for 
Search instead for 
Did you mean: 

16bit SPI on STM8

tnn1985
Associate II
Posted on March 17, 2011 at 13:19

16bit SPI on STM8

4 REPLIES 4
tnn1985
Associate II
Posted on May 17, 2011 at 15:12

Seems like nobody can help me with that. I also tried BitBanging but it doesnt work either.

fggnrc2
Associate II
Posted on May 17, 2011 at 15:12

Hello tnn!

Some years ago, I read this ST7 Application Note

http://www.st.com/internet/com/TECHNICAL_RESOURCES/TECHNICAL_LITERATURE/APPLICATION_NOTE/CD00004301.pdf

which should work for STM8 too.

I hope it could help you...

EtaPhi

tnn1985
Associate II
Posted on May 17, 2011 at 15:12

Hi,

actually i want to write something TO the Master. If i send something like :

void sendValue (signed short int value)

{

    unsigned char UpperByte = (unsigned char) (value >> 8);

    unsigned char LowerByte = (unsigned char) (value >> 0);

    //Value is Transmitted in bit 14:3

//    while (SPI_GetFlagStatus(SPI_FLAG_TXE) == RESET);

    //!!!!!first bit (bit 15) doesnt care)

    SPI_SendData(UpperByte);

//    while (SPI_GetFlagStatus(SPI_FLAG_TXE) == RESET);

    //!!!!!last three bits (bit 2:0) doesnt care)

    SPI_SendData(LowerByte);

   

}

it sends the UpperByte twice. One time in the first 8 clock cycles and the second time in the second 8 clock cycles.

tnn1985
Associate II
Posted on May 17, 2011 at 15:12

Ok, this should work. I guess the problem was that the interna Clockl f_Master was set to Clock/8 by default (HSIDIV = 8). My application has a SPI-Frequency of 2Mhz. The problem is that the highest frequency of SPI can only set to f_Master/2, which means i could only reach 1Mhz. I switched to 16Mhz High Speed External Oscillator no Prescaler to solve this problem.

 while (SPI_GetFlagStatus(SPI_FLAG_TXE) == RESET) lines need to be uncommented!!!