Driver C++ source code for MAX5216/MAX5214 16-bit/14-bit DAC SPI (50MHz) bus ICs. Low power Digital-to_Analog Converter chips which accept supply voltages of 2.7V to 5.5V. Features Rail-to-Rail Buffered Output Operation and Safe Power-On Reset (POR) to Zero DAC Output.
Dependents: MAX5216_16_Bit_DAC_Hello_Code
Fork of MAX5487_Digital_Pot_Potentiometer_Rheostat_Resistor_Wiper by
Diff: MAX5216.cpp
- Revision:
- 5:bd8dbd9be2ac
- Parent:
- 4:280d1e05f2ca
- Child:
- 6:cd8d96483262
diff -r 280d1e05f2ca -r bd8dbd9be2ac MAX5216.cpp --- a/MAX5216.cpp Sun Aug 12 10:04:09 2018 +0000 +++ b/MAX5216.cpp Mon Aug 13 04:18:09 2018 +0000 @@ -37,50 +37,44 @@ m_pin = 1; } -void MAX5216::writeCommand(setting_t setting, uint32_t value) +void MAX5216::writeCommand(setting_t setting, uint32_t value, pwrDwnMode_t mode) { char val[3] = {0, 0, 0}; int i; - - if(value > MAX521X_IC_BIT_MASK[(uint8_t)(m_ic_variant)]) { - printf("value in writeCommand is too big: %X\r\n", value); - return; - } m_pin = 0; - if (m_ic_variant == MAX5214_IC) { // MAX5214 is 14 bits - value &= MAX521X_IC_BIT_MASK[(uint8_t)(m_ic_variant)]; - } else { // MAX5216 is 16 bits - value &= MAX521X_IC_BIT_MASK[(uint8_t)(m_ic_variant)]; - value = value << 6; // least significant 6 bits are not used - val[2] = value & 0xFF; + if (setting == PwrDwn_Reg) { + val[0] = char(value<<2); + val[0] |= char(setting); + for (i = 0; i < MAX521X_NUM_BYTES_SPI[(uint8_t)(m_ic_variant)]; i++) { + m_spi.write(val[i]); + } + } else if (setting == WrtThru_Reg){ + + if(value > MAX521X_IC_BIT_MASK[(uint8_t)(m_ic_variant)]) { + printf("value in writeCommand is too big: %X\r\n", value); + return; + } + if (m_ic_variant == MAX5214_IC) { // MAX5214 is 14 bits + value &= MAX521X_IC_BIT_MASK[(uint8_t)(m_ic_variant)]; + } else { // MAX5216 is 16 bits + value &= MAX521X_IC_BIT_MASK[(uint8_t)(m_ic_variant)]; + value = value << 6; // least significant 6 bits are not used + val[2] = value & 0xFF; + value = value >> 8; + } + val[1] = value & 0xFF; value = value >> 8; - } - val[1] = value & 0xFF; - value = value >> 8; - val[0] = value; - val[0] |= setting; - //printf("mask %X, Value %X, val 0, 1, 2 %02X %02X %02X \r\n", MAX521X_IC_BIT_MASK[(uint8_t)(m_ic_variant)],value, val[0], val[1], val[2]); - - for (i = 0; i < MAX521X_NUM_BYTES_SPI[(uint8_t)(m_ic_variant)]; i++) { - m_spi.write(val[i]); + val[0] = value; + val[0] |= setting; + // printf("mask %X, Value %X, val 0, 1, 2 %02X %02X %02X \r\n", MAX521X_IC_BIT_MASK[(uint8_t)(m_ic_variant)],value, val[0], val[1], val[2]); + for (i = 0; i < MAX521X_NUM_BYTES_SPI[(uint8_t)(m_ic_variant)]; i++) { + m_spi.write(val[i]); + } } m_pin = 1; } -#if 0 // tbd -void MAX5216::writeCommand(setting_t setting, pwrDwnMode_t mode) -{ - char val[3] = {0, 0, 0}; - int i; - m_pin = 0; - val[0] = setting | (char)(mode); - for (i = 0; i < MAX521X_NUM_BYTES_SPI[(uint8_t)(m_ic_variant)]; i++) { - m_spi.write(val[i]); - } - m_pin = 1; - -} -#endif + MAX5216::~MAX5216(void) { //empty block