Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
19 years ago

SPI RX problems

Hi

I am trying to receive data via SPI on the Nios II using a Cyclone II. The Nios is the slave and the SPI master transmits data at 2MHz.

I have tested transmitting data from the Nios to the SPI master and that worked fine.

I have written the following code to test the receiving of data:

//SPI RX

while (1) {

//clears the status register

IOWR_ALTERA_AVALON_SPI_STATUS(SPI_0_BASE, 0);

//if new byte arrived via SPI

if ((IORD_ALTERA_AVALON_SPI_STATUS(SPI_0_BASE) & ALTERA_AVALON_SPI_STATUS_RRDY_MSK) == 1){

//read the byte and print it to screen

printf("%x\n", (IORD_ALTERA_AVALON_SPI_RXDATA(SPI_0_BASE) & 0x0FF));

}

}

The IF statement never becomes true. I have removed the IF and read the RXDATA. The data that the SPI master transmitted is correctly received in the RXDATA buffer but the the RRDY bit never goes high.

Does anyone have any idea why this not working? Am I doing it correctly, because I used a similar approach to TX data and that worked.

Thank you

Eric

13 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I looked back as far as message# 6.

    FWIW your code requires all bits of altera_avalon_ spi_status_rrdy_msk to be set.

    The code in message# 6 any bit at all.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Yes, you are right, the post# 6 is correct, I was inattentive.

    ALTERA_AVALON_ SPI_STATUS_RRDY_MSK consist of only 1 bit.

    I write in different programming languages, and prefer to put boolean value (0 or 1) in conditional statement.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Explicit comparisons like that can cause compilers to generate extra instructions. Comparisons against zero (as below) are ok:

    if ((foo & FOO_BIT) != 0)
    but need extra parenthesis.