cancel
Showing results for 
Search instead for 
Did you mean: 

STM8 GPIO does not stay high (Solved)

Kmax18
Senior

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;

11 REPLIES 11

Hi Tesla, thank you for your quick response. The main.c source file is attached. please have a look. This is the code example that comes with the ST Application Note AN5178. ONly SPL function write to the output, I believe.

I made one change in Line 43 to accommodate the Nucleo-8S208RB:

#define LEDS_PORT (GPIOC) //for Nucleo-8S208RB

Thank you for your feedback!

-km

Kmax18
Senior

This issue is resolved with a workaround for ST Visual Programmer (STVP). I assume e better solution exists.

Option 1: Program the Nucleo-8S208RB with the STVP. Close STVP: the Nucleo's COM LED turns red and the application starts running.

Option 2: Program the Nucleo-8S208RB with the STVP. Open the Configuration window (see below): the COM LED turns ghreen. Click OK: the application start to run.

0693W00000SudklQAB.png