stm8s---IO multiplexing configuration

Source: Internet
Author: User

1 description

Stm8s's IO Multiplexing program code is cumbersome to configure, typically operating 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.

2 configuration process

"Step1" Open STVP Software

"Step2" opens the Xxx.s19 file we need to download, ctrl+f5 (File->ram Exec)
"STEP3" configuration requires a multiplexed pin
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 in the drop-down menu in AFR1.
"step4" Download 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 high-speed 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 compare three modesTIM2_CCMR3 |=0x04;//Output comparison 3 pre-load enableTim2_ccer2 |=0x03;//Channel 3 Enable, low active, configured as output //Initialize the clock divider to 1, i.e. the counter clock frequency is Fmaster=8m/64=0.125mhzTIM2_PSCR =0x06;//Initialize the automatic load register to determine the frequency of the PWM square wave, fpwm=0.125m/62500=2hzTim2_arrh =62500/ the; TIM2_ARRL =62500% the;//Initialize 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 PD2 port to output modePD_CR1 |=0x04;//Set PD2 port to push-pull output modePd_cr2 &=0XFD;pa_ddr|=0X08;//Set PA3 port to output modePA_CR1 |=0X08;//Set PA3 port to push-pull output modePa_cr2 |=0xf7;}voidMainvoid) {clk_init (); Init_gpio (); INIT_TIM2 (); while(1);}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

stm8s---IO multiplexing configuration

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.