请教各位高手:下面是我写的一段SPI通信驱动LED的程序,运行到alt_irq_register(SPI_IRQ,(void*) &data , spi_interrupts);程序就死在那了????不知道什么问题???
使用alt_main()程序能跑但是没有办法中断,哪为高人用过SPI中断的指教小弟一下!!!
#include "system.h"
#include "altera_avalon_pio_regs.h"
#include "alt_types.h"
#include "sys/alt_irq.h"
#include "altera_avalon_spi.h"
#include "altera_avalon_spi_regs.h"
alt_u8 led;
int data;
static void spi_interrupts(void* context, alt_u32 id)
{
if(IORD_ALTERA_AVALON_SPI_STATUS(SPI_BASE)==0x40)
{
led++;
IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE, led);
}
IOWR_ALTERA_AVALON_SPI_STATUS(SPI_BASE, 0x00);
}
void DelayNS(alt_u32 time)
{
alt_u32 i,j ;
for(i=0;i<time;i++)
{
for(j=0;j<100;j++);
}
}
void spi_ini(void)
{
//IOWR_ALTERA_AVALON_SPI_SLAVE_SEL(SPI_BASE, 0x01);
alt_irq_register(SPI_IRQ,(void*) &data , spi_interrupts);
IOWR_ALTERA_AVALON_SPI_STATUS(SPI_BASE, 0x00);
IOWR_ALTERA_AVALON_SPI_CONTROL(SPI_BASE, 0xc0);
IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE, 0xff);
DelayNS(2000);
}
//int main (void) __attribute__ ((weak, alias ("alt_main")));
/*
* Use alt_main as entry point for this free-standing application
*/
int main (void)
{
const alt_u8 DISP_TAB[16] = { 0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,
0x88,0x83,0xC6,0xA1,0x86,0x8E };
alt_u8 i;
IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE, 0xf0);
spi_ini();
IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE, 0x0f);
while (1)
{
for(i=0; i<16; i++)
{
IOWR_ALTERA_AVALON_SPI_TXDATA(SPI_BASE, DISP_TAB); // 输出LED显示数据
DelayNS(2000); // 延时
}
}
return 0;
}
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |