Uncategorized

i2c references

i2c references

Activating the second I2C bus on Raspberry Pi from Python – Sebastian Ludwig 2014oct9
https://procrastinative.ninja/2014/10/29/activating-the-second-i2c-bus-on-raspberry-pi-from-python/

Using the 2nd I2C bus [ONLY] on the 2B v1.1 – HenriZ 2016feb28
https://raspberrypi.stackexchange.com/questions?sort=newest

How to get the second Raspberry Pi I2C bus to work – Chris Jones 2014aug24
How to get the second Raspberry Pi I2C bus to work

Raspberry Pi CSI-2 Connector Specifications
https://www.petervis.com/Raspberry_PI/Raspberry_Pi_CSI/Raspberry_Pi_CSI-2_Connector_Specifications.html

https://www.petervis.com/Raspberry_PI/Raspberry_Pi_CSI/Raspberry_Pi_CSI_Camera_Interface.html
https://www.petervis.com/Raspberry_PI/Raspberry_Pi_CSI/raspberry-pi-csi-interface-connector-pinout.html
https://www.petervis.com/Raspberry_PI/Raspberry_Pi_CSI/Raspberry_Pi_CSI_Camera_Module.html


Activating the second I2C bus on Raspberry Pi from Python – Sebastian Ludwig 2014oct9
https://procrastinative.ninja/2014/10/29/activating-the-second-i2c-bus-on-raspberry-pi-from-python/

Using the 2nd I2C bus [ONLY] on the 2B v1.1 – HenriZ 2016feb28
https://www.raspberrypi.org/forums/viewtopic.php?t=137848#p914965

How to get the second Raspberry Pi I2C bus to work – Chris Jones 2014aug24
How to get the second Raspberry Pi I2C bus to work

Raspberry Pi CSI-2 Connector Specifications
https://www.petervis.com/Raspberry_PI/Raspberry_Pi_CSI/Raspberry_Pi_CSI-2_Connector_Specifications.html

https://www.petervis.com/Raspberry_PI/Raspberry_Pi_CSI/Raspberry_Pi_CSI_Camera_Interface.html
https://www.petervis.com/Raspberry_PI/Raspberry_Pi_CSI/raspberry-pi-csi-interface-connector-pinout.html
https://www.petervis.com/Raspberry_PI/Raspberry_Pi_CSI/Raspberry_Pi_CSI_Camera_Module.html

Re: Enable both I2C Busses – srod
https://www.raspberrypi.org/forums/viewtopic.php?f=44&t=33092&p=287100#p286781

SCL0 [BCM2835/GPIO1] routed to S5 pin 13
SDA0 [BCM2835/GPIO0] routed to S5 pin 14
SCL1 [BCM2835/GPIO3] routed to P1 pin 5
SDA1 [BCM2835/GPIO2] routed to P1 pin 3

Rpi Schematic 2012oct18
https://www.raspberrypi.org/app/uploads/2012/10/Raspberry-Pi-R2.0-Schematics-Issue2.2_027.pdf

I soldered 2 small flying leads onto pins 13/14 of S5, connected to my device and i2cdetect -y 0 works first time.
I arrived at the same point late last night. Probing S5 with a scope.

I agree that it must be related to setting the alternate function for GPIO28 and 29 to get i2c on P5.
It might be necessary to disable the alternate function for GPIO0 and 1, making it impossible to use whatever connects to S5, think it’s the camera. For me this is not a problem since I don’t need it.

Re: Enable both I2C Busses Wed Feb 13, 2013 7:58 pm
https://www.raspberrypi.org/forums/viewtopic.php?f=44&t=33092&p=287100#p287100

#!/usr/bin/env python
#
# W. Greathouse 13-Feb-2013
#
# Enable I2C on P1 and P5 (Rev 2 boards only)
#

# #######
# For I2C configuration test
import os
import mmap

BCM2708_PERI_BASE=0x20000000
GPIO_BASE=(BCM2708_PERI_BASE + 0x00200000)
BLOCK_SIZE=4096

def _strto32bit_(str):
return ((ord(str[3])<<24) + (ord(str[2])<<16) + (ord(str[1])<<8) + ord(str[0]))

def _32bittostr_(val):
return chr(val&0xff) + chr((val>>8)&0xff) + chr((val>>16)&0xff) + chr((val>>24)&0xff)

def get_revision():
with open(‘/proc/cpuinfo’) as lines:
for line in lines:
if line.startswith(‘Revision’):
return int(line.strip()[-4:],16)
raise RuntimeError(‘No revision found.’)

def i2cConfig():
if get_revision() <= 3:
print “Rev 2 or greater Raspberry Pi required.”
return
# Use /dev/mem to gain access to peripheral registers
mf=os.open(“/dev/mem”, os.O_RDWR|os.O_SYNC)
m = mmap.mmap(mf,BLOCK_SIZE, mmap.MAP_SHARED,
mmap.PROT_READ|mmap.PROT_WRITE,offset=GPIO_BASE)
# can close the file after we have mmap
os.close(mf)
# Read function select registers
# GPFSEL0 — GPIO 0,1 I2C0 GPIO 2,3 I2C1
m.seek(0)
reg0=_strto32bit_(m.read(4))
# GPFSEL2 — GPIO 28,29 I2C0
m.seek(8)
reg2=_strto32bit_(m.read(4))
# print bin(reg0)[2:].zfill(32)[2:]
# print bin(reg2)[2:].zfill(32)[2:]

# GPFSEL0 bits –> x[26] SCL0[3] SDA0[3]
# GPIO GPIO
m0 = 0b00000000000000000000111111111111
s0 = 0b00000000000000000000100100000000
b0 = reg0 & m0
if b0 <> s0:
print “reg0 I2C configuration not correct. Updating.”
reg0 = (reg0 & ~m0) | s0
m.seek(0)
m.write(_32bittostr_(reg0))

# GPFSEL2 bits –> x[2] SCL0[3] SDA0[3] x[24]
m2 = 0b00111111000000000000000000000000
s2 = 0b00100100000000000000000000000000
b2 = reg2 & m2
if b2 <> s2:
print “reg2 I2C configuration not correct. Updating.”
reg2 = (reg2 & ~m2) | s2
m.seek(8)
m.write(_32bittostr_(reg2))

# No longer need the mmap
m.close()

if __name__ == ‘__main__’:
i2cConfig()

.END

 

Categories: Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s