Electronics- Serial Communication-I2Cdenethor.wlu.ca/pc320/lectures/i2cbeam.pdfRaspberry Pi Python...

51
Serial Communication -I2C Raspberry Pi Python I2C Library Electronics Serial Communication-I2C Terry Sturtevant Wilfrid Laurier University February 13, 2019 Terry Sturtevant Electronics Serial Communication-I2C

Transcript of Electronics- Serial Communication-I2Cdenethor.wlu.ca/pc320/lectures/i2cbeam.pdfRaspberry Pi Python...

Page 1: Electronics- Serial Communication-I2Cdenethor.wlu.ca/pc320/lectures/i2cbeam.pdfRaspberry Pi Python I2C Library Serial Communication -I2C Inter-Integrated Circuit Interface Master/slave

Serial Communication -I2CRaspberry Pi Python I2C Library

ElectronicsSerial Communication-I2C

Terry Sturtevant

Wilfrid Laurier University

February 13, 2019

Terry Sturtevant Electronics Serial Communication-I2C

Page 2: Electronics- Serial Communication-I2Cdenethor.wlu.ca/pc320/lectures/i2cbeam.pdfRaspberry Pi Python I2C Library Serial Communication -I2C Inter-Integrated Circuit Interface Master/slave

Serial Communication -I2CRaspberry Pi Python I2C Library

Serial Communication -I2C

Inter-Integrated Circuit InterfaceMaster/slave communicationUses 2 signals (and Ground),SDA and SCLMany slaves can be on the same bus since each has an addressDevice addresses are pre-programmed, but can usually bechangedSynchronous, so master controls clock rate

Terry Sturtevant Electronics Serial Communication-I2C

Page 3: Electronics- Serial Communication-I2Cdenethor.wlu.ca/pc320/lectures/i2cbeam.pdfRaspberry Pi Python I2C Library Serial Communication -I2C Inter-Integrated Circuit Interface Master/slave

Serial Communication -I2CRaspberry Pi Python I2C Library

Serial Communication -I2C

Inter-Integrated Circuit Interface

Master/slave communicationUses 2 signals (and Ground),SDA and SCLMany slaves can be on the same bus since each has an addressDevice addresses are pre-programmed, but can usually bechangedSynchronous, so master controls clock rate

Terry Sturtevant Electronics Serial Communication-I2C

Page 4: Electronics- Serial Communication-I2Cdenethor.wlu.ca/pc320/lectures/i2cbeam.pdfRaspberry Pi Python I2C Library Serial Communication -I2C Inter-Integrated Circuit Interface Master/slave

Serial Communication -I2CRaspberry Pi Python I2C Library

Serial Communication -I2C

Inter-Integrated Circuit InterfaceMaster/slave communication

Uses 2 signals (and Ground),SDA and SCLMany slaves can be on the same bus since each has an addressDevice addresses are pre-programmed, but can usually bechangedSynchronous, so master controls clock rate

Terry Sturtevant Electronics Serial Communication-I2C

Page 5: Electronics- Serial Communication-I2Cdenethor.wlu.ca/pc320/lectures/i2cbeam.pdfRaspberry Pi Python I2C Library Serial Communication -I2C Inter-Integrated Circuit Interface Master/slave

Serial Communication -I2CRaspberry Pi Python I2C Library

Serial Communication -I2C

Inter-Integrated Circuit InterfaceMaster/slave communicationUses 2 signals (and Ground),SDA and SCL

Many slaves can be on the same bus since each has an addressDevice addresses are pre-programmed, but can usually bechangedSynchronous, so master controls clock rate

Terry Sturtevant Electronics Serial Communication-I2C

Page 6: Electronics- Serial Communication-I2Cdenethor.wlu.ca/pc320/lectures/i2cbeam.pdfRaspberry Pi Python I2C Library Serial Communication -I2C Inter-Integrated Circuit Interface Master/slave

Serial Communication -I2CRaspberry Pi Python I2C Library

Serial Communication -I2C

Inter-Integrated Circuit InterfaceMaster/slave communicationUses 2 signals (and Ground),SDA and SCLMany slaves can be on the same bus since each has an address

Device addresses are pre-programmed, but can usually bechangedSynchronous, so master controls clock rate

Terry Sturtevant Electronics Serial Communication-I2C

Page 7: Electronics- Serial Communication-I2Cdenethor.wlu.ca/pc320/lectures/i2cbeam.pdfRaspberry Pi Python I2C Library Serial Communication -I2C Inter-Integrated Circuit Interface Master/slave

Serial Communication -I2CRaspberry Pi Python I2C Library

Serial Communication -I2C

Inter-Integrated Circuit InterfaceMaster/slave communicationUses 2 signals (and Ground),SDA and SCLMany slaves can be on the same bus since each has an addressDevice addresses are pre-programmed, but can usually bechanged

Synchronous, so master controls clock rate

Terry Sturtevant Electronics Serial Communication-I2C

Page 8: Electronics- Serial Communication-I2Cdenethor.wlu.ca/pc320/lectures/i2cbeam.pdfRaspberry Pi Python I2C Library Serial Communication -I2C Inter-Integrated Circuit Interface Master/slave

Serial Communication -I2CRaspberry Pi Python I2C Library

Serial Communication -I2C

Inter-Integrated Circuit InterfaceMaster/slave communicationUses 2 signals (and Ground),SDA and SCLMany slaves can be on the same bus since each has an addressDevice addresses are pre-programmed, but can usually bechangedSynchronous, so master controls clock rate

Terry Sturtevant Electronics Serial Communication-I2C

Page 9: Electronics- Serial Communication-I2Cdenethor.wlu.ca/pc320/lectures/i2cbeam.pdfRaspberry Pi Python I2C Library Serial Communication -I2C Inter-Integrated Circuit Interface Master/slave

Serial Communication -I2CRaspberry Pi Python I2C Library

Bidirectional Communication on a Single Line

How can multiple devices communicate on the same line?Each device has an open-collector (or open-drain) output.A pull-up resistor on the line allows it to go high whennothing is pulling it low.Any device which is not speaking must let their output float.Only one device can pull the line low at a time.

On the Raspberry Pi board, there are 1.8kΩ pull-up resistorsto 3.3V, so external ones are not normally required.

Terry Sturtevant Electronics Serial Communication-I2C

Page 10: Electronics- Serial Communication-I2Cdenethor.wlu.ca/pc320/lectures/i2cbeam.pdfRaspberry Pi Python I2C Library Serial Communication -I2C Inter-Integrated Circuit Interface Master/slave

Serial Communication -I2CRaspberry Pi Python I2C Library

Bidirectional Communication on a Single Line

How can multiple devices communicate on the same line?

Each device has an open-collector (or open-drain) output.A pull-up resistor on the line allows it to go high whennothing is pulling it low.Any device which is not speaking must let their output float.Only one device can pull the line low at a time.

On the Raspberry Pi board, there are 1.8kΩ pull-up resistorsto 3.3V, so external ones are not normally required.

Terry Sturtevant Electronics Serial Communication-I2C

Page 11: Electronics- Serial Communication-I2Cdenethor.wlu.ca/pc320/lectures/i2cbeam.pdfRaspberry Pi Python I2C Library Serial Communication -I2C Inter-Integrated Circuit Interface Master/slave

Serial Communication -I2CRaspberry Pi Python I2C Library

Bidirectional Communication on a Single Line

How can multiple devices communicate on the same line?Each device has an open-collector (or open-drain) output.

A pull-up resistor on the line allows it to go high whennothing is pulling it low.Any device which is not speaking must let their output float.Only one device can pull the line low at a time.

On the Raspberry Pi board, there are 1.8kΩ pull-up resistorsto 3.3V, so external ones are not normally required.

Terry Sturtevant Electronics Serial Communication-I2C

Page 12: Electronics- Serial Communication-I2Cdenethor.wlu.ca/pc320/lectures/i2cbeam.pdfRaspberry Pi Python I2C Library Serial Communication -I2C Inter-Integrated Circuit Interface Master/slave

Serial Communication -I2CRaspberry Pi Python I2C Library

Bidirectional Communication on a Single Line

How can multiple devices communicate on the same line?Each device has an open-collector (or open-drain) output.A pull-up resistor on the line allows it to go high whennothing is pulling it low.

Any device which is not speaking must let their output float.Only one device can pull the line low at a time.

On the Raspberry Pi board, there are 1.8kΩ pull-up resistorsto 3.3V, so external ones are not normally required.

Terry Sturtevant Electronics Serial Communication-I2C

Page 13: Electronics- Serial Communication-I2Cdenethor.wlu.ca/pc320/lectures/i2cbeam.pdfRaspberry Pi Python I2C Library Serial Communication -I2C Inter-Integrated Circuit Interface Master/slave

Serial Communication -I2CRaspberry Pi Python I2C Library

Bidirectional Communication on a Single Line

How can multiple devices communicate on the same line?Each device has an open-collector (or open-drain) output.A pull-up resistor on the line allows it to go high whennothing is pulling it low.Any device which is not speaking must let their output float.

Only one device can pull the line low at a time.

On the Raspberry Pi board, there are 1.8kΩ pull-up resistorsto 3.3V, so external ones are not normally required.

Terry Sturtevant Electronics Serial Communication-I2C

Page 14: Electronics- Serial Communication-I2Cdenethor.wlu.ca/pc320/lectures/i2cbeam.pdfRaspberry Pi Python I2C Library Serial Communication -I2C Inter-Integrated Circuit Interface Master/slave

Serial Communication -I2CRaspberry Pi Python I2C Library

Bidirectional Communication on a Single Line

How can multiple devices communicate on the same line?Each device has an open-collector (or open-drain) output.A pull-up resistor on the line allows it to go high whennothing is pulling it low.Any device which is not speaking must let their output float.Only one device can pull the line low at a time.

On the Raspberry Pi board, there are 1.8kΩ pull-up resistorsto 3.3V, so external ones are not normally required.

Terry Sturtevant Electronics Serial Communication-I2C

Page 15: Electronics- Serial Communication-I2Cdenethor.wlu.ca/pc320/lectures/i2cbeam.pdfRaspberry Pi Python I2C Library Serial Communication -I2C Inter-Integrated Circuit Interface Master/slave

Serial Communication -I2CRaspberry Pi Python I2C Library

Bidirectional Communication on a Single Line

How can multiple devices communicate on the same line?Each device has an open-collector (or open-drain) output.A pull-up resistor on the line allows it to go high whennothing is pulling it low.Any device which is not speaking must let their output float.Only one device can pull the line low at a time.

On the Raspberry Pi board, there are 1.8kΩ pull-up resistorsto 3.3V, so external ones are not normally required.

Terry Sturtevant Electronics Serial Communication-I2C

Page 16: Electronics- Serial Communication-I2Cdenethor.wlu.ca/pc320/lectures/i2cbeam.pdfRaspberry Pi Python I2C Library Serial Communication -I2C Inter-Integrated Circuit Interface Master/slave

Serial Communication -I2CRaspberry Pi Python I2C Library

Mixing devices with different supply voltages

Do you need optoisolators if devices require different supplyvoltages?

Each device has an open-collector (or open-drain) output.A pull-up resistor on the line allows it to go high whennothing is pulling it low.If the pull-up resistors only go to the lowest supply voltage,then the data line will never be too high.Since the Raspberry Pi has 1.8kΩ pull-up resistors to 3.3V,connecting to an I2C device with a 5V supply will not cause aproblem for the Pi.Note, however, if 3.3V inputs are not high enough for thedevice, then it might not operate correctly.

Terry Sturtevant Electronics Serial Communication-I2C

Page 17: Electronics- Serial Communication-I2Cdenethor.wlu.ca/pc320/lectures/i2cbeam.pdfRaspberry Pi Python I2C Library Serial Communication -I2C Inter-Integrated Circuit Interface Master/slave

Serial Communication -I2CRaspberry Pi Python I2C Library

Mixing devices with different supply voltages

Do you need optoisolators if devices require different supplyvoltages?

Each device has an open-collector (or open-drain) output.A pull-up resistor on the line allows it to go high whennothing is pulling it low.If the pull-up resistors only go to the lowest supply voltage,then the data line will never be too high.Since the Raspberry Pi has 1.8kΩ pull-up resistors to 3.3V,connecting to an I2C device with a 5V supply will not cause aproblem for the Pi.Note, however, if 3.3V inputs are not high enough for thedevice, then it might not operate correctly.

Terry Sturtevant Electronics Serial Communication-I2C

Page 18: Electronics- Serial Communication-I2Cdenethor.wlu.ca/pc320/lectures/i2cbeam.pdfRaspberry Pi Python I2C Library Serial Communication -I2C Inter-Integrated Circuit Interface Master/slave

Serial Communication -I2CRaspberry Pi Python I2C Library

Mixing devices with different supply voltages

Do you need optoisolators if devices require different supplyvoltages?

Each device has an open-collector (or open-drain) output.

A pull-up resistor on the line allows it to go high whennothing is pulling it low.If the pull-up resistors only go to the lowest supply voltage,then the data line will never be too high.Since the Raspberry Pi has 1.8kΩ pull-up resistors to 3.3V,connecting to an I2C device with a 5V supply will not cause aproblem for the Pi.Note, however, if 3.3V inputs are not high enough for thedevice, then it might not operate correctly.

Terry Sturtevant Electronics Serial Communication-I2C

Page 19: Electronics- Serial Communication-I2Cdenethor.wlu.ca/pc320/lectures/i2cbeam.pdfRaspberry Pi Python I2C Library Serial Communication -I2C Inter-Integrated Circuit Interface Master/slave

Serial Communication -I2CRaspberry Pi Python I2C Library

Mixing devices with different supply voltages

Do you need optoisolators if devices require different supplyvoltages?

Each device has an open-collector (or open-drain) output.A pull-up resistor on the line allows it to go high whennothing is pulling it low.

If the pull-up resistors only go to the lowest supply voltage,then the data line will never be too high.Since the Raspberry Pi has 1.8kΩ pull-up resistors to 3.3V,connecting to an I2C device with a 5V supply will not cause aproblem for the Pi.Note, however, if 3.3V inputs are not high enough for thedevice, then it might not operate correctly.

Terry Sturtevant Electronics Serial Communication-I2C

Page 20: Electronics- Serial Communication-I2Cdenethor.wlu.ca/pc320/lectures/i2cbeam.pdfRaspberry Pi Python I2C Library Serial Communication -I2C Inter-Integrated Circuit Interface Master/slave

Serial Communication -I2CRaspberry Pi Python I2C Library

Mixing devices with different supply voltages

Do you need optoisolators if devices require different supplyvoltages?

Each device has an open-collector (or open-drain) output.A pull-up resistor on the line allows it to go high whennothing is pulling it low.If the pull-up resistors only go to the lowest supply voltage,then the data line will never be too high.

Since the Raspberry Pi has 1.8kΩ pull-up resistors to 3.3V,connecting to an I2C device with a 5V supply will not cause aproblem for the Pi.Note, however, if 3.3V inputs are not high enough for thedevice, then it might not operate correctly.

Terry Sturtevant Electronics Serial Communication-I2C

Page 21: Electronics- Serial Communication-I2Cdenethor.wlu.ca/pc320/lectures/i2cbeam.pdfRaspberry Pi Python I2C Library Serial Communication -I2C Inter-Integrated Circuit Interface Master/slave

Serial Communication -I2CRaspberry Pi Python I2C Library

Mixing devices with different supply voltages

Do you need optoisolators if devices require different supplyvoltages?

Each device has an open-collector (or open-drain) output.A pull-up resistor on the line allows it to go high whennothing is pulling it low.If the pull-up resistors only go to the lowest supply voltage,then the data line will never be too high.Since the Raspberry Pi has 1.8kΩ pull-up resistors to 3.3V,connecting to an I2C device with a 5V supply will not cause aproblem for the Pi.

Note, however, if 3.3V inputs are not high enough for thedevice, then it might not operate correctly.

Terry Sturtevant Electronics Serial Communication-I2C

Page 22: Electronics- Serial Communication-I2Cdenethor.wlu.ca/pc320/lectures/i2cbeam.pdfRaspberry Pi Python I2C Library Serial Communication -I2C Inter-Integrated Circuit Interface Master/slave

Serial Communication -I2CRaspberry Pi Python I2C Library

Mixing devices with different supply voltages

Do you need optoisolators if devices require different supplyvoltages?

Each device has an open-collector (or open-drain) output.A pull-up resistor on the line allows it to go high whennothing is pulling it low.If the pull-up resistors only go to the lowest supply voltage,then the data line will never be too high.Since the Raspberry Pi has 1.8kΩ pull-up resistors to 3.3V,connecting to an I2C device with a 5V supply will not cause aproblem for the Pi.Note, however, if 3.3V inputs are not high enough for thedevice, then it might not operate correctly.

Terry Sturtevant Electronics Serial Communication-I2C

Page 23: Electronics- Serial Communication-I2Cdenethor.wlu.ca/pc320/lectures/i2cbeam.pdfRaspberry Pi Python I2C Library Serial Communication -I2C Inter-Integrated Circuit Interface Master/slave

Serial Communication -I2CRaspberry Pi Python I2C Library

SDA

Terry Sturtevant Electronics Serial Communication-I2C

Page 24: Electronics- Serial Communication-I2Cdenethor.wlu.ca/pc320/lectures/i2cbeam.pdfRaspberry Pi Python I2C Library Serial Communication -I2C Inter-Integrated Circuit Interface Master/slave

Serial Communication -I2CRaspberry Pi Python I2C Library

SDA

All floating; SDA is HIGH.Terry Sturtevant Electronics Serial Communication-I2C

Page 25: Electronics- Serial Communication-I2Cdenethor.wlu.ca/pc320/lectures/i2cbeam.pdfRaspberry Pi Python I2C Library Serial Communication -I2C Inter-Integrated Circuit Interface Master/slave

Serial Communication -I2CRaspberry Pi Python I2C Library

SDA

One output LOW; SDA is LOW.Terry Sturtevant Electronics Serial Communication-I2C

Page 26: Electronics- Serial Communication-I2Cdenethor.wlu.ca/pc320/lectures/i2cbeam.pdfRaspberry Pi Python I2C Library Serial Communication -I2C Inter-Integrated Circuit Interface Master/slave

Serial Communication -I2CRaspberry Pi Python I2C Library

SDA

SCL

START

MSB LSB ACK

STOP

I2C ; bits are read when SCL is HIGHACK is sent by receiver if OKsender must release SDA after LSB

Terry Sturtevant Electronics Serial Communication-I2C

Page 27: Electronics- Serial Communication-I2Cdenethor.wlu.ca/pc320/lectures/i2cbeam.pdfRaspberry Pi Python I2C Library Serial Communication -I2C Inter-Integrated Circuit Interface Master/slave

Serial Communication -I2CRaspberry Pi Python I2C Library

SDA

SCL

START

MSB LSB NACK

STOP

I2C ; bits are read when SCL is HIGHNACK is sent by master-receiver if OKsender must release SDA after LSB

Terry Sturtevant Electronics Serial Communication-I2C

Page 28: Electronics- Serial Communication-I2Cdenethor.wlu.ca/pc320/lectures/i2cbeam.pdfRaspberry Pi Python I2C Library Serial Communication -I2C Inter-Integrated Circuit Interface Master/slave

Serial Communication -I2CRaspberry Pi Python I2C Library

I2C write to slave register

Terry Sturtevant Electronics Serial Communication-I2C

Page 29: Electronics- Serial Communication-I2Cdenethor.wlu.ca/pc320/lectures/i2cbeam.pdfRaspberry Pi Python I2C Library Serial Communication -I2C Inter-Integrated Circuit Interface Master/slave

Serial Communication -I2CRaspberry Pi Python I2C Library

START W

Slave address

I2C write to slave register

Terry Sturtevant Electronics Serial Communication-I2C

Page 30: Electronics- Serial Communication-I2Cdenethor.wlu.ca/pc320/lectures/i2cbeam.pdfRaspberry Pi Python I2C Library Serial Communication -I2C Inter-Integrated Circuit Interface Master/slave

Serial Communication -I2CRaspberry Pi Python I2C Library

START WA

Slave address

I2C write to slave register

Terry Sturtevant Electronics Serial Communication-I2C

Page 31: Electronics- Serial Communication-I2Cdenethor.wlu.ca/pc320/lectures/i2cbeam.pdfRaspberry Pi Python I2C Library Serial Communication -I2C Inter-Integrated Circuit Interface Master/slave

Serial Communication -I2CRaspberry Pi Python I2C Library

START WA

Slave addressRegister number

I2C write to slave register

Terry Sturtevant Electronics Serial Communication-I2C

Page 32: Electronics- Serial Communication-I2Cdenethor.wlu.ca/pc320/lectures/i2cbeam.pdfRaspberry Pi Python I2C Library Serial Communication -I2C Inter-Integrated Circuit Interface Master/slave

Serial Communication -I2CRaspberry Pi Python I2C Library

START WA A

Slave addressRegister number

I2C write to slave register

Terry Sturtevant Electronics Serial Communication-I2C

Page 33: Electronics- Serial Communication-I2Cdenethor.wlu.ca/pc320/lectures/i2cbeam.pdfRaspberry Pi Python I2C Library Serial Communication -I2C Inter-Integrated Circuit Interface Master/slave

Serial Communication -I2CRaspberry Pi Python I2C Library

START WA A

Slave addressRegister number

Register data

I2C write to slave register

Terry Sturtevant Electronics Serial Communication-I2C

Page 34: Electronics- Serial Communication-I2Cdenethor.wlu.ca/pc320/lectures/i2cbeam.pdfRaspberry Pi Python I2C Library Serial Communication -I2C Inter-Integrated Circuit Interface Master/slave

Serial Communication -I2CRaspberry Pi Python I2C Library

START WA A A

Slave addressRegister number

Register data

I2C write to slave register

Terry Sturtevant Electronics Serial Communication-I2C

Page 35: Electronics- Serial Communication-I2Cdenethor.wlu.ca/pc320/lectures/i2cbeam.pdfRaspberry Pi Python I2C Library Serial Communication -I2C Inter-Integrated Circuit Interface Master/slave

Serial Communication -I2CRaspberry Pi Python I2C Library

START STOPWA A

ASlave address

Register numberRegister data

I2C write to slave register

Terry Sturtevant Electronics Serial Communication-I2C

Page 36: Electronics- Serial Communication-I2Cdenethor.wlu.ca/pc320/lectures/i2cbeam.pdfRaspberry Pi Python I2C Library Serial Communication -I2C Inter-Integrated Circuit Interface Master/slave

Serial Communication -I2CRaspberry Pi Python I2C Library

I2C read from slave register

Terry Sturtevant Electronics Serial Communication-I2C

Page 37: Electronics- Serial Communication-I2Cdenethor.wlu.ca/pc320/lectures/i2cbeam.pdfRaspberry Pi Python I2C Library Serial Communication -I2C Inter-Integrated Circuit Interface Master/slave

Serial Communication -I2CRaspberry Pi Python I2C Library

START W

Slave address

I2C read from slave register

Terry Sturtevant Electronics Serial Communication-I2C

Page 38: Electronics- Serial Communication-I2Cdenethor.wlu.ca/pc320/lectures/i2cbeam.pdfRaspberry Pi Python I2C Library Serial Communication -I2C Inter-Integrated Circuit Interface Master/slave

Serial Communication -I2CRaspberry Pi Python I2C Library

START WA

Slave address

I2C read from slave register

Terry Sturtevant Electronics Serial Communication-I2C

Page 39: Electronics- Serial Communication-I2Cdenethor.wlu.ca/pc320/lectures/i2cbeam.pdfRaspberry Pi Python I2C Library Serial Communication -I2C Inter-Integrated Circuit Interface Master/slave

Serial Communication -I2CRaspberry Pi Python I2C Library

START WA

Slave addressRegister number

I2C read from slave register

Terry Sturtevant Electronics Serial Communication-I2C

Page 40: Electronics- Serial Communication-I2Cdenethor.wlu.ca/pc320/lectures/i2cbeam.pdfRaspberry Pi Python I2C Library Serial Communication -I2C Inter-Integrated Circuit Interface Master/slave

Serial Communication -I2CRaspberry Pi Python I2C Library

START WA A

Slave addressRegister number

I2C read from slave register

Terry Sturtevant Electronics Serial Communication-I2C

Page 41: Electronics- Serial Communication-I2Cdenethor.wlu.ca/pc320/lectures/i2cbeam.pdfRaspberry Pi Python I2C Library Serial Communication -I2C Inter-Integrated Circuit Interface Master/slave

Serial Communication -I2CRaspberry Pi Python I2C Library

START WA A R

Slave addressRegister number

Slave address

I2C read from slave register

Terry Sturtevant Electronics Serial Communication-I2C

Page 42: Electronics- Serial Communication-I2Cdenethor.wlu.ca/pc320/lectures/i2cbeam.pdfRaspberry Pi Python I2C Library Serial Communication -I2C Inter-Integrated Circuit Interface Master/slave

Serial Communication -I2CRaspberry Pi Python I2C Library

START WA A RA

Slave addressRegister number

Slave address

I2C read from slave register

Terry Sturtevant Electronics Serial Communication-I2C

Page 43: Electronics- Serial Communication-I2Cdenethor.wlu.ca/pc320/lectures/i2cbeam.pdfRaspberry Pi Python I2C Library Serial Communication -I2C Inter-Integrated Circuit Interface Master/slave

Serial Communication -I2CRaspberry Pi Python I2C Library

START WA A RA

Slave addressRegister number

Slave addressRegister data

I2C read from slave register

Terry Sturtevant Electronics Serial Communication-I2C

Page 44: Electronics- Serial Communication-I2Cdenethor.wlu.ca/pc320/lectures/i2cbeam.pdfRaspberry Pi Python I2C Library Serial Communication -I2C Inter-Integrated Circuit Interface Master/slave

Serial Communication -I2CRaspberry Pi Python I2C Library

START WA A RA N

Slave addressRegister number

Slave addressRegister data

I2C read from slave register

Terry Sturtevant Electronics Serial Communication-I2C

Page 45: Electronics- Serial Communication-I2Cdenethor.wlu.ca/pc320/lectures/i2cbeam.pdfRaspberry Pi Python I2C Library Serial Communication -I2C Inter-Integrated Circuit Interface Master/slave

Serial Communication -I2CRaspberry Pi Python I2C Library

START STOPWA A RA

NSlave addressRegister number

Slave addressRegister data

I2C read from slave register

Terry Sturtevant Electronics Serial Communication-I2C

Page 46: Electronics- Serial Communication-I2Cdenethor.wlu.ca/pc320/lectures/i2cbeam.pdfRaspberry Pi Python I2C Library Serial Communication -I2C Inter-Integrated Circuit Interface Master/slave

Serial Communication -I2CRaspberry Pi Python I2C Library

Smbus

bus = smbus.SMBus(1)create objectbus.read i2c block data(addr,cmd)read from devicebus.write i2c block data(addr,cmd,vals)write to device

Terry Sturtevant Electronics Serial Communication-I2C

Page 47: Electronics- Serial Communication-I2Cdenethor.wlu.ca/pc320/lectures/i2cbeam.pdfRaspberry Pi Python I2C Library Serial Communication -I2C Inter-Integrated Circuit Interface Master/slave

Serial Communication -I2CRaspberry Pi Python I2C Library

Smbus

bus = smbus.SMBus(1)create object

bus.read i2c block data(addr,cmd)read from devicebus.write i2c block data(addr,cmd,vals)write to device

Terry Sturtevant Electronics Serial Communication-I2C

Page 48: Electronics- Serial Communication-I2Cdenethor.wlu.ca/pc320/lectures/i2cbeam.pdfRaspberry Pi Python I2C Library Serial Communication -I2C Inter-Integrated Circuit Interface Master/slave

Serial Communication -I2CRaspberry Pi Python I2C Library

Smbus

bus = smbus.SMBus(1)create objectbus.read i2c block data(addr,cmd)read from device

bus.write i2c block data(addr,cmd,vals)write to device

Terry Sturtevant Electronics Serial Communication-I2C

Page 49: Electronics- Serial Communication-I2Cdenethor.wlu.ca/pc320/lectures/i2cbeam.pdfRaspberry Pi Python I2C Library Serial Communication -I2C Inter-Integrated Circuit Interface Master/slave

Serial Communication -I2CRaspberry Pi Python I2C Library

Smbus

bus = smbus.SMBus(1)create objectbus.read i2c block data(addr,cmd)read from devicebus.write i2c block data(addr,cmd,vals)write to device

Terry Sturtevant Electronics Serial Communication-I2C

Page 50: Electronics- Serial Communication-I2Cdenethor.wlu.ca/pc320/lectures/i2cbeam.pdfRaspberry Pi Python I2C Library Serial Communication -I2C Inter-Integrated Circuit Interface Master/slave

Serial Communication -I2CRaspberry Pi Python I2C Library

Smbus

#!/ u s r / b i n / pythoni m p o r t smbusbus = smbus . SMBus ( 1 )DEVICE ADDRESS = 0 x15DEVICE REG MODE1 = 0 x00DEVICE REG LEDOUT0 = 0 x1d#Write a s i n g l e r e g i s t e rbus . w r i t e b y t e d a t a (DEVICE ADDRESS ,

DEVICE REG MODE1 , 0 x80 )

#Write an a r r a y o f r e g i s t e r sl e d o u t v a l u e s = [ 0 x f f , 0 x f f ,

0 x f f , 0 x f f , 0 x f f , 0 x f f ]bus . w r i t e i 2 c b l o c k d a t a (DEVICE ADDRESS ,

DEVICE REG LEDOUT0 , l e d o u t v a l u e s )

Terry Sturtevant Electronics Serial Communication-I2C

Page 51: Electronics- Serial Communication-I2Cdenethor.wlu.ca/pc320/lectures/i2cbeam.pdfRaspberry Pi Python I2C Library Serial Communication -I2C Inter-Integrated Circuit Interface Master/slave

Serial Communication -I2CRaspberry Pi Python I2C Library

Smbus#!/ u s r / b i n / pythoni m p o r t smbusbus = smbus . SMBus ( 1 )DEVICE ADDRESS = 0 x15DEVICE REG MODE1 = 0 x00DEVICE REG LEDOUT0 = 0 x1d#Write a s i n g l e r e g i s t e rbus . w r i t e b y t e d a t a (DEVICE ADDRESS ,

DEVICE REG MODE1 , 0 x80 )

#Write an a r r a y o f r e g i s t e r sl e d o u t v a l u e s = [ 0 x f f , 0 x f f ,

0 x f f , 0 x f f , 0 x f f , 0 x f f ]bus . w r i t e i 2 c b l o c k d a t a (DEVICE ADDRESS ,

DEVICE REG LEDOUT0 , l e d o u t v a l u e s )

Terry Sturtevant Electronics Serial Communication-I2C