Skip to content

Commit f763660

Browse files
committed
Merge branch 'wire-master-repeated-starts' of https://github.com/sandeepmistry/ArduinoCore-samd
2 parents 20104a6 + a2949d5 commit f763660

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

cores/arduino/SERCOM.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -483,8 +483,8 @@ bool SERCOM::startTransmissionWIRE(uint8_t address, SercomWireReadWriteFlag flag
483483
// 7-bits address + 1-bits R/W
484484
address = (address << 0x1ul) | flag;
485485

486-
// Wait idle bus mode
487-
while ( !isBusIdleWIRE() );
486+
// Wait idle or owner bus mode
487+
while ( !isBusIdleWIRE() && !isBusOwnerWIRE() );
488488

489489
// Send start and address
490490
sercom->I2CM.ADDR.bit.ADDR = address;
@@ -578,6 +578,11 @@ bool SERCOM::isBusIdleWIRE( void )
578578
return sercom->I2CM.STATUS.bit.BUSSTATE == WIRE_IDLE_STATE;
579579
}
580580

581+
bool SERCOM::isBusOwnerWIRE( void )
582+
{
583+
return sercom->I2CM.STATUS.bit.BUSSTATE == WIRE_OWNER_STATE;
584+
}
585+
581586
bool SERCOM::isDataReadyWIRE( void )
582587
{
583588
return sercom->I2CS.INTFLAG.bit.DRDY;

cores/arduino/SERCOM.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ class SERCOM
198198
bool isMasterWIRE( void ) ;
199199
bool isSlaveWIRE( void ) ;
200200
bool isBusIdleWIRE( void ) ;
201+
bool isBusOwnerWIRE( void ) ;
201202
bool isDataReadyWIRE( void ) ;
202203
bool isStopDetectedWIRE( void ) ;
203204
bool isRestartDetectedWIRE( void ) ;

libraries/Wire/Wire.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,11 @@ uint8_t TwoWire::requestFrom(uint8_t address, size_t quantity, bool stopBit)
8585
}
8686
sercom->prepareNackBitWIRE(); // Prepare NACK to stop slave transmission
8787
//sercom->readDataWIRE(); // Clear data register to send NACK
88-
sercom->prepareCommandBitsWire(WIRE_MASTER_ACT_STOP); // Send Stop
88+
89+
if (stopBit)
90+
{
91+
sercom->prepareCommandBitsWire(WIRE_MASTER_ACT_STOP); // Send Stop
92+
}
8993
}
9094

9195
return byteRead;
@@ -131,7 +135,11 @@ uint8_t TwoWire::endTransmission(bool stopBit)
131135
return 3 ; // Nack or error
132136
}
133137
}
134-
sercom->prepareCommandBitsWire(WIRE_MASTER_ACT_STOP);
138+
139+
if (stopBit)
140+
{
141+
sercom->prepareCommandBitsWire(WIRE_MASTER_ACT_STOP);
142+
}
135143

136144
return 0;
137145
}

0 commit comments

Comments
 (0)