Altera_Forum
Honored Contributor
15 years agoRun and debug nios project
Hello,
I am running a c file on niosii to check if the LEDs are working or not using buttons. This is my C file: #include <stdio.h> // for uart# include <unistd.h> // for uart read(), open()# include <stddef.h> // for uart# include <fcntl.h> // for uart# include "altera_avalon_pio_regs.h" // pio access# include "system.h"
int main(void)
{
alt_u8 button_pio_value = 0;
alt_u32 led_counter = 0;
alt_u8 led_counter2 = 0;
alt_u8 led_on = 0;
printf("hello world\n");
while(1)
{
button_pio_value = iord_altera_avalon_pio_data(button_pio_base);
led_counter++;
if (led_counter == 500000)
{
led_counter = 0;
led_counter2++;
switch (button_pio_value)
{
case 0: led_on = led_counter2 % 16; break;
case 1: led_on = (led_counter2 % 16) + 16; printf("button 1 pressed\n"); break;
case 2: led_on = (led_counter2 % 16) + 32; printf("button 2 pressed\n"); break;
case 4: led_on = (led_counter2 % 16) + 64; printf("button 3 pressed\n"); break;
case 8: led_on = (led_counter2 % 16) + 128; printf("button 4 pressed\n"); break;
default: led_on = led_counter2 % 16; break;
}
iowr_altera_avalon_pio_data(led_pio_base, led_on);
} // if
} // while
return 0;
} problems: 1) I am supposed to use the buttons after running the project and see the LEDs blinking, but they didnt and i see this message in the console nios2-terminal: connected to hardware target using jtag uart on cable
nios2-terminal: "usb-blaster [usb-0]", device 1, instance 0
nios2-terminal: (use the ide stop button or ctrl-c to terminate) 2) I am trying to debug and i put two breakpoints one in front of the printf and another one in front of the switch. The problem is that i cannot go to each breakpoint to see what is happening. I see only two right mark beside the bullets and the program is still running. I think: there is somthing wrong with the loops but this program is already tested by altera and i am just doing the steps to build and test. please if anyone have an idea, please help, thanks