Page 1 of 1

Notes on I2C protocol (Relay Expansion)

Posted: Sat May 04, 2019 5:47 pm
by conklech
Here are a few observations that may be helpful to anyone trying to interface with the Relay Expansion over I2C without using the main RA controller:
  • You can control the Relay Expansion over I2C using the protocol you'll find in Relay.cpp, but there are a few caveats that aren't documented in the source code.
  • The pinning of the USB connector is: Pin 1 (VBUS) +5V; Pin 2 (D-) SDA; Pin 3 (D+) SCL; Pin 4: GND. By the way, this is not the recommended pinning for I2C over USB; see page 28 of the I2C bible: https://www.nxp.com/docs/en/application-note/AN255.pdf. (Remove space in URL, because phpBB.)
  • If you're using a logic level shifter like the PCA9508 in the RA, don't use 10k pull-up resistors like the datasheet shows (and the RA uses); that's too high for a relatively high-capacitance bus like a USB cable. Texas Instruments has a nice document on computing the correct pull-up resistor value: http://www.ti.com/lit/an/slva689/slva689.pdf (Remove space in URL, because phpBB.) At a high level, that suggests that a value around 2k would be the most flexible if the bus capacitance is high, which it likely is. I used an oscilloscope to look at 5V I2C signals from a PCA9508 over a normal USB cable connected the Relay Expansion, and found that the rise time was very long with a 10k pull-up, barely reaching full voltage before the next pulse began. A 4.7k pull-up looked much more like a square wave.
  • I would also recommend trying lower pull-up resistor values for people having bus lock issues with the Reef Angel itself, although refitting a Reef Angel with a different resistor would be a little bit tricky. You could maybe bodge something on to the USB port itself. You don't have to remove the existing pull-up; just add resistors between 5V and each of SCL_5_1 and SDA_5_1
  • Speaking of bus lock: The Relay Expansion has its own RANet controller inside it. Roberto posted the source code here: http://forum.reefangel.com/viewtopic.ph ... 1f1#p44743. (Remove space in URL, because phpBB.) When the expansion turns on, the RANet controller first determines whether the USB (I2C) cable is connected. It does this the same way the RA detects bus lock: by seeing whether it can communicate with the real-time clock module inside the RA controller, which has I2C address 0x68. If there isn't an I2C slave on address 0x68, the RANet module in the expansion will act as an I2C master on its own and will send its own control messages every few seconds, overriding all the ports to whatever it thinks are their fallback states. If you're implementing your own controller, this is not helpful. You'll need to have an I2C slave on the bus with address 0x68. You may be able to do this in your own microcontroller. If you have an unlimited budget, you could just include the same RTC that the Reef Angel uses, the DS3231 from Maxim Integrated, but it's like a $7 part, which is probably almost as much as your microcontroller costs. You could also just open up the relay box and remove the RANet module, which is probably what I'll do for my personal use.
  • Your attempt to control the Relay Expansion will fail unless you deal with the previous bullet, so go back and read that if you got bored and skipped it.

Re: Notes on I2C protocol (Relay Expansion)

Posted: Tue Nov 05, 2019 3:17 pm
by Piper
conklech wrote:
  • I would also recommend trying lower pull-up resistor values for people having bus lock issues with the Reef Angel itself, although refitting a Reef Angel with a different resistor would be a little bit tricky. You could maybe bodge something on to the USB port itself. You don't have to remove the existing pull-up; just add resistors between 5V and each of SCL_5_1 and SDA_5_1
I know this thread is on the older side but maybe you're still hanging around here. Looking at the schematic and board files for the RA*, it looks like the pull-ups for SLC_5_1 and SDA_5_1 are R45C and R45D which appear to be part of a resistor network. As you mentioned, that's not going to be a trivial task to replace. At least not with my coffee hands and bad eyes. Are you saying that if make up some sort of adapter with 4K7 resistors to put between the incoming USB cable for the relay expansion and the RA* that might help with the bus locks? Take a look at the adapter in the attached image.

What did you end up doing on this for your project? Reef Pi? How did that work out for you?

~Charlie