Giter Site home page Giter Site logo

Minimum SCL frequency about softwire HOT 5 OPEN

stevemarple avatar stevemarple commented on May 29, 2024
Minimum SCL frequency

from softwire.

Comments (5)

stevemarple avatar stevemarple commented on May 29, 2024

The delay between HIGH-to-LOW, and LOW-to-HIGH transitions of the SCL clock signal are stored in a uint8_t variable. For the largest value it can store (255) this gives a maximum period for the SCL clock of 2 × 255 µs = 0.00051 s. So the lowest frequency is given by 1 ÷ 0.00051 = 1961 Hz. I2C devices can normally run at 100 kHz, some can be operated at faster clock speeds. I didn't expect there to be any requirements for the SCL clock frequency to be less than 2 kHz so storing in a uint8_t variable was acceptable, especially as RAM is such a precious resource in most microcontroller architectures.

from softwire.

taherrera avatar taherrera commented on May 29, 2024

Thanks, sounds reasonable. I will modify the library in mi application however, because I need to use I2C over a 6 meter fire-resistant wire. With 10kHz (using ESP32 hardware I2C) we have seen sporadic errors, especially at high temperatures, presumably because of signal degradation due to an increase in impedance. I will be trying out baud rate in the 500Hz range.

Btw, I am using this library because with the hardware I2C on the ESP32 we cannot set a clock lower than 10kHz for some reason.

from softwire.

stevemarple avatar stevemarple commented on May 29, 2024

I don't know what you have done with the hardware but when I needed to drive I2C over a distance of about 2 metres there were some modifications I made:

  1. I reduced the value of effective pull-up resistance to decrease the effects of noise.
  2. I used pull-up resistors at both ends of the cable, on SDA and SCL.

If the drive capability of the ESP32 is weak you might find a I2C driver specifically designed for I2C helpful. I used a PCA9517A which is sold as a level-translating I2C bus repeater.

On the software-side I am not convinced that that reducing the clock speed much lower will be helpful unless your cabling has really high capacitance. If the ESP32 has read errors from measurement noise there is one thing you could try. You could take multiple measurements of the SDA logic-level and accept the majority result. You don't even need to modify SoftWire to do this - there is the capability to set custom read and write functions. See setReadSda(). So you could do something like

uint8_t myReadSda(const SoftWire *p)
{
    uint8_t r = 0;
    uint8_t n = 5; // Should be odd
    for (int i = 0; i < n; ++i) {
        r += SoftWire::readSda(p);
    }

    return r >= ((n / 2) + 1); // Take a majority vote
}


i2c.setReadSda(myReadSda);

This of course will not help much if the device at the far end is also suffering noise when decoding the outgoing I2C message (even if just decoding the address).

from softwire.

stevemarple avatar stevemarple commented on May 29, 2024

I just realised that you could also call setSetSclLow(), setSetSclHigh(), setSetSdaLow() and setSetSdaHigh() to set custom versions that add extra delay after changing the state of SCL/SDA. That should be equivalent of increasing the delay.

from softwire.

taherrera avatar taherrera commented on May 29, 2024

Thanks for your guidance steve, greatly appreciate it.

In our hardware we are using 1k resistors on the ESP32 side. We will evaluate using two resistors on the line, maybe it is an issue with noise as you say, high currents are flowing in the ovens where the sensor is installed and this could potencially be the source of the problem.

With 100kHz, the capacitance on the line can be clearly seen using an osciloscope in the lab, with 10kHz it is greatly reduced, so that's why I am interested in lowering even further. I will send you pictures, today or tomorrow.

from softwire.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.