cancel
Showing results for 
Search instead for 
Did you mean: 

Mixing Digital inputs and Outputs on the same port.

bl
Associate II

Posted on September 02, 2013 at 13:14

Hi Folks 

I'm working with the 32F4 discovery board and I've been looking for some examples of mixed Input and output pins on the same port, however they seem a like hard to find!! I checked the Ref Manual and does seem possible to put input and output on the same port. I'm using the following setup code - is this the right way to go about it?? (the strut was declared earlier) - The outputs (3,4) seem to work fine, but I get no pull ups on the inputs....

  GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT; 

 GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;

 GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_DOWN;

 GPIO_InitStruct.GPIO_Speed = GPIO_Speed_25MHz;

 GPIO_InitStruct.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4;

 GPIO_Init(GPIOE, &GPIO_InitStruct);

 GPIO_SetBits(GPIOE, GPIO_Pin_4 );

 GPIO_SetBits(GPIOE, GPIO_Pin_3 );

 GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN; // so change the strut to from Alt funct to GPIO (in)

 GPIO_InitStruct.GPIO_Speed = GPIO_Speed_25MHz;

 GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP;

 GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;

 GPIO_Init(GPIOE, &GPIO_InitStruct);

 GPIO_SetBits(GPIOE, GPIO_Pin_0 );

 GPIO_SetBits(GPIOE, GPIO_Pin_1 );

Thanks for the time folks 

CS

16 REPLIES 16
frankmeyer9
Associate II
Posted on September 02, 2013 at 13:58

Double-check before reusing structures/variables.

You have not changed the

GPIO_InitStruct.GPIO_OType

member after the first call to

GPIO_Init()

, which should probably be

GPIO_OType_OD

for pins 0 and 1.

Posted on September 02, 2013 at 14:52

Or just use OD (Open Drain) mode with pull-ups, and set the output to 1 to permit the external driver to change the pin state and read back as an input.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
bl
Associate II
Posted on September 02, 2013 at 14:55

Hi FM

Thanks for the reply - I did this change, but it didn't fix the problem, checking the reference manual (should have done this first) is does seem to say that the (o)type(PP or OD) and the (o)speed are don't cares for input mode. 

...but thanks for the pointer. 

...I just wish I could find an example to work from!!

(clive I'll try your suggestion next)

CS

bl
Associate II
Posted on September 02, 2013 at 15:31

Hi Guys 

Thanks for the replies - I found the problem was a lack of {} else where in the program, but thanks for giving me confidence that I was on the right track, still can't get the pull ups on in either OD output or input mode - but that's something I can work a around!! CS

bl
Associate II
Posted on September 02, 2013 at 17:33

...interestingly (to me anyway) I can comment out all this code and there is no change in the program behavior, so I must be running default settings. 

...Ooo dear!!

CS

bl
Associate II
Posted on September 03, 2013 at 11:37

Mmm 

I wonder if this is a port E problem, the code below sets the pull ups on the D port not the E port

 

    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE);

    GPIO_InitTypeDef gpio1;

    GPIO_StructInit(&gpio1);

    gpio1.GPIO_Mode = GPIO_Mode_IN;

    gpio1.GPIO_PuPd = GPIO_PuPd_UP;

    gpio1.GPIO_Pin = 3; // pins zero and one!!

    GPIO_Init(GPIOE, &gpio1);

    GPIO_SetBits(GPIOE, 3);

  

    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);

    GPIO_InitTypeDef gpio;

    GPIO_StructInit(&gpio);

    //gpio.GPIO_Mode = GPIO_Mode_OUT;

    gpio.GPIO_Mode = GPIO_Mode_IN;

    gpio.GPIO_PuPd = GPIO_PuPd_UP;

    gpio.GPIO_Pin = LEDS;

    GPIO_Init(GPIOD, &gpio);

    GPIO_SetBits(GPIOD, LEDS);

bl
Associate II
Posted on September 03, 2013 at 12:11

Ho Hmmm.. 

Its a H/W problem the mems chip is on the two PortE lines I have used and must  be pulling these lines low!!

...it is a problem with the discovery board that it is difficult to disable the unused chips on the board.

frankmeyer9
Associate II
Posted on September 03, 2013 at 13:13

I can tell you by my own experience (ant that of others, just search this forum), that onboard-hardware of the discovery board can keep your external hardware quite effectively from working.

The solutions are:

 1. use other/free pins

 2. remove interfering parts/traces with soldering iron or knife

I usually prefer method one, but the discovery boards are cheap.

bl
Associate II
Posted on September 13, 2013 at 10:35

Yes I agree,

I have my own application board now running with the device - at least I know what peripherals I have attached to the device!!

:)