I have an arduino acting as I2C master that is sending messages to a slave arduino that is controlling a large led matrix.
The slave arduino is taking the text passed to it and printing it on the matrix (it is a 24x16 led matrix with an HT1623 controller)
The issue is that when the slave is writing to the screen it takes some time to shift out all the data and it shouldn't be interrupted with a subsequent screen write until it is finished.
I either need to queue incoming messages or have the master wait until the slave is done.
This is where I am not sure what the standard procedure would be.
First of all, the Wire.onReceive(handler) is this an interrupt driven event via the built in I2C hardware?
If so then I assume it is interrupting the screen writing functions.
In my handler routine I have the code to read the incoming messages from the master and then call a screen writing function to display the text it has just received in the message.
My current solution is as follows:
I have the master run a loop where it requests one byte from the
slave every 1ms before it intends to send a new message to print some text. Each time the slave device receives the request, the handler checks a global variable called "busy" to see if is set to 1 or 0. When the slave returns a value of !busy then the master knows it is safe to send a new write text message.
In order for this to work, the slaves Wire.onReceive handler has to set the busy flag to 1 before calling the write_text function and then sets it back to 0 after the function.
I assume this is a bad solution because it makes the Master wait all the time for the slave to finish things. From what I understand, the Wire.onReceive or any interrupt handler for that matter should be doing as little as possible. I assume it would be better for it to just set some sort of flag and pass the message data to the main loop of the slave so that it can better control the functions.
any tips?