Intel® FPGA University Program
University Program Material, Education Boards, and Laboratory Exercises
Announcements
Intel Support hours are Monday-Fridays, 8am-5pm PST, except Holidays. Thanks to our community members who provide support during our down time or before we get to your questions. We appreciate you!

Need Forum Guidance? Click here
Search our FPGA Knowledge Articles here.
1098 Discussions

Using the GPIO_0 (JP1) on DE2 board.

Altera_Forum
Honored Contributor II
1,041 Views

Hi 

 

I am building a robot and want to use the DE2 board to control a circuit, i want to use one of the pins on the GPIO_0 36pin port. When i press the KEY0 it should make the pin i choose active. 

 

Press key0 -> the circuit recieve a "1" from the pin -> release key0 -> the circuit revieve a "0". 

 

If someone could tell me in small steps how i could do that in C.  

 

I have come this far: 

 

volatile int * GPIO_0_base = (volatile int *) 0x10000060; 

volatile int * GPIO_0_dir = (volatile int *) 0x10000064; 

 

Then i want to make the first pin work as an output: 

 

*( GPIO_0_dir) |= 0x01; 

 

And then make it active by doing this: 

 

*(GPIO_0_base) |= 1; 

 

 

I have written interupt handlers for KEY0 and that works, one of the problems is that the circuits gets a "1" all the time... But that might have something to do with me configuring the port incorrectly. 

 

 

 

Im thankful for all the help i can get. :)
0 Kudos
4 Replies
Altera_Forum
Honored Contributor II
120 Views

Try including "altera_avalon_pio_regs.h" and use the macros defined here in order to control pio. Also, you'd better use xx_PIO_BASE defines (see system.h) instead of raw numeric address . You'll have a more portable code, indipendent of changes you possibly make in sopc builder. 

Maybe a silly question: is pio correctly connected to fpga output pins in your Quartus design? 

 

Regards
Altera_Forum
Honored Contributor II
120 Views

Oh sorry.. Im not that familiar with the DE2 board so I don't understand your silly question :p 

 

I will look into the PIO_BASE defines later when I know my code will work.
Altera_Forum
Honored Contributor II
120 Views

I only asked if you are sure your problem is related to C code. In other words, are you sure the system is ok?  

Namely: 

Is sopc pio port is connected to correct target fpga pins in the Quartus project? 

Have you tried to change the state of other pins of the pio port? Do they work? 

Is Key input read correctly?  

 

One more suggestion: 

Try use IO_RD(base,offset) instead of int* pointers; I remember had a similar problem once and I solved it this way.
Altera_Forum
Honored Contributor II
120 Views

I asked my teacher and he have rewritten the SOPC builder file along with the stf file too i think, so the default address's wont work... :p 

 

Thanks for the help anyway :)
Reply