I2C SCL frequency

Posted on
  • I am working on a project where I need faster communication on I2C. Is there a way to increase SCL frequency above 50kHz?

  • You could tweak the STM32's registers using peek and poke. It shouldn't be too hard to figure out what needs doing from the datasheet

  • thanks, I will have a look at the data sheet. I never had to bother before, thanks to your good work with Espruino! it really has saved me time.

  • If I'm honest adding the ability to chose the speed from Espruino wouldn't be hard at all - if I did it you'd just have to use a cutting edge build until 1v72 gets released though

  • That would be great. I am working on a power converter that is used for many things such as battery chargers (using large 12V to 48V batteries), solar powered chargers, super cap holdup circuits and bidirectional control of a kW or more. I hope to share some more detail on the project as the work is finished, it probably would interest many people that are into solar power, building their own off grid systems or need a power converter that can control current flow in both directions
    To save time during bench testing I am using an Espruino board to interface with my power controller. (it is really convenient to be able to interact with the Espruino while the power converter is running, many times I do not even have to power down the circuit when making changes to the function or flashing and saving new data.)

    I need a bit more speed to control an I2C Quad DAC (LTC2635CUD-LMI12) so I can more quickly reverse the direction of power flow. This type of DAC has two sets of registers. The data in the output registers shows up on the outputs as analog signals, and another register can hold new data ready to be instantaneously transferred to the output register when a hardware pin is pulled low. this allows the outputs of the four DACs to to change in an instance without need to wait for the I2C bus to transfer new data. but if it still takes time to write new data to be ready for next direction change, so faster I2C clock would definitely help in situations where the current direction must change frequently.

  • Do you have a) galvanic separation between the the measuring unit (looking at the drops at the shunts) and the control unit? - or b) do you just measure the voltages at both ends of the shunts and make the calculation? - or C) you may have a totally different way to get to the values.

  • allObjects, I am using a sense resistor and a bidirectional current sense amplifier (Linear LT1999-10) that level shifts the current sense signal to 2.5V above ground and adds a gain of 10. if the voltage drop across the sense resistor is +100mV the output signal is 2.5V-1V=1.5V, if the voltage drop is -100mV (reverse current) the output signal is 2.5V+1V=3.5V, and I can either measure two signals: the 2.5V reference and the output signal from the current sensor and make a calculation. or I can add an inverting amplifier using an opamp, and add an offset to the noninverting input, and set the gain to make the output of the opamp swing from 0V (-100mV) to 3.3V (+100mV across sense resistor) so I can get a measurement signal that can be presented to a single ADC input. to get good accuracy one needs to do a calibration for offset and gain, and I use to take a series of readings, store them in an array and sort the array, then throw away the ten highest and the ten lowest readings, and average the remaining readings. kind of a median filter. the advantage is that the worst errors that are due to the high noise levels in a switching power converter are ignored, so the readings are fairly accurate and steady.

    this gives enough accuracy for what I am doing (demonstrating how the power stage works and how it can be used in different configurations). the maximum input and output voltage level is 80V and I deal with current levels of up to 20A.

  • First of all, thank you for the explanation. 2nd, I have to say that I'm in software an hardware is 'just' a hobby. Nevertheless...

    This Linear LT1999-10 is quite an interesting device. I like the input construction: it floats. I was thinking about monitoring what pannels do, but with basic means the galvanic separation is a problem. There are galvanic separated power supplies that would be able to power a floating espruino / pico or a like to be at the measuring source (connected with ground to one end of the sense resistor. The data transfer would then have to be wireless - wifi or other radio, infrared - or via optocouplers. With the LT1999-10 I assume that I would not have to jump through such hoops. In addition, the sense resistor has not be between load and ground, which keeps ground (better) grounded... My expected loads are only up to about 10..12 A in a 12 V context.

    Did you ever think to use the ADCs from Espruino - in other words - put (one) Espruino right at the source connected to LT1999-10 output? You would then not incur the latency to get all the values into the calculations process. From the amount of thrown out values, I assume you make many measurements to still have a statistical valid number of samples. What is the expected - or required - frequency of delivering medians to the charge/flow controller?

    I used Espruino ADCs for getting the values from a touch screen and map them to display coordinates... and they do quite nicely.

  • if you are interested in measuring solar panel current you can just place the current sense resistor in series with the negative wire coming from the solar panel, because the solar panels are designed to float (up to 600V or 1000V from earth ground). solar panels usually have a ground connection, but that is connected to the metal frame. the solar cell package is floating.
    you then just connect an opamp as an inverting amplifier with two resistors, to amplify the measurement signal 3.3/0.1 = 33 times, and connect the opamp output to the ADC pin. it is not necessary to place the sense resistor in the positive lead and level shift the signal when measuring solar panel current of a low voltage solar panel.

    it is different if you measure on a solar panel array that is connected to a nonisolated dc/ac inverter. then you need isolation for safety reasons. Avago has some good optoisolated current amplifiers, for example ACPL-782T can withstand 3750Vrms from sensor to output.

    the reason why I am using a median filter is that I want a steady reading for display on an LCD alphanumeric display or on a computer screen, and I update the display at 1Hz so I can afford the computing delays. if I was to use the current measurement for charge controller function I think I would use less filtering on the signal that is used for the controller. in my power converter I am using the output from the LT1999-10 for the current limit function, so I cannot filter the signal too heavily before applying it to the controller. but this current control function is implemented by analog circuitry (opamps).

  • When thinking about monitoring, I was initially going for Arduino or a like hardware. Compared to with Espruino, it is even more suitable to run the electronics from a battery. I like the built-in interrupt drivenness of Espruino, which helps with power conservation.

    From your implementation I understand that it is not enough to directly measure voltages over a sense resistor. The few millivolts differences would deliver a too course grain ramp of values. This fact is taken care of the current sense amps. And as an added benefit, the amps provide at the same time the galvanic separation.

    #current #sense #currentsense #opamp #adc #solar

  • correct, you get better accuracy if you amplify the current sense signal. for 10A current I would use a 0.01ohm resistor, which gives 0.1V voltage drop at 10A. then amplify the signal about 33 times to get better use of he full scale 3.3V input range of the ADC.


    1 Attachment

    • amp.png
  • Ok, added. If you try one of the latest builds you should be able to do:

    I2C.setup({sda: x,  scl: y, bitrate: 400000});
    

    400000 is the fastest you can go on the Espruino board though.

    edit: The build will take an hour or so to appear...

  • Thanks Gordon! I can't wait to try it!

  • The physical/geometrical properties - and the (interfering) environment - of a connection are always part of communication reliability. Are there rules of thumb for determine for how long the connecting cable can be and how it has be built?

  • it works! I had some trouble finding the latest build (not a programmer by any means) but then I stumbled onto drazzys bigram builds and tried the latest one, successfully. now I just need to replace the 10k pullups with something else more suited for 400kHz and 3.3V..


    1 Attachment

    • pullups.jpg
  • I can only answer regarding analog circuitry such as the current measurement circuit I showed. the most important part is to connect to the sense resistor correctly, that is make connections directly to the pads of the resistor to avoid additional voltage drops in traces. you should be able to send the amplified analog signal through quite long wires from the opamp to the ADC. for example using the twisted pairs in an ordinary phone jack cable. adding an RC low pass filter at the input of the ADC will help to reduce noise.

    The physical/geometrical properties - and the (interfering) environment - of a connection >are always part of communication reliability. Are there rules of thumb for determine for how >long the connecting cable can be and how it has be built?

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

I2C SCL frequency

Posted by Avatar for tage @tage

Actions