Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Equal bytes for women.


devel / comp.arch.embedded / Re: I2C bus recovery

SubjectAuthor
* I2C bus recoverypozz
`* Re: I2C bus recoveryantispam
 `* Re: I2C bus recoverypozz
  +* Re: I2C bus recoveryRichard Damon
  |+- Re: I2C bus recoveryRick C
  |`- Re: I2C bus recoverypozz
  +- Re: I2C bus recoveryantispam
  `- Re: I2C bus recoveryMichael Schwingen

1
I2C bus recovery

<tkdre4$3s0fi$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=1203&group=comp.arch.embedded#1203

  copy link   Newsgroups: comp.arch.embedded
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: pozzu...@gmail.com (pozz)
Newsgroups: comp.arch.embedded
Subject: I2C bus recovery
Date: Tue, 8 Nov 2022 16:08:52 +0100
Organization: A noiseless patient Spider
Lines: 26
Message-ID: <tkdre4$3s0fi$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 8 Nov 2022 15:08:53 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="8946918fbe7fe579dce875fd876e1f1f";
logging-data="4063730"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+b+QmYsmZioz44nmkoWX4aS/D9QnNT2jo="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.4.2
Cancel-Lock: sha1:EMuhuHHcPHf0WWURhwHwdksRfl4=
 by: pozz - Tue, 8 Nov 2022 15:08 UTC

I wanted to implement an I2C bus recovery during initialization. The
reason is well known in literature[1].

I read the function i2c_generic_recovery[2] of Linux kernel, but I don't
understand one thing.

The bus recovery is necessary to bring a slave to the end of a byte
transmission that could be interrupted for some reason.
However the slave could be transmitting 0xFF, so why the above function
breaks the loop if SDA is detected high?

[Line 620] /* Break if SDA is high */

Maybe it's better to send 9 clock cycles whatever the level of SDA line.

And what about STOP condition at the end of the 9 clock cycles? Is it
necessary? It should be (SCL is already high): set SDA low, pause, set
SDA high.

Do you use this sort of bus recovery?

[1]
https://www.analog.com/media/en/technical-documentation/application-notes/54305147357414AN686_0.pdf

[2] https://elixir.bootlin.com/linux/v4.5/source/drivers/i2c/i2c-core.c#L604

Re: I2C bus recovery

<tkek1k$viu$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=1204&group=comp.arch.embedded#1204

  copy link   Newsgroups: comp.arch.embedded
Path: i2pn2.org!i2pn.org!aioe.org!NZ87pNe1TKxNDknVl4tZhw.user.46.165.242.91.POSTED!not-for-mail
From: antis...@math.uni.wroc.pl
Newsgroups: comp.arch.embedded
Subject: Re: I2C bus recovery
Date: Tue, 8 Nov 2022 22:08:52 -0000 (UTC)
Organization: Aioe.org NNTP Server
Message-ID: <tkek1k$viu$1@gioia.aioe.org>
References: <tkdre4$3s0fi$1@dont-email.me>
Injection-Info: gioia.aioe.org; logging-data="32350"; posting-host="NZ87pNe1TKxNDknVl4tZhw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: tin/2.4.5-20201224 ("Glen Albyn") (Linux/5.10.0-9-amd64 (x86_64))
Cancel-Lock: sha1:tvCVJnZ/fyCYkrSx5oodOHk4dk0=
X-Notice: Filtered by postfilter v. 0.9.2
 by: antis...@math.uni.wroc.pl - Tue, 8 Nov 2022 22:08 UTC

pozz <pozzugno@gmail.com> wrote:
> I wanted to implement an I2C bus recovery during initialization. The
> reason is well known in literature[1].
>
> I read the function i2c_generic_recovery[2] of Linux kernel, but I don't
> understand one thing.
>
> The bus recovery is necessary to bring a slave to the end of a byte
> transmission that could be interrupted for some reason.
> However the slave could be transmitting 0xFF, so why the above function
> breaks the loop if SDA is detected high?
>
> [Line 620] /* Break if SDA is high */

With normal devices start followed by stop should reset state of the bus.
Howere, to send start we need SDA high. If this is bus with single
master SDA should be high at least at the end of byte (bus should
flat high as device waits for ACK).
>
> Maybe it's better to send 9 clock cycles whatever the level of SDA line.

I am not sure if this helps: writer is supposed to stop seeing new
start, so it is not clear if extra clock give anything for writers.
OTOH, if bus is clocked reader could get wrong data, so it seem
better to reset bus as soon as possible (that is first time when
SDA is high).
>
> And what about STOP condition at the end of the 9 clock cycles? Is it
> necessary? It should be (SCL is already high): set SDA low, pause, set
> SDA high.
>
> Do you use this sort of bus recovery?

Well, I plan to do so. But I do not like to use untested code,
and to preperly test it I would need special driver to inject
various upsets to I2C bus.

>
> [1]
> https://www.analog.com/media/en/technical-documentation/application-notes/54305147357414AN686_0.pdf
>
> [2] https://elixir.bootlin.com/linux/v4.5/source/drivers/i2c/i2c-core.c#L604

--
Waldek Hebisch

Re: I2C bus recovery

<tkfl2t$5tl0$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=1207&group=comp.arch.embedded#1207

  copy link   Newsgroups: comp.arch.embedded
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: pozzu...@gmail.com (pozz)
Newsgroups: comp.arch.embedded
Subject: Re: I2C bus recovery
Date: Wed, 9 Nov 2022 08:32:46 +0100
Organization: A noiseless patient Spider
Lines: 70
Message-ID: <tkfl2t$5tl0$1@dont-email.me>
References: <tkdre4$3s0fi$1@dont-email.me> <tkek1k$viu$1@gioia.aioe.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 9 Nov 2022 07:32:45 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="824855d00d9178b1566bc65442100abe";
logging-data="194208"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19nioM79aLPZMtT/feFwPzOJReUr/sRylo="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.4.2
Cancel-Lock: sha1:uFdE+xG1qG0sA9Vt6uUjqTR9vPg=
In-Reply-To: <tkek1k$viu$1@gioia.aioe.org>
 by: pozz - Wed, 9 Nov 2022 07:32 UTC

Il 08/11/2022 23:08, antispam@math.uni.wroc.pl ha scritto:
> pozz <pozzugno@gmail.com> wrote:
>> I wanted to implement an I2C bus recovery during initialization. The
>> reason is well known in literature[1].
>>
>> I read the function i2c_generic_recovery[2] of Linux kernel, but I don't
>> understand one thing.
>>
>> The bus recovery is necessary to bring a slave to the end of a byte
>> transmission that could be interrupted for some reason.
>> However the slave could be transmitting 0xFF, so why the above function
>> breaks the loop if SDA is detected high?
>>
>> [Line 620] /* Break if SDA is high */
>
> With normal devices start followed by stop should reset state of the bus.
> Howere, to send start we need SDA high. If this is bus with single
> master SDA should be high at least at the end of byte (bus should
> flat high as device waits for ACK).

Do you think that a slave transmitting 0xFF interrupts the transmission
in the middle as soon as it detects a falling transition on SDA (STOP)?

Anyway, in this case the STOP transmission is necessary after reading
SDA high. I couldn't find the STOP transmission in the Linux kernel
code, only a few clock cycles until SDA is detected high.

>> Maybe it's better to send 9 clock cycles whatever the level of SDA line.
>
> I am not sure if this helps: writer is supposed to stop seeing new
> start, so it is not clear if extra clock give anything for writers.

Yes, if the slave transmitting something stops after seeing a STOP (SDA
going low). I don't know it this is a well-known specification and if
all the I2C slaves implement this specification correctly.

> OTOH, if bus is clocked reader could get wrong data, so it seem
> better to reset bus as soon as possible (that is first time when
> SDA is high).

What do you mean with reader? When the bus is stuck, the writer is the
slave and the reader should be the master that is trying to recovery the
bus, so technically it is not reading anything.

Are you thinking of a bus with multiple slaves? They shouldn't be
reading anything.

>> And what about STOP condition at the end of the 9 clock cycles? Is it
>> necessary? It should be (SCL is already high): set SDA low, pause, set
>> SDA high.
>>
>> Do you use this sort of bus recovery?
>
> Well, I plan to do so. But I do not like to use untested code,
> and to preperly test it I would need special driver to inject
> various upsets to I2C bus.

Yes, this should be ideal, but it's not simple to inject errors in the
I2C bus, so I asked for some ideas and suggestions.

>> [1]
>> https://www.analog.com/media/en/technical-documentation/application-notes/54305147357414AN686_0.pdf
>>
>> [2] https://elixir.bootlin.com/linux/v4.5/source/drivers/i2c/i2c-core.c#L604
>

Re: I2C bus recovery

<7V5bL.79500$2Rs3.1129@fx12.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=1215&group=comp.arch.embedded#1215

  copy link   Newsgroups: comp.arch.embedded
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx12.iad.POSTED!not-for-mail
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0)
Gecko/20100101 Thunderbird/102.4.2
Subject: Re: I2C bus recovery
Content-Language: en-US
Newsgroups: comp.arch.embedded
References: <tkdre4$3s0fi$1@dont-email.me> <tkek1k$viu$1@gioia.aioe.org>
<tkfl2t$5tl0$1@dont-email.me>
From: Rich...@Damon-Family.org (Richard Damon)
In-Reply-To: <tkfl2t$5tl0$1@dont-email.me>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Lines: 91
Message-ID: <7V5bL.79500$2Rs3.1129@fx12.iad>
X-Complaints-To: abuse@easynews.com
Organization: Forte - www.forteinc.com
X-Complaints-Info: Please be sure to forward a copy of ALL headers otherwise we will be unable to process your complaint properly.
Date: Thu, 10 Nov 2022 07:12:50 -0500
X-Received-Bytes: 4507
 by: Richard Damon - Thu, 10 Nov 2022 12:12 UTC

On 11/9/22 2:32 AM, pozz wrote:
> Il 08/11/2022 23:08, antispam@math.uni.wroc.pl ha scritto:
>> pozz <pozzugno@gmail.com> wrote:
>>> I wanted to implement an I2C bus recovery during initialization. The
>>> reason is well known in literature[1].
>>>
>>> I read the function i2c_generic_recovery[2] of Linux kernel, but I don't
>>> understand one thing.
>>>
>>> The bus recovery is necessary to bring a slave to the end of a byte
>>> transmission that could be interrupted for some reason.
>>> However the slave could be transmitting 0xFF, so why the above function
>>> breaks the loop if SDA is detected high?
>>>
>>>      [Line 620] /* Break if SDA is high */
>>
>> With normal devices start followed by stop should reset state of the bus.
>> Howere, to send start we need SDA high.  If this is bus with single
>> master SDA should be high at least at the end of byte (bus should
>> flat high as device waits for ACK).
>
> Do you think that a slave transmitting 0xFF interrupts the transmission
> in the middle as soon as it detects a falling transition on SDA (STOP)?

IT is suppossed to if it meets the standard. ANY change of SDA when SCL
is High resets the logic of every device on the bus in response to the
Start or Stop bit just sent.

>
> Anyway, in this case the STOP transmission is necessary after reading
> SDA high. I couldn't find the STOP transmission in the Linux kernel
> code, only a few clock cycles until SDA is detected high.

You don't need a STOP, you need either a start or stop. When you enable
the I2C controller and start a transmission, it will begin with a start,
and that will provide the needed reset.

>
>
>>> Maybe it's better to send 9 clock cycles whatever the level of SDA line.
>>
>> I am not sure if this helps: writer is supposed to stop seeing new
>> start, so it is not clear if extra clock give anything for writers.
>
> Yes, if the slave transmitting something stops after seeing a STOP (SDA
> going low). I don't know it this is a well-known specification and if
> all the I2C slaves implement this specification correctly.
>

It is a well known requirement of the I2C specification that any start
or stop bit needs to reset the logic of devices.

Not all devices support it though, but if you have one that doesn't and
you get stuck like this, your only answer is some other form of reset
(like a power cycle).

>
>> OTOH, if bus is clocked reader could get wrong data, so it seem
>> better to reset bus as soon as possible (that is first time when
>> SDA is high).
>
> What do you mean with reader? When the bus is stuck, the writer is the
> slave and the reader should be the master that is trying to recovery the
> bus, so technically it is not reading anything.
>
> Are you thinking of a bus with multiple slaves? They shouldn't be
> reading anything.
>
>
>>> And what about STOP condition at the end of the 9 clock cycles? Is it
>>> necessary? It should be (SCL is already high): set SDA low, pause, set
>>> SDA high.
>>>
>>> Do you use this sort of bus recovery?
>>
>> Well, I plan to do so.  But I do not like to use untested code,
>> and to preperly test it I would need special driver to inject
>> various upsets to I2C bus.
>
> Yes, this should be ideal, but it's not simple to inject errors in the
> I2C bus, so I asked for some ideas and suggestions.
>
>
>>> [1]
>>> https://www.analog.com/media/en/technical-documentation/application-notes/54305147357414AN686_0.pdf
>>>
>>> [2]
>>> https://elixir.bootlin.com/linux/v4.5/source/drivers/i2c/i2c-core.c#L604
>>
>

Re: I2C bus recovery

<390366cd-90ba-44c0-80ae-fd3a2cb1e0b1n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=1217&group=comp.arch.embedded#1217

  copy link   Newsgroups: comp.arch.embedded
X-Received: by 2002:ac8:524c:0:b0:39c:1435:423e with SMTP id y12-20020ac8524c000000b0039c1435423emr1462278qtn.490.1668100003124;
Thu, 10 Nov 2022 09:06:43 -0800 (PST)
X-Received: by 2002:a25:9ac6:0:b0:6ca:d6:15e6 with SMTP id t6-20020a259ac6000000b006ca00d615e6mr61351587ybo.420.1668100002821;
Thu, 10 Nov 2022 09:06:42 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.arch.embedded
Date: Thu, 10 Nov 2022 09:06:42 -0800 (PST)
In-Reply-To: <7V5bL.79500$2Rs3.1129@fx12.iad>
Injection-Info: google-groups.googlegroups.com; posting-host=2605:ba00:a220:106e:adda:1756:8a4d:54de;
posting-account=I-_H_woAAAA9zzro6crtEpUAyIvzd19b
NNTP-Posting-Host: 2605:ba00:a220:106e:adda:1756:8a4d:54de
References: <tkdre4$3s0fi$1@dont-email.me> <tkek1k$viu$1@gioia.aioe.org>
<tkfl2t$5tl0$1@dont-email.me> <7V5bL.79500$2Rs3.1129@fx12.iad>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <390366cd-90ba-44c0-80ae-fd3a2cb1e0b1n@googlegroups.com>
Subject: Re: I2C bus recovery
From: gnuarm.d...@gmail.com (Rick C)
Injection-Date: Thu, 10 Nov 2022 17:06:43 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 5304
 by: Rick C - Thu, 10 Nov 2022 17:06 UTC

On Thursday, November 10, 2022 at 8:12:57 AM UTC-4, Richard Damon wrote:
> On 11/9/22 2:32 AM, pozz wrote:
> > Il 08/11/2022 23:08, anti...@math.uni.wroc.pl ha scritto:
> >> pozz <pozz...@gmail.com> wrote:
> >>> I wanted to implement an I2C bus recovery during initialization. The
> >>> reason is well known in literature[1].
> >>>
> >>> I read the function i2c_generic_recovery[2] of Linux kernel, but I don't
> >>> understand one thing.
> >>>
> >>> The bus recovery is necessary to bring a slave to the end of a byte
> >>> transmission that could be interrupted for some reason.
> >>> However the slave could be transmitting 0xFF, so why the above function
> >>> breaks the loop if SDA is detected high?
> >>>
> >>> [Line 620] /* Break if SDA is high */
> >>
> >> With normal devices start followed by stop should reset state of the bus.
> >> Howere, to send start we need SDA high. If this is bus with single
> >> master SDA should be high at least at the end of byte (bus should
> >> flat high as device waits for ACK).
> >
> > Do you think that a slave transmitting 0xFF interrupts the transmission
> > in the middle as soon as it detects a falling transition on SDA (STOP)?
> IT is suppossed to if it meets the standard. ANY change of SDA when SCL
> is High resets the logic of every device on the bus in response to the
> Start or Stop bit just sent.
> >
> > Anyway, in this case the STOP transmission is necessary after reading
> > SDA high. I couldn't find the STOP transmission in the Linux kernel
> > code, only a few clock cycles until SDA is detected high.
> You don't need a STOP, you need either a start or stop. When you enable
> the I2C controller and start a transmission, it will begin with a start,
> and that will provide the needed reset.
> >
> >
> >>> Maybe it's better to send 9 clock cycles whatever the level of SDA line.
> >>
> >> I am not sure if this helps: writer is supposed to stop seeing new
> >> start, so it is not clear if extra clock give anything for writers.
> >
> > Yes, if the slave transmitting something stops after seeing a STOP (SDA
> > going low). I don't know it this is a well-known specification and if
> > all the I2C slaves implement this specification correctly.
> >
> It is a well known requirement of the I2C specification that any start
> or stop bit needs to reset the logic of devices.
>
> Not all devices support it though, but if you have one that doesn't and
> you get stuck like this, your only answer is some other form of reset
> (like a power cycle).
> >
> >> OTOH, if bus is clocked reader could get wrong data, so it seem
> >> better to reset bus as soon as possible (that is first time when
> >> SDA is high).
> >
> > What do you mean with reader? When the bus is stuck, the writer is the
> > slave and the reader should be the master that is trying to recovery the
> > bus, so technically it is not reading anything.
> >
> > Are you thinking of a bus with multiple slaves? They shouldn't be
> > reading anything.
> >
> >
> >>> And what about STOP condition at the end of the 9 clock cycles? Is it
> >>> necessary? It should be (SCL is already high): set SDA low, pause, set
> >>> SDA high.
> >>>
> >>> Do you use this sort of bus recovery?
> >>
> >> Well, I plan to do so. But I do not like to use untested code,
> >> and to preperly test it I would need special driver to inject
> >> various upsets to I2C bus.
> >
> > Yes, this should be ideal, but it's not simple to inject errors in the
> > I2C bus, so I asked for some ideas and suggestions.

This is why when Intel wanted to use I2C on their motherboards, they made and improvement to have a time out on the bus, so all devices could reset out of a hang condition. I forget the name of their version, SMbus or something like that.

If you use chips rated for their spec, they will work.

--

Rick C.

--+++ Get 1,000 miles of free Supercharging
--+++ Tesla referral code - https://ts.la/richard11209

Re: I2C bus recovery

<tkjc7o$bna$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=1218&group=comp.arch.embedded#1218

  copy link   Newsgroups: comp.arch.embedded
Path: i2pn2.org!i2pn.org!aioe.org!NZ87pNe1TKxNDknVl4tZhw.user.46.165.242.91.POSTED!not-for-mail
From: antis...@math.uni.wroc.pl
Newsgroups: comp.arch.embedded
Subject: Re: I2C bus recovery
Date: Thu, 10 Nov 2022 17:26:16 -0000 (UTC)
Organization: Aioe.org NNTP Server
Message-ID: <tkjc7o$bna$1@gioia.aioe.org>
References: <tkdre4$3s0fi$1@dont-email.me> <tkek1k$viu$1@gioia.aioe.org> <tkfl2t$5tl0$1@dont-email.me>
Injection-Info: gioia.aioe.org; logging-data="12010"; posting-host="NZ87pNe1TKxNDknVl4tZhw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: tin/2.4.5-20201224 ("Glen Albyn") (Linux/5.10.0-9-amd64 (x86_64))
Cancel-Lock: sha1:gVEh09FQmSVXf8S/3SxPcvJmcS8=
X-Notice: Filtered by postfilter v. 0.9.2
 by: antis...@math.uni.wroc.pl - Thu, 10 Nov 2022 17:26 UTC

pozz <pozzugno@gmail.com> wrote:
> Il 08/11/2022 23:08, antispam@math.uni.wroc.pl ha scritto:
> > pozz <pozzugno@gmail.com> wrote:
> >> I wanted to implement an I2C bus recovery during initialization. The
> >> reason is well known in literature[1].
> >>
> >> I read the function i2c_generic_recovery[2] of Linux kernel, but I don't
> >> understand one thing.
> >>
> >> The bus recovery is necessary to bring a slave to the end of a byte
> >> transmission that could be interrupted for some reason.
> >> However the slave could be transmitting 0xFF, so why the above function
> >> breaks the loop if SDA is detected high?
> >>
> >> [Line 620] /* Break if SDA is high */
> >
> > With normal devices start followed by stop should reset state of the bus.
> > Howere, to send start we need SDA high. If this is bus with single
> > master SDA should be high at least at the end of byte (bus should
> > flat high as device waits for ACK).
>
> Do you think that a slave transmitting 0xFF interrupts the transmission
> in the middle as soon as it detects a falling transition on SDA (STOP)?
>
> Anyway, in this case the STOP transmission is necessary after reading
> SDA high. I couldn't find the STOP transmission in the Linux kernel
> code, only a few clock cycles until SDA is detected high.
>
>
> >> Maybe it's better to send 9 clock cycles whatever the level of SDA line.
> >
> > I am not sure if this helps: writer is supposed to stop seeing new
> > start, so it is not clear if extra clock give anything for writers.
>
> Yes, if the slave transmitting something stops after seeing a STOP (SDA
> going low). I don't know it this is a well-known specification and if
> all the I2C slaves implement this specification correctly.
>
>
> > OTOH, if bus is clocked reader could get wrong data, so it seem
> > better to reset bus as soon as possible (that is first time when
> > SDA is high).
>
> What do you mean with reader? When the bus is stuck, the writer is the
> slave and the reader should be the master that is trying to recovery the
> bus, so technically it is not reading anything.
>
> Are you thinking of a bus with multiple slaves? They shouldn't be
> reading anything.

If you see low on SDA this could be writer slave sending 0 or
reader slave sending ACK.

--
Waldek Hebisch

Re: I2C bus recovery

<tkjujg$kp0d$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=1220&group=comp.arch.embedded#1220

  copy link   Newsgroups: comp.arch.embedded
Path: i2pn2.org!i2pn.org!aioe.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: pozzu...@gmail.com (pozz)
Newsgroups: comp.arch.embedded
Subject: Re: I2C bus recovery
Date: Thu, 10 Nov 2022 23:39:44 +0100
Organization: A noiseless patient Spider
Lines: 114
Message-ID: <tkjujg$kp0d$1@dont-email.me>
References: <tkdre4$3s0fi$1@dont-email.me> <tkek1k$viu$1@gioia.aioe.org>
<tkfl2t$5tl0$1@dont-email.me> <7V5bL.79500$2Rs3.1129@fx12.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 10 Nov 2022 22:39:44 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="be663a220befa9ea0531a11442b33472";
logging-data="680973"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/7O9bc7nHROV4OUgPzlI4DlJiQmN5WpKw="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.4.2
Cancel-Lock: sha1:Q0BMX9YWOULe585ibu5nHVTxplY=
In-Reply-To: <7V5bL.79500$2Rs3.1129@fx12.iad>
 by: pozz - Thu, 10 Nov 2022 22:39 UTC

Il 10/11/2022 13:12, Richard Damon ha scritto:
> On 11/9/22 2:32 AM, pozz wrote:
>> Il 08/11/2022 23:08, antispam@math.uni.wroc.pl ha scritto:
>>> pozz <pozzugno@gmail.com> wrote:
>>>> I wanted to implement an I2C bus recovery during initialization. The
>>>> reason is well known in literature[1].
>>>>
>>>> I read the function i2c_generic_recovery[2] of Linux kernel, but I
>>>> don't
>>>> understand one thing.
>>>>
>>>> The bus recovery is necessary to bring a slave to the end of a byte
>>>> transmission that could be interrupted for some reason.
>>>> However the slave could be transmitting 0xFF, so why the above function
>>>> breaks the loop if SDA is detected high?
>>>>
>>>>      [Line 620] /* Break if SDA is high */
>>>
>>> With normal devices start followed by stop should reset state of the
>>> bus.
>>> Howere, to send start we need SDA high.  If this is bus with single
>>> master SDA should be high at least at the end of byte (bus should
>>> flat high as device waits for ACK).
>>
>> Do you think that a slave transmitting 0xFF interrupts the
>> transmission in the middle as soon as it detects a falling transition
>> on SDA (STOP)?
>
> IT is suppossed to if it meets the standard. ANY change of SDA when SCL
> is High resets the logic of every device on the bus in response to the
> Start or Stop bit just sent.
>
>>
>> Anyway, in this case the STOP transmission is necessary after reading
>> SDA high. I couldn't find the STOP transmission in the Linux kernel
>> code, only a few clock cycles until SDA is detected high.
>
> You don't need a STOP, you need either a start or stop. When you enable
> the I2C controller and start a transmission, it will begin with a start,
> and that will provide the needed reset.

I see, anyway I was looking at an old Linux kernel code. In the actual
code[1], a STOP condition is really sent before exitigin bus recovery
function.

[1]
https://github.com/torvalds/linux/blob/master/drivers/i2c/i2c-core-base.c#L200

>>>> Maybe it's better to send 9 clock cycles whatever the level of SDA
>>>> line.
>>>
>>> I am not sure if this helps: writer is supposed to stop seeing new
>>> start, so it is not clear if extra clock give anything for writers.
>>
>> Yes, if the slave transmitting something stops after seeing a STOP
>> (SDA going low). I don't know it this is a well-known specification
>> and if all the I2C slaves implement this specification correctly.
>>
>
> It is a well known requirement of the I2C specification that any start
> or stop bit needs to reset the logic of devices.
>
> Not all devices support it though, but if you have one that doesn't and
> you get stuck like this, your only answer is some other form of reset
> (like a power cycle).

Oh yes, I thought that a slave that had started a byte transmission
needed to receive 9 clock cycles to go to the end and reset its internal
state-machine. From what you say, this is not true. Even when a STOP
condition is detected in the middle of a byte transmissione, the I2C
device should reset I2C state machine.

Of course, if this I2C slave device is transmitting 0 (keeping SDA low),
it's impossible to create a STOP or START condition from the master. The
master needs to send clock cycle until the slave release SDA (because
the byte transmission is really finished or because it is transmitting a 1).

>>> OTOH, if bus is clocked reader could get wrong data, so it seem
>>> better to reset bus as soon as possible (that is first time when
>>> SDA is high).
>>
>> What do you mean with reader? When the bus is stuck, the writer is the
>> slave and the reader should be the master that is trying to recovery
>> the bus, so technically it is not reading anything.
>>
>> Are you thinking of a bus with multiple slaves? They shouldn't be
>> reading anything.
>>
>>
>>>> And what about STOP condition at the end of the 9 clock cycles? Is it
>>>> necessary? It should be (SCL is already high): set SDA low, pause, set
>>>> SDA high.
>>>>
>>>> Do you use this sort of bus recovery?
>>>
>>> Well, I plan to do so.  But I do not like to use untested code,
>>> and to preperly test it I would need special driver to inject
>>> various upsets to I2C bus.
>>
>> Yes, this should be ideal, but it's not simple to inject errors in the
>> I2C bus, so I asked for some ideas and suggestions.
>>
>>
>>>> [1]
>>>> https://www.analog.com/media/en/technical-documentation/application-notes/54305147357414AN686_0.pdf
>>>>
>>>> [2]
>>>> https://elixir.bootlin.com/linux/v4.5/source/drivers/i2c/i2c-core.c#L604
>>>
>>
>

Re: I2C bus recovery

<slrntn1j30.28h.news-1513678000@a-tuin.ms.intern>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=1223&group=comp.arch.embedded#1223

  copy link   Newsgroups: comp.arch.embedded
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: news-151...@discworld.dascon.de (Michael Schwingen)
Newsgroups: comp.arch.embedded
Subject: Re: I2C bus recovery
Date: 13 Nov 2022 10:52:16 GMT
Lines: 22
Message-ID: <slrntn1j30.28h.news-1513678000@a-tuin.ms.intern>
References: <tkdre4$3s0fi$1@dont-email.me> <tkek1k$viu$1@gioia.aioe.org>
<tkfl2t$5tl0$1@dont-email.me>
X-Trace: individual.net GlPQNUt4v697HN8Qbdm28wrJzDtMDldveiUiLSx/jpfPhsZNjy
Cancel-Lock: sha1:0gHrPy9E3YnHJc0wgD7ko3ZhHmQ=
User-Agent: slrn/1.0.3 (Linux)
 by: Michael Schwingen - Sun, 13 Nov 2022 10:52 UTC

On 2022-11-09, pozz <pozzugno@gmail.com> wrote:
>>
>> Well, I plan to do so. But I do not like to use untested code,
>> and to preperly test it I would need special driver to inject
>> various upsets to I2C bus.
>
> Yes, this should be ideal, but it's not simple to inject errors in the
> I2C bus, so I asked for some ideas and suggestions.

I had the same problem (testing error recovery code paths, and getting the
"stop at the right time" working on a STM32F1), so I made a special test
slave based on an AtMega88:

https://www.schwingen.org/i2c-fault-injection/

(You can use an arduino nano if you don't want to build your own PCB).

Together with test code on your host, and maybe a logic analyzer, this
allows rapidly testing lots of error events.

cu
Michael

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor