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.
ltc2460.cpp
00001 #include "ltc2460.h" 00002 00003 00004 LTC2460::LTC2460(PinName csPin , PinName mosiPin, PinName misoPin, PinName sckPin,double resDividerVal ): mCSpin(csPin), mSpi(mosiPin, misoPin, sckPin){ 00005 00006 mResDividerVal= resDividerVal ; 00007 if(!initLTC2460()){}; //while(1); //TODO handle error 00008 00009 } 00010 00011 00012 bool LTC2460::initLTC2460(void){ 00013 // uint8_t data; 00014 // Setup the spi for 16 bit data 00015 // second edge capture, with a 1MHz clock rate 00016 mSpi.format(16,0); 00017 mSpi.frequency(1000000); 00018 return true; 00019 } 00020 00021 00022 uint16_t LTC2460::spiRead(void) 00023 { 00024 __disable_irq(); // Disable Interrupts 00025 mCSpin=0; 00026 uint16_t val = mSpi.write(0); // The written value is ignored, reg value is read 00027 mCSpin = 1; 00028 __enable_irq(); // Enable Interrupts 00029 return val; 00030 } 00031 00032 void LTC2460::spiWrite(uint16_t value) 00033 { 00034 __disable_irq(); // Disable Interrupts 00035 mCSpin = 0; 00036 mSpi.write(value); // New value follows 00037 mCSpin= 1; 00038 __enable_irq(); // Enable Interrupts 00039 } 00040 00041 float LTC2460::readVoltage() 00042 { 00043 00044 uint16_t rawData=spiRead() ; 00045 float temp = (float)((1.25/0xFFFF)*rawData); 00046 float val = temp*mResDividerVal+temp; 00047 return val; 00048 } 00049 00050
Generated on Fri Jul 15 2022 14:58:48 by
1.7.2