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.
AD5270.h
00001 /** 00002 * @file AD5270.h 00003 * @brief Header file for AD5270 rheostat 00004 * @author Analog Devices Inc. 00005 * 00006 * For support please go to: 00007 * Github: https://github.com/analogdevicesinc/mbed-adi 00008 * Support: https://ez.analog.com/community/linux-device-drivers/microcontroller-no-os-drivers 00009 * Product: http://www.analog.com/ad5270 00010 * More: https://wiki.analog.com/resources/tools-software/mbed-drivers-all 00011 00012 ******************************************************************************** 00013 * Copyright 2016(c) Analog Devices, Inc. 00014 * 00015 * All rights reserved. 00016 * 00017 * Redistribution and use in source and binary forms, with or without 00018 * modification, are permitted provided that the following conditions are met: 00019 * - Redistributions of source code must retain the above copyright 00020 * notice, this list of conditions and the following disclaimer. 00021 * - Redistributions in binary form must reproduce the above copyright 00022 * notice, this list of conditions and the following disclaimer in 00023 * the documentation and/or other materials provided with the 00024 * distribution. 00025 * - Neither the name of Analog Devices, Inc. nor the names of its 00026 * contributors may be used to endorse or promote products derived 00027 * from this software without specific prior written permission. 00028 * - The use of this software may or may not infringe the patent rights 00029 * of one or more patent holders. This license does not release you 00030 * from the requirement that you obtain separate licenses from these 00031 * patent holders to use this software. 00032 * - Use of the software either in source or binary form, must be run 00033 * on or directly connected to an Analog Devices Inc. component. 00034 * 00035 * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR 00036 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, 00037 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 00038 * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, 00039 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00040 * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR 00041 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00042 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00043 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00044 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00045 * 00046 ********************************************************************************/ 00047 00048 #ifndef AD5270_H 00049 #define AD5270_H 00050 00051 #include "mbed.h" 00052 00053 /** 00054 * @brief Analog Devices AD5270 SPI Digital Rheostat class 00055 */ 00056 class AD5270 00057 { 00058 public: 00059 00060 /// AD5270 commands 00061 typedef enum { 00062 NO_OP = 0x00, ///< No data 00063 NO_OP_cmd = 0x0000, ///< 16 bit no data 00064 WRITE_RDAC = 0x04, ///< Write to the RDAC Register 00065 READ_RDAC = 0x08, ///< Read from the RDAC Register 00066 STORE_50TP = 0x0C, ///< Write from RDAC to memory 00067 SW_RST = 0x10, ///< Software reset to last memory location 00068 READ_50TP_CONTENTS = 0x14, ///< Read the last memory contents 00069 READ_50TP_ADDRESS = 0x18, ///< Read the last memory address 00070 WRITE_CTRL_REG = 0x1C, ///< Write to the control Register 00071 READ_CTRL_REG = 0x20, ///< Read from the control Register 00072 SW_SHUTDOWN = 0x24, ///< Software shutdown (0) - Normal, (1) - Shutdown 00073 HI_Zupper = 0x80, ///< Get the SDO line ready for High Z 00074 HI_Zlower = 0x01, ///< Puts AD5270 into High Z mode 00075 HI_Z_Cmd = 0x8001 ///< Puts AD5270 into High Z mode*/ 00076 } AD5270Commands_t; 00077 00078 typedef enum { 00079 NORMAL_MODE = 0, 00080 SHUTDOWN_MODE = 1 00081 } AD5270Modes_t; 00082 00083 typedef enum { 00084 PROGRAM_50TP_ENABLE = 1, 00085 RDAC_WRITE_PROTECT = 2, 00086 R_PERFORMANCE_ENABLE = 4, 00087 MEMORY_PROGRAM_SUCCESFUL = 8 00088 } AD5270ControlRegisterBits_t; 00089 00090 // SPI configuration & constructor 00091 AD5270(PinName CS = SPI_CS, float max_resistance = 20000.0, PinName MOSI = SPI_MOSI, PinName MISO = SPI_MISO, PinName SCK = SPI_SCK); 00092 void frequency(int hz); 00093 00094 /* RDAC commands */ 00095 void write_ctrl_reg(uint8_t data); 00096 uint8_t read_ctrl_reg(void); 00097 void change_mode(AD5270Modes_t mode); 00098 void set_SDO_HiZ(void); 00099 00100 /* Wiper R/W methods*/ 00101 void reset_RDAC(void); 00102 void write_wiper_reg(uint16_t data); 00103 uint16_t read_wiper_reg(void); 00104 00105 00106 /* Low level methods */ 00107 uint16_t write_cmd(uint8_t command, uint16_t data = 0x00, bool toggle_cs = true); 00108 uint16_t write_reg(uint16_t data, bool toggle_cs = true); 00109 00110 /* Methods that deal with resistance in float format*/ 00111 uint16_t calc_RDAC(float resistance); 00112 float write_RDAC(float resistance); 00113 float read_RDAC(void); 00114 float get_max_resistance(void); 00115 00116 /* 50 TP methods */ 00117 void enable_50TP_programming(void); 00118 void store_50TP(void); 00119 void disable_50TP_programming(void); 00120 uint8_t read_50TP_last_address(void); 00121 uint16_t read_50TP_memory(uint8_t address); 00122 00123 void daisy_chain(uint8_t *buffer, uint8_t size); 00124 00125 SPI ad5270; ///< SPI instance of the AD5270 00126 DigitalOut cs; ///< DigitalOut instance for the chip select of the AD5270 00127 00128 private: 00129 const static int _RESET = 0xff; 00130 const static int _REG_OPERATION_TIMEOUT = 2; 00131 const static int _MEMORY_OPERATION_TIMEOUT = 6; 00132 const static int _WRITE_OPERATION_50TP_TIMEOUT = 350; 00133 const static int _DUMMY_BYTE = 0xAA; 00134 const static uint8_t _SPI_MODE = 1; 00135 float _max_resistance; 00136 }; 00137 00138 #endif
Generated on Tue Jul 12 2022 17:59:51 by
 1.7.2
 1.7.2 
     CN0357 - Toxic gas measurement
            CN0357 - Toxic gas measurement
         CN0216 - Weight Scale
            CN0216 - Weight Scale