Programmable Devices
CPLDs, FPGAs, SoC FPGAs, Configuration, and Transceivers
21611 Discussions

write char in DE2 SRAM

Altera_Forum
Honored Contributor II
1,713 Views

hello, 

 

Sorry I'm a newbie in NIOSII... 

 

I would like to write and read a char in the SRAM, I try to use itoa function but NIOSII doesn't recognize this function? 

 

I use this command: 

 

IOWR_16DIRECT((SRAM_BASE), 4, "a"); 

 

value = IORD_16DIRECT((SRAM_BASE), 4); 

printf("%d,%s\n", 4,value); 

 

How can I write a char in SRAM whithout itoa function please? 

 

Thx.
0 Kudos
5 Replies
Altera_Forum
Honored Contributor II
842 Views

Non standard itoa() function is for convert an integer to a string, it is not related to SRAM, 

 

If you want convert numbers to string just use standard function sprintf(). 

 

If you want write a single char, use simple quotes 'a', not double quotes "a".
0 Kudos
Altera_Forum
Honored Contributor II
842 Views

if i wanna write a char for exemple "abcd" what can i do ? 

thx
0 Kudos
Altera_Forum
Honored Contributor II
842 Views

For declaring an initialized string at sram use: 

 

char my_str __attribute__ ((section (".sram"))) = "abcde"; 

 

my_str must be global. This, assuming you have a sram object

 

 

For copying between memory locations just use memcpy().
0 Kudos
Altera_Forum
Honored Contributor II
842 Views

ok thx i'll try it. 

I've one more question about that... what's the ".sram" ? cuz the sram that i use is a new component that i've created in SOPC builder...would like to know if this name should be linked with the name of the component.... 

 

Thx
0 Kudos
Altera_Forum
Honored Contributor II
842 Views

I've tested your code.... 

I would like to know how you can read this char using IORD_16DIRECT ? 

How do you write a char as "abcd" at a specific adress ? 

 

Thanks for your help. 

0 Kudos
Reply