Alibaba Cloud HaaS100 IoT development board study notes (2) Preliminary hardware control-make the lights flash

Abstract: No matter what kind of development board, if you want to develop a specific function, you must first start with GPIO, and the same is true for HaaS100 development. It would be too wasteful to use only the networking function of HaaS100. HaaS100 has all the functions of other development boards, such as GPIO, IIS, IIC, SPI, PWM, etc. After the blink_demo in the example is compiled and downloaded to the HaaS100 development board, the 5 indicator lights are turned on and off at the same time. How to control each indicator is not described in detail in the official document. This article starts with controlling a specific GPIO to realize a single LED blinking, and introduces the Alibaba Cloud blink_demo routine in more depth, and enters the HaaS100 underlying hardware development with everyone.

table of Contents

Purpose

1. Operation steps

1.1 Setting up a programming environment

         1.2 Modify the program

1.3 Compile

1.4 Burn

2 Programming effect

3. Principle analysis

3.1 Hardware analysis

3.2 Software analysis

4 Conclusion

 


Hardware: HaaS100 IoT development board

Software: aos (command line version), win7 x64 system

 

Purpose

Program a single LED light to blink.

 

 

1. Operation steps

1.1 Setting up a programming environment

Please refer to the link below for detailed steps. If you have successfully compiled and downloaded helloworld_demo, it proves that you have mastered the basic operations. Please ignore the step of setting up a programming environment.

Basic steps for beginners to get started with Alibaba Cloud Haas100 development board

1.2 Modify the program

Open blink_demo.c in the C:\Users\Administrator\AliOS-Things\application\example\blink_demo directory.

Various tools can be used according to personal preference. Notepad++ is recommended.

Can be downloaded through the link https://download.csdn.net/download/youngwah292/12127037

After opening, go to line 31 and replace the original GPIO_LED_IO with 0x22. Why use the special hexadecimal number 0x22 instead? We will analyze it in detail later.

Note that after the modification, be sure to click the save button. Otherwise, the unmodified code may be compiled.

1.3 Compile

Use cmd command to open the command line

Then use the cd command to go to the alios-things directory

cd alios-things

Then run the configuration command

aos make blink_demo@haas100 -c config

Then compile

aos make

The interface for successful compilation is as shown in the figure below. If the compilation is unsuccessful, please refer to the basic steps of getting started with Alibaba Cloud Haas100 development board for beginners.

1.4 Burn

First, ensure that the development board is powered, and connect the Micro USB cable to the computer, and ensure that the USB driver is successfully installed.

Enter the directory C:\Users\Administrator\AliOS-Things\platform\mcu\haas1000\release\write_flash_gui

Find burning tool

Double click to open

Set the serial port number

Select burn

Unplug the power cord first, then plug it in again

Burning starts at this time. After the burning is completed, click Stop.

 

2 Programming effect

As shown in the figure below, the LED selected in the red frame flashes at intervals of 1 second

3. Principle analysis

3.1 Hardware analysis

Why can the specified LED blink by changing GPIO_LED_IO to 0x22 instead of blinking all at once?

Let’s look at Alibaba Cloud’s official documents, the pin numbers of these 5 LEDs are 40 41 36 35 34

https://help.aliyun.com/document_detail/184426.html?spm=a2c4g.11186623.6.692.2cfc5186bqGYXP

To represent them in hexadecimal, they are 0x28(40 LED1) 0x29(41 LED2) 0x24(36 LED3) 0x23(35 LED4) 0x22(34 LED5)

After testing, LED1 (0x28) cannot be used after programming (tested twice, the reason to be determined), the LED number is marked as follows:

3.2 Software analysis

The flicker in the routine is realized by the hal_gpio_output_toggle function, and toggle means "toggle" in English.

The prototype of the function is located in C:\Users\Administrator\AliOS-Things\platform\mcu\haas1000\hal

HAL means Hardware Abstraction Layer (Hardware Abstraction Layer)

The content of the gpio.c file is as shown in the figure below. This file has not directly operated gpio, and the hardware driver is also called to complete the hardware operation.

 

4 Conclusion

In this example, application/example/helloworld_demo/appdemo.c recommended in the official Alibaba Cloud documentation is not used, but blink_demo is used, in order to analyze the operation of GPIO more deeply. HaaS100 has rich hardware resources, and mastering a simple GPIO operation will lay the foundation for operating other hardware.

 

Please refer to other supporting documents

Basic steps for beginners to get started with Alibaba Cloud Haas100 development board

Alibaba Cloud HaaS100 IoT Development Board Study Notes (1) Introduction to Hardware Resources

 

Guess you like

Origin blog.csdn.net/youngwah292/article/details/109233621