In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to use LiteOS". Friends who are interested might as well take a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn how to use LiteOS.
1.E53_IA1 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_IA1 Smart Agriculture expansion Board
The E53_IA1 expansion board adopts the E53 standard interface, including a supplementary light, a BH1750 light intensity sensor, a small chip motor, a temperature and humidity sensor SHT30, one in which the make-up light and the chip motor are controlled by ordinary GPIO, and BH1750 and SHT30 use IIC interface to communicate.
If you are not familiar with the BH1750 light intensity and temperature and humidity sensor drivers on the expansion board, please read the embedded basic tutorial first.
two。 Migrate E53_IA1 driver to LiteOS copy bare metal driver files to LiteOS project
The BH1750 light intensity sensor and the SHT30 temperature and humidity sensor on the E53_IA1 expansion board use 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_IA1 expansion board driver file which includes the BH1750 sensor driver and the SHT30 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_IA1.c and E53_IA1.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_IA1 driver is added to the USER_SRC:
The underlying I2C interface code i2c.h path of E53_IA1 driver is added to USER_INC:
Because both SC1 and IA1 drivers include BH1750 drivers, you need to be careful to remove the E53_SC1 driver files E53_SC1.c and E53_SC1.h when adding them, otherwise it will cause conflicts.
The E53_IA1 driver file E53_IA1.c based on I2C driver is added to HARDWARE_SRC (not added by default and needs to be added manually):
The E53_IA1 driver file E53_IA1 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_IA1 bare metal driver to initialize E53_IA1 expansion board
In the first article, two ways to initialize a device in LiteOS are described in detail:
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_IA1 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_IA1 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_IA1.h" / * stores the sensor data of the E53_IA1 expansion board. You can view the semaphore defined in E53_IA1.h * / E53_IA1_Data_TypeDef E53 * synchronization between data acquisition and data processing tasks * / osal_semp_t sync_semp / * data acquisition task-low priority * / static int data_collect_task_entry () {/ * initialize the expansion board * / Init_E53_IA1 (); while (1) {/ * read the data on the expansion board and store it in the data structure E53_IA1_Data * / E53_IA1_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 tasks-High priority * / static int data_deal_task_entry () {/ * lux- current data, old-lux- last data * / int lux = 0, old_lux = 0; int temperature = 0, old_temperature = 0; int humidity; / * LCD screen cleaning 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 * / process light intensity old_lux = lux; lux = (int) E53_IA1_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); / * Light threshold is 1000, automatically turn on or turn off street lamps * / if (old_lux
< 1000 && lux >1000) {HAL_GPIO_WritePin (IA1_Light_GPIO_Port, IA1_Light_Pin, GPIO_PIN_RESET); printf ("Light OFF!\ r\ n");} else if (old_lux > 1000 & & lux
< 1000) { HAL_GPIO_WritePin(IA1_Light_GPIO_Port, IA1_Light_Pin, GPIO_PIN_SET); printf("Light ON!\r\n"); } //处理湿度数据 humidity = E53_IA1_Data.Humidity; printf("Humidity is %d\r\n", humidity); LCD_ShowString(10, 120, 200, 16, 16, "Humidity: "); LCD_ShowNum(140, 120, humidity, 5, 16); //处理温度数据 old_temperature = temperature; temperature = E53_IA1_Data.Temperature; printf("Temperature is %d\r\n", temperature); LCD_ShowString(10, 140, 200, 16, 16, "Temperature: "); LCD_ShowNum(140, 140, temperature, 5, 16); /* 温度阈值为30,自动开启或者关闭电机 */ if(old_temperature < 30 && temperature >= 30) {HAL_GPIO_WritePin (IA1_Motor_GPIO_Port, IA1_Motor_Pin, GPIO_PIN_SET); printf ("Motor ON!\ r\ n");} else if (old_temperature > = 30 & & temperature
< 30) { HAL_GPIO_WritePin(IA1_Motor_GPIO_Port, IA1_Motor_Pin, GPIO_PIN_RESET); printf("Motor OFF!\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 中将e51_ia1_driver_demo.c文件添加到makefile中,加入编译: 最后在.sdkconfig中配置开启宏定义: 编译,烧录,即可看到实验现象。 LCD屏幕上显示当前传感器采集的亮度值,温度值,湿度值,并且每2s更新一次。 当亮度值低于1000时,E53_IA1扩展板的补光灯自动点亮: 当亮度值高于1000时,E53_IA1扩展板的补光灯自动熄灭: 在调节温度的时候,可以用手按着SHT30温湿度传感器,天干物燥,务必提前触摸一下金属物体,释放静电,防止静电破坏传感器! 当温度上升到30°的时候,电机自动启动,当温度降低到30°以下时,电机自动关闭。 另外,打开IoT-Studio自带的串口终端,可以查看到串口输出的工作信息: linkmain:V1.2.1 AT 10:40:09 ON Dec 5 2019 BH1750 Value is 237Humidity is 19Temperature is 28WELCOME TO IOT_LINK SHELLLiteOS:/>BH1750 Value is 1074Light offline humorous is 19Temperature is 29BH1750 Value is 14086Humidity is 20Temperature is 30Motor on BH1750 Value is 284Light on humane is 21Temperature is 30BH1750 Value is 303Humidity is 21Temperature is 29Motor OFF! At this point, I believe you have a deeper understanding of "how to use LiteOS". 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.