Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 5 of 5

Thread: Teensy 2++ OneWire Slave

  1. #1
    Junior Member
    Join Date
    Feb 2014
    Posts
    12

    Teensy 2++ OneWire Slave

    Hi!
    I would like to "emulate" a DS2502 using a Teensy2++, but I have trouble doing it. I've searched and did not found any documented experiences using T2++ as an 1-Wire slave device, but I've found a good looking 1-Wire Slave library here https://github.com/neuoy/OneWireArduinoSlave. The functionality looks good and it is also interrupt based, which is nice.
    The problem that it does not work with the T2++, and my guess is that there is some error in the interrupt / pin configuration. Debugging this is far out of my knowledge, could anybody help me?

    Here is my sketch:
    Code:
    #include "LowLevel.h"
    #include "OneWireSlave.h"
    
    //Pin oneWireData(0);
    Pin oneWireData(2);
    
    // This is the ROM the arduino will respond to, make sure it doesn't conflict with another device
    const byte owROM[7] = { 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 };
    
    enum DeviceState
    {
    	DS_WaitingReset,
    	DS_WaitingCommand,
    };
    
    volatile DeviceState state = DS_WaitingReset;
    
    // This function will be called each time the OneWire library has an event to notify (reset, error, byte received)
    void owReceive(OneWireSlave::ReceiveEvent evt, byte data);
    
    void setup()
    {
      Serial.begin(9600);
    	// Setup the OneWire library
    	OWSlave.setReceiveCallback(&owReceive);
            OWSlave.begin(owROM, oneWireData.getPinNumber());
    	//OWSlave.begin(owROM, 0);
    }
    
    void loop()
    {
    	Serial.write("Blink");
            delay(5000);
    }
    
    void owReceive(OneWireSlave::ReceiveEvent evt, byte data)
    {
    	switch (evt)
    	{
    	case OneWireSlave::RE_Byte:
              Serial.print("BYTE RECIEVED:");
              Serial.println(data, HEX);
              break;
    
    	case OneWireSlave::RE_Reset:
              Serial.println("RESET RECIEVED");
    	  state = DS_WaitingCommand;
    	  break;
    
    	case OneWireSlave::RE_Error:
              Serial.println("ERROR RECIEVED");
    	  state = DS_WaitingReset;
    	  break;
    	}
    }
    It gives a few warnings, but compiles. I guess it never enters the loop, because there is nothing received by the serial monitor.

    Any help is appreciated!

  2. #2
    Senior Member
    Join Date
    Apr 2013
    Posts
    138
    Yes so far look at this:

    https://github.com/orgua/OneWireHub The few thinks I have done are now used in this and there it works better. Sorry for this mess.

  3. #3
    Junior Member
    Join Date
    Feb 2014
    Posts
    12
    Thanks for the reply! I examined brierfly the library, but this needs more time. I liked the functions of the previously mentioned one, because i only have to do a simple thing, with one device. Maybe You could help me showing how to do that with this OneWireHub lib?

    Basically i would like to spoof a dell power adapter. These adapters have a DS2502 1Kb EEPROM inside with the wattage info, and serial number. Upon connecting the adapter, the laptop resets the wire, send a skip rom, and a read command(0xF0), two bytes starting address (0x08, 0x00) and waits for the CRC of the command and address (which should be 0xFB). Then it waits for 3 bytes (which is the wattage, should be "090" or "130"), and that's all.

    With the "OneWireArduinoSlave library, accomlishing this seemed easy for me. Is it Your work by the way?

    EDIT:

    So I've modified the available DS2433 object like this:
    Code:
    #include "DS2433.h"
    
    DS2433::DS2433(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)
    {
        for (int i = 0; i < sizeof(memory); ++i)
            memory[i] = 0xFF;
    }
    
    bool DS2433::duty(OneWireHub *hub)
    {
        uint16_t memory_address;
        uint8_t  b;
    
        uint8_t cmd = hub->recv();
    
        switch (cmd)
        {
            // READ MEMORY
            case 0xF0:
                // Adr1
                Serial.println("Read command recieved!");
                b = hub->recv();
                reinterpret_cast<uint8_t *>(&memory_address)[0] = b;
    
                // Adr2
                b = hub->recv();
                rec2=b;
                reinterpret_cast<uint8_t *>(&memory_address)[1] = b;
    
                break;
    
            default:
                hub->raiseSlaveError(cmd);
                break;
        }
        return true;
    }
    Obviously i am waiting to my little debug message to appear, but it never does. I enabled serial debug in OneWireHub.h, and if the cable is plugged in i recieve 1 "Error: very long reset" message every 3 seconds. If i attach the cable while the sketch is running, i get 10+ "Error: very long reset" messages rapidly, then the laptop raises the error about the adapter is not genuine, and then back to 1 message every 3 seconds...

    Code:
    #include "OneWireHub.h"
    #include "DS2433.h"
    
    const uint8_t OneWire_PIN   = 1;
    
    auto hub     = OneWireHub(OneWire_PIN);
    auto ds2502 = DS2433(0x28, 0x0D, 0x01, 0x08, 0x0B, 0x02, 0x0A); 
    
    void setup()
    {
        Serial.begin(115200);
        Serial.println("I'm here");
        // Setup OneWire
        hub.attach(ds2502);
    }
    
    void loop()
    {
        // following function must be called periodically
        hub.poll();
        // this part is just for debugging (USE_SERIAL_DEBUG in OneWire.h must be enabled for output)
        if (hub.getError()) hub.printError();
    I'm kind of stuck with this. There is somebody who already accomplished what i want with an MSP chip and he captured some data about the signal levels here. Unfortunately i can not sniff what is happening with an original charger, but it should be very similar. I've already read the ds2502 from 2 adapters that i own successfully with the OneWire library, so i am really cluieless now why i only get errors when i try to emulate one and connect it to the same pin where the one in the adapter connects.
    Last edited by Kondi; 03-22-2016 at 10:51 PM.

  4. #4
    Junior Member
    Join Date
    Feb 2014
    Posts
    12
    I finally managed to get it working, by changing ONEWIRE_TIME_RESET_MAX to 2000 in OneWireHub.h.

    Here is the OneWireItem that is working perfectly, making the laptop think it is powered by a genuine Dell AC adapter

    DellAC.h

    Code:
    //  DS2502 1Kb EEPROM in genuine DELL AC adapter
    
    #ifndef ONEWIRE_DELLAC_H
    #define ONEWIRE_DELLAC_H
    
    #include "OneWireItem.h"
    
    class DellAC : public OneWireItem
    {
    private:
        uint8_t chargerData[4] = {0xFB, 0x31, 0x33, 0x30};//130W
        //uint8_t chargerData[4] = {0xFB, 0x30, 0x39, 0x30};//90W
        //uint8_t chargerData[4] = {0xFB, 0x30, 0x36, 0x36};//65W
    
    public:
        static constexpr uint8_t family_code = 0x23;
    
        DellAC(uint8_t ID1, uint8_t ID2, uint8_t ID3, uint8_t ID4, uint8_t ID5, uint8_t ID6, uint8_t ID7);
    
        bool duty(OneWireHub *hub);
    };
    
    #endif
    DellAC.cpp

    Code:
    #include "DellAC.h"
    
    DellAC::DellAC(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){}
    
    bool DellAC::duty(OneWireHub *hub)
    {
    
        uint8_t cmd = hub->recv();
    
        switch (cmd)
        {
            // READ MEMORY
            case 0xF0:
                // Adr1
                hub->recv();
                // Adr2
                hub->recv();
                hub->send(chargerData, 4);
                break;
    
            default:
                hub->raiseSlaveError(cmd);
                break;
        }
        return true;
    }
    Example

    Code:
    #include "OneWireHub.h"
    #include "DellAC.h"
    
    const uint8_t OneWire_PIN   = 0;
    auto hub     = OneWireHub(OneWire_PIN);
    auto dellACSpoofer = DellAC(0x28, 0x0D, 0x01, 0x08, 0x0B, 0x02, 0x0A); 
    
    void setup(void)
    {
      hub.attach(dellACSpoofer);
    }
    
    void loop() {
      hub.poll();
    }
    Last edited by Kondi; 04-14-2016 at 09:51 PM.

  5. #5
    Junior Member
    Join Date
    Apr 2019
    Posts
    1
    it's all don't work

    In file included from F:\My_Sunduk\Project\electronics\ARDUINO\DS2502emu lator\dellac\dellac.ino:2:0:

    F:\My_Sunduk\_Zhelezo\_soft\ARDUINO\arduino 1.8.5\arduino\arduino-1.8.5\portable\sketchbook\libraries\OneWireHub-master\src/DellAC.h:20:10: error: conflicting return type specified for 'virtual bool DellAC::duty(OneWireHub*)'

    bool duty(OneWireHub *hub);

    ^

    In file included from F:\My_Sunduk\_Zhelezo\_soft\ARDUINO\arduino 1.8.5\arduino\arduino-1.8.5\portable\sketchbook\libraries\OneWireHub-master\src/DellAC.h:6:0,

    from F:\My_Sunduk\Project\electronics\ARDUINO\DS2502emu lator\dellac\dellac.ino:2:

    F:\My_Sunduk\_Zhelezo\_soft\ARDUINO\arduino 1.8.5\arduino\arduino-1.8.5\portable\sketchbook\libraries\OneWireHub-master\src/OneWireItem.h:34:18: error: overriding 'virtual void OneWireItem::duty(OneWireHub*)'

    virtual void duty(OneWireHub * hub) = 0;



    and DS2502_DELLCHG.ino into https://github.com/orgua/OneWireHub
    dont work too
    and no detected in onewireviewer of dallas software
    all examples not detected in onewireviewer but detected real devices
    useless project...


    other project
    https://github.com/mikaelpatel/Ardui.../Slave/DS18B20
    this emulated ds18b20 it's detected
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	ScreenShot000126.jpg 
Views:	10 
Size:	50.0 KB 
ID:	16491  
    Last edited by selevo; 04-26-2019 at 09:21 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •