stm8s: GPIO configuration, light up the LED! PB4, PB5 pin LEDs do not light up

Publisher:科技创客Latest update time:2020-01-31 Source: eefocusKeywords:stm8s Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

I have been developing STM8S103 for the past two days. After adjusting the hardware, I started to write the software. The first step was to light up the LED light. It turned out to be embarrassing that it just wouldn't light up! Later, I searched Baidu and carefully checked the data sheet, only to find a big pitfall. Due to carelessness, I didn't see it and made a note as a reminder.


1. Process

To light up the LED, the process is basically the same as that of STM32:


(1) Configure GPIO (STM8S does not require the clock of each pin to be configured specifically, and the system clock can be configured at the beginning)

(2) GPIO output high and low levels

Without further ado, let's get straight to the code:


2. Code

//FUNCKTION: Initialize the LED light GPIO port

//PARA: None

//RETURN : None

void LED_Config() 

{

    GPIO_Init(GPIOB, GPIO_PIN_5, GPIO_MODE_OUT_PP_LOW_SLOW);

    GPIO_Init(GPIOB, GPIO_PIN_4, GPIO_MODE_OUT_PP_LOW_SLOW);

}


//FUNCKTION: Turn on the LED light

//PARA: None

//RETURN : None

void LED_ON()

{

    GPIO_WriteHigh(GPIOB, GPIO_PIN_4);

    GPIO_WriteHigh(GPIOB, GPIO_PIN_5);

}


//FUNCKTION: Turn off the LED light

//PARA: None

//RETURN : None

void LED_OFF()

{

    GPIO_WriteLow(GPIOB, GPIO_PIN_4);

    GPIO_WriteLow(GPIOB, GPIO_PIN_5);

}


3. The problem of LED not lighting up no matter how hard you try

Because the two GPIO ports *PB4 and PB5 are used, the following figure can be seen in the data sheet: 


Write the picture description here

You can see that the GPIO port marked in the red circle is T(3). Continue scrolling down to the bottom of the table to see the description of T(3): 

Write the picture description here

I'm not good at English, so I won't translate it. Anyway, the meaning is that you need to add pull-up or pull-down resistors externally, otherwise it will be useless.


So, I quickly found a wire, made a line, connected a resistor, and it was done. ~~~Haha. . .

Keywords:stm8s Reference address:stm8s: GPIO configuration, light up the LED! PB4, PB5 pin LEDs do not light up

Previous article:STM8S103FP6 chip PB_4/PB_5 output problem
Next article:STM8S103 tim4 ordinary timer

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号