Skip to content

Commit 8ac6be6

Browse files
author
Chuck Todd
committed
Substitute ReadMe
Substitute my ReadMe for the Arduio-esp32 default
1 parent 832a0eb commit 8ac6be6

File tree

3 files changed

+149
-149
lines changed

3 files changed

+149
-149
lines changed

README.md

Lines changed: 101 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,115 @@
1-
# Arduino core for ESP32 WiFi chip
1+
# A fork of Espressif/arduino-esp32:
2+
## i2c communications using a ISR
23

3-
[![Build Status](https://travis-ci.org/espressif/arduino-esp32.svg?branch=master)](https://travis-ci.org/espressif/arduino-esp32)
4+
The existing main fork of arduino-esp32 implement i2c communications using a polled monitoring of the I2C Hardware StateMachine. The implementation of the I2C ReSTART operations leaves the I2C Hardware StateMachine(SM) in an unstable configuration. The I2C protocol arbitrates exclusive ownership of the bus to a single Master Device from a `START` signal to the next `STOP`. A restart operation is just a start signal inserted into this `START` -> `STOP` flow. Schematically like this:
5+
`START` (Read or Write) -> `ReSTART` (Read or Write) -> `STOP`.
6+
7+
By I2C protocol as [UM10204 I2C-Bus Specification and User Manual](https://Fwww.nxp.com/docs/en/user-guide/UM10204.pdf), A valid I2C transaction must be a `START` at least one Data Byte `STOP`. The Arduino environment is base on the AVR processor series, These Atmel CPU's implementation of the the I2C protocol allows unlimited pauses between protocol elements. The Espressif implement enforces a Strict TimeOut between elements. This has resulted in perceived I2C bus stability issues ([834](https://github.com/espressif/arduino-esp32/issues/834),[811](https://github.com/espressif/arduino-esp32/issues/811),[741](https://github.com/espressif/arduino-esp32/issues/741),[682](https://github.com/espressif/arduino-esp32/issues/682),[659](https://github.com/espressif/arduino-esp32/issues/659) and many more. @lonerzzz created a partial solution [#751](https://github.com/espressif/arduino-esp32/pull/751).
8+
I spend a couple of weeks investigating these problems, and discovered this Hard TimeOut was the basis of all of these problems. Once this Hard TimeOut limit is triggered the SM cannot recover without a complete reinitialization.
9+
The existing Arduino code base is reliant on the AVR's ability to infintely pause a i2c transaction. The standard coding practice of:
10+
```c++
11+
// set internal address pointer in I2C EEPROM from which to read
12+
Wire.beginTransmission(ID);
13+
Wire.write(highByte(addr));
14+
Wire.write(lowByte(addr));
15+
uint8_t err =Wire.endTransmission(false); // don't send a STOP, just Pause I2C operations
16+
if(err==0){ // successfully set internal address pointer
17+
err=Wire.requestFrom(addr,len);
18+
if(err==0){ // read failed
19+
Serial.print("Bad Stuff!! Read Failed\n");
20+
}
21+
else {// successful read
22+
while(Wire.avaiable()){
23+
Serial.print((char)Wire.read());
24+
}
25+
Serial.println();
26+
}
27+
}
28+
```
29+
May not function correctly with the ESP32, actually *usually* will not function correctly. The current arduino-esp32 platform is built upon the espressif-idf which is built on FreeRTOS, a multi-process/processor operating system. The Arduino sketch is just one task executing on One of the Two processor cores. The TimeOut is triggered when the FreeRTOS Task Scheduler does a task switch between `Wire.endTransmission(false);` and the i2c activites inside `Wire.requestfrom()`. The maximum TimeOut interval is around 12ms.
30+
My solution is to avoid this TimeOut from every being possible. I have changed how `Wire()` uses the SM. Specifically I have changed how a `ReSTART` operation is implemented. To avoid the TimeOut I have create a i2c queuing system that does not allow an i2c transaction to start unless a `STOP` has been issued. But, alas, this creates some incompatibilities with the pre-exisiting Arduino code base. The changes to the standard Arduino `Wire()` coding are minimal, but, they are necessary:
31+
```c++
32+
// new, maybe Excessive Error Return codes for @stickbreaker:arduino-esp32
33+
typedef enum {
34+
I2C_ERROR_OK=0,
35+
I2C_ERROR_DEV,
36+
I2C_ERROR_ACK,
37+
I2C_ERROR_TIMEOUT,
38+
I2C_ERROR_BUS,
39+
I2C_ERROR_BUSY,
40+
I2C_ERROR_MEMORY,
41+
I2C_ERROR_CONTINUE,
42+
I2C_ERROR_MISSING_WRITE,
43+
I2C_ERROR_NO_BEGIN
44+
} i2c_err_t;
445
5-
### Need help or have a question? Join the chat at [![https://gitter.im/espressif/arduino-esp32](https://badges.gitter.im/espressif/arduino-esp32.svg)](https://gitter.im/espressif/arduino-esp32?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
46+
// set internal address pointer in I2C EEPROM from which to read
47+
Wire.beginTransmission(ID);
48+
Wire.write(highByte(addr));
49+
Wire.write(lowByte(addr));
50+
uint8_t err =Wire.endTransmission(false); // don't send a STOP, just Pause I2C operations
651
7-
## Contents
8-
- [Development Status](#development-status)
9-
- [Installation Instructions](#installation-instructions)
10-
- [Decoding Exceptions](#decoding-exceptions)
11-
- [Issue/Bug report template](#issuebug-report-template)
12-
- [ESP32Dev Board PINMAP](#esp32dev-board-pinmap)
52+
//err will be I2C_ERROR_CONTINUE (7), an indication that the preceding
53+
//transaction has been Queued, NOT EXECUTED
1354
14-
## Development Status
15-
Most of the framework is implemented. Most noticable is the missing analogWrite. While analogWrite is on it's way, there are a few other options that you can use:
16-
- 16 channels [LEDC](cores/esp32/esp32-hal-ledc.h) which is PWM
17-
- 8 channels [SigmaDelta](cores/esp32/esp32-hal-sigmadelta.h) which uses SigmaDelta modulation
18-
- 2 channels [DAC](cores/esp32/esp32-hal-dac.h) which gives real analog output
55+
if(err==7){ // Prior Operation has been queued, it is NOT guaranteed that it will
56+
// successfully occur!
57+
err=Wire.requestFrom(addr,len);
58+
if(err!=len){ // complete/partial read failure
59+
Serial.print("Bad Stuff!! Read Failed lastError=");
60+
Serial.print(Wire.lastError(),DEC);
61+
}
62+
// some of the read may have executed
63+
while(Wire.avaiable()){
64+
Serial.print((char)Wire.read());
65+
}
66+
Serial.println();
67+
}
68+
```
1969

20-
## Installation Instructions
70+
Additionally I have expanded the ability of `Wire()` to handle larger Reads and Writes: up to 64k-1, I have tested READs of these sizes, but the largest single WRITE i have tested is 128bytes. I can send more data to a 24LC512, but it will only store the last 128bytes.
2171

22-
- Using Arduino IDE
23-
+ [Instructions for Windows](docs/arduino-ide/windows.md)
24-
+ [Instructions for Mac](docs/arduino-ide/mac.md)
25-
+ [Instructions for Debian/Ubuntu Linux](docs/arduino-ide/debian_ubuntu.md)
26-
+ [Instructions for Fedora](docs/arduino-ide/fedora.md)
27-
+ [Instructions for openSUSE](docs/arduino-ide/opensuse.md)
28-
- [Using PlatformIO](docs/platformio.md)
29-
- [Building with make](docs/make.md)
30-
- [Using as ESP-IDF component](docs/esp-idf_component.md)
72+
I have create a few new methods for Wire:
73+
```c++
74+
uint8_t oldEndTransmission(uint8_t); //released implementation
75+
size_t oldRequestFrom(uint8_t address, size_t size, bool sendStop); //released implementation
76+
//@stickBreaker for big blocks and ISR model
77+
uint8_t writeTransaction(uint8_t address, uint8_t* buff, size_t size, bool sendStop);// big block handling
78+
size_t requestFrom(uint8_t address, size_t size, bool sendStop);
79+
size_t requestFrom(uint8_t address, uint8_t* buf, size_t size, bool sendStop);
80+
size_t polledRequestFrom(uint8_t address, uint8_t* buf, size_t size, bool sendStop);//a BigBlock test case Not USING ISR
81+
size_t transact(size_t readLen); // replacement for endTransmission(false),requestFrom(ID,readLen,true);
82+
size_t transact(uint8_t* readBuff, size_t readLen);// bigger Block read
83+
i2c_err_t lastError(); // Expose complete error
84+
void dumpInts(); // diagnostic dump for the last 64 different i2c Interrupts
85+
size_t getClock(); // current i2c Clock rate
86+
```
3187
32-
#### Decoding exceptions
88+
`transact()` coding is:
89+
```c++
90+
// set internal address pointer in I2C EEPROM from which to read
91+
Wire.beginTransmission(ID);
92+
Wire.write(highByte(addr));
93+
Wire.write(lowByte(addr));
3394
34-
You can use [EspExceptionDecoder](https://github.com/me-no-dev/EspExceptionDecoder) to get meaningful call trace.
95+
uint8_t err=Wire.transact(len);
96+
if(err!=len){ // complete/partial read failure
97+
Serial.print("Bad Stuff!! Read Failed lastError=");
98+
Serial.print(Wire.lastError(),DEC);
99+
}
100+
// some of the read may have executed
101+
while(Wire.avaiable()){
102+
Serial.print((char)Wire.read());
103+
}
104+
Serial.println();
35105
36-
#### Issue/Bug report template
37-
Before reporting an issue, make sure you've searched for similar one that was already created. Also make sure to go through all the issues labelled as [for reference](https://github.com/espressif/arduino-esp32/issues?utf8=%E2%9C%93&q=is%3Aissue%20label%3A%22for%20reference%22%20).
106+
```
38107

39-
Finally, if you're sure no one else had the issue, follow the [ISSUE_TEMPLATE](docs/ISSUE_TEMPLATE.md) while reporting any issue.
108+
This **APLHA** release should be compiled with ESP32 Dev Module as its target, and
109+
Set the "core debug level" to 'error'
40110

111+
There is MINIMAL to NO ERROR detection, BUS, BUSY. because I have not encounter any of them!
41112

42-
## ESP32Dev Board PINMAP
43113

44-
![Pin Functions](docs/esp32_pinmap.png)
45114

46-
## Hint
47-
48-
Sometimes to program ESP32 via serial you must keep GPIO0 LOW during the programming process
115+
Chuck.

README2.md

Lines changed: 0 additions & 115 deletions
This file was deleted.

README_OLD.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Arduino core for ESP32 WiFi chip
2+
3+
[![Build Status](https://travis-ci.org/espressif/arduino-esp32.svg?branch=master)](https://travis-ci.org/espressif/arduino-esp32)
4+
5+
### Need help or have a question? Join the chat at [![https://gitter.im/espressif/arduino-esp32](https://badges.gitter.im/espressif/arduino-esp32.svg)](https://gitter.im/espressif/arduino-esp32?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
6+
7+
## Contents
8+
- [Development Status](#development-status)
9+
- [Installation Instructions](#installation-instructions)
10+
- [Decoding Exceptions](#decoding-exceptions)
11+
- [Issue/Bug report template](#issuebug-report-template)
12+
- [ESP32Dev Board PINMAP](#esp32dev-board-pinmap)
13+
14+
## Development Status
15+
Most of the framework is implemented. Most noticable is the missing analogWrite. While analogWrite is on it's way, there are a few other options that you can use:
16+
- 16 channels [LEDC](cores/esp32/esp32-hal-ledc.h) which is PWM
17+
- 8 channels [SigmaDelta](cores/esp32/esp32-hal-sigmadelta.h) which uses SigmaDelta modulation
18+
- 2 channels [DAC](cores/esp32/esp32-hal-dac.h) which gives real analog output
19+
20+
## Installation Instructions
21+
22+
- Using Arduino IDE
23+
+ [Instructions for Windows](docs/arduino-ide/windows.md)
24+
+ [Instructions for Mac](docs/arduino-ide/mac.md)
25+
+ [Instructions for Debian/Ubuntu Linux](docs/arduino-ide/debian_ubuntu.md)
26+
+ [Instructions for Fedora](docs/arduino-ide/fedora.md)
27+
+ [Instructions for openSUSE](docs/arduino-ide/opensuse.md)
28+
- [Using PlatformIO](docs/platformio.md)
29+
- [Building with make](docs/make.md)
30+
- [Using as ESP-IDF component](docs/esp-idf_component.md)
31+
32+
#### Decoding exceptions
33+
34+
You can use [EspExceptionDecoder](https://github.com/me-no-dev/EspExceptionDecoder) to get meaningful call trace.
35+
36+
#### Issue/Bug report template
37+
Before reporting an issue, make sure you've searched for similar one that was already created. Also make sure to go through all the issues labelled as [for reference](https://github.com/espressif/arduino-esp32/issues?utf8=%E2%9C%93&q=is%3Aissue%20label%3A%22for%20reference%22%20).
38+
39+
Finally, if you're sure no one else had the issue, follow the [ISSUE_TEMPLATE](docs/ISSUE_TEMPLATE.md) while reporting any issue.
40+
41+
42+
## ESP32Dev Board PINMAP
43+
44+
![Pin Functions](docs/esp32_pinmap.png)
45+
46+
## Hint
47+
48+
Sometimes to program ESP32 via serial you must keep GPIO0 LOW during the programming process

0 commit comments

Comments
 (0)