B4R Question Detect error of an I2C slave

Gerardo Tenreiro

Active Member
Licensed User
Hello again and first of all thank you very much for your help.
Having said this, we enter the mess
I have 7 I2C devices model TCA9554, six of them work correctly and one of them is broken or poorly soldered, that is not the problem.
The scheme we are talking about is this:
1683747199465.png

Specifically, address 33 in decimal.
When executing this piece of code at any address other than 33, the program works correctly and the parser shows this:
1683747327719.png


Note that it is "Write 32 -> 0 -> ACK -> Read ->32 ->NACK"
The translation is to tell slave 32 that we are going to read record 0, he confirms with ACK and then we ask the slave for 1 record, record 0
The code used is this:
#Region Project Attributes
#AutoFlushLogs: True
#CheckArrayBounds: True
#StackBufferSize: 600
#End Region
'Ctrl+Click to open the C code folder: ide://run?File=%WINDIR%\System32\explorer.exe&Args=%PROJECT%\Objects\Src

Sub Process_Globals
Dim T_Ciclo As Timer
Dim Bus As WireMaster
Dim Serial1 As Serial
Dim Dire As Byte = 32

End Sub

Private Sub AppStart


Dim D(2) As Byte

Serial1.Initialize(9600)
Log("Arranque...")


T_Ciclo.Initialize("T_Ciclo_Tick",100)
T_Ciclo.Enabled = True


' Inicializa el Bus
Bus.Initialize
' Velocidad del Bus I"C 400khz
RunNative("SetWireClock", 400000)

D(0) = 3
D(1) = 255
'
Bus.WriteTo(Dire,D)


End Sub


Private Sub T_Ciclo_Tick

Dim Regi(1) As Byte

Regi(0) = 0

'
Bus.WriteTo(Dire,Regi)

Dim V0() As Byte = Bus.RequestFrom(Dire, 1)

'
Log("Long = ",V0.Length," ... ",V0(0))



End Sub




' Ajusta la Velocidad del Bus I2C
#if C
void SetWireClock(B4R::Object* o) {
Wire.setClock (o->toULong());
}
#end if

Now if instead of slave 32 I change the address of the slave to 33 with the following code:

Dim Dire As Byte = 33

1683747665115.png


an error is generated in the ESP32 that completely blocks it and even enters a loop of continuous restarts.

The query is:
How can I read the first ACK of the frame or, failing that, solve the problem so that the program detects that this I2C slave is not working correctly and take measures before the ESP32 stops completely?

As always, thank you very much and I am open to any suggestion.
 

Smartopt

New Member
  1. Send a start sequence.
  2. Send 0xC0 ( I2C address of the CMPS03 with the R/W bit low (even address)
  3. Send 0x01 (Internal address of the bearing register)
  4. Send a start sequence again (repeated start)
  5. Send 0xC1 ( I2C address of the CMPS03 with the R/W bit high (odd address)
  6. Read data byte from CMPS03.
 
Upvote 0

Gerardo Tenreiro

Active Member
Licensed User
  1. Send a start sequence.
  2. Send 0xC0 ( I2C address of the CMPS03 with the R/W bit low (even address)
  3. Send 0x01 (Internal address of the bearing register)
  4. Send a start sequence again (repeated start)
  5. Send 0xC1 ( I2C address of the CMPS03 with the R/W bit high (odd address)
  6. Read data byte from CMPS03.
Hello and thank you very much for your help, but I will comment. That was the first thing I wanted to do, the first part is no problem, I send data to the slave and any register. the slave does not respond "NACK" is seen in the parser frame. Later, when I try to read it, the problem is generated since the variable is not created and when I try to read it, the ESP32 restarts.
At the moment I am solving it by checking the length of the variable, if it is less than 1 I no longer read it and I assume that the TCA is broken.
It is a way out of the problem but the good thing would be to be able to read the ACK or the NACK of the slave so that it could make the decision before trying to read it.
Keep in mind that I have many more I2C and SPI devices on this board so the ESP32 is pretty tight on time and I don't want to waste time on the operation.
Also thank you very much for the help
 
Upvote 0
Top