2023-08-14 06:45 AM
Hi all,
I am trying to toggle a IO pin but the pin just will not turn on.
I checked register values at startup before main(), and some of the values are the the same as the reset values shown in the reference manual:
Every register has been set to the reset value of MODER of the corresponding GPIO port, but not the register's own reset value.
I initialized the IO pins and ports, and set them, but the voltage on the pin would still be GND
LL_GPIO_ResetOutputPin(TIN_PORT, TIN_PIN);
LL_GPIO_ResetOutputPin(TOUT_PORT, TOUT_PIN);
/* GPIO Ports Clock Enable */
LL_APB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA);
LL_APB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB);
LL_APB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC);
LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
GPIO_InitStruct.Pin = ADIN_PIN|(ADIN_PIN << 1);
GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
LL_GPIO_Init(ADIN_PORT, &GPIO_InitStruct);
/*TRIP GPIO Configuration
PB8 ------> TRIP
*/
GPIO_InitStruct.Pin = TRIP_PIN;
GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
GPIO_InitStruct.Pull = LL_GPIO_PULL_DOWN;
LL_GPIO_Init(TRIP_PORT, &GPIO_InitStruct);
GPIO_InitStruct.Pin = TOUT_PIN;
GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
LL_GPIO_Init(TOUT_PORT, &GPIO_InitStruct);
What is happening and is there a way to fix it?
Thanks in advance,
Zhi
Solved! Go to Solution.
2023-08-16 01:43 AM - edited 2023-08-16 01:43 AM
If you observe this behaviour for GPIO, read out and check also the respective RCC clock enable register.
If you'd do that, you'd realize what's the error:
> LL_APB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA);
JW
2023-08-14 07:12 AM
Seems like a debugger issue. Look at the settings immediately after enabling the clocks. If they're correct, step through to see where they get changed.
2023-08-15 04:37 AM - edited 2023-08-15 04:37 AM
Every register has been set to the reset value of MODER of the corresponding GPIO port, but not the register's own reset value.
This is how GPIO behave before you enable their clocks.
Read out and check/post content of GPIO registers after you've set them up.
JW
2023-08-16 01:15 AM
Hi,
I did enable the clocks in the GPIO init function:
LL_APB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA);
LL_APB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB);
LL_APB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC);
2023-08-16 01:43 AM - edited 2023-08-16 01:43 AM
If you observe this behaviour for GPIO, read out and check also the respective RCC clock enable register.
If you'd do that, you'd realize what's the error:
> LL_APB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA);
JW
2023-08-16 02:20 AM
You're right. Thank you very much!