STM8 GPIO does not stay high (Solved)
Hello, I am studying the STM8S208RB MCU and the SPL. I am using STVD and COSMIC, and the Nucleo-8S208RB board for testing.
The below code should configure port GPIOC Pin5 and set it to high and stay high. However, LED2 turns on for only a short moment, not permanently. The STM8 Nucleo-64 board has the User LED2 on GPIO Port C, Pin 5.
What is wrong with the code? Thank you!
/* Configure the LED2 GPIO */
/* Reset the GPIO Pin in CR2 register */
LED2_GPIO_PORT->CR2 &= (uint8_t)(~(LED2_GPIO_PIN));
/* Output mode selection */
LED2_GPIO_PORT->ODR |= (uint8_t)LED2_GPIO_PIN; /* High level output */
LED2_GPIO_PORT->DDR |= (uint8_t)LED2_GPIO_PIN; /* Output mode */
LED2_GPIO_PORT->CR1 |= (uint8_t)LED2_GPIO_PIN; /* Push-Pull output mode */
LED2_GPIO_PORT->CR2 |= (uint8_t)LED2_GPIO_PIN; /* 10 MHz fast output */
/* Turn On LED2 */
LED2_GPIO_PORT->ODR |= (uint8_t)LED2_GPIO_PIN;