I have an I2C master (K22) and a slave (KL03). The master reads the slave from time to time, but the slave should send variable-length messages based on the circumstances.
I plan to implement this by making the master read the maximum number of bytes and then making the slave send potentially smaller messages by NACKing the transfer after the last byte of the message. For example, master tries to read 255 bytes, but the slave only wants to send 5 bytes, so it NACKs the transfer after the 5th byte.
Should the above work given the capabilities of the I2C protocol? If not, would you recommend an alternative solution?
(Please don't advise that I should just pad the unused bytes because I want to make the protocol as efficient as possible.)