SparkFun Forums 

Where electronics enthusiasts find answers.

Have questions about a SparkFun product or board? This is the place to be.
By Pi Flyer
#195812
I'm looking for some guidance on something that is tripping me up while attempting to set the Si4703 to 2-wire mode (i2c).

To set the Si4703 to i2c mode, the SDA (SDIO) line must be held low while the reset line is transitioning from a low to high condition.

On the Raspberry Pi, most of the GPIO pins can be setup to have alternative functions...and more specifically in this case, the SDA pin could also be setup as a digital input or output. This is actually good in the case of the Si4703.

However, a problem occurs when using python. Once the SDA pin is configured with RPI.GPIO python module to be a digital output, there seems to be no way to reconfigure it back as SDA. This conflicts with the needs of the Si4703 to be reset into i2c mode, as the SDA line absolutely needs to act as a digital ouput, pulling the line low during reset.

While googling, it appears this didn't use to be a problem (pin acting as digital output and SDA line) with older revisions of the Raspberry Pi, but it certainly is now.

Any help is appreciated...I feel like I'm making this too hard.
By Pi Flyer
#195844
Take a look at the documented code below to see I'm using the python subprocess module to make a call the the WiringPi gpio program to change the pin back to ALT0 mode, or SDA after using it temporarily as a digital output.

This all fits nicely with the Si4703's busmode selection process as described in it's documentation.
Code: Select all
import RPi.GPIO as GPIO
import smbus
import time
import subprocess

# Set the GPIO module to reference BCM pin numbers
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)

# The Rpi-3 has two separate i2c busses, I'm using bus 1, which is
# SDA.1 (BCM pin 2) and SCL.1 (BCM pin 3)
i2c = smbus.SMBus(1)


# Setup BCM pin 5 as digital output, this is the pin I have connected to
# the Si4703 RST (reset) pin, change to match your setup.
GPIO.setup(5, GPIO.OUT)

# Setup BCM pin 2 as digital output, this is the pin I have connected to
# the Si4703 SDIO pin.  BCM pin 2 is set as the i2c SDA line when Raspbian
# boots, however, it needs to temporarily act as digital output to set the
# Si4703 to 2-wire (i2c) mode
GPIO.setup(2, GPIO.OUT)


# The Si4703 requires the following sequence to set it's busmode to 2-wire
# (i2c): Hold the SDIO pin low while the RST pin transitions from low to high
GPIO.output(2, GPIO.LOW) 
time.sleep(.1) #allow pin to settle
GPIO.output(5, GPIO.LOW)
time.sleep(.1)
GPIO.output(5, GPIO.HIGH)
time.sleep(.1)

# Setup BCM pin 2 back to i2c SDA line
# Make use of the subprocess module to execute the gpio program included
# with WiringPi from the Raspbian commandline.
# 'gpio' is the program to be executed, and the rest are options
# '-g' is a flag that causes pin numbers to be interpreted as BCM_GPIO
# 'mode' is the option used to select the mode of the pin
# '2' is the pin to change the mode of, which of course is SDA.1 on BCM
# 'ALT0' is the alternate pin mode code for i2c 
subprocess.check_output(['gpio', '-g', 'mode', '2', 'ALT0'])