problem with I2C sensor

xmega with MPL3115A2

Marco
Benutzer
Avatar
Geschlecht: keine Angabe
Herkunft: Italy
Beiträge: 270
Dabei seit: 10 / 2004
Betreff:

problem with I2C sensor

 · 
Gepostet: 15.04.2014 - 14:21 Uhr  ·  #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
Geschlecht:
Herkunft: Germany
Alter: 25
Homepage: e-lab.de
Beiträge: 5558
Dabei seit: 03 / 2002
Betreff:

Re: problem with I2C sensor

 · 
Gepostet: 15.04.2014 - 21:33 Uhr  ·  #2
Hello Marco,

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

rolf
Marco
Benutzer
Avatar
Geschlecht: keine Angabe
Herkunft: Italy
Beiträge: 270
Dabei seit: 10 / 2004
Betreff:

Re: problem with I2C sensor

 · 
Gepostet: 15.04.2014 - 23:21 Uhr  ·  #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
Geschlecht:
Herkunft: Belgrade, Serbia
Alter: 54
Homepage: rs.linkedin.com/in…
Beiträge: 653
Dabei seit: 07 / 2002
Betreff:

Re: problem with I2C sensor

 · 
Gepostet: 16.04.2014 - 09:58 Uhr  ·  #4
Zitat geschrieben von 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
Geschlecht:
Herkunft: Germany
Alter: 25
Homepage: e-lab.de
Beiträge: 5558
Dabei seit: 03 / 2002
Betreff:

Re: problem with I2C sensor

 · 
Gepostet: 16.04.2014 - 13:45 Uhr  ·  #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
Geschlecht: keine Angabe
Herkunft: Italy
Beiträge: 270
Dabei seit: 10 / 2004
Betreff:

Re: problem with I2C sensor

 · 
Gepostet: 21.04.2014 - 14:06 Uhr  ·  #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
Geschlecht: keine Angabe
Alter: 44
Beiträge: 308
Dabei seit: 07 / 2013
Betreff:

Re: problem with I2C sensor

 · 
Gepostet: 09.05.2014 - 11:53 Uhr  ·  #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
Geschlecht: keine Angabe
Alter: 44
Beiträge: 308
Dabei seit: 07 / 2013
Betreff:

Re: problem with I2C sensor

 · 
Gepostet: 23.02.2017 - 13:07 Uhr  ·  #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
Der an diesem Beitrag angefügte Anhang ist entweder nur im eingeloggten Zustand sichtbar oder die Berechtigung Deiner Benutzergruppe ist nicht ausreichend.
Gewählte Zitate für Mehrfachzitierung:   0

Registrierte in diesem Topic

Aktuell kein registrierter in diesem Bereich

Die Statistik zeigt, wer in den letzten 5 Minuten online war. Erneuerung alle 90 Sekunden.
MySQL Queries: 15 · Cache Hits: 14   137   151 · Page-Gen-Time: 0.040069s · Speichernutzung: 2 MB · GZIP: ein · Viewport: SMXL-HiDPI