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?

Parents
  • Quite a number of SPI slaves have problems reacting to a byte transfer, to pick up the byte from the master and emit a new outgoing byte.

    There will alsways be a race condition, unless the SPI slave has at least one read buffer and one write buffer so the program can get the full byte transfer time to respond, instead of having a half bit-time to do the read+write.

    Without buffering, the SPI will only consist of a latching shift register, where read+write must be performed between two shifts.

    A number of the NXP chips have not only one or more SPI devices, but also one or more SSP devices, where the SSP device can be configured to use the SPI protocol, but with full receive and transmit FIFO.

Reply
  • Quite a number of SPI slaves have problems reacting to a byte transfer, to pick up the byte from the master and emit a new outgoing byte.

    There will alsways be a race condition, unless the SPI slave has at least one read buffer and one write buffer so the program can get the full byte transfer time to respond, instead of having a half bit-time to do the read+write.

    Without buffering, the SPI will only consist of a latching shift register, where read+write must be performed between two shifts.

    A number of the NXP chips have not only one or more SPI devices, but also one or more SSP devices, where the SSP device can be configured to use the SPI protocol, but with full receive and transmit FIFO.

Children