Skip to content

Commit

Permalink
extend and document ds2450, ds2502, ds2506 and ds2890
Browse files Browse the repository at this point in the history
  • Loading branch information
orgua committed Nov 10, 2016
1 parent 49918bd commit b34cced
Show file tree
Hide file tree
Showing 20 changed files with 116 additions and 86 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ project(OneWireHub)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

add_subdirectory(src)
include_directories(./src)
#add_subdirectory(src)
#include_directories(./src)

set(SOURCE_FILES
main.cpp
Expand Down
107 changes: 70 additions & 37 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,69 +5,102 @@

using namespace std;

#include "OneWireHub.h"
#include "src/OneWireHub.h"

// include all libs to find errors
#include "DS2401.h" // Serial Number
#include "DS18B20.h" // Digital Thermometer
#include "DS2405.h" // Single adress switch
#include "DS2408.h" // 8-Channel Addressable Switch
#include "DS2413.h" // Dual channel addressable switch
#include "DS2423.h" // 4kb 1-Wire RAM with Counter
#include "DS2431.h" // 1kb 1-Wire EEPROM
#include "DS2433.h" // 4Kb 1-Wire EEPROM
#include "DS2438.h" // Smart Battery Monitor
#include "DS2450.h" // 4 channel A/D
#include "DS2502.h" // 1kb EEPROM
#include "DS2890.h" // Single channel digital potentiometer
#include "src/BAE910.h"
#include "src/DS18B20.h" // Digital Thermometer
#include "src/DS2401.h" // Serial Number
#include "src/DS2405.h" // Single adress switch
#include "src/DS2408.h" // 8-Channel Addressable Switch
#include "src/DS2413.h" // Dual channel addressable switch
#include "src/DS2423.h" // 4kb 1-Wire RAM with Counter
#include "src/DS2431.h" // 1kb 1-Wire EEPROM
#include "src/DS2433.h" // 4Kb 1-Wire EEPROM
#include "src/DS2438.h" // Smart Battery Monitor
#include "src/DS2450.h" // 4 channel A/D
#include "src/DS2502.h" // 1kb EEPROM
#include "src/DS2506.h" // 64kb EEPROM
#include "src/DS2890.h" // Single channel digital potentiometer



// taken from OneWireHubTest.ino

const uint8_t OneWire_PIN = 8;

auto hub = OneWireHub(OneWire_PIN);
auto hubA = OneWireHub(OneWire_PIN);
auto hubB = OneWireHub(OneWire_PIN);
auto hubC = OneWireHub(OneWire_PIN);

auto ds1822 = DS18B20(0x22, 0x0D, 0x01, 0x08, 0x02, 0x00, 0x00);
auto ds18B20 = DS18B20(0x28, 0x0D, 0x01, 0x08, 0x0B, 0x02, 0x00); // Work - Digital Thermometer
auto ds18S20 = DS18B20(0x10, 0x0D, 0x01, 0x08, 0x0F, 0x02, 0x00);
auto ds2401a = DS2401( 0x01, 0x00, 0x0D, 0x24, 0x01, 0x00, 0x0A ); // Work - Serial Number
auto ds2401b = DS2401( 0x01, 0x00, 0x0D, 0x24, 0x01, 0x00, 0x0B ); // Work - Serial Number
// auto ds2405 = DS2405( 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ); // - Single address switch
// auto ds2408 = DS2408( 0x29, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ); // - 8-Channel Addressable Switch
auto ds2405 = DS2405( 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ); // - Single address switch
auto ds2408 = DS2408( 0x29, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ); // - 8-Channel Addressable Switch
auto ds2413 = DS2413( 0x3A, 0x0D, 0x02, 0x04, 0x01, 0x03, 0x00 ); // Work - Dual channel addressable switch
// auto ds2423 = DS2423( 0x1D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ); // - 4kb 1-Wire RAM with Counter

auto ds2423 = DS2423( 0x1D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ); // - 4kb 1-Wire RAM with Counter
auto ds2431 = DS2431( 0x2D, 0xE8, 0x9F, 0x90, 0x0E, 0x00, 0x00 ); // Work - 1kb 1-Wire EEPROM
// auto ds2433 = DS2433( 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ); // - 4Kb 1-Wire EEPROM
auto ds2433 = DS2433( 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ); // - 4Kb 1-Wire EEPROM
auto ds2438 = DS2438( 0x26, 0x0D, 0x02, 0x04, 0x03, 0x08, 0x00 ); // - Smart Battery Monitor
auto ds2450 = DS2450( 0x20, 0x0D, 0x0A, 0x02, 0x04, 0x05, 0x00 ); // - 4 channel A/D
auto ds2450 = DS2450( DS2450::family_code, 0x00, 0x00, 0x50, 0x24, 0xDA, 0x00 ); // - 4 channel A/D
auto ds2502 = DS2502( DS2502::family_code, 0x00, 0xA0, 0x02, 0x25, 0xDA, 0x00 );
auto ds2501a = DS2502( 0x91, 0x00, 0xA0, 0x01, 0x25, 0xDA, 0x00 );
auto ds2501b = DS2502( 0x11, 0x00, 0xB0, 0x02, 0x25, 0xDA, 0x00 );

auto ds2503 = DS2506( 0x13, 0x00, 0x00, 0x03, 0x25, 0xDA, 0x00 );
auto ds2505 = DS2506( 0x0B, 0x00, 0x00, 0x05, 0x25, 0xDA, 0x00 );
auto ds2506 = DS2506( 0x0F, 0x00, 0x00, 0x06, 0x25, 0xDA, 0x00 );
auto ds2890A = DS2890( 0x2C, 0x0D, 0x02, 0x08, 0x09, 0x00, 0x0A ); // Work - Single channel digital potentiometer
auto ds2890B = DS2890( 0x2C, 0x0D, 0x02, 0x08, 0x09, 0x00, 0x0B );
auto ds2890C = DS2890( 0x2C, 0x0D, 0x02, 0x08, 0x09, 0x00, 0x0C );
auto bae910 = BAE910(BAE910::family_code, 0x00, 0x00, 0x10, 0xE9, 0xBA, 0x00);

int main()
{
cout << "Hello, World!" << endl;

// Setup OneWire
ds1822.setTemp(static_cast<int16_t>(21));
ds18S20.setTemp(static_cast<int16_t>(10));
hub.attach(ds1822);
hub.attach(ds18B20);
hub.attach(ds18S20);
hub.attach(ds2401a);
hub.attach(ds2401b);
hub.attach(ds2413);
hub.attach(ds2431);
hub.attach(ds2438);
//hub.attach(ds2450);
hub.attach(ds2890A);
hub.attach(ds2890B);
hub.attach(ds2890C);

hub.poll();

if (hub.getError()) hub.printError();
hubA.attach(ds1822);
hubA.attach(ds18B20);
hubA.attach(ds18S20);
hubA.attach(ds2401a);
hubA.attach(ds2401b);
hubA.attach(ds2405);
hubA.attach(ds2408);
hubA.attach(ds2413);

hubB.attach(ds2423);
hubB.attach(ds2431);
hubB.attach(ds2433);
hubB.attach(ds2438);
hubB.attach(ds2450);
hubB.attach(ds2502);
hubB.attach(ds2501a);
hubB.attach(ds2501b);

hubC.attach(ds2503);
hubC.attach(ds2505);
hubC.attach(ds2506);
hubC.attach(ds2890A);
hubC.attach(ds2890B);
hubC.attach(ds2890C);
hubC.attach(bae910);


ds1822.setTemperature(static_cast<int8_t>(21));
ds18S20.setTemperature(static_cast<int8_t>(10));

hubA.poll();
hubB.poll();
hubC.poll();

if (hubA.hasError()) hubA.printError();
if (hubB.hasError()) hubB.printError();
if (hubC.hasError()) hubC.printError();

return 0;
};
2 changes: 1 addition & 1 deletion src/BAE910.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Multifunction 1-wire slave device @@@
// works, basic functionality
// native features: unknown
// native bus-features: unknown

#ifndef ONEWIRE_BAE910_H
#define ONEWIRE_BAE910_H
Expand Down
2 changes: 1 addition & 1 deletion src/DS18B20.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// DS18B20: 9-12bit, -55 - +85 degC
// DS18S20: 9 bit, -55 - +85 degC
// DS1822: 9-12bit, -55 - +125 degC
// native features: alarm search
// native bus-features: alarm search

#ifndef ONEWIRE_DS18B20_H
#define ONEWIRE_DS18B20_H
Expand Down
2 changes: 1 addition & 1 deletion src/DS2401.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Serial Number
// Works
// native features: none
// native bus-features: none

#ifndef ONEWIRE_DS2401_H
#define ONEWIRE_DS2401_H
Expand Down
2 changes: 1 addition & 1 deletion src/DS2405.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Single address switch @@@
// works, but reading back the value is not supported, because alarm search is not implemented yet
// this IC is not using standard protocol - it sends data after searchRom and alarmSearch
// native features: alarm search
// native bus-features: alarm search

#ifndef ONEWIRE_DS2405_H
#define ONEWIRE_DS2405_H
Expand Down
2 changes: 1 addition & 1 deletion src/DS2408.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// 8-Channel Addressable Switch @@@
// works, but no alarm search and higher logic / output / control register-action
// native features: Overdrive capable, alarm search
// native bus-features: Overdrive capable, alarm search

#ifndef ONEWIRE_DS2408_H
#define ONEWIRE_DS2408_H
Expand Down
2 changes: 1 addition & 1 deletion src/DS2413.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Dual channel addressable switch
// Works, master can latch the pin and pull it thereby down
// native features: Overdrive capable
// native bus-features: Overdrive capable

#ifndef ONEWIRE_DS2413_H
#define ONEWIRE_DS2413_H
Expand Down
2 changes: 1 addition & 1 deletion src/DS2423.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// 4kb 1-Wire RAM with Counter
// works
// native features: Overdrive capable
// native bus-features: Overdrive capable

#ifndef ONEWIRE_DS2423_H
#define ONEWIRE_DS2423_H
Expand Down
2 changes: 1 addition & 1 deletion src/DS2431.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// 1Kb 1-Wire EEPROM
// works,
// note: datasheet is fuzzy, but device is similar to ds2433
// native features: Overdrive capable
// native bus-features: Overdrive capable

#ifndef ONEWIRE_DS2431_H
#define ONEWIRE_DS2431_H
Expand Down
2 changes: 1 addition & 1 deletion src/DS2433.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// 4Kb 1-Wire EEPROM
// works
// native features: Overdrive capable
// native bus-features: Overdrive capable

#ifndef ONEWIRE_DS2433_H
#define ONEWIRE_DS2433_H
Expand Down
2 changes: 1 addition & 1 deletion src/DS2438.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Smart Battery Monitor
// works, but without real EPROM copy/recall functionallity, Timer,
// native features: none
// native bus-features: none

#ifndef ONEWIRE_DS2438_H
#define ONEWIRE_DS2438_H
Expand Down
31 changes: 12 additions & 19 deletions src/DS2450.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,64 +3,57 @@
DS2450::DS2450(uint8_t ID1, uint8_t ID2, uint8_t ID3, uint8_t ID4, uint8_t ID5, uint8_t ID6, uint8_t ID7) :
OneWireItem(ID1, ID2, ID3, ID4, ID5, ID6, ID7)
{
static_assert((PAGE_COUNT*PAGE_SIZE) < 256, "Implementation does not cover the whole address-space");
static_assert(sizeof(memory) < 256, "Implementation does not cover the whole address-space");
clearMemory();
};

void DS2450::duty(OneWireHub * const hub)
{
uint16_t reg_TA, crc = 0; // target address
uint8_t data, cmd, length;
uint8_t cmd;

if (hub->recv(&cmd,1,crc)) return;
if (hub->recv(reinterpret_cast<uint8_t *>(&reg_TA),2,crc)) return;

switch (cmd)
{
case 0xAA: // READ MEMORY
if (hub->recv(reinterpret_cast<uint8_t *>(&reg_TA),2,crc)) return;

while(reg_TA < MEM_SIZE)
{
length = PAGE_SIZE - (reinterpret_cast<uint8_t *>(&reg_TA)[0] & PAGE_MASK);
const uint8_t length = PAGE_SIZE - (uint8_t(reg_TA) & PAGE_MASK);
if (hub->send(&memory[reg_TA], length, crc)) return;

crc = ~crc; // normally crc16 is sent ~inverted
if (hub->send(reinterpret_cast<uint8_t *>(&crc), 2)) return;

// prepare next page-readout
reg_TA = (reg_TA & ~PAGE_MASK) + PAGE_SIZE;
reg_TA += length;
crc = 0;
};
break;

case 0x55: // write memory (only page 1&2 allowed)
if (hub->recv(reinterpret_cast<uint8_t *>(&reg_TA),2,crc)) break;
if (reg_TA < PAGE_SIZE) break; // page 0 is off limits

while(reg_TA < MEM_SIZE)
{
uint8_t data;
if (hub->recv(&data, 1, crc)) break;

crc = ~crc; // normally crc16 is sent ~inverted
if (hub->send(reinterpret_cast<uint8_t *>(&crc), 2)) break;

if (hub->send(&data, 1)) break;
memory[reg_TA] = data; // write data
if (reg_TA >= PAGE_SIZE) memory[reg_TA] = data; // write data, page 0 is off limits

crc = ++reg_TA; // prepare next address-readout: load new TA into crc
};
correctMemory();
break;

case 0x3C: // convert, starts adc
if (hub->recv(reinterpret_cast<uint8_t *>(&cmd),1,crc)) return; // input select mask, not important
if (hub->recv(reinterpret_cast<uint8_t *>(&data),1,crc)) return; // read out control byte

// received reg_TA contains: input select mask (not important) and read out control byte
// in reality master can now set registers of potentiometers to 0x0000 or 0xFFFF to track changes

crc = ~crc; // normally crc16 is sent ~inverted
if (hub->send(reinterpret_cast<uint8_t *>(&crc),2)) return;

// takes max 5.3 ms for 16 bit ( 4 CH * 16 bit * 80 us + 160 us per request = 5.3 ms )
if (hub->sendBit(false)) return; // still converting....
break; // finished conversion: send 1, is passive ...
Expand All @@ -78,10 +71,10 @@ void DS2450::clearMemory(void)
for (uint8_t adc = 0; adc < POTI_COUNT; ++adc)
{
// CONTROL/STATUS DATA
memory[(1*PAGE_SIZE) + (adc*2) + 0] = 0x08;
memory[(1*PAGE_SIZE) + (adc*2) + 1] = 0x8C;
memory[(1*PAGE_SIZE) + (adc*2) + 0] = 0x00; // 16bit
memory[(1*PAGE_SIZE) + (adc*2) + 1] = 0x8C; // enable POR, Alarm enable high / low
// alarm settings
memory[(2*PAGE_SIZE) + (adc*2) + 1] = 0xFF;
memory[(2*PAGE_SIZE) + (adc*2) + 1] = 0xFF; // high threshold max
};
};

Expand Down Expand Up @@ -121,7 +114,7 @@ bool DS2450::setPotentiometer(const uint8_t channel, const uint16_t value)
memory[(2*channel) ] = LByte;
memory[(2*channel)+1] = HByte;
correctMemory();
return true;
return true; // TODO: check with alarm settings p2, and raise alarm, also check when data is written
};

uint16_t DS2450::getPotentiometer(const uint8_t channel) const
Expand Down
7 changes: 3 additions & 4 deletions src/DS2450.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// 4 channel A/D
// works, but without
// native features: Overdrive capable, alarm search
// works, but without alarm features and other controllable functions beside ADC-Reading
// native bus-features: Overdrive capable, alarm search

#ifndef ONEWIRE_DS2450_H
#define ONEWIRE_DS2450_H
Expand All @@ -19,12 +19,11 @@ class DS2450 : public OneWireItem
static constexpr uint8_t MEM_SIZE = PAGE_COUNT*PAGE_SIZE;

uint8_t memory[MEM_SIZE];
// Page1 : conversion results: 16bit for Channel A, B, C & D, power on default: 0x00
// Page1 : conversion results: 16 bit for Channel A, B, C & D, power on default: 0x00
// Page2 : control / status: 16 bit per channel
// Page3 : alarm settings: 16 bit per channel
// Page3 : factory calibration


void correctMemory(void);

public:
Expand Down
4 changes: 1 addition & 3 deletions src/DS2502.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// 1Kbit 1-Wire EEPROM, Add Only Memory
// works, writing could not be tested (DS9490 does not support hi-voltage mode and complains)
// Copyright by Kondi (initial version), https://forum.pjrc.com/threads/33640-Teensy-2-OneWire-Slave
// DS2501: 0x11, autoset to 512bits
// dell powersupply: 0x28
// native bus-features: none

#ifndef ONEWIRE_DS2502_H
#define ONEWIRE_DS2502_H
Expand Down
3 changes: 3 additions & 0 deletions src/DS2506.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// 64kbit EEPROM, Add Only Memory
// works, writing could not be tested (DS9490 does not support hi-voltage mode and complains)
// note: not available memory will be redirected or faked
// native bus-features: Overdrive capable

#ifndef ONEWIRE_DS2506_H
#define ONEWIRE_DS2506_H
Expand Down
Loading

0 comments on commit b34cced

Please sign in to comment.