Closed IW3IJQ closed 4 years ago
@thexeno - Any forecast for implementing this enhancement?
Hi, I got out of the project for a while and I hope you all solved in the meantime. I am doing some polishing on other libraries as well, hence also this one.
Regarding the proposal, the TWAMR will just set an overset of addresses, by making a don't care of individual bits. This means, for example, that if Address1 is 0b1010101x and Address2 0b0101010x, where x is R/W bit, doing the Address1 ^ Address2 will provide a TWAMR = 0xFF and hence matching any address, not only these two. That is why I did not implement it, as I guessed it was misunderstood.
If you need such function, you have to check for the Xmega (or similar) which has a mode called "promiscuous mode", allowing you to select individual independent addresses, but I never tried it.
In the Mega AVRs, the TWAR will do something like this -> adx1 = 0b1010011(R/W), adx2 = 0b0010011(R/W), then the TWAMR = 0b10000000, setting the TWAR = 0b00100110 allows the AVR to respond to both adx1 and adx2. So I think it can be seen as a way to exclude some bits from the TWAR from the evaluation, making them always valid. For each bit set in the TWAMR, the addresses which are acknowledged will increase by the exponent of 2. Hence, is more (or less?) than just selecting 2 addresses. Please, correct me where/if I am wrong.
Given this, I am going to put support for the TWAMR functionality, and the twi_onSlaveReceiveAddress() can be used to read the address which the slave has been addressed to, but one must put care on the additional timing involved. I am open to alternatives and, up to a different proposal, I will implement in this way soon... and not after 2 years :)
Cheers!
Done, thank you!
I will try, thank you! :-)
Here my patch to original Wire library. The patch permit to listen to multiple address in slave mode using ATMega TWAMR. onReceive and onRequest events reports the slave address, so I can do different thing depending on the address.
Example Init:
Wire.begin(address1); SlaveAddress1 = (address1<<1); SlaveAddress2 = (address2<<1); TWAMR = SlaveAddress1 ^ SlaveAddress2;
The patch is attached. (It isn't so elegant... but works...)
TWAMR.patch.TXT