Skip to main content
kumaresh
Associate II
May 27, 2015
Question

STM8 STVD coding help needed

  • May 27, 2015
  • 1 reply
  • 1327 views
Posted on May 27, 2015 at 14:04

hello again, how to do bit handling in STVD for STM8s for ex i want to set PA1 = 0 or CEN = 1, enable timer1. i dont see any header file supporting the same. please give me some examples.

thank you

#bit-handling #stm8 #stvd
    This topic has been closed for replies.

    1 reply

    rmottes
    Associate
    May 30, 2015
    Posted on May 30, 2015 at 23:29

    I think I understand your request.

    You need to add some standard modules that are included in the STM8S library.

    To set/clear bits like PA1 you need to add stm8s_gpio.c to your project, then use one of the built in functions such as,

    GPIO_WriteHigh(GPIO_TypeDef* GPIOx, GPIO_Pin_TypeDef PortPins) and

    GPIO_WriteLow(GPIO_TypeDef* GPIOx, GPIO_Pin_TypeDef PortPins) to set high and low.

    Example: GPIO_WriteHigh(GPIOA, GPIO_PIN_1); // sets port A bit 1 high

    For timers you will need to  add stm8s_timX.c to your project (Where X=1,2,3 or 4 to indicate which timer you are using).

    Example:

    // setup and start timer 3, used as a free running timer

    TIM3_DeInit();   // reset timer 3

    TIM3_TimeBaseInit(TimerPrescale, 0xffff);  // prescaler 0x7fff, time period 0xffff

    TIM3_Cmd(ENABLE); // enable timer 3

    For other functions like interrupt control registers you can write directly to an address (look up the address and bit values in the reference manual, I use RM0016).

    Example:

    EXTI->CR1 = 0x08; // set port B interrupts to falling edge only

    Hope this helps.

    Rick