sumoon_yao 发表于 2024-12-25 22:09

【英飞凌XENSIV™ PAS CO2 5V Sensor2Go套件】连接单片机

<p><span style="font-size:18px;"><span style="font-family:楷体;">&nbsp; &nbsp; 前面是使用的PAS CO2 5V Sensor2Go套件进行测试的,这次准备使用其它单片机直接对传感器进行测量。</span></span></p>

<p>&nbsp;</p>

<p><span style="font-size:18px;"><span style="font-family:楷体;">&nbsp; &nbsp; 根据文档中的要求将单片机和传感器的6个引脚按下图连接:</span></span></p>

<div style="text-align: center;"></div>

<p><span style="font-size:18px;"><span style="font-family:楷体;">&nbsp; &nbsp; 实物接好线后如下:</span></span></p>

<p>&nbsp;</p>

<div style="text-align: center;"></div>

<p>&nbsp;</p>

<p><span style="font-size:18px;"><span style="font-family:楷体;">&nbsp; &nbsp; 主要程序如下。</span></span></p>

<p><span style="font-size:18px;"><span style="font-family:楷体;">&nbsp; &nbsp; IIC地址定义:</span></span></p>

<p><span style="font-size:18px;"><span style="font-family:楷体;">#define CO2_READ_Addr&nbsp; 0X28<br />
#define CO2_WRITE_Addr&nbsp; 0X29</span></span></p>

<p>&nbsp;</p>

<p><span style="font-size:18px;"><span style="font-family:楷体;">&nbsp; &nbsp; IIC初始化:</span></span></p>

<p><span style="font-size:18px;"><span style="font-family:楷体;">void IIC0_Init(void)<br />
{<br />
&nbsp;&nbsp; &nbsp;struct bflb_device_s* gpio;<br />
&nbsp;&nbsp; &nbsp;<br />
&nbsp;&nbsp; &nbsp;gpio = bflb_device_get_by_name(&quot;gpio&quot;);<br />
&nbsp;&nbsp; &nbsp;/* I2C0_SCL */<br />
&nbsp;&nbsp; &nbsp;bflb_gpio_init(gpio, GPIO_PIN_0, GPIO_FUNC_I2C0 | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);<br />
&nbsp;&nbsp; &nbsp;/* I2C0_SDA */<br />
&nbsp;&nbsp; &nbsp;bflb_gpio_init(gpio, GPIO_PIN_1, GPIO_FUNC_I2C0 | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);<br />
&nbsp; &nbsp;&nbsp;<br />
&nbsp;&nbsp; &nbsp;/* 通信速率400K */<br />
&nbsp;&nbsp; &nbsp;i2c = bflb_device_get_by_name(&quot;i2c0&quot;);<br />
&nbsp;&nbsp; &nbsp;bflb_i2c_init(i2c, 400000);<br />
}</span></span><br />
<span style="font-size:18px;"><span style="font-family:楷体;">&nbsp; &nbsp; 读取主要几个寄存器值:</span></span></p>

<p><span style="font-size:18px;"><span style="font-family:楷体;">&nbsp; &nbsp; while (1)&nbsp;<br />
&nbsp;&nbsp; &nbsp;{<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;IIC_ReadReg(CO2_READ_Addr, 0x01, Buff, 1);<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;printf(&quot;PASCO2 Reg 01: %d\r\n\r\n&quot;,Buff);<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;bflb_mtimer_delay_ms(50);<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;IIC_ReadReg(CO2_READ_Addr, 0x02, Buff, 1);<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;printf(&quot;PASCO2 Reg 02: %d\r\n\r\n&quot;,Buff);<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;bflb_mtimer_delay_ms(50);<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;IIC_ReadReg(CO2_READ_Addr, 0x03, Buff, 1);<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;printf(&quot;PASCO2 Reg 03: %d\r\n\r\n&quot;,Buff);<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;bflb_mtimer_delay_ms(50);<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;IIC_ReadReg(CO2_READ_Addr, 0x04, Buff, 1);<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;printf(&quot;PASCO2 Reg 04: %d\r\n\r\n&quot;,Buff);<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;bflb_mtimer_delay_ms(50);<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;IIC_ReadReg(CO2_READ_Addr, 0x05, Buff, 1);<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;printf(&quot;PASCO2 Reg 05: %d\r\n\r\n&quot;,Buff);<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;bflb_mtimer_delay_ms(50);<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;IIC_ReadReg(CO2_READ_Addr, 0x06, Buff, 1);<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;printf(&quot;PASCO2 Reg 06: %d\r\n\r\n&quot;,Buff);</span></span><br />
&nbsp;</p>

<p><span style="font-size:18px;"><span style="font-family:楷体;">&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;bflb_mtimer_delay_ms(30000);</span></span></p>

<p><span style="font-size:18px;"><span style="font-family:楷体;">&nbsp; &nbsp; }</span></span><br />
<br />
<span style="font-size:18px;"><span style="font-family:楷体;">&nbsp; &nbsp; 程序运行后,连续测量值如下:</span></span></p>

<div style="text-align: center;"></div>

<p><br />
<span style="font-size:18px;"><span style="font-family:楷体;">&nbsp; &nbsp; 具体分析下01-06寄存器值:</span></span></p>

<div style="text-align: center;"></div>

<p><span style="font-size:18px;"><span style="font-family:楷体;">&nbsp; &nbsp; 寄存器01:144,16进制:0x90.</span></span></p>

<p><span style="font-size:18px;"><span style="font-family:楷体;">&nbsp; &nbsp; 根据文档描述:</span></span></p>

<div style="text-align: center;"></div>

<p><span style="font-size:18px;"><span style="font-family:楷体;">&nbsp; &nbsp; 按照上面的接线方式,ORVS位为何会报错?</span></span></p>

<p>&nbsp;</p>

<p><span style="font-size:18px;"><span style="font-family:楷体;">&nbsp; &nbsp; 寄存器02、03:60</span></span></p>

<p><span style="font-size:18px;"><span style="font-family:楷体;">&nbsp; &nbsp; 这是缺省值,表示采集周期为60秒,也即一分钟采集一次。</span></span></p>

<p>&nbsp;</p>

<p><span style="font-size:18px;"><span style="font-family:楷体;">&nbsp; &nbsp; 寄存器04:38,16进制:0x26</span></span></p>

<p><span style="font-size:18px;"><span style="font-family:楷体;">&nbsp; &nbsp; 根据文档描述:</span></span></p>

<div style="text-align: center;"></div>

<div style="text-align: center;">&nbsp;</div>

<p>&nbsp;</p>

<p><span style="font-size:18px;"><span style="font-family:楷体;">&nbsp; &nbsp; 04寄存器中缺省采集模式为空闲模式,之所以现在是连续采集模式,是因为PWM_DIS引脚接地了。</span></span></p>

<p>&nbsp;</p>

<div style="text-align: center;"></div>

<p>&nbsp;</p>

<p><span style="font-size:18px;"><span style="font-family:楷体;">&nbsp; &nbsp; 寄存器05、06:CO2浓度值。</span></span></p>

<p><span style="font-size:18px;"><span style="font-family:楷体;">&nbsp; &nbsp; 根据文档描述:</span></span></p>

<div style="text-align: center;"></div>

<p><span style="font-size:18px;"><span style="font-family:楷体;">&nbsp; &nbsp; 浓度值为2个有符号补码短整型,从实际测量值来看,高字节为负数,和采用套件及配套软件测量值900ppm左右无法对应,后边将抽时间再继续研究下。</span></span></p>

<p>&nbsp;</p>

秦天qintian0303 发表于 2024-12-26 17:18

<p>你最重要的一个引脚没有接吗?发射器都没有工作吧,这个是利用光学原理的,发射头供电是5V的,要接上</p>

秦天qintian0303 发表于 2024-12-26 17:18

<p>上一版本是12V的,要求更高&nbsp;&nbsp;</p>

秦天qintian0303 发表于 2024-12-26 17:21

<p>ORVS位报错就说明5V供电超限了&nbsp;&nbsp;</p>

sumoon_yao 发表于 2024-12-27 23:49

秦天qintian0303 发表于 2024-12-26 17:18
你最重要的一个引脚没有接吗?发射器都没有工作吧,这个是利用光学原理的,发射头供电是5V的,要接上

<p>感谢大佬的提醒,5V供电脚没接,传感器是不会正常工作的,接上之后,所有数据都正确了。</p>

<p>&nbsp;</p>

<p>单片机读出的数据:</p>

<div style="text-align: center;"></div>

<p>&nbsp;</p>

<p>套件读出的数据:</p>

<p>&nbsp;</p>

<div style="text-align: center;"></div>

<p>&nbsp;</p>

<p>读数基本一致。</p>

<p>&nbsp;</p>

秦天qintian0303 发表于 2024-12-28 10:19

sumoon_yao 发表于 2024-12-27 23:49
感谢大佬的提醒,5V供电脚没接,传感器是不会正常工作的,接上之后,所有数据都正确了。

&nbsp;

单 ...

<p>嗯嗯,环境1000还是挺正常的,一般家里的环境1000ppm算不错的了</p>
页: [1]
查看完整版本: 【英飞凌XENSIV™ PAS CO2 5V Sensor2Go套件】连接单片机