This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

What does reg[] mean in the twi_sensor example?

I am a recent student interested in Nordic. I know that my skills are very, very poor. Sorry for asking this question T_T
I want to use i2c sensor vl53l1x. I tried to refer to the SDK's basic example twi_sensor, but I couldn't understand the tx of the temperature sensor lm75b.

What I understand is that according to the data sheet, lm75b is W/R (that is, 3 bytes) and vl53l1x is [address, index1, index0, value] (that is, 4 bytes). W/R.

However, in the datasheet of vl53l1x, only the registers are modelID(0xEA), moduleType(0xCC), and Mask revision(0x11). (I found out through many searches that vl53l1x_address is 0x29.)

Not only can I not understand why uint8_t reg[] in the lm75b example was declared that way, and I don't know how to declare reg[] to test vl53l1x.

Please help ㅠㅠ

Parents
  • thank you. However, I do not understand the ST driver, so I try to use the Arduino driver. ㅜㅜ

    Arduino code:
    /*****************************************/
    void VL53L1X::writeReg(uint16_t reg, uint8_t value)
    {
    bus->beginTransmission(address);
    bus->write((reg >> 8) & 0xFF); // reg high byte
    bus->write(reg & 0xFF); // reg low byte
    bus->write(value);
    last_status = bus->endTransmission();
    }

    uint8_t VL53L1X::readReg(regAddr reg)
    {
    uint8_t value;

    bus->beginTransmission(address);
    bus->write((reg >> 8) & 0xFF); // reg high byte
    bus->write(reg & 0xFF); // reg low byte
    last_status = bus->endTransmission();

    bus->requestFrom(address, (uint8_t)1);
    value = bus->read();

    return value;
    }
    /******************************************/

    nRF52 Code:

    //void vl53l1x_set_mode()
    void writeReg(uint16_t reg, uint8_t value)
    {
    ret_code_t err_code;

    uint16_t tx_data[2];
    tx_data[0] = (((reg >> 8)& 0xFF) | reg & 0xFF);
    tx_data[1] = value;

    err_code = nrf_drv_twi_tx(&m_twi, VL53L1X_ADDR, tx_data, sizeof(tx_data), false);
    return err_code;
    }

    //void read_vl53l1x_data()
    uint8_t readReg(uint16_t reg)
    {
    ret_code_t err_code;
    uint16_t read_data[2];
    uint16_t read_addr = (((reg >> 8)& 0xFF) | reg & 0xFF);
    #if 1
    err_code = nrf_drv_twi_tx(&m_twi, VL53L1X_ADDR, &read_addr, 1, false);
    if(err_code != NRF_SUCCESS)
    {
    return err_code;
    }
    #endif
    err_code = nrf_drv_twi_rx(&m_twi, VL53L1X_ADDR, read_data, 1);

    return read_data[0];
    }
    /************************************/

    .

    .

    .

    ..

    Is it correct to change arduino wire.h like this? I tried but saw only output 0..

Reply
  • thank you. However, I do not understand the ST driver, so I try to use the Arduino driver. ㅜㅜ

    Arduino code:
    /*****************************************/
    void VL53L1X::writeReg(uint16_t reg, uint8_t value)
    {
    bus->beginTransmission(address);
    bus->write((reg >> 8) & 0xFF); // reg high byte
    bus->write(reg & 0xFF); // reg low byte
    bus->write(value);
    last_status = bus->endTransmission();
    }

    uint8_t VL53L1X::readReg(regAddr reg)
    {
    uint8_t value;

    bus->beginTransmission(address);
    bus->write((reg >> 8) & 0xFF); // reg high byte
    bus->write(reg & 0xFF); // reg low byte
    last_status = bus->endTransmission();

    bus->requestFrom(address, (uint8_t)1);
    value = bus->read();

    return value;
    }
    /******************************************/

    nRF52 Code:

    //void vl53l1x_set_mode()
    void writeReg(uint16_t reg, uint8_t value)
    {
    ret_code_t err_code;

    uint16_t tx_data[2];
    tx_data[0] = (((reg >> 8)& 0xFF) | reg & 0xFF);
    tx_data[1] = value;

    err_code = nrf_drv_twi_tx(&m_twi, VL53L1X_ADDR, tx_data, sizeof(tx_data), false);
    return err_code;
    }

    //void read_vl53l1x_data()
    uint8_t readReg(uint16_t reg)
    {
    ret_code_t err_code;
    uint16_t read_data[2];
    uint16_t read_addr = (((reg >> 8)& 0xFF) | reg & 0xFF);
    #if 1
    err_code = nrf_drv_twi_tx(&m_twi, VL53L1X_ADDR, &read_addr, 1, false);
    if(err_code != NRF_SUCCESS)
    {
    return err_code;
    }
    #endif
    err_code = nrf_drv_twi_rx(&m_twi, VL53L1X_ADDR, read_data, 1);

    return read_data[0];
    }
    /************************************/

    .

    .

    .

    ..

    Is it correct to change arduino wire.h like this? I tried but saw only output 0..

Children
Related