网络营销导向企业网站建设的原则,广州广告公司排行榜,上海网站 建设,营销型网站重要性硬件平台#xff1a;正点原子阿波罗STM32F429IGT6 zephyr版本#xff1a;Zephyr version 4.2.0 开发环境#xff1a;wsl ubuntu 24.4 前景提要#xff1a; 正点原子阿波罗STM32F429IGT6移植zephyr rtos#xff08;三#xff09;---创建一个独立的应用工程-CSDN博客 一.修… 硬件平台正点原子阿波罗STM32F429IGT6 zephyr版本Zephyr version 4.2.0 开发环境wsl ubuntu 24.4 前景提要 正点原子阿波罗STM32F429IGT6移植zephyr rtos三---创建一个独立的应用工程-CSDN博客 一.修改app.overlay
app.overlay是board设备树的覆写文件·你可以在app.overlay里边对dts文件内容进行追加修改删除。在文件中添加代码
/** Copyright (c) 2019 Nordic Semiconductor ASA** SPDX-License-Identifier: Apache-2.0*/
i2c1 {mpu605068 {compatible invensense,mpu6050;reg 0x68;status okay;int-gpios gpioa 15 GPIO_ACTIVE_LOW;};
};
二.修改prj.conf
文件中添加代码启用I2C传感器模块和MPU6050模块
# 启用 I2C 和 MPU6050 驱动
CONFIG_I2Cy
CONFIG_SENSORy
CONFIG_MPU6050y
CONFIG_MPU6050_TRIGGER_NONEy
CONFIG_CBPRINTF_FP_SUPPORTy三.修改main.c
mian.c要修改的内容就是MPU6050示例代码里边的内容文件地址/home/user/zephyrproject/zephyr/samples/sensor/mpu6050/src/main.c
/** Copyright (c) 2019 Nordic Semiconductor ASA** SPDX-License-Identifier: Apache-2.0*/#include zephyr/kernel.h
#include zephyr/device.h
#include zephyr/drivers/sensor.h
#include stdio.hstatic const char *now_str(void)
{static char buf[16]; /* ...HH:MM:SS.MMM */uint32_t now k_uptime_get_32();unsigned int ms now % MSEC_PER_SEC;unsigned int s;unsigned int min;unsigned int h;now / MSEC_PER_SEC;s now % 60U;now / 60U;min now % 60U;now / 60U;h now;snprintf(buf, sizeof(buf), %u:%02u:%02u.%03u,h, min, s, ms);return buf;
}static int process_mpu6050(const struct device *dev)
{struct sensor_value temperature;struct sensor_value accel[3];struct sensor_value gyro[3];int rc sensor_sample_fetch(dev);if (rc 0) {rc sensor_channel_get(dev, SENSOR_CHAN_ACCEL_XYZ,accel);}if (rc 0) {rc sensor_channel_get(dev, SENSOR_CHAN_GYRO_XYZ,gyro);}if (rc 0) {rc sensor_channel_get(dev, SENSOR_CHAN_DIE_TEMP,temperature);}if (rc 0) {printf([%s]:%g Cel\n accel %f %f %f m/s/s\n gyro %f %f %f rad/s\n,now_str(),sensor_value_to_double(temperature),sensor_value_to_double(accel[0]),sensor_value_to_double(accel[1]),sensor_value_to_double(accel[2]),sensor_value_to_double(gyro[0]),sensor_value_to_double(gyro[1]),sensor_value_to_double(gyro[2]));} else {printf(sample fetch/get failed: %d\n, rc);}return rc;
}int main(void)
{const struct device *const mpu6050 DEVICE_DT_GET_ONE(invensense_mpu6050);if (!device_is_ready(mpu6050)) {printf(Device %s is not ready\n, mpu6050-name);return 0;}while (!IS_ENABLED(CONFIG_MPU6050_TRIGGER)) {int rc process_mpu6050(mpu6050);if (rc ! 0) {break;}k_sleep(K_SECONDS(2));}/* triggered runs with its own thread after exit */return 0;
}四.编译烧录
在app目录下输入指令
west build -b stm32f429i_alientek -p 成功 west flash
实验现象