Accessing 16 Bit Registers on I2C
What is the function of accessing 16 Bit Resisters available on VL6180 Controller?
What is the function of accessing 16 Bit Resisters available on VL6180 Controller?
The I2C HAL API should allow you to define 8 or 16-bit wide addressing, and you can read multiple bytes. Registers in slaves typically auto-increment, such that you read 16-bit values as consecutive bytes, and recombine them, often in big-endian form
uint16_t ublox_ReadLength(void)
{
uint8_t data[2];
HAL_StatusTypeDef status = HAL_I2C_Mem_Read(&I2CHandle, (0x42 << 1), 0xFD, 1, data, sizeof(data), 100);
if (status != HAL_OK)
printf("ublox_ReadLength failed %d %08X\n", status, I2CHandle.ErrorCode);
return(((uint16_t)data[0] << 8) + (uint16_t)data[1]); // Big Endian
}The 0xFD register in this case being 1-byte (8-bit) and the data content 2-bytes (16-bit)
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.