Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the method of porting 03-E53_SC1 expansion board to LiteOS bare metal driver

2025-04-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "what is the method of porting 03-E53_SC1 expansion board to LiteOS bare metal driver", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "what is the method of transplanting 03-E53_SC1 expansion board for LiteOS bare metal drivers"?

1.E53_SC1 expansion Board and its driver about E53 Standard Interface

The E of E53 interface standard is taken from the English initials of Expansion, and the size of the board is 5 × 3cm, so the E53 is used as the prefix to name the case expansion board with the size of 5 × 3cm. Any development board that meets the standard design can be directly adapted to the E53 expansion board.

The E53 expansion board is designed according to different application scenarios, restoring the real application scene on the expansion board to the maximum extent, and the extension boards in different cases are named suffixes according to different application scenarios. For example: E53 smart SC1 Smart City SC is the abbreviation of smart city, SC1 represents the street lamp of smart city, and SC2 represents the smart manhole cover of smart city.

In terms of electrical characteristics, the E53 extended interface includes commonly used sensor communication interfaces in the sensing layer of the Internet of things, such as 5V, 3.3V, GND, SPI, UART, IIC, ADC, DAC, etc., which can adapt to various sensors and leave four common GPIO, as shown in the figure:

E53_SC1 Smart Street Lamp expansion Board

The E53_SC1 expansion board adopts the E53 standard interface and contains a street lamp bead and an BH1750 light intensity sensor, in which the street lamp bead is controlled by ordinary GPIO and BH1750 uses IIC interface to communicate.

If you are not familiar with the driver of the expansion board or BH1750 light intensity, please read the embedded basic tutorial first.

two。 Migrate E53_SC1 driver to LiteOS copy bare metal driver files to LiteOS project

The BH1750 light intensity sensor on the E53_SC1 expansion board uses the IIC communication interface, so in addition to copying the i2c.h and i2c.h files generated by STM32CubeMX, it is also necessary to copy the E53_SC1 expansion board driver file which contains the BH1750 sensor driver.

When copying files, as mentioned in the previous article, copy i2c.h to the Inc folder, copy i2c.c to the Src folder, and then copy the driver files E53_SC1.c and E53_SC1.h written by yourself to the Hardware folder.

The default project provided in IoT-Studio has copied these files and does not need to add them again, as shown in the figure:

Add driver file path

Because the entire project of LiteOS is built using make, after copying the driver file, you need to add the path to the driver file to makefile and add compilation.

The project.mk file indicates the path to all files in the project:

In this file:

C file path

HARDWARE_SRC: the Src folder under the Hardware folder

USER_SRC: corresponding Src folder

Header file path

HARDWARE_INC: the Inc folder under the Hardware folder

USER_INC: corresponding Inc folder

As follows, the underlying I2C interface code i2c.c path of the E53_SC1 driver is added to the USER_SRC:

The underlying I2C interface code i2c.h path of E53_SC1 driver is added to USER_INC:

The E53_SC1 driver file E53_SC1.c based on I2C driver is added to HARDWARE_SRC (not added by default and needs to be added manually):

The E53_SC1 driver file E53_SC1.h based on I2C driver is added to HARDWARE_INC (not added by default and needs to be added manually):

At this point, copy the file to the LiteOS project, add the newly copied file path to the makefile, add the project compilation, and complete the migration of the driver.

3. The use of E53_SC1 bare metal driver to initialize E53_SC1 expansion board

In the previous article, I described in detail two ways to initialize a device in LiteOS:

Initialize before the system starts scheduling: the device can be used by any task in the system at any time

Initialize in a task: the device is generally only used in this task

The E53_SC1 expansion board driver transplanted in this paper does not need multiple tasks to operate, but only needs the operation of the sensor data acquisition task, so the initialization is placed in the data acquisition task.

Operate the E53_SC1 expansion board

Next, first create a folder (if you already have one, don't create it again) to hold the code for this series of tutorial labs:

Create a file in this folder:

Write code:

# include # include "lcd.h" # include "E53_SC1.h" / * stores the sensor data of the E53_SC1 expansion board. You can view the semaphore * / osal_semp_t sync_semp defined in E53_SC1.h * / E53_SC1_Data_TypeDef E53 for synchronization between data acquisition and data processing tasks. / * data acquisition task-low priority * / static int data_collect_task_entry () {/ * initialize the expansion board * / Init_E53_SC1 (); while (1) {/ * read the data on the expansion board and store it in the data structure E53_SC1_Data * / E53_SC1_Read_Data () / * when the data is read, release the semaphore and wake up the data processing task * / osal_semp_post (sync_semp); / * task sleep 2s * / osal_task_sleep (2x1000) }} / * data processing task-High priority * / static int data_deal_task_entry () {/ * lux- current data, old-lux- last data * / int lux = 0, old_lux = 0; / * LCD screen removal to prevent interference with display * / LCD_Clear (WHITE) While (1) {/ * waits for semaphores, blocking and waiting * / osal_semp_pend (sync_semp, cn_osal_timeout_forever) before indicating that data has not been collected; / * semaphores wait, wake up, start processing data * / old_lux = lux; lux = (int) E53_SC1_Data.Lux Printf ("BH1750 Value is% d\ r\ n", lux); LCD_ShowString (10,100,200,16,16, "BH1750 Value is:"); LCD_ShowNum (140,100, lux, 5,16); / * threshold is 1000, automatically turn on or turn off street lamps * / if (old_lux

< 1000 && lux >

1000) {HAL_GPIO_WritePin (SC1_Light_GPIO_Port, SC1_Light_Pin, GPIO_PIN_RESET); printf ("Street Light OFF!\ r\ n");} else if (old_lux > 1000 & & lux

< 1000) { HAL_GPIO_WritePin(SC1_Light_GPIO_Port, SC1_Light_Pin, GPIO_PIN_SET); printf("Street Light ON!\r\n"); } }}/* 标准demo启动函数,函数名不要修改,否则会影响下一步实验 */int standard_app_demo_main(){ /* 创建信号量 */ osal_semp_create(&sync_semp, 1, 0); /* 数据处理任务的优先级应高于数据采集任务 */ osal_task_create("data_collect",data_collect_task_entry,NULL,0x400,NULL,3); osal_task_create("data_deal",data_deal_task_entry,NULL,0x400,NULL,2); return 0;} 然后按照之前的方法,在 user_demo.mk 中将lcd_driver_demo.c文件添加到makefile中,加入编译: 最后在.sdkconfig中配置开启宏定义: 编译,烧录,即可看到实验现象。 LCD屏幕上显示当前传感器采集的亮度值,并且每2s更新一次,当亮度值低于1000时,E53_SC1扩展板的路灯自动点亮: 当亮度值高于1000时,E53_SC1扩展板的路灯自动熄灭: 另外,打开IoT-Studio自带的串口终端,可以查看到串口输出的工作信息: linkmain:V1.2.1 AT 10:40:09 ON Dec 5 2019 BH1750 Value is 220WELCOME TO IOT_LINK SHELLLiteOS:/>

BH1750 Value is 612BH1750 Value is 566BH1750 Value is 14109Street Light offset BH1750 Value is 14814BH1750 Value is 178Street Light onward BH1750 Value is... At this point, I believe you have a deeper understanding of "what is the method of porting 03-E53_SC1 expansion board to LiteOS bare metal driver". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report