Forum Discussion

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

Three lines of code to read/write codec SPI data each sample?

Hi.

I have a NIOS2 design that requires real time data in and out via codec.

I'll be processing one data point at a time.

My code will read SPI for data ready, when ready - write data to SPI, then read returned data from SPI.

I ran across the following code on the next thread over - it uses only IOWR and IORD functions, so it is simpler than the examples i've studied, but it's about the complexity i would hope for, for simple A/D/A to/from NIOS2.

Does this code look OK as is? I guess i will need to add a 'reset data-ready flag' instruction, right?

# include <altera_avalon_spi_regs.h># include <altera_avalon_spi.h>

main{

int test;

while (!(IORD_ALTERA_AVALON_SPI_STATUS(SPI_BASE) & ALTERA_AVALON_SPI_STATUS_TRDY_MSK));

IOWR_ALTERA_AVALON_SPI_TXDATA(SPI_BASE, 0xFFFF);

test=IORD_ALTERA_AVALON_SPI_RXDATA(SPI_BASE);

}

To recap then - Is this all i need (in main C NIOS2) to poll, write, read? Any obvious things Missing?

Thanks all,