完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
void lis2dh12_self_test(void)
{undefined stmdev_ctx_t dev_ctx; lis2dh12_reg_t reg; uint8_t i, j; /* Initialize mems driver interface / dev_ctx.write_reg = platform_write; dev_ctx.read_reg = platform_read; // dev_ctx.handle = &SENSOR_BUS; / Wait boot time and initialize platform specific hardware / platform_init(); / Wait sensor boot time / platform_delay(BOOT_TIME); / Check device ID */ // uint8_t value=0; // for(uint8_t i=0;i<255;i++) // {undefined // I2C_dma_BlockRead_Sleep(i,LIS2DH12_WHO_AM_I,&value,1); // platform_delay(1); // if(valueLIS2DH12_ID) // { // value=0; // } // value=0; // } //验证传感器读写是否OK uint8_t value=0xaa; // I2C_dma_BlockWrite_Sleep(LIS2DH_I2C_ADDR2,LIS2DH12_INT1_THS,&value,1); // platform_delay(1); // value=0; // I2C_dma_BlockRead_Sleep(LIS2DH_I2C_ADDR2,LIS2DH12_INT1_THS,&value,1); // platform_delay(1); // if(0xaavalue) // {undefined // value=0;//验证传感器读写是否OK // } value=0xFF; // I2C_dma_BlockWrite_Sleep(LIS2DH_I2C_ADDR2,LIS2DH12_CTRL_REG3,&value,1); platform_delay(1); value=0; I2C_dma_BlockRead_Sleep(LIS2DH_I2C_ADDR2,LIS2DH12_CTRL_REG3,&value,1); platform_delay(1); if(0xFF==value) {undefined value=0;//验证传感器读写是否OK } lis2dh12_device_id_get(&dev_ctx, ®.byte); if (reg.byte != LIS2DH12_ID) {undefined while (1) {undefined /* manage here device not found */ } } /* Initialization of sensor */ lis2dh12_iic_write_byte(0x20, 0x37); /* CTRL_REG1(20h): 关闭sensor,设置进入掉电模式 ODR 25HZ */ // lis2dh12_iic_write_byte(0x20, 0x57); /* CTRL_REG1(20h): 关闭sensor,设置进入低功耗模式 ODR 100HZ / lis2dh12_iic_write_byte(0x21, 0x03); / CTRL_REG2(21h): IA1、IA2 开启高通滤波 bc */ lis2dh12_iic_write_byte(0x22, 0xc0); /* CTRL_REG3(22h): 0x80 使能单击中断到INT_1 INT_2 */ // lis2dh12_iic_write_byte(0x22, 0xD0); /* CTRL_REG3(22h): 0x80 使能单击中断到INT_1 INT_2 / lis2dh12_iic_write_byte(0x23, 0x88); / CTRL_REG4(23h): 使能快,数据更新,全量程+/-2G,非常精度模式 / // lis2dh12_iic_write_byte(0x25, 0x00); / CTRL_REG6(25h): 高电平(上升沿)触发中断 */ /* INT1 翻转检测,中断*/ //0x6a lis2dh12_iic_write_byte(0x30, 0x7f); /* INT1_CFG(30h): 使能,6D X/Y/Z任一超过阈值中断 */ // lis2dh12_iic_write_byte(0x30, 0x4f); /* INT1_CFG(30h): 使能,6D X/Y任一超过阈值中断 / // lis2dh12_iic_write_byte(0x31, 0x20); / INT1_SRC(31h): 设置中断源 */ lis2dh12_iic_write_byte(0x32, 0x03); /* INT1_THS(32h): 设置中断阀值 0x10: 16*2(FS) 0x20: 32*16(FS) */ // lis2dh12_iic_write_byte(0x33, 0x02); /* INT1_DURATION(33h): 1LSB=1/ODR 如果ODR=25HZ 那么1LSB=40ms 设置延时 1s,对应25->0x19 / // lis2dh12_iic_write_byte(0x33, 0x03); / INT1_DURATION(33h): 1LSB=1/ODR 如果ODR=50HZ 那么1LSB=20ms 设置延时 1s,对应50->0x32 / lis2dh12_iic_write_byte(0x33, 0x00); / INT1_DURATION(33h): 1LSB=1/ODR 如果ODR=100HZ 那么1LSB=10ms 设置延时 1s,对应100->0x64 */ // /* INT2 单击中断 / lis2dh12_iic_write_byte(0x24, 0x01); / CTRL_REG5(24h): / // lis2dh12_iic_write_byte(0x25, 0xa0); / CTRL_REG6(25h): Click interrupt on INT2 pin / // // lis2dh12_iic_write_byte(0x38, 0x15); / CLICK_CFG (38h): 单击识别中断使能 / lis2dh12_iic_write_byte(0x39, 0x10); // lis2dh12_iic_write_byte(0x3a, 0x7f); / CLICK_THS (3Ah): 单击阀值 / // lis2dh12_iic_write_byte(0x3b, 0xff); / TIME_LIMIT (3Bh): 时间限制窗口6 ODR 1LSB=1/ODR 1LSB=1/100HZ,10ms,设置延时1s,对应100—>0x64*/ // lis2dh12_iic_write_byte(0x3c, 0xff); /* TIME_LATENCY (3Ch): 中断电平持续时间1 ODR=10ms / // lis2dh12_iic_write_byte(0x3d, 0x01); / TIME_WINDOW (3Dh): 单击时间窗口 */ /* Start sensor */ 1 // lis2dh12_iic_write_byte(0x20, 0x37); lis2dh12_iic_write_byte(0x20, 0x5f); /* CTRL_REG1(20h): Start sensor at ODR 100Hz Low-power mode */ } |
|
|
|
只有小组成员才能发言,加入小组>>
3329 浏览 9 评论
3009 浏览 16 评论
3503 浏览 1 评论
9088 浏览 16 评论
4102 浏览 18 评论
1212浏览 3评论
626浏览 2评论
const uint16_t Tab[10]={0}; const uint16_t *p; p = Tab;//报错是怎么回事?
612浏览 2评论
用NUC131单片机UART3作为打印口,但printf没有输出东西是什么原因?
2353浏览 2评论
NUC980DK61YC启动随机性出现Err-DDR是为什么?
1915浏览 2评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-1-7 06:21 , Processed in 1.258566 second(s), Total 47, Slave 39 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号