此版本与stm32f405之间的最大区别是加速度计+陀螺仪,磁力计和高度计数据的读数。
该版本使用直接使用spi的原始单元SPI RT-Theme设备驱动程序结构读取数据。
这是便于分析的源加速度计和陀螺仪单元的列表。
1,总线设备链接到总线(CS引脚配置)
rt1050_spi_bus_attach_device(“ SPI3”,“ spi32”,64);
此代码显示与SPI3总线上的第三个icm20602器件和GPIO_AD_B1_05 cs引脚(64个名称GPIO_AD_B1_05,cs引脚为icm20602的GPIO_AD_B1_05)的spic关联。
2,SPI总线参数配置
structrt_spi_configurationcfg; cfg
data_width = 8; cfg
模式= RT_SPI_MODE_0 | RT_SPI_MSB; / * SPI兼容:Mode0和Mode3 * / cfg。
max_hz = MPU6000_SPI_BAUD; / * * 1M / rt_spi_configure(spi_acc_gyro_device-> rt_spi_device,
3.专用巴士服务
为确保使用多个互斥的SPI3器件,需要额外的icm20602互斥操作:
staticvoidsensor_lock(structspi_acc_gyro_device * sensor_device){rt_mutex_take(sensor_device->锁,RT_WAITING_FOREVER);}staticvoidsensor_unlock(structspi_acc_gyro_device * sensor_device){rt_mutex_release(sensor_device>
4,读写日志
staticvoidicm20602_write_reg(uint8_treg,uint8_tvalue){uint8_tsend_buffer[2]; send_buffer[0]= regsend_buffer[1]=值; rt_spi_send(spi_acc_gyro_device-> rt_spi_device,send_buffer_2_t_t_t_t_t_t_t_t]; txBuf[0]= reg | 0x80; rt_spi_send_then_recv(spi_acc_gyro_device-> rt_spi_device,txBuf,1,rxBuf,2); returnrxBuf[0];}staticuint8_ticm20602_read_t_t_t_t_t_t_t_t_t_t_t_t_t_t_t_t_t_t_t_t_t_t_t_t_t_t_t_t_t_t_t_t_t_t_t_t_t_t_t_t_t_t_t_t_t_t_t_t_t_t_t_t_t_t_t_t_t_t_t_t_t_t_t_t_t_t_t_t[20]; sensor_lock(spi_acc_gyro_device); txBuf[0]= reg | 0x80; rt_spi_send_then_recv(spi_acc_gyro_device-> rt_spi_device,txBuf,1,rxBuf,len); rt_memcpy(缓冲区,rxBacc)}
5,加速度和陀螺仪数据读取
staticuint8_ticm20602_get_accel(int16_t * Accel,int16_t * temp){uint8_tbuf[10]; icm20602_read_buffer(ICM20_ACCEL_XOUT_H,buf,8); Accel[0]=((int16_t)buf[0]
内部icm20602_read_buffer排除功能已添加,因此无需读取排除操作。
使用RT线程
1,动态内存管理。
2,GPIO设备驱动架构。
3. RTC设备驱动程序体系结构。
4. SPI设备驱动程序体系结构。
5. SDIO设备驱动程序体系结构。
6,串行设备驱动程序架构。
7,MSH命令行。
8,FATFS文件系统。
