2015-06-30 08:08 AM
Hi,
Based on the code below I'm not able to toggle LED PD12 on my STM32F4 Discovery board. It seems that the ''HAL_TIM_OC_DelayElapsedCallback'' function isn't triggered. Channel 1 of TIM1 (PE9) is toggeling, I have check this with a scoop. I don't see any reason why PD12 is not toggled. Why is PD12 not toggled?/*Pinout Configuration*/
void MX_GPIO_Init(void) {
GPIO_InitTypeDef GPIO_InitStruct;
/* GPIO Ports Clock Enable */
__GPIOD_CLK_ENABLE();
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
GPIO_InitStruct.Pin = GPIO_PIN_12;
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
}
int main(int argc, char* argv[]) {
uwPrescalerValue = ((SystemCoreClock / 2) / 84000) - 1;
MX_USART2_UART_Init();
MX_GPIO_Init();
printf(menu);
TimHandle.Instance = TIM1;
TimHandle.Init.Prescaler = uwPrescalerValue;
TimHandle.Init.Period = 65535;
TimHandle.Init.ClockDivision = 0;
TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
if (HAL_TIM_OC_Init(&TimHandle) != HAL_OK) {
/* Initialization Error */
}
/* Common configuration for all channels */
sConfig.OCMode = TIM_OCMODE_TOGGLE;
sConfig.OCPolarity = TIM_OCPOLARITY_LOW;
sConfig.OCNPolarity = TIM_OCNPOLARITY_HIGH;
sConfig.OCFastMode = TIM_OCFAST_DISABLE;
sConfig.OCIdleState = TIM_OCIDLESTATE_RESET;
sConfig.OCNIdleState = TIM_OCNIDLESTATE_RESET;
/* Set the pulse value for channel 1 */
sConfig.Pulse = 40961;
HAL_TIM_OC_ConfigChannel(&TimHandle, &sConfig, TIM_CHANNEL_1);
/* Start channel 1 in Output compare mode */
if (HAL_TIM_OC_Start_IT(&TimHandle, TIM_CHANNEL_1) != HAL_OK) {
/* Starting Error */
}
// Infinite loop
while (1) {
}
}
void HAL_TIM_OC_DelayElapsedCallback(TIM_HandleTypeDef *htim) {
if (htim->Channel == HAL_TIM_ACTIVE_CHANNEL_1) {
HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_12);
}
}
#hal
2018-06-15 11:43 PM
did you put a break point at
HAL_TIM_OC_DelayElapsedCallback to see whether control is indeed coming to that 'if' condition .
also i think you have to use no pull here
GPIO_InitStruct.Pull = GPIO_PULLUP;