Forum Discussion
Altera_Forum
Honored Contributor
10 years agoNIOS II SPI communication
Hi All! I've a problem with Nios SPI communication. I studied "Embedded Peripherals IP User Guide" but I didn't understand how to use alt_avalon_spi_command() function. I understood that an Avalon...
Altera_Forum
Honored Contributor
10 years agoI tried to write a simple code section in C language to make SPI communication, with NIOS as slave. Can you check if my code is good please?
static void spi_rx_isr(void* isr_context); static void spi_rx_isr(void* isr_context){ IOWR_ALTERA_AVALON_SPI_STATUS(SPI_SLAVE_BASE, 0x0); } int ret; int status; alt_u16 rddata; //this registers slave IRQ with NIOS ret = alt_iic_isr_register(SPI_SLAVE_IRQ_INTERRUPT_CONTROLLER_ID,SPI_SLAVE_IRQ,spi_rx_isr,(void *)spi_command_string_tx,0x0); //check if slave status is good do{ status = IORD_ALTERA_AVALON_SPI_STATUS(SPI_SLAVE_BASE); } while ((status & ALTERA_AVALON_SPI_STATUS_RRDY_MSK) == 0); //copy received byte into rddata variable rddata = IORD_ALTERA_AVALON_SPI_RXDATA(SPI_SLAVE_BASE); //set slave IRQ to enable a new byte receiving IOWR_ALTERA_AVALON_SPI_CONTROL(SPI_SLAVE_BASE, ALTERA_AVALON_SPI_CONTROL_SSO_MSK | ALTERA_AVALON_SPI_CONTROL_IRRDY_MSK);