Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++

PIO Direction

Altera_Forum
Honored Contributor II
3,186 Views

hi all, 

 

I am using bidirectional pio for my design.Can some one tell me how to set the directions. 

 

I am using IOWR_ALTERA_AVALON_PIO_DIRECTION(PIO_DATA_BASE, 0); 

for using pio as output and 

 

IOWR_ALTERA_AVALON_PIO_DIRECTION(PIO_DATA_BASE, 1);  

for input. 

 

is it correct or not,because my design is not working as expected. 

 

Thanks in advance, 

Sarat
0 Kudos
5 Replies
Altera_Forum
Honored Contributor II
1,641 Views

Actually they are inverted: 0 is for input and 1 for output. 

Moreover this is correct only for single I/O pio: if your pio is wider, you need to set all the required bits. 

Last thing you need to check is if you enabled the bidirecitonal feature in sopc/Qsys pio properties
0 Kudos
Altera_Forum
Honored Contributor II
1,641 Views

Hi, 

 

Thank you for your reply. 

I am using 8 bit PIO for my design.I have set it as bidirectional in QSYS.  

What I understood from your post is,if I have to write 8 bits from the bus I have to write like this 

IOWR_ALTERA_AVALON_PIO_DIRECTION(PIO_DATA_BASE, 0); 

IOWR_ALTERA_AVALON_PIO_DIRECTION(PIO_DATA_BASE+2, 0); 

IOWR_ALTERA_AVALON_PIO_DIRECTION(PIO_DATA_BASE+4, 0); 

IOWR_ALTERA_AVALON_PIO_DIRECTION(PIO_DATA_BASE+6, 0); 

IOWR_ALTERA_AVALON_PIO_DIRECTION(PIO_DATA_BASE+8, 0); 

IOWR_ALTERA_AVALON_PIO_DIRECTION(PIO_DATA_BASE+10, 0); 

IOWR_ALTERA_AVALON_PIO_DIRECTION(PIO_DATA_BASE+12, 0); 

IOWR_ALTERA_AVALON_PIO_DIRECTION(PIO_DATA_BASE+14, 0); 

IOWR_ALTERA_AVALON_PIO_DATA ( PIO_DATA_BASE , address ); 

and for reading 

IOWR_ALTERA_AVALON_PIO_DIRECTION(PIO_DATA_BASE, 1); 

IOWR_ALTERA_AVALON_PIO_DIRECTION(PIO_DATA_BASE+2, 1); 

IOWR_ALTERA_AVALON_PIO_DIRECTION(PIO_DATA_BASE+4, 1); 

IOWR_ALTERA_AVALON_PIO_DIRECTION(PIO_DATA_BASE+6, 1); 

IOWR_ALTERA_AVALON_PIO_DIRECTION(PIO_DATA_BASE+8, 1); 

IOWR_ALTERA_AVALON_PIO_DIRECTION(PIO_DATA_BASE+10, 1); 

IOWR_ALTERA_AVALON_PIO_DIRECTION(PIO_DATA_BASE+12, 1); 

IOWR_ALTERA_AVALON_PIO_DIRECTION(PIO_DATA_BASE+14, 1); 

data = IORD_ALTERA_AVALON_PIO_DATA(PIO_DATA_BASE); 

 

am I correct?
0 Kudos
Altera_Forum
Honored Contributor II
1,641 Views

Wrong! 

You must write the same register but different bits 

bit 0 = I/O nr. 1 

bit 1 = I/O nr. 2 

... 

bit 7 = I/O nr. 8 

 

For example: 

IOWR_ALTERA_AVALON_PIO_DIRECTION(PIO_DATA_BASE, 0x43); 

sets I/O 1,2 and 7 as outputs and all the others as inputs, since 

0x43 is binary 01000011 

 

The same applies for writing output values or reading inputs 

 

In Qsys you have the option "Enable individual bit set/clear output register"; if you selected it, you can set/clear a single output through outset/outclear registers, otherwise you must write all of them jointly. 

i.e. IOWR_ALTERA_AVALON_PIO_DATA(PIO_DATA_BASE, 0x42) 

sets an high level on lines 2 and 7 (clearly they must have been previously set as outputs) 

 

Reading is simpler: you call data = IORD_ALTERA_AVALON_PIO_DATA(PIO_DATA_BASE) 

and simply test the required bits of data.
0 Kudos
Altera_Forum
Honored Contributor II
1,641 Views

Thank you very much for reply, 

 

It is working.you really saved my life :).
0 Kudos
Altera_Forum
Honored Contributor II
1,641 Views

I have almost the same problem. 

I created a component in Qsys with 3 differently Conduits (sd_clk, sd_cmd and sd_dat) and for this component I have just one Base. 

How can I use the function IOWR_ALTERA_AVALON_PIO_DIRECTION(component_base, _____) to write output and input for each of the conduits? 

Does anyone have an idea? 

Thank a lot in advance!!!
0 Kudos
Reply