cancel
Showing results for 
Search instead for 
Did you mean: 

Using PH2 as GPIO

jr777
Associate
Posted on December 04, 2013 at 11:27

Hi,

i'm using a STM32L151VD for a little project and i want to use the Port H2 as a normal Output for SPI CS. Using another Port (e.g. PC8) all works fine, but with PH2 it does not work at all.

GPIO_InitTypeDef GPIO_InitStructure;
 uint8 condition; 
// SPI CS via PH2
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_400KHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; 
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOH, &GPIO_InitStructure);
// Code only for debugging
GPIO_HIGH(GPIOH, GPIO_Pin_2);
condition = GPIO_ReadInputDataBit(GPIOH, GPIO_Pin_2);
GPIO_LOW(GPIOH, GPIO_Pin_2);
condition = GPIO_ReadInputDataBit(GPIOH, GPIO_Pin_2);
GPIO_HIGH(GPIOH, GPIO_Pin_2);
condition = GPIO_ReadInputDataBit(GPIOH, GPIO_Pin_2);
GPIO_LOW(GPIOH, GPIO_Pin_2);
condition = GPIO_ReadInputDataBit(GPIOH, GPIO_Pin_2);
condition = condition; 
// To prevent compiler warning

The var condition above is always 0 and the port is low all the time. In the datasheet PH2 is defined as IO-Port, is that right or is it a mistake in the datasheet? What should i keep in mind using PH2 as described? Best regards, Juergen #gpioh #stm32 #spi #cs #ph2
2 REPLIES 2
Posted on December 04, 2013 at 16:55

I'm not aware of any magic properties of PH2, so lets start with the basics and confirm you are enabling the GPIOH bank clock. Confirm also other register settings within the bank, and if these also are stuck at zero.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
jr777
Associate
Posted on December 04, 2013 at 18:31

Uh, the bank clock... #SelfFail

Enabling the clock for the bank and it works fine.

Thank you very much for the fast answer. #ThumbsUp