2013-09-02 04:14 AM
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
2013-09-02 04:58 AM
Double-check before reusing structures/variables.
You have not changed theGPIO_InitStruct.GPIO_OType
member after the first call toGPIO_Init()
, which should probably beGPIO_OType_OD
for pins 0 and 1.2013-09-02 05:52 AM
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.
2013-09-02 05:55 AM
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)CS2013-09-02 06:31 AM
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!! CS2013-09-02 08:33 AM
...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!!CS2013-09-03 02:37 AM
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);2013-09-03 03:11 AM
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.2013-09-03 04:13 AM
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.2013-09-13 01:35 AM
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!!:)