Embedded software from JeeLabs

Embello Home Page
Hardware Documentation
Forth Library Documentation

MCP9808 I2C temperature sensor

This is an I2C driver for the Microchip MCP9808 temperature sensor.


To initialize the chip and the driver mcp9808-init must be called. This places the chip in continuous conversion mode with 0.125C resolution. mcp9808-data returns the result of the last conversion as a 32-bit integer representing 1/100th degrees centigrade (rounded).

: mcp9808-init ( -- nak ) \ put device into continuous mode, 0.125C precision
: mcp9808-data ( -- v ) \ read data, return as 1/100th centigrade

For low power operation (e.g. battery) the chip can be put to sleep and woken up when a conversion is desired. Start with mcp9808-sleep and when a conversion is desired, use mcp9808-convert to initiate a conversion. It returns the number of milliseconds to wait before the conversion data can be retrieved using mcp9808-data. Then place the chip to sleep again using mcp9808-sleep. Note that mcp9808-convert places the chip into continuous conversion mode so mcp9808-sleep is required, there is no single-shot conversion mode in this chip.

: mcp9808-sleep ( -- ) \ put device to sleep
: mcp9808-convert ( -- ms ) \ put device into continuous mode, returns ms before first cvt


The I2C address is hard-coded as $18.