The goal of the following program is to read the ambient temperature register from an MCP9808 temperature sensor.
import Timer from "timer";
import Digital from "pins/digital";
import SMBus from "pins/smbus";
let count = 0;
let mcp9808 = new SMBus({address: 0x18});
Timer.repeat(() => {
Digital.write(13, ~count & 1);
let rawTemp = mcp9808.readWord(0x05);
trace(`repeat ${++count} ${rawTemp}\n`);
}, 200);
When run, the program results in the following error:
/home/brian/src/moddable/modules/pins/i2c/i2c.c (156) # Break: (host): write file!
Line 156 in i2c.c is here.
I think the problem here is that the SMBus readWord method implements an SMBus transaction as two I2C transactions, i.e., a write transaction followed by a read transaction. The MCP9808 only appears to work if the write is followed by a "repeat start" and then a read. See sample code on page 25 of the MCP9808 datasheet.
I have verified that the MCP9808 is connected up correctly and can successfully read the ambient temperature register with program implemented in C using the Espressif IoT Development Framework.
The goal of the following program is to read the ambient temperature register from an MCP9808 temperature sensor.
When run, the program results in the following error:
Line 156 in i2c.c is here.
I think the problem here is that the SMBus readWord method implements an SMBus transaction as two I2C transactions, i.e., a write transaction followed by a read transaction. The MCP9808 only appears to work if the write is followed by a "repeat start" and then a read. See sample code on page 25 of the MCP9808 datasheet.
I have verified that the MCP9808 is connected up correctly and can successfully read the ambient temperature register with program implemented in C using the Espressif IoT Development Framework.