Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Valued Contributor III
929 Views

Using the GPIO_0 (JP1) on DE2 board.

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
Highlighted
Valued Contributor III
8 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
0 Kudos
Highlighted
Valued Contributor III
8 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.
0 Kudos
Highlighted
Valued Contributor III
8 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.
0 Kudos
Highlighted
Valued Contributor III
8 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 :)
0 Kudos