SPI doesn't work in AT91SAM7X uC

Thread Starter


Joined Feb 20, 2009
I configured the SPI as it is written in the DS:

  • SPI enabled
  • Works in Master mode
  • 8 bits per transfer
  • Fixed peripheral select
  • PCSDEC = 0 (which means that the chip selects are directly connected to the peripheral device)
  • PCS (Peripheral Chip Select) equals 7 decimal. Which means that CS number 3 is low/active.
  • SCBR (baud rate) field equals 1. Which means that the SPI clock equals the Master clock (MCK).
  • CSAAT (Chip Select Active After Transfer) equals 1. This configuration is required by the peripheral device.
  • CPOL & NCPHA = 0 & 0 accordingly.
  • RDRF (Receive Data Register Full) interrupt enabled.

The following code followed the initialization:

Rich (BB code):
for(int i=0; i<write_count; ++i)
        (AT91C_BASE_SPI0->SPI_SR & AT91C_SPI_TDRE)    // Wait for the Data Transmit Register to be empty
    AT91C_BASE_SPI0->SPI_TDR = (char)*(data + i);    // Write to the Data Transmit Register
In the first iteration of the 'for' loop, the 'while' loop gets evaluated as TRUE instantly.
Also, as I could see with a scope, the clock stayed low after writing to the Transmit Data Register. Which means that the data doesn't transmitted to the peripheral device that's connected to the SPI pins.

In the second iteration of the 'for' loop, the processor gets stuck in the 'while' loop forever.

What did I do wrong?
Am I need to configure something with the PDC?

Thanks for your attention


Thread Starter


Joined Feb 20, 2009
Apparently the MCU is problematic.

I saw with a scope that the Chip Select goes high for 17usec, but the data is transmitted for a much longer time.
In short: CS is driven low way too soon.

I've tried to activate both SPI0 and SPI1 interfaces but it seems that they both fail to act properly.

In addition - while connecting a floating probe cable, the processor gets stuck in the 'while' loop that I've written in the code above.

I appreciate any advice. Thank you.

Note: All the tests that I've done - do not appear in the errata section.