I am using the jdy-16 bluetooth module and I am having a hard time interacting with it over I2C. According to the datasheet (see below), the procedure for reading from the device is to :
write the device address
write the desired register address (“internal function address” in the datasheet)
read the desire register value
(data follows from device to microcontroller - “Data N” in the datasheet)
The problem is between steps 2 and 3. The actual reading is implemented as Wire.requestFrom(deviceAddress, numberOfBytes). Which puts the device address again on the bus, contradicting the datasheet.
… or perhaps there is a way to publicly inherit from Wire and override the requestFrom() method? - I have tried but am getting compile errors within the Wire header.
That looks like a pretty standard I2C protocol transaction.
Do a Wire.beginTransmission(deviceAddr)
Do a Wire.write(internalFunctionAddr) then Wire.endTransmission(false). The false is necessary so the stop is not sent so you can do the read next.
3/4: Do a Wire.requestFrom(deviceAddr, quantity)
There is a second address sent after Internal Function Address, as is typical for I2C. Just make sure you endTransmission(false) otherwise there will be a stop and the transaction will be wrong.
That’s what I thought. Yet the module isn’t sending anything back. After debugging the for a couple of hours, I came up with the code below. The problem I suspect, is that the module expects an I2C read immediately after the master wrote the register address. At least it’s the way I interpret the snippet in the datasheet. A DSO probing session reveals that requestFrom puts the module’s address again on the bus (screenshot below).