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 // example code to get MAX5842 working 00002 // Copyright (c) 2009, sford 00003 // Released under the MIT License: http://mbed.org/license/mit 00004 00005 // MAX5842 setup: ADD = 0v, REF = 3.3v, OUTA -> p16 00006 00007 #include "mbed.h" 00008 00009 AnalogIn result(p16); // input to test MAX5842 output 00010 DigitalOut led(LED1); 00011 00012 I2C max5842(p9, p10); 00013 00014 int main() { 00015 00016 max5842.frequency(400000); // 400 KHz 00017 00018 // ADDR: 011 110 ADD, where ADD = 0 00019 // 011 1100 == 0x3C 00020 const int addr = 0x3C; 00021 00022 // Power up the DAC 00023 // - Extended Commands [ 1111 0000 xx DCBA PD1 PD0 ] 00024 // - DCBA = 1111 means select all, PD = 00 means power on 00025 char power_up[2] = {0xF0, 0x3C}; 00026 max5842.write(addr, power_up, 2); 00027 00028 // set A output to 50% 00029 // 0 (set A) D DD 00030 char data[2] = {0x08, 0x00}; 00031 max5842.write(addr, data, 2); 00032 00033 while(1) { 00034 printf("res = %f\n", result.read()); 00035 led = !led; 00036 wait(0.25); 00037 } 00038 }
Generated on Wed Jul 13 2022 22:44:10 by
1.7.2