Skip to content

Commit

Permalink
Merge pull request #184 from dsanders11/master
Browse files Browse the repository at this point in the history
Fix stopBit = false mode in nRF51 Wire library
  • Loading branch information
sandeepmistry authored Aug 18, 2017
2 parents 1ec43d4 + bd8bba2 commit 4f5f026
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions libraries/Wire/Wire.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class TwoWire : public Stream
bool master;
bool receiving;
bool transmissionBegun;
bool suspended;

// RX Buffer
RingBuffer rxBuffer;
Expand Down
14 changes: 11 additions & 3 deletions libraries/Wire/Wire_nRF51.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ TwoWire::TwoWire(NRF_TWI_Type * p_twi, uint8_t pinSDA, uint8_t pinSCL)
this->_uc_pinSDA = g_ADigitalPinMap[pinSDA];
this->_uc_pinSCL = g_ADigitalPinMap[pinSCL];
this->transmissionBegun = false;
this->suspended = false;
}

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

_p_twi->ADDRESS = address;
_p_twi->SHORTS = 0x1UL; // To trigger suspend task when a byte is received
_p_twi->TASKS_RESUME = 0x1UL;
_p_twi->TASKS_STARTRX = 0x1UL;

if (!this->suspended) {
_p_twi->TASKS_RESUME = 0x1UL;
_p_twi->TASKS_STARTRX = 0x1UL;
}

for (byteRead = 0; byteRead < quantity; byteRead++)
{
if (byteRead == quantity - 1)
{
// To trigger stop task when last byte is received, set before resume task.
_p_twi->SHORTS = 0x2UL;
if (stopBit) {
_p_twi->SHORTS = 0x2UL;
}
}

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

if (stopBit || _p_twi->EVENTS_ERROR)
{
this->suspended = false;
_p_twi->TASKS_STOP = 0x1UL;
while(!_p_twi->EVENTS_STOPPED);
_p_twi->EVENTS_STOPPED = 0x0UL;
}
else
{
this->suspended = true;
_p_twi->TASKS_SUSPEND = 0x1UL;
while(!_p_twi->EVENTS_SUSPENDED);
_p_twi->EVENTS_SUSPENDED = 0x0UL;
Expand Down

0 comments on commit 4f5f026

Please sign in to comment.