Programmable Devices
CPLDs, FPGAs, SoC FPGAs, Configuration, and Transceivers
21602 Discussions

Easy nios design with buttons

Altera_Forum
Honored Contributor II
2,695 Views

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
0 Kudos
7 Replies
Altera_Forum
Honored Contributor II
1,629 Views

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); 

}
0 Kudos
Altera_Forum
Honored Contributor II
1,629 Views

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

Maybe it comes from my quartus II design ?
0 Kudos
Altera_Forum
Honored Contributor II
1,629 Views

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
0 Kudos
Altera_Forum
Honored Contributor II
1,629 Views

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 ?
0 Kudos
Altera_Forum
Honored Contributor II
1,629 Views

1. Check your pin assignments. 

2. Verify that your base addresses for PIOS in SOPC are same that ones in "system.h".
0 Kudos
Altera_Forum
Honored Contributor II
1,629 Views

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
0 Kudos
Altera_Forum
Honored Contributor II
1,629 Views

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
0 Kudos
Reply