dxpwny
Advanced Member level 4
My question concerns the i2c protocol. I am using two microcontrollers, one is always the master, one always the slave. There is no i2c peripheral involved, just my two microcontrollers. I am familiar with the master/slave concept and the use of the read/write bit, etc. So, my description below is a bit simplified.
When a master initiates a read operation, is it possible for the slave to determine the number of bytes that it will transfer ?
In all the i2c projects I've done, the master reads a predetermined number of bytes from the slave. In my current project, it is conceivable that the slave may have a variable number of bytes available for reading.
When the master performs the read operation, I need the slave to send all of the data - however, its length may vary from one read to the next.
My understanding of the i2c protocol tells me that the only way for me to do this is to have the master perform an initial read operation, and the slave would always reply with one (or two) bytes which indicates how many bytes it has. Then the master would initiate a second read of exactly that number of bytes.
In other words, the master would send the slave address, and a "register address". The slave, knowing that that specific "register address" is being read, would respond with the number of bytes it has. Then the master would initiate a second read operation, sending the slave address, then a different "register address". The Slave then outputs the data as the master clocks it out, the master terminating the transfer after the count is reached.
Is that the only way to handle a slave which may only have a variable number of bytes available ?
When a master initiates a read operation, is it possible for the slave to determine the number of bytes that it will transfer ?
In all the i2c projects I've done, the master reads a predetermined number of bytes from the slave. In my current project, it is conceivable that the slave may have a variable number of bytes available for reading.
When the master performs the read operation, I need the slave to send all of the data - however, its length may vary from one read to the next.
My understanding of the i2c protocol tells me that the only way for me to do this is to have the master perform an initial read operation, and the slave would always reply with one (or two) bytes which indicates how many bytes it has. Then the master would initiate a second read of exactly that number of bytes.
In other words, the master would send the slave address, and a "register address". The slave, knowing that that specific "register address" is being read, would respond with the number of bytes it has. Then the master would initiate a second read operation, sending the slave address, then a different "register address". The Slave then outputs the data as the master clocks it out, the master terminating the transfer after the count is reached.
Is that the only way to handle a slave which may only have a variable number of bytes available ?