Interface to Analog devices AD5258 digital I2C potentiometer
AD5258.h@2:8a71db02417b, 2013-11-12 (annotated)
- Committer:
- RodColeman
- Date:
- Tue Nov 12 12:57:07 2013 +0000
- Revision:
- 2:8a71db02417b
- Parent:
- 1:64570234d7b5
- Child:
- 3:f5b60d166896
v4.29: first release with RF Detect I2C trimmer (manual only)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
RodColeman | 0:8920c7d857d8 | 1 | #include "mbed.h" |
RodColeman | 0:8920c7d857d8 | 2 | |
RodColeman | 0:8920c7d857d8 | 3 | #ifndef MBED_AD5258_H |
RodColeman | 0:8920c7d857d8 | 4 | #define MBED_AD5258_H |
RodColeman | 0:8920c7d857d8 | 5 | |
RodColeman | 2:8a71db02417b | 6 | // Interface to the AD5258 I2C 64-step (0x00 to 0x3F)6-Bit digital Potentiometer |
RodColeman | 2:8a71db02417b | 7 | |
RodColeman | 2:8a71db02417b | 8 | // measure reference voltage on the pin6 of U3 LM293 |
RodColeman | 2:8a71db02417b | 9 | // be sure to remove R11, and check R4 is 220 |
RodColeman | 2:8a71db02417b | 10 | |
RodColeman | 2:8a71db02417b | 11 | /*Examples: RDAC = |
RodColeman | 2:8a71db02417b | 12 | 0x00, Vref=1,0V |
RodColeman | 2:8a71db02417b | 13 | 0x03, Vref=1,1V |
RodColeman | 2:8a71db02417b | 14 | 0x05, Vref=1,2V |
RodColeman | 2:8a71db02417b | 15 | 0x0F, Vref=1,5V |
RodColeman | 2:8a71db02417b | 16 | 0x20, Vref=1,82V // default |
RodColeman | 2:8a71db02417b | 17 | 0x30, Vref=2,0V |
RodColeman | 2:8a71db02417b | 18 | 0x3F, Vref=2,2V |
RodColeman | 2:8a71db02417b | 19 | */ |
RodColeman | 2:8a71db02417b | 20 | |
RodColeman | 0:8920c7d857d8 | 21 | |
RodColeman | 0:8920c7d857d8 | 22 | class AD5258 { |
RodColeman | 0:8920c7d857d8 | 23 | public: |
RodColeman | 0:8920c7d857d8 | 24 | /** Create an instance of the AD5258 connected to specfied I2C pins, with the specified address. |
RodColeman | 0:8920c7d857d8 | 25 | * |
RodColeman | 0:8920c7d857d8 | 26 | * @param sda The I2C data pin |
RodColeman | 0:8920c7d857d8 | 27 | * @param scl The I2C clock pin |
RodColeman | 0:8920c7d857d8 | 28 | * @param address The I2C address for this AD5258 |
RodColeman | 0:8920c7d857d8 | 29 | */ |
RodColeman | 0:8920c7d857d8 | 30 | AD5258(PinName sda, PinName scl, int address); |
RodColeman | 0:8920c7d857d8 | 31 | |
RodColeman | 0:8920c7d857d8 | 32 | /** Read the RDAC value |
RodColeman | 0:8920c7d857d8 | 33 | * |
RodColeman | 0:8920c7d857d8 | 34 | * @return The 6-bit value read |
RodColeman | 0:8920c7d857d8 | 35 | */ |
RodColeman | 0:8920c7d857d8 | 36 | int read(); |
RodColeman | 0:8920c7d857d8 | 37 | |
RodColeman | 1:64570234d7b5 | 38 | /** Write to the RDAC |
RodColeman | 0:8920c7d857d8 | 39 | * |
RodColeman | 0:8920c7d857d8 | 40 | * @param data The 6-bits value: 0x00 to 0x3F to write to the pots RDAC |
RodColeman | 0:8920c7d857d8 | 41 | */ |
RodColeman | 0:8920c7d857d8 | 42 | void write(int data); |
RodColeman | 1:64570234d7b5 | 43 | |
RodColeman | 1:64570234d7b5 | 44 | // READ and WRITE EEPROM |
RodColeman | 1:64570234d7b5 | 45 | |
RodColeman | 1:64570234d7b5 | 46 | /** Read the EEPROM value |
RodColeman | 1:64570234d7b5 | 47 | * |
RodColeman | 1:64570234d7b5 | 48 | * @return The 6-bit value read |
RodColeman | 1:64570234d7b5 | 49 | */ |
RodColeman | 1:64570234d7b5 | 50 | int readEE(); |
RodColeman | 1:64570234d7b5 | 51 | |
RodColeman | 1:64570234d7b5 | 52 | /** Write to the RDAC |
RodColeman | 1:64570234d7b5 | 53 | * |
RodColeman | 1:64570234d7b5 | 54 | * @param data The 6-bits value: 0x00 to 0x3F to write to the pots RDAC |
RodColeman | 1:64570234d7b5 | 55 | */ |
RodColeman | 1:64570234d7b5 | 56 | void writeEE(int data); |
RodColeman | 1:64570234d7b5 | 57 | |
RodColeman | 1:64570234d7b5 | 58 | |
RodColeman | 1:64570234d7b5 | 59 | |
RodColeman | 1:64570234d7b5 | 60 | |
RodColeman | 1:64570234d7b5 | 61 | // STORE and RESTORE: |
RodColeman | 1:64570234d7b5 | 62 | |
RodColeman | 1:64570234d7b5 | 63 | /** store the RDAC value into the EEPROM, for nonvolatile keeping of the value |
RodColeman | 1:64570234d7b5 | 64 | * |
RodColeman | 1:64570234d7b5 | 65 | */ |
RodColeman | 1:64570234d7b5 | 66 | void store(void); |
RodColeman | 1:64570234d7b5 | 67 | |
RodColeman | 1:64570234d7b5 | 68 | /** restore to the RDAC the value from the EEPROM. NOP issued afterward, to put back into low-power idle mode |
RodColeman | 1:64570234d7b5 | 69 | * |
RodColeman | 1:64570234d7b5 | 70 | */ |
RodColeman | 1:64570234d7b5 | 71 | void restore(void); |
RodColeman | 2:8a71db02417b | 72 | |
RodColeman | 2:8a71db02417b | 73 | |
RodColeman | 2:8a71db02417b | 74 | /** update write protect bit |
RodColeman | 2:8a71db02417b | 75 | * |
RodColeman | 2:8a71db02417b | 76 | * @param enable: TRUE to SET WP, FALSE to lift WP |
RodColeman | 2:8a71db02417b | 77 | */ |
RodColeman | 2:8a71db02417b | 78 | |
RodColeman | 2:8a71db02417b | 79 | void writeProtect(bool enable); |
RodColeman | 2:8a71db02417b | 80 | |
RodColeman | 2:8a71db02417b | 81 | // TODO: tolerance register access |
RodColeman | 2:8a71db02417b | 82 | |
RodColeman | 1:64570234d7b5 | 83 | |
RodColeman | 0:8920c7d857d8 | 84 | |
RodColeman | 0:8920c7d857d8 | 85 | private: |
RodColeman | 0:8920c7d857d8 | 86 | I2C _i2c; |
RodColeman | 0:8920c7d857d8 | 87 | int _address; |
RodColeman | 0:8920c7d857d8 | 88 | }; |
RodColeman | 0:8920c7d857d8 | 89 | |
RodColeman | 0:8920c7d857d8 | 90 | #endif |