2024-02-02 10:33 AM
Hi all,
Can anyone help me out how I should read out the two bytes 10 bits ADC result from the MCP3021
https://ww1.microchip.com/downloads/aemDocuments/documents/APID/ProductDocuments/DataSheets/20001805C.pdf
My address is 0x4C 1001100(RD/WR)
I'm using the HAL generated library:
HAL_I2C_Mem_Read(&hi2c1, (uint16_t)ZTP_I2C_ADDRESS, 0, 8, (uint8_t*)aRxBuffer, 16, 1000);
It is not very clear to me what the units should be, bits or bytes?
2024-02-02 11:35 AM
> what the units should be, bits or bytes?
Bytes. By tradition these devices send data in big endian order. Convert the 16-bit data to little endian.
2024-02-02 02:35 PM
To read two bytes from the device:
uint8_t data[2];
HAL_I2C_Master_Receive(&hi2c1, 0x4C << 1, data, 2, HAL_MAX_DELAY);
uint16_t value = data[0] << 8 + data[1];