most of those questions are answered above:
1 master is some other electronics, controller is not relevant , but ARM based.
2: the Nano (328P) is supposed to behave as a slave.
3: I2C
4: 0x0B
5: the master (beyond my control) sends a Write to 0x0B with a command as the second byte. The Slave (Arduino) must respond to word/block request by sending Read 0x0B and the rest of the response depends on the command byte - response is 4--12 bytes including 8-bitCRC.
6: see above
7: no special handshake, normal 7-bit I2C
my testcode now is something like:
uint8_t req;
bool requested=false;
#include <Wire.h>
void setup()
{
Wire.begin(0x0B);
Wire.onRequest(requestEvent);
Wire.onReceive(receiveEvent);
}
void loop() { delay (10); }
void receiveEvent(int howMany)
{
int x = Wire.read(); // receive command byte
if (x == 0x28) { prepare28(); requested=true; }
if (x == 0x29) { prepare29(); requested=true; }
}
void requestEvent()
{
if (requested == true) {
Wire.write(Buffer, Buff_p); //write data response for the recieived command
requested = false;
}
}
The challenges are:
1: whenever I register Arduino as slave, ( Wire.begin(0x0B); ) it will automatically respond to any request, if the buffer is not filled yet, the Wire.onRequest(requestEvent); Wire.onReceive(receiveEvent); are commented out, there is NO expectation of anything working... yet see screenshot "slave nothing more".
Ardunio will respond with some garbage or empty buffer anytime once registered as slave.
2: if I uncomment the two Wire.onRe* lines, and have no handling for command 0x90 , yep, Arduino will still respond to 0x90.
3: this ... is so far not the main issue that prevents me from emulating the I2C slave I emulate.. what is worse, is that the resonse have no option to inter-byte delay (the unmodified device waits 0.1ms ) between bytes, I suspect that the fact Arduino responds "instantly" may be causing some of the strange dropouts.
In other words : I wish for more granular I2C interaction. I imagine this is somehow achievable:
on master Write master contacts slave, a function is called, I check the command, then I am free to send bytes in response at the desired rate (with delay, if needed).
4: I do not understand why it seems to be necessary to use the "requested" flag.