MLX90614修改地址

默认地址
  • 0x00 - 为设备的硬件地址,不可修改,接一个传感器推荐使用,修改地址时使用0x00
  • 0x5A - 出厂设备的eeprom 地址,可修改,如需接多个传感器,修改此地址即可
修改地址
  • 注意事项:

    • 存储地址的地址是0x2E,不是0x0E
    • 修改地址之前必须先擦除,写3个字节到0x2E(0x00;0x00; PEC(0x6F))
    • 延时
    • 修改地址需要写3个字节到0x2E(7bit-addr;0xBE; PEC)
    • 重新上电
  • pec校验算法

uint8_t pec_calculation(uint8_t pec[])
{
    uint8_t crc[6];
    uint8_t bit_position = 47;
    uint8_t shift, i, j, temp;

    do
    {
        /*Load pattern value 0x000000000107*/

        crc[5] = 0;
        crc[4] = 0;
        crc[3] = 0;
        crc[2] = 0;
        crc[1] = 0x01;
        crc[0] = 0x07;

        /*Set maximum bit position at 47 ( six bytes byte5...byte0,MSbit=47)*/
        bit_position = 47;

        /*Set shift position at 0*/
        shift = 0;

        /*Find first "1" in the transmited message beginning from the MSByte byte5*/
        i = 5;
        j = 0;

        while ((pec[i] & (0x80 >> j)) == 0 && i > 0)
        {
            bit_position--;

            if (j < 7)
            {
                j++;
            }
            else
            {
                j = 0x00;
                i--;
            }
        }/*End of while */

        /*Get shift value for pattern value*/
        shift = bit_position - 8;

        /*Shift pattern value */
        while (shift)
        {
            for (i = 5; i < 0xFF; i--)
            {
                if ((crc[i - 1] & 0x80) && (i > 0))
                {
                    temp = 1;
                }
                else
                {
                    temp = 0;
                }

                crc[i] <<= 1;
                crc[i] += temp;
            }/*End of for*/

            shift--;
        }/*End of while*/

        /*Exclusive OR between pec and crc*/
        for (i = 0; i <= 5; i++)
        {
            pec[i] ^= crc[i];
        }/*End of for*/
    }
    while (bit_position > 8); /*End of do-while*/

    return pec[0];
}
  • 修改地址函数封装demo
/* 需要你自己实现i2c读写函数接口哦 */
#define I2C_WRITE_BYTES(addr, reg, buf, len) i2c_write_bytes(addr, reg, buf, len)
#define I2C_READ_BYTES(addr, reg, buf, len) i2c_read_bytes(addr, reg, buf, len)


void mlx90614_modify_addr(uint8_t addr, uint8_t new_addr)
{
    uint8_t buf[6];

    buf[5] = 0;
    buf[4] = addr;
    buf[3] = 0x2E;
    buf[2] = 0x0;
    buf[1] = 0x0;
    buf[0] = 0;

    buf[2] = pec_calculation(buf);
    buf[0] = 0x0;
    buf[1] = 0x0;
    I2C_WRITE_BYTES(addr, 0x2e, buf, 3);

    delay_ms(100);

    buf[5] = 0;
    buf[4] = addr;
    buf[3] = 0x2E;
    buf[2] = new_addr;
    buf[1] = 0xBE;
    buf[0] = 0;

    buf[2] = pec_calculation(buf);
    buf[0] = new_addr;
    buf[1] = 0xBE;
    I2C_WRITE_BYTES(addr, 0x2e, buf, 3);
}
  • 修改实例
    /* 修改7bit地址0x20 */
    #define MLX90614_NEW_7BIT_ADDR	(0x20)
    mlx90614_modify_addr(0x00<<1, MLX90614_NEW_7BIT_ADDR);
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

路人 假

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值