Forum: ARM programming with GCC/GNU tools sam9g45 SPI problem

von Roman Bel (Guest)

Rate this post
0 useful
not useful
Dear Mr,

I have problem with SPI interface on SAM9G45.  Osciloscope is connected 
to MOSI, SCK, CS wire. I set SPI interface to 8bit mode, master mode. If 
I send 8bit word to TDR(transmit data register), I see on scope always 
previous 8bit word. I try to write this problem on example:

1.     while ((*AT91C_SPI0_SR & AT91C_SPI_TXEMPTY) == 0){};

2.    *AT91C_SPI0_TDR=0xF1;

3.    while ((*AT91C_SPI0_SR & AT91C_SPI_TXEMPTY) == 0){};

4.    *AT91C_SPI0_TDR=0x01;

At note 1. im waiting for clear transmit buffer

At note 2. im  transmiting number 0xF1

At note 3. im waiting for clear transmit buffer

At note 4. im transmiting number 0x01. I see on my osciloscope that 
number is not 0x01 but 0xF1!!! Transmit function, as I know from Atmega 
chips and AVR32 chips, would transmit 0x01.

I think setting of SPI interface is good. But where is the problem?

All setting code is here:

void spi_init(void)


      uint32_t baudrate;

      *AT91C_PMC_PCER= SPI0_PERIPH_ID; //clock for spi0 enabled


      *AT91C_SPI0_CR=AT91C_SPI_SWRST;  //reset

      *AT91C_SPI0_CR=AT91C_SPI_SWRST;  //reset

*AT91C_SPI0_MR=AT91C_SPI_MSTR | AT91C_SPI_MODFDIS;//master mode, disable 
fault detection

      baudrate = BOARD_MCK/1000000;//1Mbit

      *AT91C_SPI0_CSR=AT91C_SPI_BITS_8 | AT91C_SPI_CPOL | 
AT91C_SPI_NCPHA | ((baudrate&0xFF)<<8) |AT91C_SPI_DLYBS;//| 





Thank you, RB


Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]

Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.