stm8s---IO multiplexing configuration (STVP mode)

Source: Internet
Author: User

1 description

Stm8s's IO Multiplexing program code is more cumbersome to configure. Typically, you manipulate flash to manipulate the option byte byte. Configuration registers are more cumbersome and can be set using the STM standard Peripheral driver Library.

This article uses an interface configuration to configure the IO multiplexing pin, which is configured using STVP. Because the data that is saved by Flash is not lost, first use STVP to erase the option bytes, then use the STVD emulator to burn the code to achieve IO multiplexing.

?? Program Mode configuration IO multiplexing See here

2 configuration process

"Step1" Open STVP Software

"Step2" opens the Xxx.s19 file we need to download, ctrl+f5 (File->ram Exec)
"STEP3" configuration of the required pins
The reuse function of IO port is mainly configured in AFR0-AFR7. Here we configure the Timer TIM2_CH3 Channel PWM output pin multiplexing, the default is PD2 for the output, it is configured to re-use as the PA3 output. For example, select PA3 from the drop-down menu in AFR1.

"step4" Download the program to stm8s. progam->all tabs. This enables the IO multiplexing configuration.
3 Test procedure
/*tim2_ch3 PWMPD2 output*/#include <STM8S103F3P.h>voidClk_init (void){Clk_ickr|=0x01;//Enable internal fast clock HSICLK_CKDIVR|=0x08;//16M internal RC via 2, System clock is 8M  while(! (clk_ickr&0x02));//hsi ready .Clk_swr=0xe1;//HSI Primary Clock source}voidINIT_TIM2 (void) {TIM2_CCMR3 |=0X70;//Set timer 23-channel (PD2) output in three modesTIM2_CCMR3 |=0x04;//Output 3 pre -loaded enableTim2_ccer2 |=0x03;//Channel 3 enable. Low level active. Configured as output //Initialize the clock divider to 1. That is, the clock frequency of the counter is Fmaster=8m/64=0.125mhzTIM2_PSCR =0x06;//Initialize your own active load register. Determines the frequency of the PWM square wave, fpwm=0.125m/62500=2hzTim2_arrh =62500/ the; TIM2_ARRL =62500% the;//Initialize the comparison register to determine the duty ratio of the PWM square wave: 5000/10000 = 50%TIM2_CCR3H =31250/ the; TIM2_CCR3L =31250% the;//Start count; Update Interrupt deactivationTIM2_CR1 |=0x81;//tim2_ier |= 0x00; }voidInit_gpio (void){/ * Set to push-pull output, PD2 LED light * /pd_ddr|=0x04;//Set Pd2port to output modePD_CR1 |=0x04;//Set Pd2port to push-pull output modePd_cr2 &=0XFD;pa_ddr|=0X08;//Set Pa3port to output modePA_CR1 |=0X08;//Set Pa3port to push-pull output modePa_cr2 |=0xf7;}voidMainvoid) {clk_init (); Init_gpio (); INIT_TIM2 (); while(1);}

stm8s---IO multiplexing configuration (STVP mode)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.