Forum Discussion
Writing SDRAM HELP !!!!!!!!
Hi, I wrote a function in C to W SDRAM memory :
void write_sdram() { int *buffer = (int *) 0x00800000; // SDRAM addr base buffer[0]=0xaaaa; buffer[1]=0xcccc; } When I read the SDRAM with altera DE1 control panel data is : addr 0 = aaaa addr 1 = 0000 addr 2 = cccc addr 3 = 0000 Why ??? If the SDRAM data width is 16 bits , I'm waiting for addr 0 = aaaa addr 1 = cccc Help me please !!!!!6 Replies
- Altera_Forum
Honored Contributor
Could it be because int is 32 bits data type variable? Try alt_u16 for buffer and I think this will work.
--- Quote Start --- Hi, I wrote a function in C to W SDRAM memory : void write_sdram() { int *buffer = (int *) 0x00800000; // SDRAM addr base buffer[0]=0xaaaa; buffer[1]=0xcccc; } When I read the SDRAM with altera DE1 control panel data is : addr 0 = aaaa addr 1 = 0000 addr 2 = cccc addr 3 = 0000 Why ??? If the SDRAM data width is 16 bits , I'm waiting for addr 0 = aaaa addr 1 = cccc Help me please !!!!! --- Quote End --- - Altera_Forum
Honored Contributor
Ok , Thanks !!!!! it was the solution, but now I have another problem:
I want to write some data in SDRAM with a FOR cicle and connect the audio codec MIC (in) to audio codec spk(out), the audio code segment is ok, the problem is when I add the write sdram function because the program stops, I saw (before running program) that initially some data (probably code) is in sdram memory and I think maybe the write sdram function is changing the program code. Here the question is: Why program data in SDRAM if I configured in SOPC builder reset and exception vector in SRAM ??? What I can do to put the code program on SRAM and not SDRAM. Here the code : # include "sdram_to_audio.h" long i; alt_u16 cont=0; void write_sdram() { alt_u16 *buffer = (alt_u16 *) 0x00800000; // base addr SDRAM for (i=0; i<=127; i++){ buffer[i]=cont; cont++; } } int main() { volatile int * audio_ptr = (int *) 0x10003040; // audio port long audiobuf[128]; /* used for audio record/playback */ int fifospace;//, leftdata, rightdata; int buffer_index = 0; write_sdram(); while (1) { fifospace = *(audio_ptr+1); // read the audio port fifospace register if ((fifospace & 0x000000FF) > 96) { audiobuf[buffer_index] = *(audio_ptr + 3); // read right channel only buffer_index++; } fifospace = *(audio_ptr+1); // read the audio port fifospace register if (((fifospace & 0x00ff0000)>>16) > 96) { buffer_index--; //Write to both channels *(audio_ptr + 2) = audiobuf[buffer_index]; *(audio_ptr + 3) = audiobuf[buffer_index]; } } } - Altera_Forum
Honored Contributor
Right click in your project and click "System library properties". Make sure that program memory, stack memory, etc are all set to SRAM and not SDRAM.
Kumaran - Altera_Forum
Honored Contributor
I'm sure all it's correct (SOPC builder, and monitor program are configure with SRAM) but running the program some code (maybe program code is on SDRAM) and when I execute the write sdram function it writes a zone with code causing the program stops.....
- Altera_Forum
Honored Contributor
- Altera_Forum
Honored Contributor
I found the solution !!!!!!!!!!! my system has a timer and my C program doesn't have a handler for timer interrupt, If I don't use the timer I have to desactivate it on system properties.
Thanks for your help !!!!!!!!!!!!!!!!!!!!!!!