Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Altera_Forum
Honored Contributor I
808 Views

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,
0 Kudos
1 Reply
Altera_Forum
Honored Contributor I
54 Views

Hi, 

 

1. SPI Slave or Master configuration? 

The same code is been discussed on previous thread,You can refer links. 

http://www.alterawiki.com/wiki/spi_core 

https://alteraforum.com/forum/showthread.php?t=51485 

 

Best Regards, 

Anand Raj Shankar 

(This message was posted on behalf of Intel Corporation)
Reply