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.
MCP4726.cpp
00001 //********************** 00002 // MCP4726.cpp for mbed 00003 // 00004 // MCP4726 mcp4726(P0_5,P0_4); 00005 // or 00006 // I2C i2c(P0_5,P0_4); 00007 // MCP4726 mcp4726(i2c); 00008 // 00009 // Max Frequency with I2C mode 00010 // Standard mode 3.4KHz=100KHz / 29bits 00011 // Fast mode 13.8KHz=400KHz / 29bits 00012 // Fast mode Plus 34.5KHz=1MHz / 29bits 00013 // HS mode 117KHz =3.4MHz / 29bits 00014 // 00015 // (C)Copyright 2014 All rights reserved by Y.Onodera 00016 // http://einstlab.web.fc2.com 00017 //********************** 00018 00019 #include "mbed.h" 00020 #include "MCP4726.h" 00021 00022 MCP4726::MCP4726 (PinName sda, PinName scl) : _i2c(sda, scl) { 00023 init(); 00024 } 00025 MCP4726::MCP4726 (I2C& p_i2c) : _i2c(p_i2c) { 00026 init(); 00027 } 00028 00029 00030 void MCP4726::put(unsigned short a) 00031 { 00032 00033 da.Val = a; 00034 buf[0]=0x0F & da.byte.HB; 00035 buf[1]=da.byte.LB; 00036 _i2c.write(MCP4726_ADDR, buf, 2); 00037 00038 } 00039 00040 00041 void MCP4726::init() 00042 { 00043 00044 // Set fast mode 00045 _i2c.frequency(400000); // default 100Kbps 00046 00047 // wait POR 60us+ 00048 wait_us(100); 00049 00050 // reset 00051 // buf[0]=0x06; 00052 // _i2c.write(0x00, buf, 1); 00053 // wakeup 00054 // buf[0]=0x09; 00055 // _i2c.write(0x00, buf, 1); 00056 00057 // Set Configuration 00058 buf[0]=0x80; 00059 _i2c.write(MCP4726_ADDR, buf, 1); 00060 00061 } 00062
Generated on Wed Jul 20 2022 03:41:51 by
1.7.2