Thanks for listing out the problems you see. I hope I am able to clarify some things.
Do you use SoftWire by Steve Marple from the Library Manager ?
No. I was using SoftI2CMaster with the Wire wrapper by Bernhard Nebel and Peter Fleury. I chose this one because the previous operation of the Command board used it to communicate with a sensor. I can take a look at Steve Marple's library and see if that behaves better or is easier to debug.
When connecting a 3.3V I2C bus to a 5V I2C bus, there is a voltage mismatch and you might expect troubles.
Correct, but there is a hardware level shifter. I have a PCA9517 between the different voltage devices. Currently, there are 4.7k pull ups on the 5V side and 3.3k pull ups on the 3.3V side. I apologize for breaking this into a new forum topic (which is apparently frowned upon at this forum), as the level shifting and resistors are discussed in the original thread.
While level shifters are not ideal (as you note in your write-up), this setup has been used before to communicate between the Command board and a 5V sensor board.
you use a software I2C library
Why do you use a software I2C library ? Is there a good reason for that ?
Yes. I do not have access to the standard Arduino ports for I2C/Serial comms on the Command board. Using a default Arduino is not appropriate to the application of the project for various reasons not worth discussing here.
a sketch that is too complex
you create a full Serial TX buffer in the Slave (which is bad)
What is bad about this? Can you provide more info? Should I not be using a struct/buffer to hold the data which are communicated between the two units?
there is no STOP condition in the function issue_cmd()
I'm confused by this. This is not a
requestFrom command, but sending a package to the peripheral. It is terminated by
some variables should be 'volatile'
using a 16-bit integer on a 8-bit microcontroller in a interrupt is not fail-safe
Are we talking about the
HAVE_REQ counters? Those are only there for quick debugging/demonstration, but they can be made
volatile uint8_t easily enough.
Did you connect the grounds ?
Bonus info: the SCL and SDA are separated by a ground wire, not next to each other.
Did you read my opinion that the I2C bus is not the best solution between Arduino boards and that a voltage mismatch on the I2C bus can not be ignored and Arduino in Slave mode requires knowledge about clean programming ?
Of course. The voltage mismatch would be something I'd love to ignore, but I know I can't! The "clean programming" is a challenge and kinda vague. I am hacking my way through this and learning as I go. Learning what counts as "clean" has to come from "dirty" failure.
I am very fond of the LHT00SU1 logic analyzer in combination with Sigrok/PulseView. It can decode Serial/UART and I2C data.
Thanks for the suggestion. That seems very similar to what I used in my last lab, but I don't have one at my home lab.