Problem with SPI in bidirectional mode

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

cross mob
Anonymous
Not applicable

I am trying to use the SPI Master block in bidirectional mode (only one sdat pin instead of MOSI and MISO). I can't seem to get a read signal. Is there anything specific I need to do in the programming or in the TopDesign differently from the MOSI/MISO mode? How should I be using TxEnable/TxDisable methods?

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

When reading from SPI you have to call SPIM_TxDisable() before, when wanting to transmit call SPIM_TxEnable().

   

Not working communication is mostly caused by different clock / mode, check that twice.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Thank you for your response.

   

I have been using TxEnable/TxDisable before and after reading and writing. I measured the clock cycle on the oscilloscope and it was at the correct frequency required for our application. The mode also seems to be correct. However, is there anything else on the sdata pin that I need to change (like open drain/strong drive etc.)? Also, should I clear the buffer upon every read and write? And I discovered that CheckBufferSize() seems to take the data from the buffer. How does that function?

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

Can you post your project here so that we can have a look at? Maybe there is something not as you want it.

   

To do so, select Build->clean project

   

File->create workspace bundle(minimal)

   

Then upload the compressed file here.

   

 

   

Bob

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

 I have attached the zip file. Thank you.

0 Likes
Anonymous
Not applicable

A couple of things,

   

1.Get the latest PSoC Creator

   

2. I noticed you have connected the Chip Select pin to your SPI module directly.

   

I think thats the issue.You see,that is one devious chip select on the SPI module.The problem is,the SPI master toggles this around sending and getting a byte.when ideally,it should be toggled around a transaction.

   

Solution?

   

Toggle the CS manually,around an entire transaction.

   

AccSPI_CS_Write(0);

   

//Send SPI command to accelo

   

//Get some funky data back

   

AccSPI_CS_Write(1);

   

I guess that should do it.

0 Likes
Anonymous
Not applicable

i.e it should look like this-->

   

Note that Reset should be connected to 0..(but oddly enough even the example project in the recent edition of creator doesnt..)

   

 

   

0 Likes
Anonymous
Not applicable

 Hi,

   

I'm trying to use the SPI master in the same way.

   

So far I've been able to read data as well.

   

The issue got is when managing the bidirectional I/O.

   

When I switch form input to output, it seems get locked in that state.

   

It has been one of the questions mentionned above. 

   

Do we have to manage the bidirectional I/O drive mode when using SPI 3-wire?

   

 

   

Thank you for your time.

   

 

   

David

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

Datasheet says for SPIM

   

SPIM_TxEnable() and SPIM_Tx_Disable() API functions should be used to switch between Rx and Tx mode.

   

and for SPIS

   

SPIS_TxEnable() and SPIS_Tx_Disable() API functions should be used to switch between Rx and Tx mode.

   

 

   

Bob

0 Likes