- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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);
}
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You should try first not to enable the interrupt and regularly check the ready bit on the status register, just to be sure an interrupt would be triggered by the SPI component.
Then I don't think it is recommended to call printf() within an ISR, as it can use interrupts itself when talking to the hardware. You should either use another debugging method (such as LEDs) or compile with the small C library which doesn't use interrupts in I/O IIRC.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Even if your serial port doesn't use interrupts, it is unlikely that the uart driver is interrupt safe.
It is also possibly that even the 'small' versions of printf() are not interrupt safe. The other 'problem' is the sheer number of cpu cycles that printf() will take, that alone might cause interrupt latency issues.- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page