2009-09-24 02:45 AM
SPI like shift register
2011-05-17 04:24 AM
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 ...2011-05-17 04:24 AM
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, Danish2011-05-17 04:24 AM
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.2011-05-17 04:24 AM
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.