Altera_Forum
Honored Contributor
13 years agoInterrupt Driven SPI
I am having trouble configuring the SPI to create interrupts. I am calling the function below inside a key press interrupt(that works) to start an SPI transfer. My initialization, and following routine are posted below as well. From what I have read, the interrupt should occur when the selected interrupt bit (from spi control register) and status bit (from spi status register) are both 1. I am not recieving any message on the NIOS II IDE console except the boot up message, and the key press interrupt does work as I display the keys on an LCD.
I don't know if this applies, but I have configured SPI on this device as the master with 8 select channels. Any help is much appreciated!
alt_avalon_spi_command(SPI_BASE, 1, 16, &spiDataOut, 16, &spiDataIn, 0);
This is the code I have so far.
void init_spi_interrupt()
{
void* edge_capture_ptr = (void*) &spiDataIn;
//enable receive interrupt
IOWR_ALTERA_AVALON_SPI_STATUS(SPI_BASE, 0x0);
//reset flags
IOWR_ALTERA_AVALON_SPI_CONTROL(SPI_BASE, ALTERA_AVALON_SPI_CONTROL_SSO_MSK | ALTERA_AVALON_SPI_CONTROL_IRRDY_MSK);
//when status flag and control flag are both 1 interrupt occurs
alt_irq_register(SPI_IRQ, edge_capture_ptr, spi_ISR);
}
static void spi_ISR(void* context, alt_u32 id)
{
printf("SPI INTERRUPT DETECTED!\n");
IOWR_ALTERA_AVALON_SPI_CONTROL(SPI_BASE, 0x0);
volatile int* edge_capture_ptr = (volatile int*) context;
*edge_capture_ptr = IORD_ALTERA_AVALON_SPI_RXDATA(SPI_BASE);
//reset the interrupt flags
IOWR_ALTERA_AVALON_SPI_STATUS(SPI_BASE, 0x0);
//reset flags
IOWR_ALTERA_AVALON_SPI_CONTROL(SPI_BASE, ALTERA_AVALON_SPI_CONTROL_SSO_MSK | ALTERA_AVALON_SPI_CONTROL_IRRDY_MSK);
}