Mbed library for LTC2601 / Mikroe DAC 2 Click peripheral.
LTC2601.h@0:11d039b90bde, 2020-08-25 (annotated)
- Committer:
- elelthvd
- Date:
- Tue Aug 25 14:26:48 2020 +0800
- Revision:
- 0:11d039b90bde
Add LTC2601 library for Mbed OS
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
elelthvd |
0:11d039b90bde | 1 | |
elelthvd |
0:11d039b90bde | 2 | #ifndef _LTC2601_H |
elelthvd |
0:11d039b90bde | 3 | #define _LTC2601_H |
elelthvd |
0:11d039b90bde | 4 | #include "mbed.h" |
elelthvd |
0:11d039b90bde | 5 | |
elelthvd |
0:11d039b90bde | 6 | class LTC2601 { |
elelthvd |
0:11d039b90bde | 7 | public: |
elelthvd |
0:11d039b90bde | 8 | /** Commands (Table 1): |
elelthvd |
0:11d039b90bde | 9 | * C3 C2 C1 C0 |
elelthvd |
0:11d039b90bde | 10 | * 0 0 0 0 Write to Input Register |
elelthvd |
0:11d039b90bde | 11 | * 0 0 0 1 Update (Power Up) DAC Register |
elelthvd |
0:11d039b90bde | 12 | * 0 0 1 1 Write to and Update (Power Up) |
elelthvd |
0:11d039b90bde | 13 | * 0 1 0 0 Power Down (and ignores data word) |
elelthvd |
0:11d039b90bde | 14 | * 1 1 1 1 No Operation (ignores data word) |
elelthvd |
0:11d039b90bde | 15 | * The first three commands all seem to have the same effect (update and power up). Commands not shown seem ignored. |
elelthvd |
0:11d039b90bde | 16 | * |
elelthvd |
0:11d039b90bde | 17 | */ |
elelthvd |
0:11d039b90bde | 18 | enum CommandName { |
elelthvd |
0:11d039b90bde | 19 | WRITE = (0b0000<<4), |
elelthvd |
0:11d039b90bde | 20 | UPDATE = (0b0001<<4), |
elelthvd |
0:11d039b90bde | 21 | WRITE_UPDATE = (0b0011<<4), |
elelthvd |
0:11d039b90bde | 22 | POWERDOWN = (0b0100<<4), |
elelthvd |
0:11d039b90bde | 23 | NOOPERATION = (0b1111<<4), |
elelthvd |
0:11d039b90bde | 24 | } ; |
elelthvd |
0:11d039b90bde | 25 | /* Constructor */ |
elelthvd |
0:11d039b90bde | 26 | LTC2601 (SPI *spi, PinName cs, PinName rst); |
elelthvd |
0:11d039b90bde | 27 | |
elelthvd |
0:11d039b90bde | 28 | /* Set DAC voltage 0...5.0V */ |
elelthvd |
0:11d039b90bde | 29 | void updateVoltage(float voltage); |
elelthvd |
0:11d039b90bde | 30 | /* Set DAC voltage 0...0xFFFF */ |
elelthvd |
0:11d039b90bde | 31 | void updateVoltage(uint16_t dac_value); |
elelthvd |
0:11d039b90bde | 32 | void powerDown(); |
elelthvd |
0:11d039b90bde | 33 | /* |
elelthvd |
0:11d039b90bde | 34 | * DAC 2 Click only has no MOSI function |
elelthvd |
0:11d039b90bde | 35 | * |
elelthvd |
0:11d039b90bde | 36 | * Input First SPI write 16-bit: |
elelthvd |
0:11d039b90bde | 37 | * 8 bits of don't care |
elelthvd |
0:11d039b90bde | 38 | * 4 bits of command word (C3-C0) |
elelthvd |
0:11d039b90bde | 39 | * 4 bits if don't care |
elelthvd |
0:11d039b90bde | 40 | * |
elelthvd |
0:11d039b90bde | 41 | * Input Second SPI write 16-bit: |
elelthvd |
0:11d039b90bde | 42 | * 16 bits of data word (D15-D0) |
elelthvd |
0:11d039b90bde | 43 | * This data word encodes the desired DAC value between 0.0V and Vref. |
elelthvd |
0:11d039b90bde | 44 | * Vref on the Mikroe DAC2 Click equals 5.0V (jumper default). |
elelthvd |
0:11d039b90bde | 45 | * |
elelthvd |
0:11d039b90bde | 46 | */ |
elelthvd |
0:11d039b90bde | 47 | void writeRegister(CommandName command, uint16_t data); |
elelthvd |
0:11d039b90bde | 48 | void hwReset(); |
elelthvd |
0:11d039b90bde | 49 | protected: |
elelthvd |
0:11d039b90bde | 50 | private: |
elelthvd |
0:11d039b90bde | 51 | SPI *_spi; |
elelthvd |
0:11d039b90bde | 52 | DigitalOut _cs; |
elelthvd |
0:11d039b90bde | 53 | DigitalOut _rst; |
elelthvd |
0:11d039b90bde | 54 | }; |
elelthvd |
0:11d039b90bde | 55 | |
elelthvd |
0:11d039b90bde | 56 | |
elelthvd |
0:11d039b90bde | 57 | #endif // _LTC2601_H |