Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Altera DE2 - Nios code confusion

Status
Not open for further replies.

IronDi51010

Newbie level 3
Joined
May 20, 2012
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,328
I am working with Altera DE2 board and using the NIOS IDE to load code to the processor on the board and am confused byt he example code. Input are 8 toggle switches and output is 8 leds.

I created a SOPC, with the following components:
-8 bit input, Mem. Address [0x0003000 - 0x000300f]
-8 bit output, Mem. Address [0x0003010 - 0x000301f]
-Nios II processor
-JTAG Uart interface - to communicate the computer with the board
-4 KB of onboard RAM memory

The code in the NIOS IDE:
#include "sys/alt_stdio.h"
#define Switches (volatile char*) 0x00030000
#define LEDs (char*) 0x0003010
int main()
{
alt_putstr("Hello from Nios II!\n");

/* Event loop never exits. */
while (1)
*LEDs = *Switches;

return 0;
}

The code I extracted from a guide I found, but it did not explain the code just to enter it. What I thought was happening was I mapping the output to the input. When I loaded the program all the LED's were on. No matter what the input was. Changing the value of Switches did not make any changes.

When I tried to enter in hard values of *LEDs (e.g. *LEDs = "00000000" or *LEDs = '00000000') two random leds turned on. For example using the first statement in the parentheses turned on LED 3 and 1, mean while the second statement in the parantheses turn on LED 3 and 4.

If anyone can point me in the right direction I would very much appreciate it.
 

I've done something similar before, but I recall I used Altera's GPIO function.
By the way, are you assigning a string to LED, or what you meant was a hex value?
 

I've done something similar before, but I recall I used Altera's GPIO function.
By the way, are you assigning a string to LED, or what you meant was a hex value?

Thanks for the response. This morning I figured out what I was doing wrong.

The code I submitted was from a tutorial on programming the NIOS II processor, however, this code is specifically used through the Altera University Monitor program, not the NIOS II IDE. The tutorial did not explain the code, just use it. But I think the idea is the base address of the LEDs are mapped to the switch address. But I could be wrong.

Through some google-fu I found a video tutorial on how to program the LEDs through NIOS II and finally got it to work. Although it is embedded C which I am not used to. I still need a lot of time going through examples/tutorials.

Could you expand on the GPIO function?
 

Altera provides a GPIO module which we can attach to Avalon bus. It comes with C functions we can use to write to and read from GPIO module. I mapped the pins of the GPIO I instantiated to the control lines I had...
I think you can get more information about it from help on the module.
 

Hi,

I am working with Altera DE2 board and using the NIOS IDE to load code to the processor on the board and am confused byt he example code. Input are 8 toggle switches and output is 8 leds.

I created a SOPC, with the following components:
-8 bit input, Mem. Address [0x0003000 - 0x000300f]

Here I can see the PIO address is 0x3000.

#define Switches (volatile char*) 0x00030000

However here your are using 0x30000 (3 and four '0').

Franck.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top