This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Periodic SPI Data Corruption

I have noticed intermittant data corruption while using the SPI on an LPC 2103:

If the master is generating the clock so the slave can provide data to the master and if a SPDR 'read delay' is not used in the SPI ISR prior to reading the data (and sending the next clock byte) the next data byte received is corrupted.

According to NXP (which took great care I see in describing the terminating conditions of each device):

"When a master, this bit is set at the end of the last cycle of the transfer. When a slave, this bit is set on the last data sampling edge of the SCK."

I read this as the following (crude drawings included):

If this is the last SCK pulse, the master sets its SPIF when the end of the last cycle is over:

---\ 
    \ set
     \ |
      \|
       |
 SCK


If this is the last SCK pulse, the slave sets its SPIF on the last data sampling edge:

  set
   |
---\ 
   |\ 
   | \ 
      \ 
 SCK


I have read the 2103 errata concerning the SPI if CPHA = 0 but the settings for these devices are CPOL = 0, CPHA = 1, so that is not the problem.

The SPSR is read prior to the SPDR (with delay in between the SR and data register accesses. If the delay is set to 8 iterations or more, there is no data corruption (delay via NOPs or equivalent).

The master SPI clock supports NXP requirement: "As a result, bit 0 must always be 0. The value of the register must also always be greater than or equal to 8."

Is it possible that this corruption is a result of the timing differences between the master and slave SPIF notifications or does this seem to be something more fundamental? Or has anyone else ever seen this?