HarmonyOS小熊派 | HarmonyOS传感器驱动开发--E53_SC2读取三轴加速度

举报
Yuchuan 发表于 2021/07/24 13:56:31 2021/07/24
【摘要】 传感器驱动开发--E53_SC2读取三轴加速度

BearPi-HM_Nano开发板传感器驱动开发——E53_SC2读取三轴加速度

本示例将演示如何在BearPi-HM_Nano开发板上使用E53_SC2读取三轴加速度

BearPi-HM_Nano

E53_SC2 API分析

本案例主要使用了以下API完成三轴加速度读取

1、InitE53SC2()

/***************************************************************
* 函数名称: InitE53SC2
* 说    明: 初始化Init_E53_SC2
* 参    数: 无
* 返 回 值: 无
***************************************************************/
void InitE53SC2(void)

描述:

初始化E53_SC2

2、ReadDataE53SC2()

/***************************************************************
* 函数名称: ReadDataE53SC2
* 说    明: 读取数据
* 参    数: 无
* 返 回 值: 无
***************************************************************/
void ReadDataE53SC2(void)

描述: 读取三轴加速度及温度

3、LED_D1_StatusSet()

/***************************************************************
* 函数名称: LED_D1_StatusSet
* 说    明: LED_D1状态设置
* 参    数: status,ENUM枚举的数据
*									OFF,关
*									ON,开
* 返 回 值: 无
***************************************************************/
void LED_D1_StatusSet(E53_SC2_Status_ENUM status)

描述: 设置D1 LED的状态

3、LED_D2_StatusSet()

/***************************************************************
* 函数名称: LED_D2_StatusSet
* 说    明: LED_D2状态设置
* 参    数: status,ENUM枚举的数据
*									OFF,关
*									ON,开
* 返 回 值: 无
***************************************************************/
void LED_D2_StatusSet(E53_SC2_Status_ENUM status)

描述: 设置D2 LED的状态

硬件设计

本案例将用到 E53_SC2 智慧井盖扩展板与 BearPi-HM_Nano 开发板,其中E53_SC2扩展板原理图如下,三轴加速度传感器MPU6050是通过I2C来驱动。

E53_SC2 智慧井盖扩展板与 BearPi-HM_Nano 开发板安装

软件设计

主要代码分析

首先调用 InitE53SC2() 函数初始化E53_SC2所接的引脚的功能,然后循环调用 ReadDataE53SC2() 函数读取三轴加速度并通过串口打印出来,设置第一次读出的三轴加速度为水平状态,当倾斜开发板后会点亮扩展板上倾斜倾斜状态的灯

yuchuan_e53_sc2.c

#include <stdio.h>
#include <string.h>
#include <unistd.h>

#include "e53_sc2.h"
#include "ohos_init.h"
#include "cmsis_os2.h"

#define TASK_E53_SC2_CB_SIZE 0U
#define TASK_E53_SC2_STACK_SIZE 1024 * 8
#define TASK_E53_SC2_PRIORITY 25

E53_SC2_Data_TypeDef E53_SC2_Data;
int X = 0, Y = 0, Z = 0;

static void YuchuanE53SC2Task(void)
{
    // 初始化E53 接口
    InitE53SC2();
    while (1)
    {
        printf("===============================================\r\n");
        printf("*************Yuchuan E53_SC2_Example***********\r\n");
        printf("===============================================\r\n");

        // 通过E53接口读取传感器数据
        ReadDataE53SC2();

        printf("\r\n******************************Temperature      is  %d\r\n", (int)E53_SC2_Data.Temperature);
        printf("\r\n******************************Accel[0]         is  %d\r\n", (int)E53_SC2_Data.Accel[0]);
        printf("\r\n******************************Accel[1]         is  %d\r\n", (int)E53_SC2_Data.Accel[1]);
        printf("\r\n******************************Accel[2]         is  %d\r\n", (int)E53_SC2_Data.Accel[2]);

        if (X == 0 && Y == 0 && Z == 0)
        {
            X = (int)E53_SC2_Data.Accel[0];
            Y = (int)E53_SC2_Data.Accel[1];
            Z = (int)E53_SC2_Data.Accel[2];
        }
        else
        {
            if ((X + 100) < E53_SC2_Data.Accel[0] || (X - 100) > E53_SC2_Data.Accel[0] || (Y + 100) < E53_SC2_Data.Accel[1] || (Y - 100) > E53_SC2_Data.Accel[1] || (Z + 100) < E53_SC2_Data.Accel[2] || (Z - 100) > E53_SC2_Data.Accel[2])
            {
                LED_D1_StatusSet(OFF);
                LED_D2_StatusSet(ON);
            }
            else
            {
                LED_D1_StatusSet(ON);
                LED_D2_StatusSet(OFF);
            }
        }
        usleep(1000000);
    }
}

static void YuchuanE53SC2Entry(void)
{
    osThreadAttr_t threadAttr;
    threadAttr.attr_bits = 0U;
    threadAttr.cb_mem = NULL;
    threadAttr.cb_size = TASK_E53_SC2_CB_SIZE;
    threadAttr.stack_mem = NULL;
    threadAttr.stack_size = TASK_E53_SC2_STACK_SIZE;
    threadAttr.priority = TASK_E53_SC2_PRIORITY;

    threadAttr.name = "YuchuanE53SC2Task";
    if (osThreadNew((osThreadFunc_t)YuchuanE53SC2Task, NULL, &threadAttr) == NULL)
    {
        printf("Falied To Create YuchuanE53SC2Task!!!\n");
    }
}

APP_FEATURE_INIT(YuchuanE53SC2Entry);

src/e53_sc2.c

/*
 * Copyright (c) 2020 Nanjing Xiaoxiongpai Intelligent Technology Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <math.h>

#include "e53_sc2.h"
#include "iot_gpio.h"
#include "iot_gpio_ex.h"
#include "iot_i2c.h"
#include "iot_i2c_ex.h"
#include "cmsis_os2.h"

#define IOT_IO_LED_GPIO_7 7
#define IOT_IO_E53_GPIO_8 8
#define IOT_IO_GPIO_0_I2C1_SDA 0
#define IOT_IO_GPIO_1_I2C1_SCL 1
#define IOT_I2C_IDX_1 1

/***************************************************************
* 函数名称: IoInitE53SC2
* 说    明: E53_SC2_GPIO初始化
* 参    数: 无
* 返 回 值: 无
***************************************************************/
static void IoInitE53SC2(void)
{
    // 初始化LED GPIO
    IoTGpioInit(IOT_IO_LED_GPIO_7);
    // 设置GPIO的输出方向
    IoTGpioSetDir(IOT_IO_LED_GPIO_7, IOT_GPIO_DIR_OUT);
    // 设置GPIO的功能为普通GPIO
    IoTGpioSetFunc(IOT_IO_LED_GPIO_7, IOT_GPIO_FUNC_GPIO_7_GPIO);

    // 初始化E53 GPIO
    IoTGpioInit(IOT_IO_E53_GPIO_8);
    IoTGpioSetDir(IOT_IO_E53_GPIO_8, IOT_GPIO_DIR_OUT);
    IoTGpioSetFunc(IOT_IO_E53_GPIO_8, IOT_GPIO_FUNC_GPIO_8_GPIO);

    // 初始化I2C_SDA
    IoTGpioInit(IOT_IO_GPIO_0_I2C1_SDA);
    IoTGpioSetFunc(IOT_IO_GPIO_0_I2C1_SDA, IOT_GPIO_FUNC_GPIO_0_I2C1_SDA);

    // 初始化I2C_SCL
    IoTGpioInit(IOT_IO_GPIO_1_I2C1_SCL);
    IoTGpioSetFunc(IOT_IO_GPIO_1_I2C1_SCL, IOT_GPIO_FUNC_GPIO_1_I2C1_SCL);

    // 初始化I2C
    // unsigned int IoTI2cInit(unsigned int id, unsigned int baudrate);
    /* baudrate: 400kbps */
    IoTI2cInit(IOT_I2C_IDX_1, 400000);
}

/***************************************************************
  * 函数功能: 通过I2C写入一个值到指定寄存器内
  * 输入参数: Addr:I2C设备地址
  *           Reg:目标寄存器
  *           Value:值
  * 返 回 值: 无
  * 说    明: 无
  **************************************************************/
static void WrieDataI2CMPU6050(uint8_t Reg, uint8_t Value)
{
    uint8_t send_data[2] = {Reg, Value};
    // unsigned int IoTI2cWrite(unsigned int id, unsigned short deviceAddr, const unsigned char *data, unsigned int dataLen);
    IoTI2cWrite(IOT_I2C_IDX_1, (MPU6050_SLAVE_ADDRESS) << 1 | 0x00, send_data, 2);
}

/***************************************************************
  * 函数功能: 写数据到MPU6050寄存器
  * 输入参数: 无
  * 返 回 值: 无
  * 说    明: 无
  ***************************************************************/
static void WriteRegMPU6050(uint8_t reg_add, uint8_t reg_dat)
{
    // 通过I2C写数据到寄存器
    WrieDataI2CMPU6050(reg_add, reg_dat);
}

/***************************************************************
  * 函数功能: 自由落体中断
  * 输入参数: 无
  * 返 回 值: 无
  * 说    明: 无
  **************************************************************/
void Free_Fall_Interrupt(void)
{
    // 自由落体阈值
    WriteRegMPU6050(MPU6050_RA_FF_THR,0x01);
    // 自由落体检测时间20ms 单位1ms 寄存器0X20
    WriteRegMPU6050(MPU6050_RA_FF_DUR,0x01);
}

/***************************************************************
  * 函数功能: 运动中断
  * 输入参数: 无
  * 返 回 值: 无
  * 说    明: 无
  **************************************************************/
void Motion_Interrupt(void)
{
    // 运动阈值
    WriteRegMPU6050(MPU6050_RA_MOT_THR, 0x03);
    // 检测时间20ms 单位1ms 寄存器0X20
    WriteRegMPU6050(MPU6050_RA_MOT_DUR, 0x14);
}

/***************************************************************
  * 函数功能: 静止中断
  * 输入参数: 无
  * 返 回 值: 无
  * 说    明: 无
  **************************************************************/
void Zero_Motion_Interrupt(void)
{
    // 静止阈值
    WriteRegMPU6050(MPU6050_RA_ZRMOT_THR,0x20);
    // 静止检测时间20ms 单位1ms 寄存器0X20
    WriteRegMPU6050(MPU6050_RA_ZRMOT_DUR,0x20);
}

/***************************************************************
  * 函数功能: 初始化MPU6050芯片
  * 输入参数: 无
  * 返 回 值: 无
  * 说    明: 无
  ***************************************************************/
static void InitMPU6050(void)
{
    int i = 0, j = 0;
    //在初始化之前要延时一段时间,若没有延时,则断电后再上电数据可能会出错
    for (i = 0; i < 1000; i++)
    {
        for (j = 0; j < 1000; j++)
        {
            ;
        }
    }
    // 复位MPU6050
    WriteRegMPU6050(MPU6050_RA_PWR_MGMT_1, 0X80);
    usleep(20000);
    // 唤醒MPU6050
    WriteRegMPU6050(MPU6050_RA_PWR_MGMT_1, 0X00);
    // 关闭所有中断
    WriteRegMPU6050(MPU6050_RA_INT_ENABLE, 0X00);
    // I2C主模式关闭
    WriteRegMPU6050(MPU6050_RA_USER_CTRL, 0X00);
    // 关闭FIFO
    WriteRegMPU6050(MPU6050_RA_FIFO_EN, 0X00);
    // 中断的逻辑电平模式,设置为0,中断信号为高电;设置为1,中断信号为低电平时。
    WriteRegMPU6050(MPU6050_RA_INT_PIN_CFG, 0X80);
    // 运动中断
    Motion_Interrupt();
    // 配置外部引脚采样和DLPF数字低通滤波器
    WriteRegMPU6050(MPU6050_RA_CONFIG, 0x04);
    // 加速度传感器量程和高通滤波器配置
    WriteRegMPU6050(MPU6050_RA_ACCEL_CONFIG, 0x1C);
    // INT引脚低电平平时
    WriteRegMPU6050(MPU6050_RA_INT_PIN_CFG, 0X1C);
    // 中断使能寄存器
    WriteRegMPU6050(MPU6050_RA_INT_ENABLE, 0x40);
}

/***************************************************************
* 函数名称: InitE53SC2
* 说    明: 初始化Init_E53_SC2
* 参    数: 无
* 返 回 值: 无
***************************************************************/
void InitE53SC2(void)
{
    // 初始化E53接口相关的GPIO
    IoInitE53SC2();
    // 初始化MPU6050芯片
    InitMPU6050();
    osDelay(100);
}

/***************************************************************
  * 函数功能: 通过I2C读取一段寄存器内容存放到指定的缓冲区内
  * 输入参数: Addr:I2C设备地址
  *           Reg:目标寄存器
  *           RegSize:寄存器尺寸(8位或者16位)
  *           pBuffer:缓冲区指针
  *           Length:缓冲区长度
  * 返 回 值: HAL_StatusTypeDef:操作结果
  * 说    明: 无
  **************************************************************/
uint8_t I2C_MPU6050_ReadBuffer(uint8_t Reg, uint8_t *pBuffer, uint16_t Length)
{
    uint32_t status = 0;
    IotI2cData mpu6050_i2c_data = {0};
    uint8_t buffer[1] = {Reg};
    mpu6050_i2c_data.sendBuf = buffer;
    mpu6050_i2c_data.sendLen = 1;
    mpu6050_i2c_data.receiveBuf = pBuffer;
    mpu6050_i2c_data.receiveLen = Length;
    // unsigned int IoTI2cWriteread(unsigned int  id, unsigned short deviceAddr, const IotI2cData *i2cData);
    status = IoTI2cWriteread(IOT_I2C_IDX_1, (MPU6050_SLAVE_ADDRESS << 1) | 0x00, &mpu6050_i2c_data);
    if (status != 0)
    {
        printf("===== Error: I2C write status = 0x%x! =====\r\n", status);
        return status;
    }
    return 0;
}

/***************************************************************
  * 函数功能: 从MPU6050寄存器读取数据
  * 输入参数: 无
  * 返 回 值: 无
  * 说    明: 无
***************************************************************/
void MPU6050_ReadData(uint8_t reg_add, unsigned char *Read, uint8_t num)
{
    I2C_MPU6050_ReadBuffer(reg_add, Read, num);
}

/***************************************************************
  * 函数功能: 读取MPU6050的ID
  * 输入参数: 无
  * 返 回 值: 无
  * 说    明: 无
  ***************************************************************/
uint8_t MPU6050ReadID(void)
{
    unsigned char Re = 0;
    // 读器件地址
    MPU6050_ReadData(MPU6050_RA_WHO_AM_I, &Re, 1);
    if (Re != 0x68)
    {
        printf("Re is : %x\r\n",Re);
        printf("MPU6050 dectected error!\r\n");
        return 0;
    }
    else
    {
        return 1;
    }
}

/***************************************************************
  * 函数功能: 读取MPU6050的加速度数据
  * 输入参数: 无
  * 返 回 值: 无
  * 说    明: 无
***************************************************************/
static void MPU6050ReadAcc(short *accData)
{
    uint8_t buffer[6];
    MPU6050_ReadData(MPU6050_ACC_OUT, buffer, 6);
    accData[0] = (buffer[0] << 8) | buffer[1];
    accData[1] = (buffer[2] << 8) | buffer[3];
    accData[2] = (buffer[4] << 8) | buffer[5];
}

/***************************************************************
  * 函数功能: 读取MPU6050的角速度数据
  * 输入参数: 无
  * 返 回 值: 无
  * 说    明: 无
 ***************************************************************/
static void MPU6050ReadGyro(short *gyroData)
{
    uint8_t buff[6];
    MPU6050_ReadData(MPU6050_GYRO_OUT,buff,6);
    gyroData[0] = (buff[0] << 8) | buff[1];
    gyroData[1] = (buff[2] << 8) | buff[3];
    gyroData[2] = (buff[4] << 8) | buff[5];
}

/***************************************************************
  * 函数功能: 读取MPU6050的温度数据,转化成摄氏度
  * 输入参数: 无
  * 返 回 值: 无
  * 说    明: 无
  **************************************************************/
static void MPU6050_ReturnTemp(short *Temperature)
{
    short temp3;
    uint8_t buff[2];
    //读取温度值
    MPU6050_ReadData(MPU6050_RA_TEMP_OUT_H, buff, 2);
    temp3 = (buff[0] << 8) | buff[1];
    *Temperature = (((double)(temp3 + 13200)) / 280) - 13;
}

/***************************************************************
* 函数名称: ReadDataE53SC2
* 说    明: 读取数据
* 参    数: 无
* 返 回 值: 无
***************************************************************/
void ReadDataE53SC2(void)
{
    short Accel[3];
    short Temp;

    if (MPU6050ReadID() == 0)
    {
        while (1)
            ;
    }

    MPU6050ReadAcc(Accel);
    MPU6050_ReturnTemp(&Temp);
    E53_SC2_Data.Temperature = Temp;
    E53_SC2_Data.Accel[0] = Accel[0];
    E53_SC2_Data.Accel[1] = Accel[1];
    E53_SC2_Data.Accel[2] = Accel[2];
    usleep(50000);
}

/***************************************************************
* 函数名称: LED_D1_StatusSet
* 说    明: LED_D1状态设置
* 参    数: status,ENUM枚举的数据
*									OFF,关
*									ON,开
* 返 回 值: 无
***************************************************************/
void LED_D1_StatusSet(E53_SC2_Status_ENUM status)
{
    if (status == ON)
    {
        IoTGpioSetOutputVal(IOT_IO_LED_GPIO_7, IOT_GPIO_VALUE1);
    }
    if (status == OFF)
    {
        IoTGpioSetOutputVal(IOT_IO_LED_GPIO_7, IOT_GPIO_VALUE0);
    }
}

/***************************************************************
* 函数名称: LED_D2_StatusSet
* 说    明: LED_D2状态设置
* 参    数: status,ENUM枚举的数据
*									OFF,关
*									ON,开
* 返 回 值: 无
***************************************************************/
void LED_D2_StatusSet(E53_SC2_Status_ENUM status)
{
    if (status == ON)
    {
        IoTGpioSetOutputVal(IOT_IO_E53_GPIO_8, IOT_GPIO_VALUE1);
    }
    if (status == OFF)
    {
        IoTGpioSetOutputVal(IOT_IO_E53_GPIO_8, IOT_GPIO_VALUE0);
    }
}

incude/e53_sc2.h

/*
 * Copyright (c) 2020 Nanjing Xiaoxiongpai Intelligent Technology Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef __E53_SC2_H__
#define __E53_SC2_H__

typedef enum
{
    OFF = 0,
    ON
}E53_SC2_Status_ENUM;

/* E53_SC2传感器数据类型定义 ------------------------------------------------------------*/
typedef struct
{
    // 温度
    short Temperature;
    short Accel[3];
}E53_SC2_Data_TypeDef;

extern E53_SC2_Data_TypeDef E53_SC2_Data;

/* 类型定义 ------------------------------------------------------------------*/
/* 宏定义 --------------------------------------------------------------------*/
#define MPU6050_RA_PWR_MGMT_1 0x6B
// MPU6050寄存器读地址
#define MPU6050_SLAVE_ADDRESS 0x68
// 中断使能寄存器
#define MPU6050_RA_INT_ENABLE 0x38
// 
#define MPU6050_RA_USER_CTRL 0x6A
#define MPU6050_RA_FIFO_EN 0x23
// 中断/旁路设置寄存器
#define MPU6050_RA_INT_PIN_CFG 0x37
// 运动检测阀值设置寄存器
#define MPU6050_RA_MOT_THR 0x1F
// 运动检测时间阀值
#define MPU6050_RA_MOT_DUR 0x20
#define MPU6050_RA_CONFIG 0x1A
#define MPU6050_RA_ACCEL_CONFIG 0x1C
#define MPU6050_RA_WHO_AM_I 0x75
// MPU6050加速度数据寄存器地址
#define MPU6050_ACC_OUT 0x3B
#define MPU6050_RA_TEMP_OUT_H 0x41
// MPU6050陀螺仪数据寄存器地址
#define MPU6050_GYRO_OUT 0x43
// 
#define MPU6050_RA_ZRMOT_THR 0x21
#define MPU6050_RA_ZRMOT_DUR 0x22

// 
#define MPU6050_RA_FF_THR 0x1D
#define MPU6050_RA_FF_DUR 0x1E

// /* 扩展变量 ------------------------------------------------------------------*/
// /* 函数声明 ------------------------------------------------------------------*/
// static void IoInitE53SC2(void);
// static void WriteRegMPU6050(uint8_t reg_add, uint8_t reg_dat);
// static void WrieDataI2CMPU6050(uint8_t Reg, uint8_t Value);
// void Motion_Interrupt(void);

// uint8_t MPU6050ReadID(void);
// void MPU6050_ReadData(uint8_t reg_add, unsigned char *Read, uint8_t num);
// uint8_t I2C_MPU6050_ReadBuffer(uint8_t Reg, uint8_t *pBuffer, uint16_t Length);
// static void MPU6050ReadAcc(short *accData);
// static void MPU6050_ReturnTemp(short *Temperature);
// void LED_D1_StatusSet(E53_SC2_Status_ENUM status);
// void LED_D2_StatusSet(E53_SC2_Status_ENUM status);

// void MPU6050ReadGyro(short *gyroData);
// void MPU6050_PWR_MGMT_1_INIT(void);
// void Zero_Motion_Interrupt(void);        //静止中断
// void Free_Fall_Interrupt(void);        //自由落体中断

// 初始化E53_SC2 
void InitE53SC2(void);
// 读取E53接口传感器的数据
void ReadDataE53SC2(void);
// 设置D1 LED灯的状态
void LED_D1_StatusSet(E53_SC2_Status_ENUM status);
// 设置D2 LED灯的状态
void LED_D2_StatusSet(E53_SC2_Status_ENUM status);

#endif /* __E53_SC2_H__ */

编译调试

//applications/sample/BearPi/BearPi-HM_Nano/sample/C4_YuchuanE53SC2/BUILD.gn

static_library("YuchuanE53SC2"){
    sources = [
        "yuchuan_e53_sc2.c",
        "src/e53_sc2.c",
    ]

    include_dirs = [
        "//utils/native/lite/include",
        "//kernel/liteos_m/kal/cmsis",
        "include",
        "//base/iot_hardware/peripheral/interfaces/kits",
    ]
}

修改 BUILD.gn 文件

修改applications\BearPi\BearPi-HM_Nano\sample路径下 BUILD.gn 文件,指定 YuchuanE53SC2 参与编译。

# Copyright (c) 2020 Nanjing Xiaoxiongpai Intelligent Technology Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import("//build/lite/config/component/lite_component.gni")

lite_component("sample") {
    features = [
        #"A1_kernal_thread:thread_example",
        #"A2_kernel_timer:timer_example",
        #"A3_kernel_event:event_example",
        #"A4_kernel_mutex:mutex_example",
        #"A5_kernel_semaphore:semaphore_example",
        #"A6_kernel_message:message_example",

        #"B1_basic_led_blink:led_example",
        #"B2_basic_button:button_example",
        #"B3_basic_pwm_led:pwm_example",
        #"B4_basic_adc:adc_example", 
        #"B5_basic_i2c_nfc:i2c_example",
        #"B6_basic_uart:uart_example",
        
        #"C1_e53_sf1_mq2:e53_sf1_example",
        #"C2_e53_ia1_temp_humi_pls:e53_ia1_example",
        #"C3_e53_sc1_pls:e53_sc1_example",
        #"C4_e53_sc2_axis:e53_sc2_example",
        #"C5_e53_is1_infrared:e53_is1_example",

        #"D1_iot_wifi_ap:wifi_ap",
        #"D2_iot_wifi_sta_connect:wifi_sta_connect",        
        #"D3_iot_udp_client:udp_client",
        #"D4_iot_tcp_server:tcp_server",
        #"D5_iot_mqtt:iot_mqtt",        
        #"D6_iot_cloud_oc:oc_mqtt",
        #"D7_iot_cloud_onenet:onenet_mqtt",
        #"D8_iot_cloud_oc_smoke:cloud_oc_smoke",
        #"D9_iot_cloud_oc_light:cloud_oc_light",
        #"D10_iot_cloud_oc_manhole_cover:cloud_oc_manhole_cover",
        #"D11_iot_cloud_oc_infrared:cloud_oc_infrared",
        #"D12_iot_cloud_oc_agriculture:cloud_oc_agriculture",
        #"D13_iot_cloud_oc_gps:cloud_oc_gps",
        #"B1_YuchuanBasicLEDBlink:yuchuanLED",
        #"B2_YuchuanBasicButton:yuchuanButton",
        #"C1_YuchuanE53_SF1_MQ2:YuchuanE53SF1Mq2",
        #"C2_YuchuanE53IA1:yuchuanE53IA1",
        #"C3_YuchuanE53SC1:yuchuanE53SC1",
        #"LinuxCExample:linuxC",
        "C4_YuchuanE53SC2:YuchuanE53SC2",
    ]
}

运行结果

示例代码编译烧录代码后,按下开发板的RESET按键,通过串口助手查看日志,会打印温度和三轴加速度信息。当倾斜开发板后会点亮扩展板上倾斜倾斜状态的灯。

ready to OS start
sdk ver:Hi3861V100R001C00SPC025 2020-09-03 18:10:00
formatting spiffs...
FileSystem mount ok.
wifi init success!

hiview init success.00 00:00:00 0 196 D 0/HIVIEW: log limit init success.
00 00:00:00 0 196 I 1/SAMGR: Bootstrap core services(count:3).
00 00:00:00 0 196 I 1/SAMGR: Init service:0x4b104c TaskPool:0xe4b7c
00 00:00:00 0 196 I 1/SAMGR: Init service:0x4b1058 TaskPool:0xe4b9c
00 00:00:00 0 196 I 1/SAMGR: Init service:0x4b1508 TaskPool:0xe4bbc
00 00:00:00 0 228 I 1/SAMGR: Init service 0x4b1058 <time: 0ms> success!
00 00:00:00 0 128 I 1/SAMGR: Init service 0x4b104c <time: 0ms> success!
00 00:00:00 0 72 I 1/SAMGR: Init service 0x4b1508 <time: 0ms> success!
00 00:00:00 0 72 I 1/SAMGR: Initialized all core system services!
00 00:00:00 0 128 I 1/SAMGR: Bootstrap system and application services(count:0).
00 00:00:00 0 128 I 1/SAMGR: Initialized all system and application services!
00 00:00:00 0 128 I 1/SAMGR: Bootstrap dynamic registered services(count:0).
===============================================
*************Yuchuan E53_SC2_Example***********
===============================================
Re is : 0
MPU6050 dectected error!
**********watchdog isr**********
**********syserr info start**********
kernel_ver      : Hi3861V100 R001C00SPC025,2020-09-03 18:10:00
**********Exception Information**********
PC Task Name    : YuchuanE
PC Task ID      = 2
Cur Task ID     = 2
Task Stack Size = 0x2000
Exception Type  = 0x80000021
**********reg info**********
mepc         = 0x4a1b8a
mstatus      = 0x1880
mtval        = 0x0
mcause       = 0x80000021
ccause       = 0x0
ra           = 0x4a1b88
sp           = 0xecc60
gp           = 0x11a9c0
tp           = 0x6a899210
t0           = 0x3f4884
t1           = 0x3fad96
t2           = 0x0
s0           = 0x11d000
s1           = 0x4b1000
a0           = 0x0
a1           = 0x1a
a2           = 0x0
a3           = 0x40008000
a4           = 0xd00a0dff
a5           = 0xd00a0dff
a6           = 0xa
a7           = 0x6c
s2           = 0x4b1000
s3           = 0x4b1000
s4           = 0x4b1000
s5           = 0x4b1000
s6           = 0x4b1000
s7           = 0x8080808
s8           = 0x7070707
s9           = 0x6060606
s10          = 0x5050505
s11          = 0x4040404
t3           = 0x0
t4           = 0x11d000
t5           = 0x0
t6           = 0x13131313
**********memory info**********
Pool Addr    = 0xe8400
Pool Size    = 0x301c0
Fail Count   = 0x0
Peek Size    = 0x13e54
Used Size    = 0x11c30
**********task info**********
Name         : YuchuanE
ID           = 2
Status       = 0x14
Stack Index  = 0x8
Stack Peak   = 0x300
Stack Size   = 0x2000
SP           = 0x119880
Stack        : 0xead60 to 0xecd60
Real SP      = 0xecc60
Stack Overflow  = 0
**********track_info**********
current_item:0x1
item_cnt:10
Index   TrackType   TrackID  CurTime  Data1  Data2
0001 0016 0007 0xc23 0x4a1b8a 0x0
0002 0065 0007 0xc1e 0x3f5e78 0x3f5e78
0003 0065 0002 0xc1e 0x3f5e78 0x4a1b8a
0004 0016 0007 0xc1e 0x4a1b8a 0x0
0005 0016 0007 0xc1f 0x4a1b8a 0x0
0006 0065 0006 0xc20 0x4a1b8a 0x3f5e78
0007 0065 0002 0xc20 0x3f5e78 0x4a1b8a
0008 0016 0007 0xc20 0x4a1b8a 0x0
0009 0016 0007 0xc21 0x4a1b8a 0x0
0010 0016 0007 0xc22 0x4a1b8a 0x0
**********Call Stack**********
Call Stack 0 -- 4a1cfc addr:ecd1c
Call Stack 1 -- 3f78c0 addr:ecd4c
Call Stack 2 -- 3f5e24 addr:ecd5c
**********Call Stack end**********
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。