Forum Discussion

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

Programming IO ports in NIOS II

Hi, Im new to nios ii software programming.I need to implement a hardware on an fpga.But as there are no sufficient pins availabile on the board,i thought of using a nios 2 processor to give external inputs to the fpga.As im new to nios ii im not able to program the PIOs of the nios ii properly.Can anyone help me by giving some sample codes for this....

4 Replies

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

    Adding extra nios cpu won't magically generate extra IO pins!

    Your best hope is to add external logic to multiplex/demultiplex the information, these days that would typically be done in a small fpga!
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Thankyou for your suggestion.actually im a student and is interested in learning nios ii.so i thought of using it.

    I know that the pio core provides upto 32 IO ports.But how can i access each one of them.im familiar with 8051 programming.can u help me with this.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    PIO ports are memory mapped.

    For a PIO input you check the bits corresponding to the input you want to test.

    For a PIO output you change the bits.

    Nios tools provide some macros to easily work with PIOs.

    Say PIO_BASE is base address (assigned in sopc builder) of a 16 wide PIO output port;

    this will set high outputs 2,5,6,7,8,12 of a 16

    IOWR_ALTERA_AVALON_PIO_DATA(PIO_BASE, 0x10F2);

    Similar for an input port. This will test if input 6 is high:

    if (IORD_ALTERA_AVALON_PIO_DATA(PIO_BASE) & 0x0040) ....
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    This was indeed very helpful.Now im able to program my nios IOs.Thankyou.