--- Quote Start ---
originally posted by mondoemme+dec 4 2006, 11:53 am--><div class='quotetop'>quote (mondoemme @ dec 4 2006, 11:53 am)</div>
--- quote start ---
<!--quotebegin-ericbaker@Dec 4 2006, 11:32 AM
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
<div align='right'><{post_snapback}> (index.php?act=findpost&pid=19808)
--- quote end ---
--- Quote End ---
Hi,
try this:
//SPI RX
while (1) {
//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));
}
//clears the status register
IOWR_ALTERA_AVALON_SPI_STATUS(SPI_0_BASE, 0);
}
<div align='right'><{post_snapback}> (index.php?act=findpost&pid=19809)</div>
[/b]
--- Quote End ---
opps!
provided that you are interested in rx only ....
//SPI RX
while (1) {
//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));
//clears the status register
IOWR_ALTERA_AVALON_SPI_STATUS(SPI_0_BASE, 0);
}
}