Hey Guys,
Quick question regarding the I2C Slave library that was not immediately apparent. I understand that the receive method returns a status to check regarding if there is a read/write request from the master. I would like to set up my slave program to have multiple readable and writable registers like most slave devices. I have not, however, seen a way to get the data address that the master is trying to access.
Ex. My device address is 0x10 and should implement the following table:
Name | Permissions | Data Address | Read Response | Write Action |
Whoami | R | 0x00 | Device ID | N/A |
Control1 | RW | 0x01 | Actual Value | Set Setpoint |
Control2 | RW | 0x02 | Actual Value | Set Setpoint |
Sensor | R | 0x03 | Sensor Data | N/A |
So, in this case, the program pattern should go something like:
...
int i = slave.receive();
switch(i) {
case I2CSlave::ReadAddressed:
//SOMEHOW GET THE DATA ADDRESS
//STORE IN SOME VARIABLE v
switch(v) {
case 0x00: //This is the whoami register, return device id
buf[0] = 0x10;
slave.write(buf,1);
break;
...
}
break;
...
}
...
Can anyone point me in the right diection?
Hey Guys,
Quick question regarding the I2C Slave library that was not immediately apparent. I understand that the receive method returns a status to check regarding if there is a read/write request from the master. I would like to set up my slave program to have multiple readable and writable registers like most slave devices. I have not, however, seen a way to get the data address that the master is trying to access.
Ex. My device address is 0x10 and should implement the following table:
So, in this case, the program pattern should go something like:
Can anyone point me in the right diection?