Forum Discussion
Altera_Forum
Honored Contributor
16 years agoSwitch on leds on DE2
Hey, im trying to switch on LEds on DE2.
http://thalandinenop99.free.fr/image.jpg You can see here the system that i've generated. Leds is set in output with 8 bits and Switch set in input with 8 bits I've generated the system then i've programmed it to my DE2, then i've written this code in C with NIOS 2 IDE in oder to switch on the LED : # define SWITCHES_BASE_ADDRESS 0x00009010# define LEDR_BASE_ADDRESS 0x00009000 int main(void) { int * red_leds = (int *) LEDR_BASE_ADDRESS; /* red_leds is a pointer to the LEDRs */ volatile int * Switch = (int *) SWITCHES_BASE_ADDRESS; /* switches point to toggle switches */ printf("Hello from Nios II!\n"); while(1) { *(red_leds) = *(Switch); /* Red LEDR[k] is set equal to SW[k] */ } return 0; } i've send this to DE2. i don't understand why, LED's doesn't want to switch on....any idea ?? is there any turorial of how i have to code in C if yes, where can i download this file...could you plus help me to solve this problem. Thanks2 Replies
- Altera_Forum
Honored Contributor
thanks it works fine
- Altera_Forum
Honored Contributor
If you have used Nios II full version, addresses below to 0x8000000 are cacheable, so you will experience problems accesing hardware in the way you're doing. I strongly suggest use the IORD and IOWR macros, they use I/O instructions. So according to your SOPC system
base address definitions are made on "system.h".# include "system.h" # include "io.h" ... while(1) { IOWR(LEDS_BASE,0,IORD(SWITCH_BASE,0)); } ......