i2c.reqfrom hang ?

Here we can discuss about the problem found
TyuTyu
Posts: 19
Joined: Sun Apr 09, 2023 5:38 am
Has thanked: 3 times

i2c.reqfrom hang ?

Post by TyuTyu »

Hi,

I have problem. I tried read from PCF8574 inputs. (on another address PCF8574 write to relay is OK.)
Board is OK, I tried with original fw (KinCony) and I tried with Micropython too. Both of them reading is OK.

*****************
I2C.SETUP 4, 15

i2c.begin &h22
i2c.reqfrom &h22, 1
x = i2c.read
i2c.end
*****************
Always hang the program. I tried with latest stable Annex v48 and beta v49 too.
I tried diferent type of boards...ESP32 (Kincony) and pure ESP32-S3 on bredboard too.

Any idea ?
Hints are welcome....

TyuTyu
User avatar
cicciocb
Site Admin
Posts: 2781
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 592 times
Been thanked: 1990 times
Contact:

Re: i2c.reqfrom hang ?

Post by cicciocb »

Thanks for reporting,
I'll give a look at the problem
User avatar
cicciocb
Site Admin
Posts: 2781
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 592 times
Been thanked: 1990 times
Contact:

Re: i2c.reqfrom hang ?

Post by cicciocb »

OK, I found the cause of the problem, but not easy to fix as is inside the SDK ...
User avatar
cicciocb
Site Admin
Posts: 2781
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 592 times
Been thanked: 1990 times
Contact:

Re: i2c.reqfrom hang ?

Post by cicciocb »

Is fixed in the latest 1.51.1 version
User avatar
Oli
Posts: 91
Joined: Tue Feb 09, 2021 10:07 am
Location: Germany, Meissen
Has thanked: 23 times
Been thanked: 62 times
Contact:

i2c.reqfrom PCF8574

Post by Oli »

Hi,
Annex32-C3 CAN USB 1.60.1 qio LFS
https://www.myrapidq.it/annex_mirror/el ... tputs.html
I am trying unsuccessfully to read the PCF8574.
I am following the help and the sample exactly.
writing and LCD.INIT works.
but when reading I always get x -1 back. Y come 0, is connected

Code: [Local Link Removed for Guests]

  i2c.begin &h21
 i2c.reqfrom &h21, 1
 x = i2c.read
 Y = i2c.end
now I have tried the same program on an ESP8266, with 1.50 it works there.

Code: [Local Link Removed for Guests]

i2c.begin &h21
i2c.write 255
i2c.end
works with both controllers,

I have connected 2 PCF8574, &h20 for LCD, and &h21 for buttons, but reading does not work individually either,
User avatar
Electroguard
Posts: 1094
Joined: Mon Feb 08, 2021 6:22 pm
Has thanked: 373 times
Been thanked: 392 times

Re: i2c.reqfrom hang ?

Post by Electroguard »

Hi Oli,
Module works on 8266, but only partially works on C3 ?
Which means the C3 addressing is OK.
So presumably its either a C3 internal issue, or an i2c timing issue.
The value of the i2c pullups depends on how many modules are attached (and bus length).
I seem to remember that a single i2c module should be about 10k pullups, but 4.7k is needed for two devices, and perhaps 2k to 3k for more.
You've got more than one i2c module, so perhaps try lower i2c pullup values.
User avatar
cicciocb
Site Admin
Posts: 2781
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 592 times
Been thanked: 1990 times
Contact:

Re: i2c.reqfrom hang ?

Post by cicciocb »

I remember that I did a fix for that in the code of the SDK, but I'm not sure if this was only for the ESP32 (and the ESP32-S3).

Probably the same fix is required for the ESP32-C3 too.
User avatar
cicciocb
Site Admin
Posts: 2781
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 592 times
Been thanked: 1990 times
Contact:

Re: i2c.reqfrom PCF8574

Post by cicciocb »

[Local Link Removed for Guests] wrote: [Local Link Removed for Guests]Fri Sep 27, 2024 7:59 am Hi,
Annex32-C3 CAN USB 1.60.1 qio LFS
https://www.myrapidq.it/annex_mirror/el ... tputs.html
I am trying unsuccessfully to read the PCF8574.
I am following the help and the sample exactly.
writing and LCD.INIT works.
but when reading I always get x -1 back. Y come 0, is connected

Code: [Local Link Removed for Guests]

  i2c.begin &h21
 i2c.reqfrom &h21, 1
 x = i2c.read
 Y = i2c.end
now I have tried the same program on an ESP8266, with 1.50 it works there.

Code: [Local Link Removed for Guests]

i2c.begin &h21
i2c.write 255
i2c.end
works with both controllers,

I have connected 2 PCF8574, &h20 for LCD, and &h21 for buttons, but reading does not work individually either,
I re-read the post and I misunderstood the issue as the title of the post is "i2c.reqfrom hang ?" but you are talking about another problem.

If I understand well you are trying to read from the PCF8574 and you receive always -1.
-1 means "No data available".

In fact there is an error in the code present in the help file as one line must be removed.
This is because the PCF8574 do not work as the "classic" I2C devices so the SUB PCF8574_read(c) must be :

Code: [Local Link Removed for Guests]

sub PCF8574_read(x)
  i2c.reqfrom device_address, 1
  x = i2c.read
  i2c.end
end sub
User avatar
Oli
Posts: 91
Joined: Tue Feb 09, 2021 10:07 am
Location: Germany, Meissen
Has thanked: 23 times
Been thanked: 62 times
Contact:

Re: i2c.reqfrom hang ?

Post by Oli »

hi Francesco,

yes it was :-)
a bit confusing, the ESP8266 must have it, the ESP32 must not have it: i2c.begin. in this case PCF

Here is the sample program:

Code: [Local Link Removed for Guests]

I2C.SETUP 8, 9  ' set I2C port on pins 21 and 22

PCF8574a_address = &h21   'set to first  module i2c address - here used as active low inputs
                               
PCF8574a_write 255              
p0=1: p1=1: p2=1: p3=1: p4=1: p5=1: p6=1: p7=1
x = 0
r = 0

wlog "started"

PCF8574a_read r
gosub paint
onhtmlreload paint


Anf:

 PCF8574a_read r
   r = r XOR 255 'bits invertieren  
 wlog str$(r)
 showleds r
pause 10
goto anf

sub showleds x
'p0 to p7 represent the status of each of the individual input ports
p0 = x AND 1
p1 = x AND 2
p2 = x AND 4
p3 = x AND 8
p4 = x AND 16
p5 = x AND 32
p6 = x AND 64
p7 = x AND 128
refresh
end sub

sub PCF8574a_write(x)
 i2c.begin PCF8574a_address
 i2c.write x
 i2c.end
end sub

sub PCF8574a_read(x)
' i2c.begin PCF8574a_address
 i2c.reqfrom PCF8574a_address, 1
 x = i2c.read
 i2c.end
end sub


paint:
cls
a$ = ""
a$ = a$ + led$(p0)
a$ = a$ + led$(p1)
a$ = a$ + led$(p2)
a$ = a$ + led$(p3)
a$ = a$ + led$(p4)
a$ = a$ + led$(p5)
a$ = a$ + led$(p6)
a$ = a$ + led$(p7) + "<br>"
html a$
return
User avatar
cicciocb
Site Admin
Posts: 2781
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 592 times
Been thanked: 1990 times
Contact:

Re: i2c.reqfrom hang ?

Post by cicciocb »

I think that it should also work for the ESP8266 without this line.

Maybe you can test and report .
Post Reply