AnsweredAssumed Answered

STM32F405 - Change GPIO Direction Dynamically.

Question asked by dengle.aaditya on Jan 15, 2015
Latest reply on Jan 15, 2015 by Danish Ali
Hi,
Consider me a newbie in ARM. For last few days I am trying to control a set of GPIO pins dynamically. What I want to do is, to change the direction (Input to output or output to input), of the GPIO dynamically i.e. on the fly. All this is require to establish a 8 bit parallel bus to communicate with other hardware I have. I am using CoIDE, and dont want to use FSMC. Following is what I have done till now.
01.typedef enum{
02.    Data_INPUT,
03.    Data_OUTPUT
04.}Data_Direction;
05. 
06..
07..
08..
09..
10..
11. 
12.void DataDirection(Data_Direction dtDirect){
13.switch (dtDirect) {
14.DATA_PORT->BSRRH =DATA_BUS;
15.DATA_PORT->ODR = DATA_PORT->ODR & 0xffff0000;
16. 
17.    case Data_INPUT:
18.        DATA_PORT->MODER = (DATA_PORT->MODER & 0xffff0000);
19.        DATA_PORT->PUPDR = (DATA_PORT->PUPDR & 0xffff0000);
20.        DATA_PORT->OTYPER =(DATA_PORT->OTYPER & 0xffffff00);
21.        DATA_PORT->OSPEEDR = (DATA_PORT->OSPEEDR & 0xffff0000) | (uint16_t) 0xAAAA;
22.        Delay(100);
23.        break;
24.    case Data_OUTPUT:
25.        DATA_PORT->MODER = (DATA_PORT->MODER & 0xffff0000) | (uint16_t) 0x5555;
26.        DATA_PORT->OTYPER =(DATA_PORT->OTYPER & 0xffffff00);
27.        DATA_PORT->OSPEEDR =(DATA_PORT->OSPEEDR & 0xffff0000) | (uint16_t) 0xAAAA;
28.        DATA_PORT->PUPDR = (DATA_PORT->PUPDR & 0xffff0000)|(uint16_t) 0x5555;
29.        Delay(100);
30.        break;
31.}
32. 
33..
34..
35..
36..
37..

I have to configure PortC's first 8 pins in this manner, remaining of it will always have output configuration and will not change dynamically. 

As a result of the the above code I have observed that when I shift the pins direction from Output to Input, the pin state is not getting low or in other words I cant read the pins for their true value. 

Please let me know how to implement the 8 bit dynamic parallel bus over GPIO. 

Outcomes