Go Down

Topic: TWI/I2C address verification (Read 127 times) previous topic - next topic

DKWatson

Not sure if this is the correct forum or should be in programming. Try here first so as to not cross post.

Setting device as TWI slave and enabling TWGCE means that the slave receives messages posted to its ID as well as any General Call message. My question, is there any way of knowing whether the received message was one or the other?

I want my slaves to have a priority in responding to a general call and not reply immediately in lieu of a response from a higher prioritized unit.

dkw
Don't tell me it can't be done. Come up with ideas as to how we're going to do it!

chucktodd

#1
Oct 12, 2017, 04:16 am Last Edit: Oct 12, 2017, 04:22 am by chucktodd Reason: more
Not sure if this is the correct forum or should be in programming. Try here first so as to not cross post.

Setting device as TWI slave and enabling TWGCE means that the slave receives messages posted to its ID as well as any General Call message. My question, is there any way of knowing whether the received message was one or the other?

I want my slaves to have a priority in responding to a general call and not reply immediately in lieu of a response from a higher prioritized unit.

dkw
To utilize General Call YOU are going to have to modify Wire.h library.  Currently it does differentiate General Call and Slave Address data.

Look at ISR(TWI_vect) in C:\Program Files\Arduino\hardware\arduino\avr\libraries\Wire\src\utility\twi.c

TW_SR_DATA_ACK, TW_SR_GCALL_DATA_ACK  are combined into the same Switch() case.  You will have to modify it to either support a different event callback or something.


Chuck.
Currently building mega http server 90% done, the Last 10% is killing me.

DKWatson

Thanks Chuck. I decided to packetize the data and then use the dest_addr to differentiate. In the end I've tossed TWI/I2C in favour of RS485. Too much susceptibility to noise with the former. In any event, need to plan for longer distances than a meter.

Wrote a peer-to-peer protocol with CRC and ACK/NAK that works real well. It's on my GitHub page if anybody is interested.
Don't tell me it can't be done. Come up with ideas as to how we're going to do it!

Go Up