2020-10-13 04:24 AM
Hello, in STM32F10x, I need to use Stop mode. However, before going to stop mode, I need to stop PWM channels and leave them high (in output). How can I stop change some pins (A0 and A6) from timer PWM mode to normal output mode? I tried this method but it did not work:
HAL_TIM_PWM_Stop(&htim2,TIM_CHANNEL_1);
HAL_TIM_PWM_Stop(&htim3,TIM_CHANNEL_1);
HAL_GPIO_DeInit(GPIOA,GPIO_PIN_0);
HAL_GPIO_DeInit(GPIOA,GPIO_PIN_6);
HAL_GPIO_Init(GPIOA,GPIO_PIN_0);
HAL_GPIO_Init(GPIOA,GPIO_PIN_6);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_6, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOA,GPIO_PIN_0,1);
HAL_GPIO_WritePin(GPIOA,GPIO_PIN_6,1);
This way also did not work:
//Make PWM channels outputs:
//Reset A port
GPIOA->CRL |= (1<<9);
//output mode General purpose output push/pull (PA0)
GPIOA->CRL &= ~(0b0000<<0);
GPIOA->CRL |=(0b0010<<0);
//output mode General purpose output push/pull (PA6)
GPIOA->CRL &= ~(0b0000<<24);
GPIOA->CRL |=(0b0010<<24);
//Set PA0 high
GPIOA->ODR |= GPIO_ODR_ODR0;
//Set PA6 high
GPIOA->ODR |= GPIO_ODR_ODR6;
2020-10-13 06:12 AM
> HAL_GPIO_DeInit(GPIOA,GPIO_PIN_0);
> HAL_GPIO_DeInit(GPIOA,GPIO_PIN_6);
> HAL_GPIO_Init(GPIOA,GPIO_PIN_0);
> HAL_GPIO_Init(GPIOA,GPIO_PIN_6);
This should have given you error during compiling.
See the following example for how to initialize GPIO pins:
2020-10-13 06:16 AM
Thank you. But why the second method does not work?
2020-10-13 06:59 AM
2020-10-13 07:08 AM
Wouldn't this clear the bits?
GPIOA->CRL &= ~(0b0000<<0);
Then how can I clear them?
2020-10-13 07:12 AM
ah yes GPIOA->CRL &= ~(0b0011<<0);
Would work I believe