Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
16 years ago

write char in DE2 SRAM

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.

5 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    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".
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    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().
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    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
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    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.