Maxim Onewire libary using I2c bridge DS2484

HI everybody,
i have a little problem using the OneWire Libary from Maxim / Analog.
Iam using a I2c <-> OneWire Bridge ic because the combination of OneWire and Stm32 made me some unexpacted trouble in my first try.
Iam using this Libary from Maxim GitHub - adi-archives/OneWire: 1-Wire® library for Arduino.
Communication and so on is working so far everything is working well.
Sensor ID`s and temprature readout of the DS18B20 are also working.

Here's the Example

`#include "OneWire.h"
 
using namespace OneWire;
using namespace RomCommands;

void print_rom_id(RomId & romId);

DS2484 owm;

void setup() 
{
  Serial.begin(9600);
  while(!Serial);
  
  Serial.println("Starting Demo");
  Serial.println();

  OneWireMaster::CmdResult result = owm.begin();
  
  if(result != OneWireMaster::Success)
  {
    Serial.println("Failed to initialize OneWire Master");
    Serial.println("Ending Program");
    while(1);
  }
}

void loop()
{
  Serial.println();
  Serial.println();
  
  SearchState searchState;
  OneWireMaster::CmdResult result = owm.OWReset();
  if(result == OneWireMaster::Success)
  {
    Serial.println("1-wire devices detected");

    result = OWFirst(owm, searchState);
    if(result == OneWireMaster::Success)
    {
      do
      {
        print_rom_id(searchState.romId);
        if(searchState.romId.familyCode() == 0x28)
        {
            MultidropRomIterator selector(owm);
            DS18B20 tempds18(selector);
            tempds18.setRomId(searchState.romId);

            DS18B20::CmdResult tempResult = DS18B20::OperationFailure;
            float ds18B20Temp;

            tempResult = tempds18.convertTemperature(ds18B20Temp);
            if(tempResult == DS18B20::Success)
            {
                Serial.println("Convert Temperature Success");
                Serial.print("Temperature = ");
                Serial.println(ds18B20Temp, 2);
            }
            else
            {
                Serial.print("Convert Temperature Failed with code: ");
                Serial.println(tempResult, DEC);
            }
        }
        result = OWNext(owm, searchState);
      }
      while(result == OneWireMaster::Success);
    }
    else
    {
      Serial.print("OWFirst failed with error code: ");
      Serial.println(result, DEC);
    }
  }
  else
  {
    Serial.println("Failed to detect any 1-wire devices");
  }

  delay(1000);
}
 
 
//*********************************************************************
void print_rom_id(RomId & romId)
{
    //print the rom number
    Serial.println();
    for(uint8_t idx = 0; idx < RomId::byteLen; idx++)
    {
      if(romId[idx] < 16)
      {
        Serial.print("0x0");
        Serial.print(romId[idx], HEX);
        Serial.print(" ");
      }
      else
      {
        Serial.print("0x");
        Serial.print(romId[idx], HEX);
        Serial.print(" ");
      }
    }
    Serial.println();
}
`

Now my problem, somehow my brain is not understanding the libary...
I would like to enumerate the Sensors like Ds18B20[1...n] based one the specific ID and dump the temp for the specific sensor.
Like "Temp1 = Ds18B20[1]."
But right now i have no clue how to do it.

If somebody could help me, that would be great!

Kind regards Pako

Welcome to the forum.

Please always use the newest Arduino IDE, the newest build environments and the newest libraries.

You found a library that I didn't even know existed. It is 7 years old and no long maintained. I only know how to use the ID from the DS18B20 with the normal OneWire library: multiple temp sensors ds18b20 - #6 by Koepel
The normal OneWire library is in the Library Manager. If you want to try that, then you first have to remove the old one.

Where did you buy the DS18B20 ? If you bought it on Ebay/Amazon/AliExpress, then they are counterfeit. Those will not work well with 3.3V or with high and low temperatures or with longer cables.

Which problem are you trying to solve with the I2C <-> 1-Wire bridge ? There might be a better way for your project.
Can you give a link to the module with the bridge that you use ?

Hi,
thanks for the welcome!

Every libary and the IDE is up to date.

This libary is a little bit special because it has the i2c stuff for the ds2484 implemented.
The "regular" dallas libary commuinicates with the the sensors via a digital pin direct, but because i use a onewire master IC witch is doing the whole onewire stuff.

The Sensors are genuine ones from Farnell or Mouser. So everythings fine with them.

Iam using a stm32L4, yeah and thats where the trouble with onewire begins. I havent figured out whats the origin of the Issue is. It seems that its connected with the TIM timers. After startup if i disconnet the sensor and reconnect it works. But from time to time it stops dumping data. Reconnect helps. The easiest way was to using the Bridge ic.

The example in the first post ist working fine without any issues. But in my sketch i need the tempratur of a specific sensor. And somehow i have no clue how to handle it right now....

Can you give a broader view of your project ?
When someone asks a specific question on this forum, then we like to know more about the project. Sometimes there is a XY problem: https://xyproblem.info/
Start with the temperature. For example: Measuring the temperature of 12 bee hives at 2km altitude and the bee hives are ordered in a matrix of 3x4 with 3 meters distance, but one bee hive is at 2 meters.

I think that I'm slowly getting it:

The normal OneWire for Arduino has the STM32 specific code here: https://github.com/PaulStoffregen/OneWire/blob/master/util/OneWire_direct_gpio.h#L237
It don't know where those "digitalReadFast()" functions are, but it seems to rely on the Arduino mode for the STM32 as shown in this Issue: STM32F103C8 compile error · Issue #81 · PaulStoffregen/OneWire · GitHub
Which Arduino board do you have ?

I have a CAN-bus network with round about 20 nodes, some nodes are for gathering data (e.g. pressure temprature, flow etc.) some nodes control things (valves, relays, pumps etc.). And a few boards do both things. This board is one of them and it is doing booth things.

The Hardware side:
STM32l433KCCU6
STMCAN (CAN0)
PWM (TIM1)
ADC
I/O
Usart
USB (only for changing variables)
DS2484 I2C (OneWire 12 * DS18B20)
MCP4725 I2C (DAC)
MCP9600 I2C (RTD)
MCP2515 SPI (CAN1)
MAX31865 (Thermocouple)

The PCB is custommade

Every IC is on the PCB and everything is working as expected, also the DS2484.

The libary is doing what it should, my problem is to understand propper how the temprature dump is working because there is no example. The Code what i posted in the first post is a modificated one to read the DS18B20 sensors an that works great.
But i have to implement it into the whole programm.

MultidropRomIterator selector(owm);
            DS18B20 tempds18(selector);
            tempds18.setRomId(searchState.romId);

if i exchange tempds18.setRomId(searchState.romId);
with a ID of an DS12B20 i will not get the temprature of the specific sensor.

Hopefullly now you have a better overview of my problem

Thanks patrick

Thank you.

There are libraries that turn off interrupts to make a timing specific pulse train: OneWire, Neopixel, DHT and other libraries. The tutorials and Youtube videos often show just one thing, and almost never a combination of things. Regardless if you can make the hardware work, you should stay away from a library that turns off the interrupts.

You could add an Arduino board to run the normal/common OneWire and that Arduino board can sent via Serial all the data to the STM32.

I'm going to take a deep dive in that Dallas/outdated OneWire now :diving_mask: ... Okay, there are two options:

Option 1: You can use the OWFirst() and the OWNext() and request all the temperatures and sort them yourself. Find the ID in a list and put the right temperature in the right place.

Option 2: Use the ID.

  • OWverify() checks if that ID is on the bus.
  • OWMatchRom() to select a DS18B20 by its ID and turns on the "Overdrive" mode. That is a faster mode and only for short distances.
  • OWOverdriveMatchRom() selects a DS18B20 by its ID while in Overdrive mode.

The are no examples for the "MatchRom" functions, and I assume that you don't want the "Overdrive" mode.
That is all too vague, don't use it.
Can you make it work with Option 1 ?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.