Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp@0:95864d5b2c85, 2010-08-05 (annotated)
- Committer:
- Santhosh
- Date:
- Thu Aug 05 09:11:32 2010 +0000
- Revision:
- 0:95864d5b2c85
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Santhosh | 0:95864d5b2c85 | 1 | /* This program is used to interface an Mbed board to Analog devices AD7151- |
| Santhosh | 0:95864d5b2c85 | 2 | Capacitance to Digital Converter IC, which uses simple I2C protocal for data |
| Santhosh | 0:95864d5b2c85 | 3 | transfer.This code contains writing to some of the AD7151 registers & reading |
| Santhosh | 0:95864d5b2c85 | 4 | CDC values*/ |
| Santhosh | 0:95864d5b2c85 | 5 | |
| Santhosh | 0:95864d5b2c85 | 6 | #include "mbed.h" |
| Santhosh | 0:95864d5b2c85 | 7 | |
| Santhosh | 0:95864d5b2c85 | 8 | int main() |
| Santhosh | 0:95864d5b2c85 | 9 | { |
| Santhosh | 0:95864d5b2c85 | 10 | I2C cdc(p28, p27); // I2C cdc |
| Santhosh | 0:95864d5b2c85 | 11 | cdc.frequency(50000); // frequency set |
| Santhosh | 0:95864d5b2c85 | 12 | |
| Santhosh | 0:95864d5b2c85 | 13 | cdc.start(); // Start condition |
| Santhosh | 0:95864d5b2c85 | 14 | cdc.write(0x90); // Address 0x90 write(to write address of AD7151) |
| Santhosh | 0:95864d5b2c85 | 15 | //Setup Register |
| Santhosh | 0:95864d5b2c85 | 16 | cdc.write(0x0B); // Setup register Address |
| Santhosh | 0:95864d5b2c85 | 17 | cdc.write(0xCF); // Data to be written into Setup Register |
| Santhosh | 0:95864d5b2c85 | 18 | //Configuration Register |
| Santhosh | 0:95864d5b2c85 | 19 | cdc.start(); // Start condition |
| Santhosh | 0:95864d5b2c85 | 20 | cdc.write(0x90); // Address 0x90 write(to write address of AD7151) |
| Santhosh | 0:95864d5b2c85 | 21 | cdc.write(0x0F); // Configuration Register Address |
| Santhosh | 0:95864d5b2c85 | 22 | cdc.write(0x31); // Adaptive threshold |
| Santhosh | 0:95864d5b2c85 | 23 | //cdc.write(0xB1); // For Fixed Threshold Mode |
| Santhosh | 0:95864d5b2c85 | 24 | //Capdac Register |
| Santhosh | 0:95864d5b2c85 | 25 | cdc.start(); // Start condition |
| Santhosh | 0:95864d5b2c85 | 26 | cdc.write(0x90); // Address 0x90 write(to write address of AD7151) |
| Santhosh | 0:95864d5b2c85 | 27 | cdc.write(0x11); // CAPDAC register Address |
| Santhosh | 0:95864d5b2c85 | 28 | cdc.write(0x00); // Data |
| Santhosh | 0:95864d5b2c85 | 29 | /*Fixed Threshold Register(09 & 0A) |
| Santhosh | 0:95864d5b2c85 | 30 | cdc.start(); // Start condition |
| Santhosh | 0:95864d5b2c85 | 31 | cdc.write(0x90); // Address 0x90 write(to write address of AD7151) |
| Santhosh | 0:95864d5b2c85 | 32 | cdc.write(0x09); // Fixed Threshold register Address |
| Santhosh | 0:95864d5b2c85 | 33 | cdc.write(0x00); // Data |
| Santhosh | 0:95864d5b2c85 | 34 | cdc.write(0xF0); // Data in auto address update*/ |
| Santhosh | 0:95864d5b2c85 | 35 | //Sensitivity Register(09 ) |
| Santhosh | 0:95864d5b2c85 | 36 | cdc.start(); // Start condition |
| Santhosh | 0:95864d5b2c85 | 37 | cdc.write(0x90); // Address 0x90 write(to write address of AD7151) |
| Santhosh | 0:95864d5b2c85 | 38 | cdc.write(0x09); // Sensitivity register Address |
| Santhosh | 0:95864d5b2c85 | 39 | cdc.write(0x11); // Data |
| Santhosh | 0:95864d5b2c85 | 40 | |
| Santhosh | 0:95864d5b2c85 | 41 | cdc.start(); // Start condition |
| Santhosh | 0:95864d5b2c85 | 42 | cdc.write(0x90); // Address 0x90 write(to write address of AD7151) |
| Santhosh | 0:95864d5b2c85 | 43 | cdc.write(0x0A); // Setup register Address |
| Santhosh | 0:95864d5b2c85 | 44 | cdc.write(0x00); // Data |
| Santhosh | 0:95864d5b2c85 | 45 | |
| Santhosh | 0:95864d5b2c85 | 46 | cdc.stop(); // Stop condition |
| Santhosh | 0:95864d5b2c85 | 47 | wait(1); // wait 1 second |
| Santhosh | 0:95864d5b2c85 | 48 | |
| Santhosh | 0:95864d5b2c85 | 49 | while(1) |
| Santhosh | 0:95864d5b2c85 | 50 | { |
| Santhosh | 0:95864d5b2c85 | 51 | cdc.start(); // Repeated start |
| Santhosh | 0:95864d5b2c85 | 52 | cdc.write(0x90); // Address 0x90 write(to write address of AD7151) |
| Santhosh | 0:95864d5b2c85 | 53 | cdc.write(0x05); // Address pointer to be read |
| Santhosh | 0:95864d5b2c85 | 54 | cdc.start(); // Stop condition |
| Santhosh | 0:95864d5b2c85 | 55 | cdc.write(0x91); // Address 0x91 to read(to read address of AD7151) |
| Santhosh | 0:95864d5b2c85 | 56 | cdc.read(I2C::ACK); // Read contents in Address 0x05 |
| Santhosh | 0:95864d5b2c85 | 57 | cdc.read(I2C::NoACK); // Read contents in Address 0x06 |
| Santhosh | 0:95864d5b2c85 | 58 | cdc.stop(); // Stop condition |
| Santhosh | 0:95864d5b2c85 | 59 | wait_ms(20); |
| Santhosh | 0:95864d5b2c85 | 60 | } |
| Santhosh | 0:95864d5b2c85 | 61 | |
| Santhosh | 0:95864d5b2c85 | 62 | } |