2013-12-04 02:27 AM
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
2013-12-04 07:55 AM
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.
2013-12-04 09:31 AM
Uh, the bank clock... #SelfFail
Enabling the clock for the bank and it works fine. Thank you very much for the fast answer. #ThumbsUp