FreeBsd I2C utility gives same value as MSB and LSB from DS75 sensor 16bit register.

Rodney W. Grimes freebsd-rwg at gndrsh.dnsmgr.net
Wed May 22 22:15:09 UTC 2019


> On Wed, 2019-05-08 at 14:06 -0500, Karl Denninger wrote:
> > On 5/3/2019 06:43, Prasad M wrote:
> > > Hi Folks,
> > > 
> > > I am trying to access a DS75 I2C temperature sensor. It kind of works with
> > > the default i2c utility. But it returns twice the high byte instead of the
> > > high and low byte for the temperature. Probably because it does 1 byte
> > > reads on the I2C bus, sending a stop condition after every byte.
> > > 
> > > The device expects continuous reads and no stop/start in between the 2
> > > bytes. Trying all options i2c, most notably the -m mode switch, yields the
> > > same results all the time. Looking at the code in i2c.c
> > > 
> > > Could any one help to solve this problem with working I2CRDWR utility.
> > 
> > I don't know if you can do it with that utility, but coding up a simple
> > (~10-15 lines of "C") that reads two bytes is trivially easy.
> > 
> > You simply stuff a message buffer requesting 2 bytes in response and
> > call ioctl; you get back two bytes.
> > 
> 
> This should now be fixed as of r348120 in 13-current, which I will MFC
> to 12-stable after it gets some testing.  The fix adds a new "-m tr"
> mode.  'tr' is for "transfer", a mode in which the complete set of i2c
> operations are all handed to the driver at once using I2CRDWR, rather
> than doing a set of individual START/REPEAT/STOP commands from
> userland.  Some drivers (such as rpi) only work with complete
> transfers.
> 
> So, to read the temperature from a DS75, it should now work like:
> 
>  i2c -m tr -a 0x40 -d r -o 0 -w 8 -c 2

Thank you, I think this is going to be well used!

> -- Ian
-- 
Rod Grimes                                                 rgrimes at freebsd.org


More information about the freebsd-arm mailing list