CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

What happens at the receive part when we write with SPI?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
rikotech8



Joined: 10 Dec 2011
Posts: 376
Location: Sofiq,Bulgariq

View user's profile Send private message

What happens at the receive part when we write with SPI?
PostPosted: Tue Aug 16, 2016 8:49 am     Reply with quote

Hi, I know this is not a specific CCS question, but I did't know where else to ask, moreover I have an user account here.

So this is it:

When SPI master writes to the slave, something is shifting into the receive buffer right?
If yes, then it is normal "RXDATAAVAILABLE" flag to be set? It is nonsense! We send data, and when data is sent, we get notified that there is data received.

If all of my statements are correct, then how do we know what the correct data is into the RXFIFO?

Suppose we send two bytes frame. The first one is the address and the second one is dummy in order to read the value in that address (of the slave). Then suppose we have two levels Rx FIFO. In that FIFO instead the value read from the slave, we have two bytes, the first is GOD knows what, and the second the value read from the slave.

So the question is: how do we manage to receive only what is necessary, without getting all that crap during the write part of the frame?

I know my English sucks, yet I hope you get the Idea.
_________________
A person who never made a mistake never tried anything new.
Ttelmah



Joined: 11 Mar 2010
Posts: 19520

View user's profile Send private message

PostPosted: Tue Aug 16, 2016 9:17 am     Reply with quote

That is all down to the design of the transaction.

Normally the transaction from a master will always begin with a write. The data returned during this will be defined in the slave paperwork as one of three basic possibilities. 1) A particular fixed state (1 or 0). 2) "Don't care / high impedance" 3) In some cases slaves will clock back a status byte.

So (for instance), on the 25AA040, for a 'read', the master begins by writing the 'read' command, followed by the address to read from. Only once these are sent, does it then clock back the read byte. The data on the SPI I line for the first two transactions is defined as 'high impedance' (so garbage).

Yes the master will receive the garbage bytes for the first two transactions. It is up to the code to ignore these.

There is not a buffer full flag for a master device. When the master has finished a transaction, and sent a byte the SSPIF bit gets set. The buffer full bit is only valid in slave mode. If you look at a typical PIC data sheet:
Code:

bit 0 BF: Buffer Full Status bit (Receive mode only)
1 = Receive complete, SSPBUF is full
0 = Receive not complete, SSPBUF is empty


Note 'receive only'.
rikotech8



Joined: 10 Dec 2011
Posts: 376
Location: Sofiq,Bulgariq

View user's profile Send private message

PostPosted: Tue Aug 16, 2016 1:34 pm     Reply with quote

This is exactly what I've asked for Very Happy
Thank you @Ttelmah, excellent answer.
_________________
A person who never made a mistake never tried anything new.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group