盛思瑞CO2传感器读数据错误,百思不解。

[复制链接]
5147|6
Aist2018 发表于 2025-9-17 13:14 | 显示全部楼层 |阅读模式
这是CRC函数:uint8_t sensirion_i2c_generate_crc(const uint8_t* in, uint16_t count) {
    uint16_t current_byte;
    uint8_t crc = CRC8_INIT;
    uint8_t crc_bit;

    /* calculates 8-Bit checksum with given polynomial */
    for (current_byte = 0; current_byte < count; ++current_byte) {
        crc ^= (in[current_byte]);
        for (crc_bit = 8; crc_bit > 0; --crc_bit) {
            if (crc & 0x80)
                crc = (crc << 1) ^ CRC8_POLYNOMIAL;
            else
                crc = (crc << 1);
        }
    }
    return crc;
}     uint8_t buf[2] = {0x00, 0x11};   #define CRC8_POLYNOMIAL 0x31
#define CRC8_INIT 0xFF
#define CRC8_LEN 1  crc_test = sensirion_i2c_generate_crc((uint8_t*)&buf[0],2);                                                                                                                                                                                                                                                               下面是发指令代码:              iic_Start();
                // 1. Write command phase (use write address 0x28)
                iic_SendData(0x52); // Slave write address (0x29 >> 1 = 0x14? Or check datasheet for correct write address)
                iic_Wait_Ack();
                iic_SendData(0x36); // Command byte 3
                iic_Wait_Ack();
                iic_SendData(0x15); // Argument byte 1
                iic_Wait_Ack();
                iic_SendData(0x00); // Argument byte 2
                iic_Wait_Ack();
                iic_SendData(0x11); // Argument byte 3
                                                          iic_Wait_Ack();
                                                          iic_SendData(0xf3); // Argument byte 3
                                                                iic_Wait_Ack();
                                                                iic_Stop();
                                                                delay_100us(100);   出现的错误现象是:iic_SendData(0xf3);就会通讯失败,注意0xF3是CRC计算值, 但是如果任意发一个CRC字节,不是计算的0xf3结果, 任意一个。比如:0xfd, 或者0x31,这时虽然下面的读数据失败,但是通讯并没有死亡。再后面的读product id指令还能读到结果。 但是如果发的是函数计算的0xf3作为CRC字节发送,通讯就死亡。后面读product id也失败了。为什么发的是正确的CRC反而导致通讯死亡呢?
 楼主| Aist2018 发表于 2025-9-17 13:16 | 显示全部楼层

盛思瑞CO2传感器读数据错误,百思不解。

传感器STC31-C-R3
dirtwillfly 发表于 2025-9-18 08:27 | 显示全部楼层
没用过,这种建议问厂家啊
dffzh 发表于 2025-9-18 09:06 | 显示全部楼层
朋友搞定没?
xinmeng_wit 发表于 2025-9-18 11:20 | 显示全部楼层
要不寄过来,我帮你看看
LTYJX 发表于 2025-9-18 18:04 | 显示全部楼层
示波器看看波形,跟芯片手册里的波形对比一下看看
大大财迷 发表于 2025-9-19 13:07 | 显示全部楼层
时序问题
您需要登录后才可以回帖 登录 | 注册

本版积分规则

17

主题

90

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部