Nios® II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
Announcements
Intel Support hours are Monday-Fridays, 8am-5pm PST, except Holidays. Thanks to our community members who provide support during our down time or before we get to your questions. We appreciate you!

Need Forum Guidance? Click here
Search our FPGA Knowledge Articles here.
12455 Discussions

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

Altera_Forum
Honored Contributor II
956 Views

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 II
202 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