Maxim Integrated MAX5171 14-bit Force/Sense DAC
Dependents: MAX5171BOB_Tester MAX5171BOB_14bit_Remote_Sense_SPI_DAC MAX5171BOB_Serial_Tester
Diff: MAX5171.cpp
- Revision:
- 5:e8c0dfaeb53b
- Parent:
- 4:1984eef51fe3
- Child:
- 6:f661c4a61207
--- a/MAX5171.cpp Wed Oct 30 15:43:40 2019 -0700 +++ b/MAX5171.cpp Thu Mar 12 23:33:56 2020 +0000 @@ -1,5 +1,5 @@ // /******************************************************************************* -// * Copyright (C) 2019 Maxim Integrated Products, Inc., All Rights Reserved. +// * Copyright (C) 2020 Maxim Integrated Products, Inc., All Rights Reserved. // * // * Permission is hereby granted, free of charge, to any person obtaining a // * copy of this software and associated documentation files (the "Software"), @@ -43,7 +43,7 @@ // Device Name = MAX5171 // Device Description = Low-Power, Serial, 14-Bit, 1-Channel DACs with Force/Sense Voltage Output and SPI Interface -// Device DeviceBriefDescription = 14-bit Force/Sense DAC +// Device DeviceBriefDescription = 14-bit Force/Sense DAC // Device Manufacturer = Maxim Integrated // Device PartNumber = MAX5171AEEE+ // Device RegValue_Width = DataWidth16bit_HL @@ -137,13 +137,15 @@ // SPI CS = ActiveLow // SPI FrameStart = CS m_SPI_cs_state = 1; - m_cs_pin = m_SPI_cs_state; + if (m_cs_pin.is_connected()) { // avoid mbed runtime error if pin is NC not connected + m_cs_pin = m_SPI_cs_state; + } // SPI CPOL = 0 // SPI CPHA = 0 // SPI MOSI and MISO Data are both stable on Rising edge of SCLK // SPI SCLK Idle Low - m_SPI_dataMode = 0; //SPI_MODE0; // CPOL=0,CPHA=0: Rising Edge stable; SCLK idle Low + m_SPI_dataMode = 0; //SPI_MODE0; // CPOL=0,CPHA=0: Rising Edge stable; SCLK idle Low m_spi.format(8,m_SPI_dataMode); // int bits_must_be_8, int mode=0_3 CPOL=0,CPHA=0 // SPI SCLKMaxMHz = 10 @@ -151,7 +153,7 @@ //#define SPI_SCLK_Hz 48000000 // 48MHz //#define SPI_SCLK_Hz 24000000 // 24MHz //#define SPI_SCLK_Hz 12000000 // 12MHz - //#define SPI_SCLK_Hz 6000000 // 6MHz + //#define SPI_SCLK_Hz 6000000 // 6MHz //#define SPI_SCLK_Hz 4000000 // 4MHz //#define SPI_SCLK_Hz 2000000 // 2MHz //#define SPI_SCLK_Hz 1000000 // 1MHz @@ -159,23 +161,23 @@ m_spi.frequency(m_SPI_SCLK_Hz); // - // FB Analog Input to MAX5171 device - // - // RS Configuration Input to MAX5171 device + // FB Analog Input to MAX5171 device + // + // RS Configuration Input to MAX5171 device m_RS_pin = 1; // output logic high -- initial value in constructor - // - // PDLb Configuration Input to MAX5171 device + // + // PDLb Configuration Input to MAX5171 device m_PDLb_pin = 1; // output logic high -- initial value in constructor - // - // CLRb Configuration Input to MAX5171 device + // + // CLRb Configuration Input to MAX5171 device m_CLRb_pin = 1; // output logic high -- initial value in constructor - // - // SHDN Configuration Input to MAX5171 device + // + // SHDN Configuration Input to MAX5171 device m_SHDN_pin = 1; // output logic high -- initial value in constructor - // - // OUT Analog Output from device - // - // UPO General-Purpose Output from device + // + // OUT Analog Output from device + // + // UPO General-Purpose Output from device } MAX5171::~MAX5171() @@ -183,7 +185,7 @@ // do nothing } -/// set SPI SCLK frequency +/// set SPI SCLK frequency void MAX5171::spi_frequency(int spi_sclk_Hz) { m_SPI_SCLK_Hz = spi_sclk_Hz; @@ -193,10 +195,12 @@ // Assert SPI Chip Select // SPI chip-select for MAX5171 // -void MAX5171::SPIoutputCS(int isLogicHigh) +inline void MAX5171::SPIoutputCS(int isLogicHigh) { m_SPI_cs_state = isLogicHigh; - m_cs_pin = m_SPI_cs_state; + if (m_cs_pin.is_connected()) { // avoid mbed runtime error if pin is NC not connected + m_cs_pin = m_SPI_cs_state; + } } // SPI write 16 bits @@ -224,11 +228,11 @@ // // Arduino: begin critical section: noInterrupts() masks all interrupt sources; end critical section with interrupts() //~ interrupts(); - // Optional Diagnostic function to print SPI transactions - if (onSPIprint) - { - onSPIprint(byteCount, (uint8_t*)mosiData, (uint8_t*)misoData); - } + // Optional Diagnostic function to print SPI transactions + if (onSPIprint) + { + onSPIprint(byteCount, (uint8_t*)mosiData, (uint8_t*)misoData); + } // // VERIFY: SPIwrite24bits print diagnostic information //cmdLine.serial().printf(" MOSI->")); @@ -284,7 +288,7 @@ } //---------------------------------------- -// Menu item '!' +// Menu item '!' // Initialize device // @return 1 on success; 0 on failure uint8_t MAX5171::Init(void) @@ -525,7 +529,7 @@ //---------------------------------------- // CMD_1111_0xxx_xxxx_xxxx_MODE1_DOUT_SCLK_RISING_EDGE // -// Mode 1, DOUT clocked out on SCLK's rising edge. +// Mode 1, DOUT clocked out on SCLK's rising edge. // @return 1 on success; 0 on failure uint8_t MAX5171::MODE1_DOUT_SCLK_RISING_EDGE(void) {