SPI doesn't work in AT91SAM7X uC

Discussion in 'Embedded Systems and Microcontrollers' started by dor, Oct 16, 2009.

  1. dor

    Thread Starter Active Member

    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:

    Code ( (Unknown Language)):
    1. for(int i=0; i<write_count; ++i)
    2. {
    3.     while(!
    4.         (AT91C_BASE_SPI0->SPI_SR & AT91C_SPI_TDRE)    // Wait for the Data Transmit Register to be empty
    5.     );
    7.     AT91C_BASE_SPI0->SPI_TDR = (char)*(data + i);    // Write to the Data Transmit Register
    8. }
    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

  2. KitCarlson


    Sep 27, 2009
    Are you using pull-up resistors on the lines?
  3. dor

    Thread Starter Active Member

    Feb 20, 2009
    yes - the uC internal pull-up resistors as far as I know.
    Also I'm using the Evaluation Kit.
  4. dor

    Thread Starter Active Member

    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.