- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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, MyriamLink Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Myriam,
Without getting into a discussion about better ways of handling buttons, here are some changes that should get your code doing what you expected it to do: # 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; alt_u8 button; while (1) { button = IORD_ALTERA_AVALON_PIO_DATA(BUTTON_PIO_BASE); switch (button) { case 0x1 : led=0x1; break; case 0x2 : led=0x2; break; case 0x4 : led=0x4; break; case 0x8 : led=0x8; break; } IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE, led); } Note that the button PIO is read with an IORD_ function call. I imagine your problem with printf is that you do not have a device configured for stdout.
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page