User avatar
Posts: 14689
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: i2c repeated start transactions

Sun Jun 04, 2017 5:28 pm

rchackman wrote:@joan thanks for swift reply... and pigpio really is excellent, just not fast enough for my project (sadly). Have you considered creating a version directly callable from python rather than via the daemon (or am I being stupid)?.
You can always use the smbus module from Python, that won't have any overhead - of course this assumes you are not running the script from a remote PC. pigpio does not force you to use the in-built I2C functions.

Posts: 4
Joined: Sun Jun 04, 2017 3:11 pm

Re: i2c repeated start transactions

Mon Jun 05, 2017 9:09 pm

@joan Indeed I am using smbus and my code is running local on the pi.

The i2c device I want to communicate with is a homebrew based on a PIC12F1840.

Fortunately, the PIC allows me to hold off the clock on the falling edge of the 8th bit (to support user decision whether to ACK or not). The pi honours this stretch allowing me to read and buffer bytes _before_ the ACK on WRITEs. Interrupts are still generated on the 9th bit falling edge (the ACK bit) but I can detect which side of the ACK bit I am and release the clock very quickly in this case.

At 100 kbaud I'm in and out of my ISR after ACKs in time for the RESTART condition to be met on WRITE-READ transactions - the RESTART you correctly asserted would be present in bcm2835 - and combined WRITE READ transactions are correctly executed.

The scheme falls over at 200k and 400k (the only other values I've had time to test tonight). I've not yet had a chance to fully diagnose the cause but I anticipate it'll be something to do with even the short hold off following ACKs being long enough to mess up the timing.

Posts: 1
Joined: Thu Jul 13, 2017 11:05 am

Re: i2c repeated start transactions

Thu Jul 13, 2017 11:09 am

Just to clarify, following on from Joan's post...if the "current (updated) i2c_bcm2835" automatically sends repeated starts as needed, is any configuration needed at all as shown in previous posts? I'm new to Raspberry Pi and finding it slightly hard to follow this thread. I'm trying to read data from a MMA8451 Accelerometer.

Thanks in advance.

Posts: 4
Joined: Sun Jun 04, 2017 3:11 pm

Re: i2c repeated start transactions

Mon Jul 24, 2017 7:03 pm

My own problems were born out of attempting to interface to a 'homebrew' PIC-based slave device over I2C. My device needed time to assemble responses to RESTART-READ requests forcing me to stretch the clock (wherein the PIC slave holds the clock line low preventing the RPi master from proceeding with the transaction until the slave is ready)... and the RPi didn't like it.

I personally have no experience of the device you are interfacing to but, if it does not stretch the clock, you stand a good chance of things working straight off (as long as you have enabled I2C on the RPi).

Posts: 30
Joined: Wed Nov 13, 2013 7:57 pm

Re: i2c repeated start transactions

Sun Aug 27, 2017 4:22 pm

I've been trying to read the humidity and temperature values from the Si7021 adafruit packaged sensor with smbus with little success. ... 21-A20.pdf This is the datasheet. I can successfully read the user register using a read byte data function but I cant read the humidity values with a read word data.

The i2c transaction is: S, Slave add, W, [A], Measure command, [A], Sr, Slave add, r, [NA*], Sr, Slave address, r, [A], [MS Byte], a, [LS Byte], NA, P

*Note: Device will NACK the slave address byte until conversion is complete.
[ ] = slave

Now I'm not sure if this is because my RPi isnt doing the repeated start transactions. I'm on a RPi 3 model b with all the latest software.

I run my programs with python3 so should I install python3-smbus rather than the standard library

I'm probably getting terms a little confused but I've had a real good go at trying the different SMbus commands to try and get this thing working!

Posts: 695
Joined: Tue Oct 16, 2012 6:21 pm
Location: Drammen, Norway

Re: i2c repeated start transactions

Sat Sep 02, 2017 12:37 pm

I found this in the datasheet:
Depending on the conversion command, the Si7021 may hold the master during the conversion (clock stretch).

It doesn't have to be your problem, but clock stretching is broken on the i2c controller.
You can try the i2c gpio bit banging driver, there's a DT overlay and a search will probably yield how-tos.

Return to “Interfacing (DSI, CSI, I2C, etc.)”