cancel
Showing results for 
Search instead for 
Did you mean: 

Reading from SPI (Bidirectional one line)

talhakoc
Associate
Posted on June 02, 2012 at 05:01

Hi all,

I'm trying to use the SPI interface of a TFT controller that uses only one line for write and read. I have the following problem:

1)First I set the SPI direction as Tx and write one byte data to the line, the clock is automatically generated.

2)Next, I use SPI_BiDirectionalLineConfig(SPI_Direction_Rx) to change direction.

3)But how am I going to read data from the same line, because the clock is not generated? Should I write something dummy to generate the clock? But the line is Rx now, and wouldn't it be meaningless to write in this mode? I really got stuck here.

Here is my setting for SPI:

/* SPI configuration -------------------------------------------------------*/

SPI_I2S_DeInit(SPI2);

SPI_InitStructure.SPI_Direction = SPI_Direction_1Line_Tx;

SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;

SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;

SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;

SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;

SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4;

SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;

/* SPI_InitStructure.SPI_CRCPolynomial = 7;*/

SPI_InitStructure.SPI_Mode = SPI_Mode_Master;

SPI_Init(SPI2, &SPI_InitStructure);

0690X00000605UAQAY.png

stm32f4-spi

1 REPLY 1
Posted on June 02, 2012 at 16:48

The use of throwaway writes on SPI buses is quite common, the fact the signal goes nowhere, or the device ignores it makes no difference, the purpose is to generate a clock.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..