cancel
Showing results for 
Search instead for 
Did you mean: 

f4discovery : weird gpio behavior

jejeva
Associate II
Posted on April 17, 2013 at 22:08

Hello fellow f4/stm32 Users.

I just bought a f4Discovery and i'm trying to get a grip on this great ''little'' piece of hardware.

i'm trying to do very basic things just to get a grip by reimplementing a little piece of a game i made a while ago. (basically driving leds through 595 with some microswitches as input).

Here is my problem :

i'm trying to trigger an nvic interrupt on GPIOE set like that : 

 &sharpdefine PORTBTN GPIOE

&sharpdefine RCC_AHB1Periph_PORTBTN RCC_AHB1Periph_GPIOE

&sharpdefine PLAYER1_PIN GPIO_Pin_0

&sharpdefine PLAYER2_PIN GPIO_Pin_1

&sharpdefine EXTI_PortSource_PORTBTN EXTI_PortSourceGPIOE

GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;

GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;

GPIO_InitStructure.GPIO_Pin = PLAYER1_PIN|PLAYER2_PIN;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;

GPIO_Init(PORTBTN, &GPIO_InitStructure);

interrupt setup:

 SYSCFG_EXTILineConfig(EXTI_PortSource_PORTBTN, EXTI_PinSource0|EXTI_PinSource1);

  EXTI_InitStructure.EXTI_Line = EXTI_Line0;

  EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;

  EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling;  

  EXTI_InitStructure.EXTI_LineCmd = ENABLE;

  EXTI_Init(&EXTI_InitStructure);

  NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;

  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x01;

  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x01;

  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

  NVIC_Init(&NVIC_InitStructure);

but, this is provoking something strange in my hardware around the microswitches.

(the behavior is normal with the �c it was develloped for originally, namely atmega, same thing with a msp, another arm and a cypress ).

the hardware setup is (sorry image manager not working for me) : 

http://i.imgur.com/QZw4vOm.png

with all the other �c, VD between the +5 side of the resistor & iopin side is +5v is ~0v without pushing the �switch and +5 while pushing (yey pullup...)

as soon as i plug the pin in it goes +5v all the time, just like if the GPIO pins were already grounded... i didn't put any pulldown while configuring the pin so... i'm surely missing something pretty important here regarding the STM gpios....

any idea what ?

sincerely,

jege

#discovery #stm32f4 #gpio #pullup
14 REPLIES 14
Posted on April 17, 2013 at 22:14

Can't OR these like this

  SYSCFG_EXTILineConfig(EXTI_PortSource_PORTBTN, EXTI_PinSource0|EXTI_PinSource1);
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
jejeva
Associate II
Posted on April 17, 2013 at 22:53

Ok thanks clive, i'll make 2 exti lines.

any idea about the GPIO setup ?

Posted on April 18, 2013 at 02:12

void ConfigureEXTI0_1(void)
{
EXTI_InitTypeDef EXTI_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
/* Enable GPIOE clock */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE);
/* Enable SYSCFG clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
/* Configure PE0/PE1 pin as input floating */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;
GPIO_Init(GPIOE, &GPIO_InitStructure);
/* Connect EXTI Line0 to PE0 pin */
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOE, EXTI_PinSource0);
/* Connect EXTI Line1 to PE1 pin */
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOE, EXTI_PinSource1);
/* Configure EXTI Line0 */
EXTI_InitStructure.EXTI_Line = EXTI_Line0;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; // Or whatever
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
/* Configure EXTI Line1 */
EXTI_InitStructure.EXTI_Line = EXTI_Line1;
EXTI_Init(&EXTI_InitStructure);
/* Enable EXTI Line0 Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* Enable EXTI Line1 Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = EXTI1_IRQn;
NVIC_Init(&NVIC_InitStructure);
}
void EXTI0_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line0) != RESET)
{
/* Clear the EXTI line 0 pending bit */
EXTI_ClearITPendingBit(EXTI_Line0);
// Do something here
}
}
void EXTI1_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line1) != RESET)
{
/* Clear the EXTI line 1 pending bit */
EXTI_ClearITPendingBit(EXTI_Line1);
// Do something here
}
}

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
jejeva
Associate II
Posted on April 18, 2013 at 22:48

Hey guys,

apparently i'm more missing something on the physical layer,

i followed clyve advice and added a seond exti line for the 2nd Pin.

i tryed (after poking around in gdb with openocd and finding funny values in the GPIO_InitStructure) to remove the size optimization. this solved the gpio setup problem and now, when i'm poking around the pin with my multimeter the breakpoint i have put on the IRQ handler fires up (yey, getting closer). but, even in this setting the pin seems to be ''not really floating'' but linked to vdd in some way.

anyone knows the breaking value of the diode protecting the vdd in 5v compliant GPIO (schema p 186 in DM00031020.pdf (family datasheet) ) ? i might have fallen upon a chip with a weak protection diode... is this a possible cause or am i completely ''out there'' ?

if you look at the schema of my circuit i posted in the 1st post i can't see any other way to explain that the voltage between the pin and the +5 side of the resistor is a +5v... gonna try tomorrow with another port entirely...

Posted on April 19, 2013 at 00:06

Not sure why the need to use 5V. The 3V supply should be quite adequate.

With the resistor attached to the pin, the voltage wrt ground should be 5V, when the button makes it's connection you'll get ground, check if the switch is a normally open, or normally closed.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
jejeva
Associate II
Posted on April 19, 2013 at 08:12

Hello,

i need to use 5v because some parts in be circuit needs 5v supply and that i can't get 2 different power levels on the board (i have a 3.3v input tolerant, 5v powered componant (74hct595) that is getting the logic inputs from the stm (unshown part of the code) and distributing the logic to the rest of the board that is powered by 5v), that shouldn't matter anyway since GPIOE is supposed to be 5v tolerant.

the button & pullup works a treat as long as it's not connected to the stm (works with other arm based boards), i used this board with a variety of µControllers (both ttl and cmos level), in fact this board is used as a baseline for me to evaluate different platforms in term of programming complexity to do some basic tasks, adc, interrupts, timers, spi & i²c...

Insofar i'm pretty pleased with the stm for everything (but this) in term of bang for the bucks.

if anyone's aware of a hardware specificity of the stm i should take into account...

frankmeyer9
Associate II
Posted on April 19, 2013 at 08:42

How much current had this other board been pulling ?

I suspect your wiring, especially ground, could be inadequate. Such a ground-floating effect would intensify with the current requirements of the MCU.

jejeva
Associate II
Posted on April 19, 2013 at 21:53

worst situation the board is pulling 14mA (7x595 + 11 led + writing 1x24LC00T  eeprom + button not pushed) , even with the stm it's far under the 500mA the usb can provide...

i'm really scratching my head here

frankmeyer9
Associate II
Posted on April 20, 2013 at 10:39

Just to make my idea more clear, I believe the stm32f4 pulls significantly more current than other MCUs you mentioned.

And I never experienced such problems with (as I guess) similiar setups.