完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
由于在平坦表面上移动传感器,我无法检测到LIS3DH加速度计的内部中断。传感器使用I2C与Arduino Uno连接。我正在使用AN3308的第6.3.1节中的示例,LIS3DH应用笔记。我可以成功读取加速度值。我也尝试检查两个中断端口,int 1和int 2。
请参阅下面附带的Arduino代码。 & sharpinclude< Wire.h> const int LIS3DH_ADDR = 0x18; int pin = 13; int int1Pin = 2; int int2Pin = 3; / * I2C通信设置------------------------------------------- -------------- * / unsigned int readRegister(byte reg){ Wire.beginTransmission(LIS3DH_ADDR); Wire.write(REG); Wire.endTransmission(); Wire.requestFrom(LIS3DH_ADDR,1); return Wire.read(); } void writeRegister(byte reg,byte data){ Wire.beginTransmission(LIS3DH_ADDR); Wire.write(REG); Wire.write(数据); Wire.endTransmission(); } / *初始化主处理器中的加速度计。 ---------------------------------- * / //初始化程序启动后只需要执行一次。 void init_ACC(void) { //控制寄存器的配置 writeRegister(0x20,0xA7); //将A7h写入CTRL_REG1; //使用ODR = 100Hz正常模式打开传感器。 writeRegister(0x21,0x00); //将00h写入CTRL_REG2; //禁用高通滤波器(HPF) writeRegister(0x22,0x40); //将40h写入CTRL_REG3; // ACC AOI1中断信号被路由到INT1引脚。 writeRegister(0x23,0x00); //将00h写入CTRL_REG4; //满刻度= +/- 2克 writeRegister(0x24,0x00); //将00h写入CTRL_REG5; // 默认值。 INT1引脚上的中断信号未锁存。 //用户无需读取INT1_SRC寄存器即可清除中断信号。 //唤醒和静止检测的配置 writeRegister(0x32,0x10); //将10h写入INT1_THS; //阈值(THS)= 16LSBs * 15.625mg / LSB = 250mg。 writeRegister(0x33,0x00); //将33h写入INT1_DURAtiON; //持续时间= 1LSBs *(1 / 10Hz)= 0.1s。 writeRegister(0x30,0x0A); //将0Ah写入INT1_CFG; //启用XLIE,YLIE中断生成,OR逻辑。 } void setup(){ Wire.begin(); Serial.begin(9600); int res = readRegister(0x0F); //我是谁 Serial.println(RES); pinMode(引脚,OUTPUT); //将数字引脚13设置为输出 pinMode(int1Pin,INPUT); //将数字引脚2设置为输入 pinMode(int2Pin,INPUT); //将数字引脚2设置为输入 } void loop(){ //读取两个中断引脚 int int1 = digitalRead(int1Pin); int int2 = digitalRead(int2Pin); Serial.print(INT1); Serial.print( '', ''); Serial.println(INT2); if(digitalRead(int1Pin)== 0&& digitalRead(int2Pin)== 0){ //如果两者都是低写 writeRegister(0x30,0x0A); } 其他{ digitalWrite(pin,HIGH); int intEvent = readRegister(0x31); Serial.println(intEvent); 延迟(2000); } 延迟(0); } #lis3dh-interrupt #accelerometer#lis3dh#lis3dh-interrupt 以上来自于谷歌翻译 以下为原文 I am unable to detect an interial interrupt from the LIS3DH accelerometer as a result of moving the sensor on a flat surface. The sensor is interfaced with an Arduino Uno using I2C. I am using the example in section 6.3.1 of AN3308, LIS3DH application notes. I can successfully read acceleration values. I also tried checking both interrupt ports, int 1 and int 2. Please see attached Arduino code below. &sharpinclude const int LIS3DH_ADDR = 0x18; int pin = 13; int int1Pin = 2; int int2Pin = 3; /* I2C Communication Set-up ---------------------------------------------------------*/ unsigned int readRegister(byte reg) { Wire.beginTransmission(LIS3DH_ADDR); Wire.write(reg); Wire.endTransmission(); Wire.requestFrom(LIS3DH_ADDR, 1); return Wire.read(); } void writeRegister(byte reg, byte data) { Wire.beginTransmission(LIS3DH_ADDR); Wire.write(reg); Wire.write(data); Wire.endTransmission(); } /* Initialize accelerometer in the host processor. ----------------------------------*/ //It only needs to be executed one time after power up in initialization routine. void init_ACC(void) { // configurations for control registers writeRegister(0x20, 0xA7); //Write A7h into CTRL_REG1; // Turn on the sensor with ODR = 100Hz normal mode. writeRegister(0x21, 0x00); //Write 00h into CTRL_REG2; // High-pass filter (HPF) disabled writeRegister(0x22, 0x40); //Write 40h into CTRL_REG3; // ACC AOI1 interrupt signal is routed to INT1 pin. writeRegister(0x23, 0x00); //Write 00h into CTRL_REG4; // Full Scale = +/-2 g writeRegister(0x24, 0x00); //Write 00h into CTRL_REG5; // Default value. Interrupt signals on INT1 pin is not latched. //Users don�t need to read the INT1_SRC register to clear the interrupt signal. // configurations for wakeup and motionless detection writeRegister(0x32, 0x10); //Write 10h into INT1_THS; // Threshold (THS) = 16LSBs * 15.625mg/LSB = 250mg. writeRegister(0x33, 0x00); //Write 33h into INT1_DURATION; // Duration = 1LSBs * (1/10Hz) = 0.1s. writeRegister(0x30, 0x0A); //Write 0Ah into INT1_CFG; // Enable XLIE, YLIE interrupt generation, OR logic. } void setup() { Wire.begin(); Serial.begin(9600); int res = readRegister(0x0F); //WHO_AM_I Serial.println(res); pinMode(pin, OUTPUT); // sets the digital pin 13 as output pinMode(int1Pin, INPUT); // sets the digital pin 2 as input pinMode(int2Pin, INPUT); // sets the digital pin 2 as input } void loop() { //Read both interrupt pins int int1 = digitalRead(int1Pin); int int2 = digitalRead(int2Pin); Serial.print(int1); Serial.print('',''); Serial.println(int2); if (digitalRead(int1Pin) == 0 && digitalRead(int2Pin) == 0){ //if both are low write writeRegister(0x30, 0x0A); } else { digitalWrite(pin, HIGH); int intEvent = readRegister(0x31); Serial.println(intEvent); delay(2000); } delay(0); } #lis3dh-interrupt #accelerometer #lis3dh #lis3dh-interrupt |
|
相关推荐
2个回答
|
|
我能够从acc lis3dh中读出x y z原始数据。
但我不能生成INT信号。有我的配置acc。 LIS3DH_WriteReg(LIS3DH_CTRL_REG1,0x27); LIS3DH_WriteReg(LIS3DH_CTRL_REG2,0x01); //中断驱动到INT1焊盘,INT1上的AOI1中断。 --- 0100 LIS3DH_WriteReg(LIS3DH_CTRL_REG3,0x40); // FS = 2g满量程选择 LIS3DH_WriteReg(LIS3DH_CTRL_REG4,0x00); //暂时禁用FIFO; 0:中断请求未锁存; --- 0x00 //锁定0000 1000 --- 0x08 LIS3DH_WriteReg(LIS3DH_CTRL_REG5,0x08); LIS3DH_WriteReg(LIS3DH_INT1_THS,0x08的); // 0010 1010超越thresh hold; 0001 0101低于thresh hold。事件 LIS3DH_WriteReg(LIS3DH_INT1_CFG,0x2a); uint8 val; LIS3DH_ReadReg(0x31,& val); // INT1_SRC ------ 当我摇动acc时,它不会产生INT信号,INT1引脚为低电平。 以上来自于谷歌翻译 以下为原文 I am be able to read out the x y z raw data from the acc lis3dh. But I it can not generate INT signal. There is my configuration of the acc. LIS3DH_WriteReg(LIS3DH_CTRL_REG1,0x27); LIS3DH_WriteReg(LIS3DH_CTRL_REG2,0x01); // Interrupt driven to INT1 pad, AOI1 interrupt on INT1. ---0100 LIS3DH_WriteReg(LIS3DH_CTRL_REG3,0x40); // FS = 2g Full scale selection LIS3DH_WriteReg(LIS3DH_CTRL_REG4,0x00); // Disable FIFO temporarily; 0: interrupt request not latched;---0x00 //latched 0000 1000 ---0x08 LIS3DH_WriteReg(LIS3DH_CTRL_REG5,0x08); LIS3DH_WriteReg(LIS3DH_INT1_THS,0x08); // 0010 1010 beyond thresh hold ; 0001 0101 below thresh hold. event LIS3DH_WriteReg(LIS3DH_INT1_CFG,0x2a); uint8 val; LIS3DH_ReadReg(0x31, &val); //INT1_SRC ------ When I shake the acc, it just not generate INT signal , INT1 pin is low. |
|
|
|
发现问题。
!没有I2C操作之间的延迟,ACC配置不正确!!! 添加延迟。有用。 MCU是Dialog M0。 以上来自于谷歌翻译 以下为原文 Problem Found. !!! without the delays between I2C operations, ACC is not configured correctly!!! Add delays. It works. MCU is Dialog M0. |
|
|
|
只有小组成员才能发言,加入小组>>
请教:在使用UDE STK时,单片机使用SPC560D30L1,在配置文件怎么设置或选择?里面只有SPC560D40的选项
2634 浏览 1 评论
3208 浏览 1 评论
请问是否有通过UART连接的两个微处理器之间实现双向值交换的方法?
1783 浏览 1 评论
3609 浏览 6 评论
5987 浏览 21 评论
939浏览 4评论
1315浏览 4评论
在Linux上安装Atollic TRUEStudio的步骤有哪些呢?
582浏览 3评论
使用DMA激活某些外设会以导致外设无法工作的方式生成代码是怎么回事
1302浏览 3评论
1357浏览 3评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-22 13:14 , Processed in 1.257419 second(s), Total 79, Slave 62 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号