Skip to content
Snippets Groups Projects
Commit d7e4f8ca authored by Gijs Schoonderbeek's avatar Gijs Schoonderbeek
Browse files

Added support for multiple I2C busses on the CM4

parent 98c0bbdd
No related branches found
No related tags found
1 merge request!2Modified the scripts to run on Raspberry Pi.
......@@ -19,6 +19,7 @@ class I2C:
def __init__(self, ADDRESS='040'):
self.I2C_Address = ADDRESS
self.BUS_NR = 1 # not used for Laptop but to enable Pi multiple busses.
# def chk_ack(self):
......
......@@ -23,14 +23,13 @@ import sys
from time import *
DEBUG=False
BUS_NR = 1
class I2C:
def __init__(self, ADDRESS='040'):
self.I2C_Address = ADDRESS
bus = smbus.SMBus(BUS_NR)
self.BUS_NR = 1
bus = smbus.SMBus(self.BUS_NR)
def read_bytes(self, register, bytes_to_read=2):
......
......@@ -20,9 +20,11 @@ sys.path.insert(0,'.')
import os
if os.name =="posix":
from I2C_serial_pi import *
else:
from I2C_serial import *
I2CBUSNR=1
sleep_time=0.05
WRITE_DATA = True
READ_BYTE = True
......@@ -40,6 +42,7 @@ def Read_byte_ADC(ADC_reg_address, ADC_bytes=0, ADC_NR = 0, ADDRESS=0x20 ):
# Read Byte from the ADC
#
I2C_device = I2C(ADDRESS)
I2C_device.bus = I2CBUSNR
ADC_rw = 0x01 # 0 for write, 1 for read
stri = "Read ADC from Address {:8x}".format(ADC_reg_address)
......
......@@ -23,6 +23,7 @@ if os.name =="posix":
else:
from I2C_serial import *
I2CBUSNR=1
sleep_time=0.05
PWR_RST = False
SET_PLL = True
......@@ -42,6 +43,7 @@ def Write_byte_PLL(reg_address, wr_data, ADDRESS=0x20):
# Write Byte to the ADC
#
I2C_device = I2C(ADDRESS)
I2C_device.bus = I2CBUSNR
PLL_rw = 0x00 # 0 for write, 1 for read
stri = "Write : 0x{0:{fill}2x} to Address : 0x{1:{fill}2x}".format(wr_data, reg_address, fill='0')
print(stri)
......@@ -69,6 +71,7 @@ def Read_byte_PLL(reg_address, nof_bytes=1, ADDRESS=0x20 ):
# Read Byte from the ADC
#
I2C_device = I2C(ADDRESS)
I2C_device.bus = I2CBUSNR
PLL_rw = 0x01 # 0 for write, 1 for read
I2C_device.write_bytes(0x06, 0x2C)
......@@ -105,6 +108,7 @@ def Read_byte_PLL(reg_address, nof_bytes=1, ADDRESS=0x20 ):
def power(state):
ADDRESS_IO = 0x20
I2C_IO_device = I2C(ADDRESS_IO)
I2C_device.bus = I2CBUSNR
I2C_IO_device.write_bytes(0x06, 0x2C)
I2C_IO_device.write_bytes(0x07, 00)
if state:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment