adamS
New Contributor
7 years agowrite continuous data to sdram on DE0 nano board
Hi,
I want to write data to sdram via nios2, then read data out and connect to LEDs to see if the data is correct.
Below is my code and results.
In the code I add printf("isr\n") to make sure interrupt is in effect.
Before "return 0" in the main(), I add printf("b\n") to check if the program is executed outside of while(1) loop, which is not allowed.
But when I write to the 65th date, the program is stuck,
and the interrupt is not working also.
I don't know what happened,
could anyone help me?
thanks a lot!
2019/3/21 update:
I attach my fpga file,
for .elf file please use SPCM2.
#include <stdio.h>
#include <unistd.h>
#include "system.h"
#include "alt_types.h"
#include "io.h"
#include "altera_avalon_pio_regs.h"
#include "sys/alt_irq.h"
int bKeyPressed = 0;
int cnt = 1;
alt_u16 incre = 0;
alt_u16 data, data0;
void KEY_ISR(void* context){
bKeyPressed = 1;
IOWR_ALTERA_AVALON_PIO_EDGE_CAP(KEY_BASE,0);
printf("isr\n");
}
void EnableKeyInterrupt(void){
int error;
IOWR_ALTERA_AVALON_PIO_IRQ_MASK(KEY_BASE,0x03);
IOWR_ALTERA_AVALON_PIO_EDGE_CAP(KEY_BASE,0);
bKeyPressed = 0;
error = alt_irq_register (KEY_IRQ, 0, KEY_ISR);
if (error)
printf("Failed to register interrut\r\n");
}
int main()
{
EnableKeyInterrupt();
IOWR(LED_BASE, 0, (alt_u8)0);
while(1)
{
if(bKeyPressed)
{
bKeyPressed = 0;
*((alt_u8*)NEW_SDRAM_CONTROLLER_0_BASE + incre) = cnt;
data = *((alt_u8*)NEW_SDRAM_CONTROLLER_0_BASE + incre);
printf("cnt = %d, ", cnt);
printf("incre = %d, ", incre);
printf("data=%d\n", data);
IOWR(LED_BASE, 0, (alt_u8)data);
cnt ++;
incre += 1;
}
}
printf("b\n");
return 0;
}isr
cnt = 1, incre = 0, data=1
isr
cnt = 2, incre = 1, data=2
isr
cnt = 3, incre = 2, data=3
isr
cnt = 4, incre = 3, data=4
isr
cnt = 5, incre = 4, data=5
isr
cnt = 6, incre = 5, data=6
.
.
.
.
isr
cnt = 65, incre = 64, data=65