Changeset 12 for ds1624

Show
Ignore:
Timestamp:
10/19/07 01:35:46 (15 months ago)
Author:
mlalondesvn
Message:

DS1624:

ADDED - Support for read/write to the EEPROM
ADDED - DS1624_USE_EEPROM Define in the config to enable eeprom functions
MODIF - Moved the start/stop conversion routine to the start/stopConversion() functions


DS1803 & DS1337:

FIXED - Removed r/w addresses and changed for single address

Location:
ds1624
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • ds1624/ds1624.cpp

    r7 r12  
    1919{ 
    2020    Wire.beginTransmission(DS1624_ADDR); 
    21     Wire.send(DS1624_CONFIG); 
     21    Wire.send(DS1624_CONFIG_ADDR); 
    2222    Wire.send(DS1624_CONFIGS); 
    2323    Wire.endTransmission(); 
    2424     
    25     delay(10); 
     25    delay(5); 
    2626     
    27     Wire.beginTransmission(DS1624_ADDR); 
    28     Wire.send(DS1624_CONFIG); 
    29     Wire.endTransmission(); 
    30      
    31     Wire.requestFrom(DS1624_ADDR, 1); 
    32      
     27    if (DS1624_CONFIGS == DS1624_CONFIG_CONT) { 
     28        startConversion(); 
     29    } 
     30} 
     31 
     32void DS1624::startConversion(void) 
     33{ 
    3334    Wire.beginTransmission(DS1624_ADDR); 
    3435    Wire.send(DS1624_SMPL_START); 
    3536    Wire.endTransmission(); 
     37     
     38#ifdef DS1624_HANDLE_BOOT_DELAY 
     39    delay(1000); 
     40#endif 
     41} 
    3642 
    37 #ifdef DS1624_HANDLE_BOOT_DELAY 
    38     delay(1500); 
    39 #endif 
     43void DS1624::stopConversion(void) 
     44{ 
     45    Wire.beginTransmission(DS1624_ADDR); 
     46    Wire.send(DS1624_SMPL_STOP); 
     47    Wire.endTransmission(); 
    4048} 
    4149 
     
    4654    Wire.send(DS1624_READ_TEMP); 
    4755    Wire.endTransmission(); 
     56     
     57    delay(5); 
    4858     
    4959    Wire.requestFrom(DS1624_ADDR, 2); 
     
    5969    return res; 
    6070} 
     71 
     72#ifdef DS1624_USE_EEPROM 
     73void DS1624::writeData(uint8_t *data) 
     74{ 
     75    writeData(data, DS1624_EEPROM_SIZE, 0); 
     76} 
     77 
     78void DS1624::writeData(uint8_t *data, uint8_t dataLength) 
     79{ 
     80    writeData(data, dataLength, 0); 
     81} 
     82 
     83void DS1624::writeData(uint8_t *data, uint8_t dataLength, uint8_t memoryPosition) 
     84{ 
     85    // We can only write one page at a time! 
     86    if (memoryPosition%DS1624_EEPROM_PAGE != 0) return; 
     87     
     88    // Make sure we don't overlap 
     89    if (dataLength == 0 || dataLength > (DS1624_EEPROM_SIZE - memoryPosition)) return; 
     90     
     91    uint8_t buffer[DS1624_EEPROM_PAGE]; 
     92    uint8_t pagePosition    = 0; 
     93    uint8_t pageSize        = 0; 
     94    uint8_t buffLen         = 0; 
     95     
     96    stopConversion(); 
     97     
     98    for (uint16_t pageStart = 0; pageStart < dataLength; pageStart+=DS1624_EEPROM_PAGE) 
     99    {    
     100        if (pageStart+DS1624_EEPROM_PAGE < dataLength || dataLength%DS1624_EEPROM_PAGE == 0) 
     101            pageSize    = DS1624_EEPROM_PAGE; 
     102        else 
     103            pageSize    = dataLength%DS1624_EEPROM_PAGE; 
     104         
     105        pagePosition = 0; 
     106        while (pagePosition < pageSize) 
     107        { 
     108            buffer[pagePosition]    = data[pageStart+pagePosition]; 
     109             
     110            pagePosition++; 
     111        } 
     112         
     113        writePage(buffer, pageSize, (memoryPosition + pageStart)); 
     114         
     115    } 
     116     
     117    startConversion(); 
     118     
     119    return; 
     120} 
     121 
     122void DS1624::writePage(uint8_t *data, uint8_t dataLength, uint8_t pagePosition) 
     123{ 
     124    if (dataLength == 0 || dataLength > DS1624_EEPROM_PAGE) return; 
     125     
     126    Wire.beginTransmission(DS1624_ADDR); 
     127    Wire.send(DS1624_ACCESS_MEM); 
     128    Wire.send(pagePosition); 
     129     
     130    Wire.send(data, dataLength); 
     131     
     132    Wire.endTransmission(); 
     133     
     134    // Wait for the DS1624 to finish writing the eeprom 
     135    delay(50); 
     136} 
     137 
     138void DS1624::readData(uint8_t *data) 
     139{ 
     140    return readData(data, DS1624_EEPROM_SIZE, 0); 
     141} 
     142 
     143void DS1624::readData(uint8_t *data, uint8_t dataLength) 
     144{ 
     145    return readData(data, dataLength, 0); 
     146} 
     147 
     148void DS1624::readData(uint8_t *data, uint8_t dataLength, uint8_t memoryPosition) 
     149{ 
     150    // Make sure we don't overlap 
     151    if (dataLength == 0 || dataLength > (DS1624_EEPROM_SIZE - memoryPosition)) return; 
     152     
     153    uint8_t pagePosition; 
     154    for (uint16_t pagePosition = 0; pagePosition < dataLength; pagePosition++) 
     155    { 
     156        // Send the access memory command along with the starting position 
     157        Wire.beginTransmission(DS1624_ADDR); 
     158        Wire.send(DS1624_ACCESS_MEM); 
     159        Wire.send((int)(memoryPosition + pagePosition)); 
     160        Wire.endTransmission(); 
     161         
     162        // Wait for the DS1624 to set the position pointer 
     163        delay(5); 
     164         
     165        Wire.requestFrom(DS1624_ADDR, 1); 
     166         
     167        while (!Wire.available()); 
     168         
     169        data[pagePosition] = Wire.receive(); 
     170    } 
     171     
     172    return; 
     173} 
     174#endif 
  • ds1624/ds1624.h

    r7 r12  
    99 
    1010/** 
    11  * Registers and bit mask definition 
     11 * Sampling configurations 
    1212**/ 
    13 #define DS1624_CONFIG       0xAC 
    14 #define DS1624_CONFIG_DONE  B10000000 
    1513#define DS1624_CONFIG_1SHOT B00000001 
    1614#define DS1624_CONFIG_CONT  B00000000 
    1715 
    18 // Select your config here! 
     16// Select either 1shot or continous themometer mode 
    1917#define DS1624_CONFIGS      DS1624_CONFIG_CONT 
    2018 
     19// DS1624 Commands 
     20#define DS1624_CONFIG_ADDR  0xAC 
    2121#define DS1624_READ_TEMP    0xAA 
    2222#define DS1624_SMPL_START   0xEE 
     
    2424#define DS1624_ACCESS_MEM   0x17 
    2525 
     26// Bit masks 
     27#define DS1624_CONFIG_DONE  B10000000 
     28 
     29// Size of the EEPROM memory in bytes 
     30#define DS1624_EEPROM_SIZE  255 /* There are actually 256 bytes, but the twi functions only support reading 255 at a time!*/ 
     31#define DS1624_EEPROM_PAGE  8 
     32 
    2633class DS1624 
    2734{ 
    2835    public: 
    2936        DS1624(); 
     37         
     38        /** 
     39         * Init: runs the initializationr outine 
     40        **/ 
    3041        void        Init(void); 
     42         
     43        /** 
     44         * readTemp: reads the temperature and returns 
     45         * a 16 byte integer in which the 2 highest bytes 
     46         * are used as (int8_t)degrees and the 2 lowest 
     47         * are used (uint8_t)decimals 
     48        **/ 
    3149        uint16_t    readTemp(void); 
     50         
     51        /** 
     52         * Start conversion, used at startup in 
     53         * continous mode, or before a read 
     54         * in 1shot mode 
     55        **/ 
     56        void        startConversion(void); 
     57         
     58        /** 
     59         * stopConversion: stops the temperature acquisition 
     60        **/ 
     61        void        stopConversion(void); 
     62    /** 
     63     * EEPROM Support functions 
     64    **/ 
     65    #ifdef DS1624_USE_EEPROM 
     66        /** 
     67         * writeData: writes data to the eeprom 
     68         * pass it an array of uint8_t containing the values to write,  
     69         * the start position (must be %8 == 0) and the length. 
     70         * The two last can be omnited. 
     71        **/ 
     72        void        writeData(uint8_t *, uint8_t, uint8_t); 
     73        void        writeData(uint8_t *, uint8_t); 
     74        void        writeData(uint8_t *); 
     75         
     76        /** 
     77         * writeData: writes data to the eeprom 
     78         * pass it an array of uint8_t to store the result,  
     79         * the start position and the length. The two last can be omnited 
     80        **/ 
     81        void        readData(uint8_t *, uint8_t, uint8_t); 
     82        void        readData(uint8_t *, uint8_t); 
     83        void        readData(uint8_t *); 
     84    #endif 
    3285    private: 
     86    #ifdef DS1624_USE_EEPROM 
     87        /** 
     88         * writePage: writes a single page (or less) to the eeprom 
     89         * pass it an array of uint8_t to store the result,  
     90         * the start position and the length. 
     91        **/ 
     92        void        writePage(uint8_t *, uint8_t, uint8_t); 
     93    #endif 
    3394         
    3495};