Forum Discussion

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

Easy nios design with buttons

Hello,

I am a newbie with Quartus II and Nios II and I have been trying to do an easy nios design in order to light on a led when pressing a button. I am working on the Altera Cyclone III EP3C25F324 board. I think the problem comes from my code in nios II that I put below. I don't really know when to write "IOWR_ALTERA_AVALON_PIO_DATA(...);" maybe the problem comes from here. Plus, when I try to write some "printf", there is an error :

collect2: ld returned 1 exit status

make: *** [button_led.elf] Error 1

Here is my program :

#include "system.h"# include "altera_avalon_pio_regs.h"# include "alt_types.h"# include "stdio.h"# include "stdlib.h"

int alt_main (void)

{

alt_u8 led = 0x2;

alt_u8 button = 0x2;

IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE, led);

IOWR_ALTERA_AVALON_PIO_DATA(BUTTON_PIO_BASE, button);

while (1)

{

switch (button) {

case 0x1 :

led=0x1;

break;

case 0x2 :

led=0x2;

break;

case 0x4 :

led=0x4;

break;

case 0x8 :

led=0x8;

break;

}

}

Do someone can help me?

Thank you very much,

Myriam

7 Replies

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

    try this:

    # include "system.h"# include "altera_avalon_pio_regs.h"# include "alt_types.h"# include "stdio.h"# include "stdlib.h"

    int alt_main (void){

    alt_u8 button = 0x2;

    while(1){

    button = IORD_ALTERA_AVALON_PIO_DATA(BUTTON_PIO_BASE);

    IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE, button);

    }

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

    It lights on the 4 leds without any change when I press a button.

    Maybe it comes from my quartus II design ?
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I would double check the pin connections of the buttons . A good tip is to use signal tap to see if anything happens on those pins.

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

    I am trying your idea but it is the first time I am unsing the tap signal interface and I am not succeeding. I read the literature on Altera but I still don't understand my mistakes. First, a word about my design. I added to the CIII_NiosII_Small design provided by Altera a BUTTON[3..0] signal as another entry. On the SignalTap II Embedded Logic Analyzer, I added the four signal (corresponding to each button), the clock and entered the hardware setup (USB).

    Now I have errors from the Analyzer :

    ISED_PROGRAM_DEVICE CAUSE: You attempted to run the SignalTap II Logic Analyzer, but the current design does not match the design programmed in the device. ACTION: Program the device with the current design, and re-attempt to run the run the SignalTap II Logic Analyzer.

    And from Quartus :

    Error: Current license file does not support incremental compilation

    Can you help me ?
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    1. Check your pin assignments.

    2. Verify that your base addresses for PIOS in SOPC are same that ones in "system.h".
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hello,

    I've been doing some other stuff and I am now back to my button design.

    I checked my pin assignments (they are fine) and my base addresses for PIOS in SOPC and the ones in "system.h" matches.

    I tried the easy program below and when I press the button, nothing happens. It seems that there is still another connection problem but I don't know which one.

    int alt_main (void)

    {

    alt_u8 button = 0x2;

    while(1){

    button = IORD_ALTERA_AVALON_PIO_DATA(PIO_0_BASE);

    if (button==0x01)

    printf("button 1");

    }

    return 0;

    }

    Thanks for your patience,

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

    Hello,

    Maybe it's the problem of alt_main(), unlike main(), some driver initialization should be added manually.

    # include "sys/alt_sys_init.h"

    in alt_main():

    alt_sys_init();

    alt_io_redirect (ALT_STDOUT, ALT_STDIN, ALT_STDERR);

    I haven't checked myself it yet. but you could try using main() instead if you have enough RAM

    Yue