Skip to content

Commit 4f5f026

Browse files
Merge pull request sandeepmistry#184 from dsanders11/master
Fix stopBit = false mode in nRF51 Wire library
2 parents 1ec43d4 + bd8bba2 commit 4f5f026

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

libraries/Wire/Wire.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ class TwoWire : public Stream
8484
bool master;
8585
bool receiving;
8686
bool transmissionBegun;
87+
bool suspended;
8788

8889
// RX Buffer
8990
RingBuffer rxBuffer;

libraries/Wire/Wire_nRF51.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ TwoWire::TwoWire(NRF_TWI_Type * p_twi, uint8_t pinSDA, uint8_t pinSCL)
3636
this->_uc_pinSDA = g_ADigitalPinMap[pinSDA];
3737
this->_uc_pinSCL = g_ADigitalPinMap[pinSCL];
3838
this->transmissionBegun = false;
39+
this->suspended = false;
3940
}
4041

4142
void TwoWire::begin(void) {
@@ -102,15 +103,20 @@ uint8_t TwoWire::requestFrom(uint8_t address, size_t quantity, bool stopBit)
102103

103104
_p_twi->ADDRESS = address;
104105
_p_twi->SHORTS = 0x1UL; // To trigger suspend task when a byte is received
105-
_p_twi->TASKS_RESUME = 0x1UL;
106-
_p_twi->TASKS_STARTRX = 0x1UL;
106+
107+
if (!this->suspended) {
108+
_p_twi->TASKS_RESUME = 0x1UL;
109+
_p_twi->TASKS_STARTRX = 0x1UL;
110+
}
107111

108112
for (byteRead = 0; byteRead < quantity; byteRead++)
109113
{
110114
if (byteRead == quantity - 1)
111115
{
112116
// To trigger stop task when last byte is received, set before resume task.
113-
_p_twi->SHORTS = 0x2UL;
117+
if (stopBit) {
118+
_p_twi->SHORTS = 0x2UL;
119+
}
114120
}
115121

116122
_p_twi->TASKS_RESUME = 0x1UL;
@@ -129,12 +135,14 @@ uint8_t TwoWire::requestFrom(uint8_t address, size_t quantity, bool stopBit)
129135

130136
if (stopBit || _p_twi->EVENTS_ERROR)
131137
{
138+
this->suspended = false;
132139
_p_twi->TASKS_STOP = 0x1UL;
133140
while(!_p_twi->EVENTS_STOPPED);
134141
_p_twi->EVENTS_STOPPED = 0x0UL;
135142
}
136143
else
137144
{
145+
this->suspended = true;
138146
_p_twi->TASKS_SUSPEND = 0x1UL;
139147
while(!_p_twi->EVENTS_SUSPENDED);
140148
_p_twi->EVENTS_SUSPENDED = 0x0UL;

0 commit comments

Comments
 (0)