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

git-svn-id: svn+ssh://oldsvn/home/mlalondesvn/svn/cral@12 3ee9b42a-b53c-0410-a25e-f0b6218d5d5b
master
mlalondesvn 17 years ago
parent ead75702d2
commit 9f68d8eeac

@ -1,11 +1,6 @@
#ifndef DS1337_CONFIG
#define DS1337_CONFIG
/**
* Define the DS1337 I2C addresses
**/
#define DS1337_WADDR B01101000 /* 0x68 */
// Ucomment this to enable setting the clock from a
// unix time stamp with gmt and dst correction
#define DS1337_USE_SET_UTS

@ -15,4 +15,10 @@
**/
#define DS1624_HANDLE_BOOT_DELAY
/**
* Uncomment this to support reading and writing
* to the 256 bytes of EEPROM on the DS1624
**/
#define DS1624_USE_EEPROM
#endif

@ -38,7 +38,7 @@ int8_t DS1337::Init(void)
delay(500); //Account for the crystal startup time
// Check address and returns false is there is an error
if (Wire.checkAddress(DS1337_WADDR)) {
if (Wire.checkAddress(DS1337_ADDR)) {
// Possibly set the default registers here
clockExists = true;
@ -53,7 +53,7 @@ int8_t DS1337::Init(void)
#endif
}
return DS1337_WADDR;
return DS1337_ADDR;
} else clockExists = false;
return -1;
@ -71,7 +71,7 @@ int8_t DS1337::Init(void)
clockStart();
}
return DS1337_WADDR;
return DS1337_ADDR;
}
#endif
@ -89,7 +89,7 @@ void DS1337::writeRegister(uint8_t registerNumber, uint8_t registerValue)
{
if (!clockExists) return;
Wire.beginTransmission(DS1337_WADDR);
Wire.beginTransmission(DS1337_ADDR);
Wire.send(registerNumber);
Wire.send(registerValue);
@ -101,11 +101,11 @@ uint8_t DS1337::getRegister(uint8_t registerNumber)
{
if (!clockExists) return 0;
Wire.beginTransmission(DS1337_WADDR);
Wire.beginTransmission(DS1337_ADDR);
Wire.send(registerNumber);
Wire.endTransmission();
Wire.requestFrom(DS1337_WADDR, 1);
Wire.requestFrom(DS1337_ADDR, 1);
while (!Wire.available());
@ -125,11 +125,11 @@ void DS1337::clockRead(void)
{
if (!clockExists) return;
Wire.beginTransmission(DS1337_WADDR);
Wire.beginTransmission(DS1337_ADDR);
Wire.send(0x00);
Wire.endTransmission();
Wire.requestFrom(DS1337_WADDR, 7);
Wire.requestFrom(DS1337_ADDR, 7);
while (!Wire.available());
for(int i=0; i<7; i++)
@ -146,7 +146,7 @@ void DS1337::clockSave(void)
// Stop the clock
clockStop();
Wire.beginTransmission(DS1337_WADDR);
Wire.beginTransmission(DS1337_ADDR);
Wire.send(0x00);
for(int i=0; i<7; i++)
@ -591,7 +591,7 @@ boolean DS1337::alarmCheck(void)
void DS1337::alarmSave(void)
{
Wire.beginTransmission(DS1337_WADDR);
Wire.beginTransmission(DS1337_ADDR);
Wire.send((alarmId == false ? DS1337_ALARM1 : DS1337_ALARM2));
for(uint8_t i=(alarmId == false ? 0 : 1); i<4; i++)

@ -38,10 +38,9 @@
/**
* Define the DS1337 I2C addresses
**/
#ifndef DS1337_WADDR
#define DS1337_WADDR 0x68
#ifndef DS1337_ADDR
#define DS1337_ADDR B01101000
#endif
#define DS1337_RADDR DS1337_WADDR | 0x01
/**
* Define registers and bit masks
@ -87,6 +86,9 @@
#define DS1337_ALARM_MODE 4
#define DS1337_ALARM_DT 5
/**
* Match Day of the week or match date
**/
#define DS1337_ALARM_DT_DOW true
#define DS1337_ALARM_DT_DATE false

@ -18,27 +18,35 @@ DS1624 TEMP = DS1624();
void DS1624::Init(void)
{
Wire.beginTransmission(DS1624_ADDR);
Wire.send(DS1624_CONFIG);
Wire.send(DS1624_CONFIG_ADDR);
Wire.send(DS1624_CONFIGS);
Wire.endTransmission();
delay(10);
delay(5);
Wire.beginTransmission(DS1624_ADDR);
Wire.send(DS1624_CONFIG);
Wire.endTransmission();
Wire.requestFrom(DS1624_ADDR, 1);
if (DS1624_CONFIGS == DS1624_CONFIG_CONT) {
startConversion();
}
}
void DS1624::startConversion(void)
{
Wire.beginTransmission(DS1624_ADDR);
Wire.send(DS1624_SMPL_START);
Wire.endTransmission();
#ifdef DS1624_HANDLE_BOOT_DELAY
delay(1500);
delay(1000);
#endif
}
void DS1624::stopConversion(void)
{
Wire.beginTransmission(DS1624_ADDR);
Wire.send(DS1624_SMPL_STOP);
Wire.endTransmission();
}
uint16_t DS1624::readTemp(void)
{
uint16_t res = 0;
@ -46,6 +54,8 @@ uint16_t DS1624::readTemp(void)
Wire.send(DS1624_READ_TEMP);
Wire.endTransmission();
delay(5);
Wire.requestFrom(DS1624_ADDR, 2);
while (!Wire.available());
@ -58,3 +68,107 @@ uint16_t DS1624::readTemp(void)
return res;
}
#ifdef DS1624_USE_EEPROM
void DS1624::writeData(uint8_t *data)
{
writeData(data, DS1624_EEPROM_SIZE, 0);
}
void DS1624::writeData(uint8_t *data, uint8_t dataLength)
{
writeData(data, dataLength, 0);
}
void DS1624::writeData(uint8_t *data, uint8_t dataLength, uint8_t memoryPosition)
{
// We can only write one page at a time!
if (memoryPosition%DS1624_EEPROM_PAGE != 0) return;
// Make sure we don't overlap
if (dataLength == 0 || dataLength > (DS1624_EEPROM_SIZE - memoryPosition)) return;
uint8_t buffer[DS1624_EEPROM_PAGE];
uint8_t pagePosition = 0;
uint8_t pageSize = 0;
uint8_t buffLen = 0;
stopConversion();
for (uint16_t pageStart = 0; pageStart < dataLength; pageStart+=DS1624_EEPROM_PAGE)
{
if (pageStart+DS1624_EEPROM_PAGE < dataLength || dataLength%DS1624_EEPROM_PAGE == 0)
pageSize = DS1624_EEPROM_PAGE;
else
pageSize = dataLength%DS1624_EEPROM_PAGE;
pagePosition = 0;
while (pagePosition < pageSize)
{
buffer[pagePosition] = data[pageStart+pagePosition];
pagePosition++;
}
writePage(buffer, pageSize, (memoryPosition + pageStart));
}
startConversion();
return;
}
void DS1624::writePage(uint8_t *data, uint8_t dataLength, uint8_t pagePosition)
{
if (dataLength == 0 || dataLength > DS1624_EEPROM_PAGE) return;
Wire.beginTransmission(DS1624_ADDR);
Wire.send(DS1624_ACCESS_MEM);
Wire.send(pagePosition);
Wire.send(data, dataLength);
Wire.endTransmission();
// Wait for the DS1624 to finish writing the eeprom
delay(50);
}
void DS1624::readData(uint8_t *data)
{
return readData(data, DS1624_EEPROM_SIZE, 0);
}
void DS1624::readData(uint8_t *data, uint8_t dataLength)
{
return readData(data, dataLength, 0);
}
void DS1624::readData(uint8_t *data, uint8_t dataLength, uint8_t memoryPosition)
{
// Make sure we don't overlap
if (dataLength == 0 || dataLength > (DS1624_EEPROM_SIZE - memoryPosition)) return;
uint8_t pagePosition;
for (uint16_t pagePosition = 0; pagePosition < dataLength; pagePosition++)
{
// Send the access memory command along with the starting position
Wire.beginTransmission(DS1624_ADDR);
Wire.send(DS1624_ACCESS_MEM);
Wire.send((int)(memoryPosition + pagePosition));
Wire.endTransmission();
// Wait for the DS1624 to set the position pointer
delay(5);
Wire.requestFrom(DS1624_ADDR, 1);
while (!Wire.available());
data[pagePosition] = Wire.receive();
}
return;
}
#endif

@ -8,28 +8,89 @@
#define DS1624_ADDR DS1624_BASE_ADDR | (DS1624_A0 * B00000001) | (DS1624_A1 * B00000010) | (DS1624_A2 * B00000100)
/**
* Registers and bit mask definition
* Sampling configurations
**/
#define DS1624_CONFIG 0xAC
#define DS1624_CONFIG_DONE B10000000
#define DS1624_CONFIG_1SHOT B00000001
#define DS1624_CONFIG_CONT B00000000
// Select your config here!
// Select either 1shot or continous themometer mode
#define DS1624_CONFIGS DS1624_CONFIG_CONT
// DS1624 Commands
#define DS1624_CONFIG_ADDR 0xAC
#define DS1624_READ_TEMP 0xAA
#define DS1624_SMPL_START 0xEE
#define DS1624_SMPL_STOP 0x22
#define DS1624_ACCESS_MEM 0x17
// Bit masks
#define DS1624_CONFIG_DONE B10000000
// Size of the EEPROM memory in bytes
#define DS1624_EEPROM_SIZE 255 /* There are actually 256 bytes, but the twi functions only support reading 255 at a time!*/
#define DS1624_EEPROM_PAGE 8
class DS1624
{
public:
DS1624();
/**
* Init: runs the initializationr outine
**/
void Init(void);
/**
* readTemp: reads the temperature and returns
* a 16 byte integer in which the 2 highest bytes
* are used as (int8_t)degrees and the 2 lowest
* are used (uint8_t)decimals
**/
uint16_t readTemp(void);
/**
* Start conversion, used at startup in
* continous mode, or before a read
* in 1shot mode
**/
void startConversion(void);
/**
* stopConversion: stops the temperature acquisition
**/
void stopConversion(void);
/**
* EEPROM Support functions
**/
#ifdef DS1624_USE_EEPROM
/**
* writeData: writes data to the eeprom
* pass it an array of uint8_t containing the values to write,
* the start position (must be %8 == 0) and the length.
* The two last can be omnited.
**/
void writeData(uint8_t *, uint8_t, uint8_t);
void writeData(uint8_t *, uint8_t);
void writeData(uint8_t *);
/**
* writeData: writes data to the eeprom
* pass it an array of uint8_t to store the result,
* the start position and the length. The two last can be omnited
**/
void readData(uint8_t *, uint8_t, uint8_t);
void readData(uint8_t *, uint8_t);
void readData(uint8_t *);
#endif
private:
#ifdef DS1624_USE_EEPROM
/**
* writePage: writes a single page (or less) to the eeprom
* pass it an array of uint8_t to store the result,
* the start position and the length.
**/
void writePage(uint8_t *, uint8_t, uint8_t);
#endif
};

@ -22,9 +22,9 @@ DS1803 DPOT = DS1803();
void DS1803::setWiper(uint8_t value, uint8_t wiperAddr)
{
if (!Wire.checkAddress(DS1803_WADDR)) return;
if (!Wire.checkAddress(DS1803_ADDR)) return;
Wire.beginTransmission(DS1803_WADDR);
Wire.beginTransmission(DS1803_ADDR);
Wire.send(wiperAddr); // Send the wiper address
Wire.send(value);
@ -35,9 +35,9 @@ void DS1803::setWiper(uint8_t value, uint8_t wiperAddr)
#ifdef DS1803_USE_GET_VALUE_FUNC
uint8_t DS1803::getValue()
{
if (!Wire.checkAddress(DS1803_WADDR)) return;
if (!Wire.checkAddress(DS1803_ADDR)) return;
Wire.requestFrom(DS1803_RADDR, 2);
Wire.requestFrom(DS1803_ADDR, 2);
while (Wire.available()) {
Serial.println((uint8_t)Wire.receive(), DEC);

@ -14,8 +14,7 @@
#endif
#define DS1803_BASE_ADDR B00101000
#define DS1803_WADDR DS1803_BASE_ADDR | (DS1803_A0 * B00000001) | (DS1803_A1 * B00000010) | (DS1803_A2 * B00000100)
#define DS1803_RADDR DS1803_WADDR | 0x01
#define DS1803_ADDR DS1803_BASE_ADDR | (DS1803_A0 * B00000001) | (DS1803_A1 * B00000010) | (DS1803_A2 * B00000100)
/**
* The number of available potentiometer wipers

Loading…
Cancel
Save