Skip to content

Commit 7a93c00

Browse files
committed
Fix changes requested.
Add to docs for pointing out enabling repeat start.
1 parent 17009ec commit 7a93c00

File tree

4 files changed

+16
-9
lines changed

4 files changed

+16
-9
lines changed

docs/ar_ibus.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ The following is an example of an I2C class in Arduino based on the previous pla
202202
> [!NOTE]
203203
> This class implements a ```isConnected()``` method that calls the ```ping()``` method of the I2C bus class being used, and if this passes, then calls the ```checkDeviceID()``` method of the superclass.
204204
205+
> [!NOTE]
206+
> If your device supports repeated starts, make sure to include ```_theI2CBus.setStop(false)``` in your begin function. Otherwise this can cause issues with your device.
207+
205208
```c++
206209
207210
class myArduinoDriverI2C : public myDriverClass
@@ -214,6 +217,10 @@ class myArduinoDriverI2C : public myDriverClass
214217
{
215218
if (_theI2CBus.init(MY_DEVICE_ADDRESS) != kSTkErrOk)
216219
return false;
220+
221+
// OPTIONAL: If your device supports repeat starts.
222+
_theI2CBus.setStop(false);
223+
217224
setCommunicationBus(&_theI2CBus);
218225
219226
return myDriverClass::begin();

src/sfeTk/sfeTkII2C.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3131
class sfeTkII2C : public sfeTkIBus
3232
{
3333
public:
34-
// set the address to No address and stop flag to false
35-
sfeTkII2C() : _address{kNoAddress}, _stop{false}
34+
// set the address to No address and stop flag to true
35+
sfeTkII2C() : _address{kNoAddress}, _stop{true}
3636
{
3737
}
3838
sfeTkII2C(uint8_t addr) : _address{addr}

src/sfeTkArdI2C.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,10 @@ sfeTkError_t sfeTkArdI2C::readRegisterByte(uint8_t devReg, uint8_t &dataToRead)
183183
nData++;
184184
}
185185

186-
if (nData == 1) // Only update outputPointer if a single byte was returned
186+
if (nData == sizeof(uint8_t)) // Only update outputPointer if a single byte was returned
187187
dataToRead = result;
188188

189-
return (nData == 1 ? kSTkErrOk : kSTkErrFail);
189+
return (nData == sizeof(uint8_t) ? kSTkErrOk : kSTkErrFail);
190190
}
191191
//---------------------------------------------------------------------------------
192192
// readRegisterWord()
@@ -203,7 +203,7 @@ sfeTkError_t sfeTkArdI2C::readRegisterWord(uint8_t devReg, uint16_t &dataToRead)
203203
size_t nRead;
204204
sfeTkError_t retval = readRegisterRegion(devReg, (uint8_t *)&dataToRead, sizeof(uint16_t), nRead);
205205

206-
return (retval == kSTkErrOk && nRead == 2 ? kSTkErrOk : retval);
206+
return (retval == kSTkErrOk && nRead == sizeof(uint16_t) ? kSTkErrOk : retval);
207207
}
208208

209209
//---------------------------------------------------------------------------------

src/sfeTkArdSPI.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,17 +179,17 @@ sfeTkError_t sfeTkArdSPI::writeRegisterRegion(uint8_t devReg, const uint8_t *dat
179179
sfeTkError_t sfeTkArdSPI::readRegisterByte(uint8_t devReg, uint8_t &data)
180180
{
181181
size_t nRead;
182-
sfeTkError_t retval = readRegisterRegion(devReg, (uint8_t *)&data, sizeof(data), nRead);
182+
sfeTkError_t retval = readRegisterRegion(devReg, (uint8_t *)&data, sizeof(uint8_t), nRead);
183183

184-
return (retval == kSTkErrOk && nRead == sizeof(data) ? kSTkErrOk : retval);
184+
return (retval == kSTkErrOk && nRead == sizeof(uint8_t) ? kSTkErrOk : retval);
185185
}
186186

187187
sfeTkError_t sfeTkArdSPI::readRegisterWord(uint8_t devReg, uint16_t &data)
188188
{
189189
size_t nRead;
190-
sfeTkError_t retval = readRegisterRegion(devReg, (uint8_t *)&data, sizeof(data), nRead);
190+
sfeTkError_t retval = readRegisterRegion(devReg, (uint8_t *)&data, sizeof(uint16_t), nRead);
191191

192-
return (retval == kSTkErrOk && nRead == sizeof(data) ? kSTkErrOk : retval);
192+
return (retval == kSTkErrOk && nRead == sizeof(uint16_t) ? kSTkErrOk : retval);
193193
}
194194
//---------------------------------------------------------------------------------
195195
// readRegisterRegion()

0 commit comments

Comments
 (0)