8000 Double I2C read in one transaction skips a clock pulse (#5528) (based on I2C reduce iRAM) by TD-er · Pull Request #6592 · esp8266/Arduino · GitHub
[go: up one dir, main page]

Skip to content

Double I2C read in one transaction skips a clock pulse (#5528) (based on I2C reduce iRAM) #6592

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 27 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7126fbf
Reduce the IRAM (and heap) usage of I2C code
earlephilhower Jul 22, 2019
5ba2dd3
Make most variables ints, not uint8_ts
earlephilhower Jul 22, 2019
f55ab36
Make local flag vars int
earlephilhower Jul 22, 2019
37e10b9
Factor out !scl in onSdaChange
earlephilhower Jul 22, 2019
423a5bf
Make tiny twi_reply inline
earlephilhower Jul 22, 2019
62f9599
Inline additional twi_** helper functions
earlephilhower Jul 22, 2019
014f87f
Convert state machine to 1-hot for faster lookup
earlephilhower Jul 22, 2019
9ae9af1
Factor out twi_status setting
earlephilhower Jul 24, 2019
b975996
Use a struct to hold globals for TWI
earlephilhower Jul 24, 2019
52bf8ac
Use enums for states, move one more var to twi struct
earlephilhower Jul 25, 2019
31e54a0
Save 4 heap bytes by reprdering struct
8000 earlephilhower Jul 25, 2019
fd8b6c5
Convert to C++ class, clean up code
earlephilhower Jul 26, 2019
0cdca29
Run astyle core.conf, clean up space/tab/etc.
earlephilhower Jul 26, 2019
eb7b2b9
Merge branch 'master' into reducei2ciram
earlephilhower Aug 8, 2019
3552bfc
Merge branch 'master' into reducei2ciram
earlephilhower Aug 19, 2019
51e1e34
Merge branch 'master' into reducei2ciram
earlephilhower Sep 15, 2019
1c14e9e
Merge branch 'master' into reducei2ciram
d-a-v Oct 3, 2019
1c63358
Double I2C read in one transaction skips a clock pulse (#5528)
TD-er Oct 3, 2019
f04d65c
Merge branch 'master' into reducei2ciram
earlephilhower Oct 4, 2019
f67ddf5
Add enum use comment, rename twi::delay, fix SDA/SCL_READ bool usage
earlephilhower Oct 4, 2019
dd6a854
Replace clock stretch repeated code w/inline loop
earlephilhower Oct 4, 2019
a23864a
Remove slave code when not using slave mode
earlephilhower Oct 4, 2019
eb85c68
Double I2C read in one transaction skips a clock pulse (#5528)
TD-er Oct 3, 2019
900bf65
Merge remote-tracking branch 'origin/bugfix/issue5528_I2C_reduceiram'…
TD-er Oct 14, 2019
138e1ec
Restyle core_esp8266_si2c.cpp
TD-er Oct 14, 2019
0dac904
Merge branch 'master' into bugfix/issue5528_I2C_reduceiram
d-a-v Oct 14, 2019
a6c3700
Add libraries/Wire to restyle.sh
TD-er Oct 15, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Factor out !scl in onSdaChange
If SCL is low then all branches of the case are no-ops, so factor that
portion outo to remove some redundant logic in each case.

Sketch uses 270843 bytes (25%) of program storage space. Maximum is 1044464 bytes.
Global variables use 27944 bytes (34%) of dynamic memory, leaving 53976 bytes for local variables. Maximum is 81920 bytes.

401000cc l     F .text1	00000014 twi_delay
401000ec l     F .text1	00000020 twi_reply$part$1
4010010c g     F .text1	00000035 twi_reply
4010014c g     F .text1	00000052 twi_stop
401001a0 g     F .text1	0000003b twi_releaseBus
40100204 g     F .text1	000001e6 twi_onTwipEvent
40100404 l     F .text1	000001e7 onSdaChange
401005f8 l     F .text1	000002fd onSclChange
401008f8 l     F .text1	0000003b onTimer

0x0000000040107468                _text_end = ABSOLUTE (.)
  • Loading branch information
earlephilhower committed Jul 22, 2019
commit 37e10b9aa0f424f2fb0a06144cb00d5a5e32ab21
98 changes: 42 additions & 56 deletions cores/esp8266/core_esp8266_si2c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -687,12 +687,10 @@ void ICACHE_RAM_ATTR onSdaChange(void)
sda = SDA_READ();
scl = SCL_READ();

switch (twip_state)
if (scl) /* !DATA */ switch (twip_state)
{
case TWIP_IDLE:
if (!scl) {
// DATA - ignore
} else if (sda) {
if (sda) {
// STOP - ignore
} else {
// START
Expand All @@ -711,72 +709,60 @@ void ICACHE_RAM_ATTR onSdaChange(void)
case TWIP_READ_ACK:
case TWIP_RWAIT_ACK:
case TWIP_WRITE:
if (!scl) {
// DATA - ignore
} else {
// START or STOP
SDA_HIGH(); // Should not be necessary
twip_status = TW_BUS_ERROR;
twi_onTwipEvent(twip_status);
twip_mode = TWIPM_WAIT;
twip_state = TWIP_BUS_ERR;
}
// START or STOP
SDA_HIGH(); // Should not be necessary
twip_status = TW_BUS_ERROR;
twi_onTwipEvent(twip_status);
twip_mode = TWIPM_WAIT;
twip_state = TWIP_BUS_ERR;
break;

case TWIP_WAIT_STOP:
case TWIP_BUS_ERR:
if (!scl) {
// DATA - ignore
if (sda) {
// STOP
SCL_LOW(); // clock stretching
ets_timer_disarm(&timer);
twip_state = TWIP_IDLE;
twip_mode = TWIPM_IDLE;
SCL_HIGH();
} else {
if (sda) {
// STOP
SCL_LOW(); // clock stretching
ets_timer_disarm(&timer);
twip_state = TWIP_IDLE;
twip_mode = TWIPM_IDLE;
SCL_HIGH();
// START
if (twip_state == TWIP_BUS_ERR) {
// ignore
} else {
// START
if (twip_state == TWIP_BUS_ERR) {
// ignore
} else {
bitCount = 8;
twip_state = TWIP_REP_START;
ets_timer_arm_new(&timer, twi_timeout_ms, false, true); // Once, ms
}
bitCount = 8;
twip_state = TWIP_REP_START;
ets_timer_arm_new(&timer, twi_timeout_ms, false, true); // Once, ms
}
}
break;

case TWIP_SLA_W:
case TWIP_READ:
if (!scl) {
// DATA - ignore
// START or STOP
if (bitCount != 7) {
// inside byte transfer - error
twip_status = TW_BUS_ERROR;
twi_onTwipEvent(twip_status);
twip_mode = TWIPM_WAIT;
twip_state = TWIP_BUS_ERR;
} else {
// START or STOP
if (bitCount != 7) {
// inside byte transfer - error
twip_status = TW_BUS_ERROR;
twi_onTwipEvent(twip_status);
twip_mode = TWIPM_WAIT;
twip_state = TWIP_BUS_ERR;
// during first bit in byte transfer - ok
SCL_LOW(); // clock stretching
twip_status = TW_SR_STOP;
twi_onTwipEvent(twip_status);
if (sda) {
// STOP
ets_timer_disarm(&timer);
twip_state = TWIP_IDLE;
twip_mode = TWIPM_IDLE;
} else {
// during first bit in byte transfer - ok
SCL_LOW(); // clock stretching
twip_status = TW_SR_STOP;
twi_onTwipEvent(twip_status);
if (sda) {
// STOP
ets_timer_disarm(&timer);
twip_state = TWIP_IDLE;
twip_mode = TWIPM_IDLE;
} else {
// START
bitCount = 8;
ets_timer_arm_new(&timer, twi_timeout_ms, false, true); // Once, ms
twip_state = TWIP_REP_START;
twip_mode = TWIPM_IDLE;
}
// START
bitCount = 8;
ets_timer_arm_new(&timer, twi_timeout_ms, false, true); // Once, ms
twip_state = TWIP_REP_START;
twip_mode = TWIPM_IDLE;
}
}
break;
Expand Down
0