Basic I2C driver and application: 16 bit temperature sensor

XCore Project reviews, ideas, videos and proposals.
User avatar
mjcross
Member++
Posts: 16
Joined: Wed Jun 29, 2011 5:39 pm
Contact:

Basic I2C driver and application: 16 bit temperature sensor

Postby mjcross » Sun Sep 11, 2011 5:15 pm

Version: 2
Status: Public release
License: BSD
Download: /files/project_builds/thermometer.zip

This project interfaces an XC-1A to an Analog Devices ADT7410 temperature sensor, which has an I2C two-wire serial interface.


The ADT7410 is a cheap, 5% accurate 16 bit temperature sensor (see datasheet. It is a surface mount device and physically rather small, so I used a 'surfboard' prototyping PCB (see here) to convert it to make it a bit more manageable and to carry a de-coupling capacitor.


Rather than use the XCORE component for I2C, I decided to write my own driver. This was to validate my understanding of the standard, and also to explore using port counters and timed clock edges in XC (statements of the form port @ counterVal <: data). Some background on how I approached writing the driver can be found on the project WIKI page.


Note: this simple I2C driver does not currently implement clock stretching or multiple masters on the same bus.


This project builds on my previous project, to interface a cheap 2x16 alphanumeric LCD display ( the project page).


The I2C driver was also my first experiment in using the peek() function to read the value of a port configured as a 'pull-down' output (i.e. one that is in high-impedence mode when outputing a '1', so the pin itself may be pulled low by an external device). Using peek() like this lets you achieve a rapid bi-directional port while still enjoying the benefits of buffering, port counters, serialisation etc. - but it only works with a one-bit port and requires judicious use of sync() statements to ensure you sample the port at the right time (due to output buffering).


Images:
User avatar
phalt
Respected Member
Posts: 298
Joined: Thu May 12, 2011 11:14 am
Contact:

Postby phalt » Thu Sep 15, 2011 10:09 am

It's good to see your ability growing with these projects. How accurate is the temperature sensor?
User avatar
mjcross
Member++
Posts: 16
Joined: Wed Jun 29, 2011 5:39 pm
Contact:

Postby mjcross » Fri Sep 16, 2011 11:43 am

Still lots to learn...

Regarding the accuracy of the sensor, there are two parts to the answer. The absolute accuracy is +/- half a degree; whereas the resolution (in 16 bit mode) is about a hundredth of a degree.

In reality the thermal noise is around three or four hundredths of a degree in any case.
User avatar
mjcross
Member++
Posts: 16
Joined: Wed Jun 29, 2011 5:39 pm
Contact:

Postby mjcross » Sun Oct 09, 2011 10:10 pm

Please note latest software revision, which corrects an error in the 'drive' mode of the ports used to drive the I2C bus: they were previously configured with set_mode_pull_up() whereas they should be pull_down.

The new revision also adds support for XK-1 boards. The only changes necessary were in LCDdriver.h and I2Cdriver.h

Return to “Projects”

Who is online

Users browsing this forum: No registered users and 7 guests