There are human beings behind the development of the Wire.requestFrom(deviceaddress, 7) method; unfortunately, they have not prepared detailed Technical Manual describing the functional/design anatomy of the method; as a result, a curious mind desires to proceed as per following critical thinking (Platform: UNO and 24C512 EEPROM, Fig-1) to formulate the functional mechanism of the requestFrom() function.
Figure-1: TWI Bus connection between Arduino UNO and 24C512 EEPROM
1. Assume that the Master wishes to read 7-byte data from 24C512 EEPROM starting at location 0x1000. Also, assume that the base address has been successfully set by executing the following instructions:
//----- put eeprom address = 0x1000
Wire.beginTransmission(0B1010010); //EEPROM deviceaddress
Wire.write((int)(eelocaddress >> 8)); // MSB
Wire.write((int)(eelocaddress & 0xFF)); // LSB
byte sts = Wire.endTransmission();
if (ss != 0x00)
return; //transmission is not successful
2. Master generates 8 SCL pulses (Fig-2); 8-data bits from current EEPROM location enters into Data Register (TWDR) of Master. After releasing 8 data bits and at the end of 8th SCL pulse, the Slave releases the SDA line which, by virtue of pull-up resistor, assumes H-state.
Figure-2: Diagram depicting the BusEvents of TWI Bus Transmission(data reception from Slave)
3. Master generates 9th SCL pulse during which Master creates ACK signal by pulsating the SDA line (LH ---> LL ---> LH). This ACK signal works as a supplementary clock which advances the Address Counter of the EPROM to 0x1001, generates a known valued status word (0x50 for ACK) within Status Register (TWSR) of the Master, and triggers the TWI Logic of the Master to generate the next set of SCL pulses for reading the data of the EEPROM location 0x1001. The user increments the byteCounter.
4. Assume that there has happened two successful Transmissions. The user program has removed the data bytes from TWDR register into a pre-declared buffer (the dataArray). Now, we have the following situations:
byteCounter = 0x02
Address Counter = 0x1002;
dataArray, dataArray are filled up locations.
5. The 3rd Transmission has begun. The Master has generated 8 SCL pulses; 8-bit data of EEPROM location 0x1002 has entered into TWDR. At the end of 8th SCL pulse, something has gone wrong within the TWI Logic of the Slave; the Slave could not release the SDA line to H-state or the SDA line is permanently stuck at H-state. The following events are expected to occur:
a. The Master can not create the ACK pulse by pulsating the SDA line (LH ---> LL ---> LH); instead, there appears a NACK signal to the TWI Logic of the Master.
b. The user does not increment the byteCounter; he does not move data from TWDR into dataArray. The Address Counter is not advanced. The status word (0x58 for NACK) is generated within TWSR Register of the Master instead of 0x50 for ACK.
c. The Intellect of ATmega328 finds status word 0x58 and understands that there is no need to generate anymore SCL pulses; it terminates the communication session and makes a safe return to the Control Program.
6. I ask questions to myself:
a. What value would Wire.requestFrom() return? Ans: 2.
b. What value would Wire.available() return? Ans: I am not sure?
c. How many data bytes are there for the user to process? Ans: 2.
d. What is the actual benefit of incorporating the Wire.available() function in the TWI Protocol?Ans: I am not sure!
e. Is it possible to frame the above critical thinking into an experimental setup? Ans: It can be tried!