It's not often I ask a question. This one has me a little stumped though.
Scenario:
I have an 328PB (internal 8mhz), it speaks to a multiplexer on Wire1 (the PB's second IC2 - Minicore lib). The multiplexer speaks to many sensors. That is all working just fine.
I have a logic analyser hooked up to the key points so I can see what is going on.
I have a Nano (external 16mhz) hooked up to Wire (the PB's first I2C), it sends a master request.
The PB is master on Wire1 and slave on Wire.
For some reason the Nano's request on (address 8) is acknowledged by the PB but then the subsequent reads deliver a zero byte and an NACK.
I'm just asking for one byte to troubleshoot. Previous attempts at multiple bytes would deliver the expected bytes but all of them zero.
Strange thing I'm seeing on the logic analyser is that the PB to Multiplexer communication seems to be slower than the Nano to PB (much slower).
I've looked through the libraries and both Wire and Wire1 seem to calculate the speed down to 100khz. I'm using the standard Arduino Wire on the Nano. Given that the initial Address comms gets an ACK. I'm stumped why the subsequent read gets zero and a NACK.
Any help to restore my sanity is much appreciated.
Chances are I'm having a dumb moment. My suspicions are that the clock differences are to blame (but logically they shouldn't be).
Edit:
This is the analyser recording. The dodgy byte is highlighted in Blue.
The communication from the Atmega328pb to the multiplexer and then on to the temperature sensor is working fine. Not all of the multiplexer channels have sensors at the moment hence the NACKs but you can see success on channel 1 to the right of the screenshot. The Nano to Atmega328pb communication starts off good but I'm expecting to see 0X41 in the blue box not 0x00.
This is going to end up being something simple, I'm going to kick myself.
Nano code:
#include <Wire.h>
void setup() {
Wire.begin();
Serial.begin(9600); // start serial for output.
}
void loop() {
Wire.requestFrom(8, 1); // request 1 byte from slave device #8
char c = Wire.read(); // receive a byte as character
Serial.print("The character: ");
Serial.println(c); // print the character
delay(1000);
}
Atmega328pb requestEvent code:
void requestEvent() {
Wire.write("A");
}
Edit:
There are other wires for programming etc, but they are disconnected during test.
Edit: I commented out all the usage of Wire1 in the PB code. And the result was that the Nano got it's byte. I wove the usage of Wire1 back into the code. Right up until it was actually active i.e. communicating with the multiplexer. At that point the Nano started getting a zero byte again.
It seems to be when they are both active. Which suggests it is something in the Wire/Wire1 library by Minicore.
I suspect there is something in the registers but scanning the datasheet for the PB is not yielding any insights. Except for this:
26.1 - Device can Operate as Transmitter or Receiver
There is no elaboration in the document that I can see.
I've tried staggering the communication so that neither is active at the same time. Still the same result.
Still hoping that someone here has the answer ;-)