cancel
Showing results for 
Search instead for 
Did you mean: 

SPI like shift register

pvandroux9
Associate II
Posted on September 24, 2009 at 11:45

SPI like shift register

4 REPLIES 4
pvandroux9
Associate II
Posted on May 17, 2011 at 13:24

Hello,

I would use the SPI like a shift register (slave mode), ie transmit again the data received. how and when write SPI1->DR with the data in the same SPI1->DR ?

It work OK with 2 SPI in slave mode(SP1 receiver and SPI2 transmiter) but i don't anderstand why it doesn't work with one SPI ...

danish
Associate II
Posted on May 17, 2011 at 13:24

Presumably you tried:

SPI1->DR = SPI1->DR;

I would expect that to work because DR is declared as volatile so reads and writes should not be optimized away.

But if it does not, you would need to do something along the lines of

temp = SPI1->DR;

SPI1->DR = temp;

Hope this helps,

Danish

pvandroux9
Associate II
Posted on May 17, 2011 at 13:24

i try this but it doesn't work :

...

// SPI1 configuration (slave mode)

SPI_I2S_DeInit(SPI1);

SPI_StructInit(&SPI_InitStructure);

SPI_InitStructure.SPI_DataSize = SPI_DataSize_16b;

SPI_Init(SPI1, &SPI_InitStructure)

// Enable SPI1

SPI_Cmd(SPI1, ENABLE);

...

//Enable RX SPI1 interrupt.

SPI_I2S_ITConfig(SPI1,SPI_I2S_IT_RXNE, ENABLE);

void SPI1_IRQHandler(void)

{

u16 data;

data = SPI_I2S_ReceiveData(SPI1);

while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);

SPI_I2S_SendData(SPI1, data);

}

The SPI send anything.

pvandroux9
Associate II
Posted on May 17, 2011 at 13:24

news of my problem.

Read SPI->DR and write itself work only if CPHA=0 and CPOL=1 !!

If CPOL=0 it doens't work.

I do not understand why.