cancel
Showing results for 
Search instead for 
Did you mean: 

Code for Fast Switching of Bidirectional GPIO pins

bruce
Associate II
Posted on August 05, 2008 at 20:18

Code for Fast Switching of Bidirectional GPIO pins

2 REPLIES 2
bruce
Associate II
Posted on May 17, 2011 at 12:41

Is there a fast way to switch the GPIO's from input to output and vice-versa? In my application, I want all 16 pins on Port D to function as a bi-directional data bus.

Using the library, it appears that the only way is to use the GPIO_Init function.

Can I just do for inputs:

GPIOD->CRL = 0x44444444;

GPIOD->CRH = 0x44444444;

or for outputs:

GPIOD->CRL = 0x22222222;

GPIOD->CRH = 0x22222222;

GPIOD->ODR = 0xABCD; // or whatever data value I want to write

??

picguy
Associate II
Posted on May 17, 2011 at 12:41

I would use a bit of assembly code that does the following - -

ldr r0,=basePORTD

ldr r1,=0x44444444 or 0x22222222 depending on your direction

str r1,[r0,# GPIO_CRL]

str r1,[r0,# GPIO_CRH]

; I might wait a few clocks before reading

; I assume no wait is needed before you str (data reg),[r0,GPIO_ODR]

Unless you use your GPIOD structure for something else I would not bother updating it.

-PICguy

The following equates may prove useful

basePORTD equ 0x40011400

GPIO_CRL equ 0x000 ;def low 8 bits of GPIO

GPIO_CRH equ 0x004 ;def high 8 bits of GPIO

GPIO_IDR equ 0x008 ;data register (input)

GPIO_ODR equ 0x00C ;data register (output - all 16 bits)

GPIO_BSRR equ 0x010 ;clr (top 16 bits), set (low 16 bits)

GPIO_BRR equ 0x014 ;clr port bits set in low 16

GPIO_LCKR equ 0x018 ;lock given port config (complex setup sequence)