cancel
Showing results for 
Search instead for 
Did you mean: 

STM8 STVD coding help needed

kumaresh
Associate II
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
1 REPLY 1
rmottes
Associate II
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