HCS08 - SPI Slave Mode - Data Integrity / Overwrite / Discard SPID

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

HCS08 - SPI Slave Mode - Data Integrity / Overwrite / Discard SPID

752 Views
alexanderbuerge
Contributor II


Dear Community,

I want to share data between two MCUs via SPI. One would be the Master, one would be the slave. Since the slave samples some I/O's continuously, I would like to provide always the latest status information to the master.

If I understood the principle of the SPI in HCS08 correct, this is not possible, since SPID (SPI-Data-Register) is a 2-Level FIFO.

So the sequence on the slave would be like:

1) Slave samples I/Os

2) Slave checks if SPID can be written

3) If yes, write status info into SPID

 

On the master:

Read SPI-Byte from slave at "some time".

 

However, one can see that the master always reads "old" information, e.g. if the master only reads data via SPI once in 10 minutes, it will always read information that is 10 minutes old.

 

So my question is: Is there a way to overwrite the data in SPID periodically? If yes, the slave could write new data there e.g. every 10 ms....

 

Thank you and best regards,

Alex

Labels (1)
0 Kudos
1 Reply

505 Views
tonyp
Senior Contributor II

The two-way buffer nature of SPI does not block you from doing what you want.

It's by convention that when you have nothing to say you send either an all-zero or all-ones byte.  So, the master will have to send two (or more -- depending on response size) bytes to the slave, and the slave the same number of response bytes to the master.

For example (for a single byte response case):

Master sends 0,0

Slave sends 0,value

Now, if more than one type of data is returned, then

Master sends DataID,0

Slave sends 0,value-for-given-data-id

Now, if your system is so fast that you cannot afford to 'waste' one extra SPI byte transfer per value returned, that means you need continuous data transfers at the maximum possible speed.

In which case I would question whether the data can be considered old.