Skip to content

Commit 9da648c

Browse files
authored
ReSTART, Sequencing
pr espressif#1665 introduce a problem with ReSTART, when solving this problem I found an interaction between the TxFifo refill, RxFifo empty and CMD[] fill. during certain sequences a dataqueue command would be skipped, this skipping resulted in a mismatch between the contents of the TxFifo and the i2c command sequence. The problem manifested as an ACK error. In addition to this required bug fix I propose: * `Wire.begin()` be changed from a `void` to a `bool` this will allow the reset functionality of `Wire.begin()` to be reported. Currently `Wire.begin()` attempts to reset the i2c Peripheral, but cannot report success/failure. * `Wire.busy()` be added. this `bool` function returns the hardware status of the bus. This status can be use in multi-master environments for application level interleaving of commands, also in single master environment, it can be used to detect a 'hung' bus. With the functional change to `Wire.begin()` this allows app level recover of a hung bus. * `Wire.lastError()` value updated for all errors, previously when interleaving `Wire.endTransmission(false)` and `Wire.readTransmission(false)`, the 128 byte `Wire.write()` buffer was exhausted without generating and error(very exotic). I discovered this error when I created a sequence of directed reads to a EEPROM. Each directed read used 2 bytes of the 128 byte `write()` buffer, so after 64 consecutive ReSTART writes with ReSTART reads, `Wire()` had no room to record the directed address bytes. It generated just a NAK check without setting the EEPROMs internal register address. The succeeding ReSTART read succeeded at incorrect address. * Changes to the HAL layer: ** added `i2cGetStatus()` which returns the i2c peripheral status word, used to detect bus_busy currently ** added `i2cDebug()` programmatic control of debug buffer output ** changed `i2cAddQueue()` to allow data_only queue element this will allow a i2c transaction to use multiple data pointers. ** removed direct access to DumpInts(), DumpI2c() from app, use i2cDebug() to set trigger points *
1 parent 22afc3a commit 9da648c

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

Diff for: libraries/Wire/src/Wire.h

+7-4
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#include "freertos/queue.h"
3131
#include "Stream.h"
3232

33-
#define STICKBREAKER V0.2.2
33+
#define STICKBREAKER V1.0.1
3434
#define I2C_BUFFER_LENGTH 128
3535
typedef void(*user_onRequest)(void);
3636
typedef void(*user_onReceive)(uint8_t*, int);
@@ -67,7 +67,7 @@ class TwoWire: public Stream
6767
public:
6868
TwoWire(uint8_t bus_num);
6969
~TwoWire();
70-
void begin(int sda=-1, int scl=-1, uint32_t frequency=0);
70+
bool begin(int sda=-1, int scl=-1, uint32_t frequency=0);
7171

7272
void setClock(uint32_t frequency); // change bus clock without initing hardware
7373
size_t getClock(); // current bus clock rate in hz
@@ -129,15 +129,18 @@ class TwoWire: public Stream
129129
void onReceive( void (*)(int) );
130130
void onRequest( void (*)(void) );
131131

132-
void dumpInts();
133-
void dumpI2C();
132+
uint32_t setDebugFlags( uint32_t setBits, uint32_t resetBits);
133+
bool busy();
134134
};
135135

136136
extern TwoWire Wire;
137137
extern TwoWire Wire1;
138138

139139

140140
/*
141+
V1.0.1 02AUG2018 First Fix after release, Correct ReSTART handling, change Debug control, change begin()
142+
to a function, this allow reporting if bus cannot be initialized, Wire.begin() can be used to recover
143+
a hung bus busy condition.
141144
V0.2.2 13APR2018 preserve custom SCL,SDA,Frequency when no parameters passed to begin()
142145
V0.2.1 15MAR2018 Hardware reset, Glitch prevention, adding destructor for second i2c testing
143146
*/

0 commit comments

Comments
 (0)