@@ -36,6 +36,7 @@ TwoWire::TwoWire(NRF_TWI_Type * p_twi, uint8_t pinSDA, uint8_t pinSCL)
36
36
this ->_uc_pinSDA = g_ADigitalPinMap[pinSDA];
37
37
this ->_uc_pinSCL = g_ADigitalPinMap[pinSCL];
38
38
this ->transmissionBegun = false ;
39
+ this ->suspended = false ;
39
40
}
40
41
41
42
void TwoWire::begin (void ) {
@@ -102,15 +103,20 @@ uint8_t TwoWire::requestFrom(uint8_t address, size_t quantity, bool stopBit)
102
103
103
104
_p_twi->ADDRESS = address;
104
105
_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
+ }
107
111
108
112
for (byteRead = 0 ; byteRead < quantity; byteRead++)
109
113
{
110
114
if (byteRead == quantity - 1 )
111
115
{
112
116
// 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
+ }
114
120
}
115
121
116
122
_p_twi->TASKS_RESUME = 0x1UL ;
@@ -129,12 +135,14 @@ uint8_t TwoWire::requestFrom(uint8_t address, size_t quantity, bool stopBit)
129
135
130
136
if (stopBit || _p_twi->EVENTS_ERROR )
131
137
{
138
+ this ->suspended = false ;
132
139
_p_twi->TASKS_STOP = 0x1UL ;
133
140
while (!_p_twi->EVENTS_STOPPED );
134
141
_p_twi->EVENTS_STOPPED = 0x0UL ;
135
142
}
136
143
else
137
144
{
145
+ this ->suspended = true ;
138
146
_p_twi->TASKS_SUSPEND = 0x1UL ;
139
147
while (!_p_twi->EVENTS_SUSPENDED );
140
148
_p_twi->EVENTS_SUSPENDED = 0x0UL ;
0 commit comments