Forum Discussion

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

PIO

Hi all,

I'm trying to write/read to and from some PIO. I have read as much as I can find about this topic on the forums and nios wiki but im not having much luck. Ive made a little test program:

<div class='codetop'>CODE</div><div class='codemain' style='height:200px;white-space:pre;overflow:auto'>#include <stdio.h># include <asm/io.h>

int main(void)

{

printf("writing to port:\n");

writew(0xFFFF,0x10402020); //data

return 0;

}</div>

where 0x10402020 is the address of my PIO. The code doesn&#39;t do anything really... ive tried a few other methods, none seemed to work. Can anyone help!?!?!?

3 Replies

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

    You will need to bypass cache by turning on address bit 31.

    writew(0xFFFF,0x10402020 | 0x80000000); //data

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

    <div class='quotetop'>QUOTE (hippo @ Aug 7 2009, 10:54 AM) <{post_snapback}> (index.php?act=findpost&pid=23449)</div>

    --- Quote Start ---

    You will need to bypass cache by turning on address bit 31.

    writew(0xFFFF,0x10402020 | 0x80000000); //data

    - Hippo[/b]

    --- Quote End ---

    Hi, what does that acually mean?

    Unfortunately that didn&#39;t work. My output port are all set to high no matter what. Also, I have two ports, one output and one bidirectional. Is there a way to change the direction of a port? Or does writew /readw take care of that?
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    <div class='quotetop'>QUOTE (Gaz @ Aug 7 2009, 10:16 AM) <{post_snapback}> (index.php?act=findpost&pid=23448)</div>

    --- Quote Start ---

    Hi all,

    I&#39;m trying to write/read to and from some PIO. I have read as much as I can find about this topic on the forums and nios wiki but im not having much luck. Ive made a little test program:

    <div class='codetop'>CODE

    --- Quote End ---

    <div class='codemain' style='height:200px;white-space:pre;overflow:auto'>#include <stdio.h># include <asm/io.h>

    int main(void)

    {

    printf("writing to port:\n");

    writew(0xFFFF,0x10402020); //data

    return 0;

    }</div>

    where 0x10402020 is the address of my PIO. The code doesn&#39;t do anything really... ive tried a few other methods, none seemed to work. Can anyone help!?!?!?[/b]

    --- Quote End ---

    got it! had to find the correct register to change the direction (can find them in the nios2eds io.h). so doing utw(0xFFFF,(0x10402020+4)) wrote 0xFFFF to the direction register and changed the port to an output. Maybe this will help someone else one day....