@@ -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
4142void  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