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
00001 /* This program is used to interface an Mbed board to Analog devices AD7151- 00002 Capacitance to Digital Converter IC, which uses simple I2C protocal for data 00003 transfer.This code contains writing to some of the AD7151 registers & reading 00004 CDC values*/ 00005 00006 #include "mbed.h" 00007 00008 int main() 00009 { 00010 I2C cdc(p28, p27); // I2C cdc 00011 cdc.frequency(50000); // frequency set 00012 00013 cdc.start(); // Start condition 00014 cdc.write(0x90); // Address 0x90 write(to write address of AD7151) 00015 //Setup Register 00016 cdc.write(0x0B); // Setup register Address 00017 cdc.write(0xCF); // Data to be written into Setup Register 00018 //Configuration Register 00019 cdc.start(); // Start condition 00020 cdc.write(0x90); // Address 0x90 write(to write address of AD7151) 00021 cdc.write(0x0F); // Configuration Register Address 00022 cdc.write(0x31); // Adaptive threshold 00023 //cdc.write(0xB1); // For Fixed Threshold Mode 00024 //Capdac Register 00025 cdc.start(); // Start condition 00026 cdc.write(0x90); // Address 0x90 write(to write address of AD7151) 00027 cdc.write(0x11); // CAPDAC register Address 00028 cdc.write(0x00); // Data 00029 /*Fixed Threshold Register(09 & 0A) 00030 cdc.start(); // Start condition 00031 cdc.write(0x90); // Address 0x90 write(to write address of AD7151) 00032 cdc.write(0x09); // Fixed Threshold register Address 00033 cdc.write(0x00); // Data 00034 cdc.write(0xF0); // Data in auto address update*/ 00035 //Sensitivity Register(09 ) 00036 cdc.start(); // Start condition 00037 cdc.write(0x90); // Address 0x90 write(to write address of AD7151) 00038 cdc.write(0x09); // Sensitivity register Address 00039 cdc.write(0x11); // Data 00040 00041 cdc.start(); // Start condition 00042 cdc.write(0x90); // Address 0x90 write(to write address of AD7151) 00043 cdc.write(0x0A); // Setup register Address 00044 cdc.write(0x00); // Data 00045 00046 cdc.stop(); // Stop condition 00047 wait(1); // wait 1 second 00048 00049 while(1) 00050 { 00051 cdc.start(); // Repeated start 00052 cdc.write(0x90); // Address 0x90 write(to write address of AD7151) 00053 cdc.write(0x05); // Address pointer to be read 00054 cdc.start(); // Stop condition 00055 cdc.write(0x91); // Address 0x91 to read(to read address of AD7151) 00056 cdc.read(I2C::ACK); // Read contents in Address 0x05 00057 cdc.read(I2C::NoACK); // Read contents in Address 0x06 00058 cdc.stop(); // Stop condition 00059 wait_ms(20); 00060 } 00061 00062 }
Generated on Wed Jul 13 2022 09:55:34 by
1.7.2