SPI BiDirectional Newbie in need of help!

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Hello All,

   

 

   

I am an absolute newbie to SPI and using it with these PSoCs.

   

I have not found adequate documentation or examples on how to perform SPI Master READ.

   

I am able to write data to the SPI slave device, however how do you read data?

   

Using Oscilloscope, I can see that the SCLK pin is driven during a write operation, but it is not being driven during a read command!!! (It remains low)

   

I call:

   

SPIM_WriteTxData(0x80);

   

while((SPIM_ReadTxStatus()&8)==0);

   

SPIM_WriteTxData(0x10);

   

while((SPIM_ReadTxStatus()&8)==0);

   

SPIM_TxDisable();
        
PSOC_DEBUG_BUF[15] = SPIM_ReadRxData();

   

I can see SCLK and SDIO is driven during the two write cycles, and the correct bits are set, however SCLK is never driven for the SPI Slave Device to write data!!

   

How is SCLK driven for read mode?

   

-Thank you!

   

-Gytis

0 Likes
4 Replies
Anonymous
Not applicable

NEVERMIND ,

   

 

   

CASE SOLVED--- SPI is not a standard serial programming interface (send byte, receive byte)

   

There is a huge difference... SPI alternates data senders (master/slave)  every bit, not between bytes.

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable
        Hi Gytis, Please find attached example project for SPI bidirectional implementation. Kindly go through the project. As mentioned in the example project we need to clear the SPIS and SPIM FIFOs as specified and also we need to initiate a dummy SPIM write operation (when SPIM Tx is disabled) in order to generate SCLK as required by the slave. Hope the example project will be helpful for you. Thanks, Goverdhan   
0 Likes
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

SPI does not 'alternate' the direction 'per bit' - its just full-duplex (which means that data can be transferred in both directions at the same time).

   

So when a slave transmits data to the master, the clock needs to be working, so the master needs to generate it. To do that, typically a dummy value is transmitted by the master.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

When using SPI in bidirectional mode have a look at the two pictures in the SPI datasheet page 2. They show exactly what is going on.

   

Clock is always generated by the master.

   

Data is always fed back into the sender (master or slave)

   

 

   

The SPI interface is byte-oriented, there is no direction-switching at bit-wise level.

   

 

   

Bob

0 Likes