problem with I2C sensor

xmega with MPL3115A2

Marco
Benutzer
Avatar
Gender: n/a
Location: Italy
Posts: 270
Registered: 10 / 2004
Subject:

problem with I2C sensor

 · 
Posted: 15.04.2014 - 14:21  ·  #1
Hi,
i have a strange problem with a barometer sensor on I2C.
On TWI interface of my ATXMEGA128A3U I have connected two sensors;
a BMP085 and a MPL3115A2.
I have no problems reading from the BMP085, but no way to get results from MPL3115A2...
Checking of the Bmp085 with TWIstatE(BMP085_ADDRESS) is always successful, but the same on the other sensor TWIstatC(MPL3115A2_ADDRESS) fail.

After trying to read from MPL also the check on BMP fails few times (seems the I2C bus in a wrong status), then the BMP start to reply correctly.
I have read on forums that the MPL sensor use such "repeated start" in I2C protocol, thus I am wondering if it is compatible with TWI library of AVRco.

Regards,
Marco
rh
Administrator
Avatar
Gender:
Location: Germany
Age: 24
Homepage: e-lab.de
Posts: 5558
Registered: 03 / 2002
Subject:

Re: problem with I2C sensor

 · 
Posted: 15.04.2014 - 21:33  ·  #2
Hello Marco,

there was a thread here concerning the "repeared start" problem.
But I could not find it now.

rolf
Marco
Benutzer
Avatar
Gender: n/a
Location: Italy
Posts: 270
Registered: 10 / 2004
Subject:

Re: problem with I2C sensor

 · 
Posted: 15.04.2014 - 23:21  ·  #3
Hi Rolf,
I have found this topic.php?t=2854&page=1
but it's in german and google translate is not much clear to me...
Can you resume the meaning of the discussion ? is there a workaround / solution ?

Marco
Avra
Schreiberling
Avatar
Gender:
Location: Belgrade, Serbia
Age: 53
Homepage: rs.linkedin.com/in…
Posts: 653
Registered: 07 / 2002
Subject:

Re: problem with I2C sensor

 · 
Posted: 16.04.2014 - 09:58  ·  #4
Quote by Marco
...thus I am wondering if it is compatible with TWI library of AVRco.

If it turns out that "repeated start" is not a problem, then consider this:

Have you tried the same sensors with software I2C lib? Can you try another board? Do you have another barometer sensor to try? Is it the same with 100kbs and with 400kbps (if supported by both sensors)?
rh
Administrator
Avatar
Gender:
Location: Germany
Age: 24
Homepage: e-lab.de
Posts: 5558
Registered: 03 / 2002
Subject:

Re: problem with I2C sensor

 · 
Posted: 16.04.2014 - 13:45  ·  #5
Hello Marco,

sorry. I can't explain what is going on in this thread because I don't know anything about
repeated start. But it seems that user ThomasW69 has a solution for it. Maybe he can
help you.

rolf
Marco
Benutzer
Avatar
Gender: n/a
Location: Italy
Posts: 270
Registered: 10 / 2004
Subject:

Re: problem with I2C sensor

 · 
Posted: 21.04.2014 - 14:06  ·  #6
Hi Rolf and Avra,
I have verified it is a problem of the way to Read I2C.
With some new slave devices, must be used the so called "repeted Start" during multiple bytes read.

I have tested the solution kindly exposed by Thomas.AC
topic.php?p=19606#real19606
and it seems work on XMega with my sensor also :-)

Of course would be also nice have this type of read in AVRco.

Happy Easter,
Marco
Thomas.AC
Benutzer
Avatar
Gender: n/a
Age: 43
Posts: 308
Registered: 07 / 2013
Subject:

Re: problem with I2C sensor

 · 
Posted: 09.05.2014 - 11:53  ·  #7
I use my solution/workaround to communicate with ADAU1701 Audio DSP.
Please consider that I've uncomment some code lines (Reset TWI stuff).

@Rolf Repeated start is descibed in specification of I2C and in xmega datasheets/Manuals.


Thomas.AC


Code

{-------------------------------------------------------------------------------
TWICombinedRead
input parameters:
subaddress  : subaddress
pdata       : location for the read data
bytesToRead : bytes to read
-------------------------------------------------------------------------------}
var twitimeout : SysTimer8;

function twiCombinedRead (
    subaddress  : Word;
    pData       : pointer;
    bytesToRead : byte
              ) : boolean;
begin


  SetSysTimer(twitimeout,2); //

  // Reset TWIE //
  //uDelay(2);
  //TWIEMASTERCTRLA  := $00;
  //TWIEMASTERCTRLA  := $08;
  //TWIEMASTERSTATUS := $FD; // clear all flags, force bus state = idle;

  // write I2C address Byte + RW = 0
  TWIEMASTERADDR := DSPADDR shl 1;
  repeat
  until Bit(TWIEMASTERSTATUS, 6) or isSysTimerZero(twitimeout);   // wif?
  if TWIEMASTERSTATUS <> $62 then     // return, if incorrect STATUS
    Return (false);
  endif;

  // write subaddress
  TWIEMASTERDATA := HI(subaddress); // write highbyte subaddress
  repeat
  until Bit(TWIEMASTERSTATUS, 6) or isSysTimerZero(twitimeout);     // wif?
  if TWIEMASTERSTATUS <> $62 then     // return, if incorrect STATUS
    Return (false);
  endif;
  TWIEMASTERDATA := LO(subaddress); // write lowbyte subaddress
  repeat
  until Bit(TWIEMASTERSTATUS, 6) or isSysTimerZero(twitimeout);     // wif
  if TWIEMASTERSTATUS <> $62 then     // return, if incorrect STATUS
    Return (false);
  endif;

  // bytesToRead?
  if bytesToRead = 0 then
    TWIEMASTERCTRLC := $07;                    // stop
    Return(true);
  endif;

  // read first byte (read access with repeated start condition)
  TWIEMASTERADDR := (DSPADDR shl 1) or $01;  // write I2C address + R/W = 1
  repeat
  until Bit(TWIEMASTERSTATUS, 7) or isSysTimerZero(twitimeout);    // rif?
  if TWIEMASTERSTATUS <> $A2 then           // return, if incorrect STATUS
    Return (false);
  endif;
  pData^++ := TWIEMASTERDATA;
  dec(bytesToRead);

  // read next bytes
  while bytesToRead > 0 do
    TWIEMASTERCTRLC := $02; // ack + read more byte
    repeat
    until Bit(TWIEMASTERSTATUS, 7) or isSysTimerZero(twitimeout); // rif?
    if TWIEMASTERSTATUS <> $A2 then // return, if incorrect STATUS
      Return (false);
    endif;
    pData^++ := TWIEMASTERDATA;
    dec(bytesToRead);
  endwhile;

  // send stop condition
  TWIEMASTERCTRLC := $07;
  Return(true);
end;
Thomas.AC
Benutzer
Avatar
Gender: n/a
Age: 43
Posts: 308
Registered: 07 / 2013
Subject:

Re: problem with I2C sensor

 · 
Posted: 23.02.2017 - 13:07  ·  #8
Hallo Rolf,

ich möchte die Anforderung nach einem Repeated-Start bei I2C noch einmal hervorholen,
da man es auch bei einem EEPROM-Lesezugriff benötigt. Laut Datenblatt soll ein Random-read mit einem Repeated-Start erfolgen (siehe Bild).
Ich benötige dieses Feature zwar im Moment nicht, würde es jedoch gut finden, wenn in Zukunft die Möglichkeit im Treiberpaket vorhanden wäre.

Zusatzinfo: Beim 24LC256SN ist Random-Read auch ohne Repeated-Start möglich, beim 24AA025E48 (EEPROM mit MAC-Adresse) jedoch nicht.

Gruß
Thomas
Attachments
eeprom_random_read
Filename: eeprom_random_read.png
Filesize: 45.09 KB
Title: eeprom_random_read
Download counter: 98
Selected quotes for multi-quoting:   0

Registered users in this topic

Currently no registered users in this section

The statistic shows who was online during the last 5 minutes. Updated every 90 seconds.
MySQL Queries: 16 · Cache Hits: 15   138   153 · Page-Gen-Time: 0.051911s · Memory Usage: 2 MB · GZIP: on · Viewport: SMXL-HiDPI