Forum Discussion
Altera_Forum
Honored Contributor
15 years agoI am having a problem with accessing externa SRAM on DE2 board using C program in NiosII IDE. I am using the SRAM controller provided by the University Program. As shown in the snapshot, I have two dedicated on chip memory, one for data and one for instruction. I also have LED to display data and switch to control which data must be displayed. The snapshot of the SOPC is attached. The instruction and data memory are both 32 bit wide.
Now I write a simple C code to write and then read from the SRAM. Following is the code # include "sys/alt_stdio.h"# include "system.h"# include "altera_avalon_pio_regs.h"# include <stdio.h># include <alt_types.h># include <io.h># include <string.h> # include "sys/alt_dma.h" int main() { int count; int offset; int pattern; pattern = 4; int delay; for (offset = 0; offset < 192; offset+=2) { printf("Hello from Nios II 1!%d %d\n", offset, pattern); IOWR_32DIRECT(SRAM_BASE, offset, pattern); } printf("Hello from Nios II!\n"); pattern=1; for (offset = 192; offset < 384; offset+=2) { printf("Hello from Nios II 2! %d %d\n", offset, pattern); IOWR_32DIRECT(SRAM_BASE, offset, pattern); } while(1) { printf("Hello from Nios II 2!\n"); } } I use the occasional printf statements to check how the program is running. The problem that I am having is as follows. When I run the above code on Nios Processor it starts to increment the offset and then starts printing garbage in the form of "yyyyyyyy..........". I looked into the code a bit in details and found that the offset is not incrementing after a certain value. I think I am making some fundamental mistake. Any help would be highly appreciated. Thanks in advance, D