admin管理员组文章数量:1400628
I need to respond to a specific registry read over I2C on an RPi.
Currently, following the usual instructions for the pigpio package here: .html#bsc_xfer i can see the reads to the device address. I cannot however in the documentation see how to respond to a specific registry read on the device
The master device (outside of my control) will read the Slave (RPi), on address 0x20. It will then look to access the register 0x1c5h (for example) to read any data stored there. I cannot see how to:
- Detect which register is being read
- See how to respond appropriately (i.e. with the data that should be "stored" at that address)
Code used so far (ignore the prints for debug!).
from decimal import Decimal
import bitstring
import time
import pigpio
I2C_ADDR = 0x50 #device address
def i2c(id, tick):
global pi
#s, b, d = pi.bsc_i2c(I2C_ADDR)
#print(bitstring.BitArray(d).bin) #Print anything written
s, b, d = pi.bsc_i2c(I2C_ADDR, '1240') #respond to read
#convert decimal to bytes
def decimal_to_bytes(num):
x = Decimal(str(num))
a = x ** Decimal(1) / Decimal(7)
s = str(a)
b = s.encode('ascii')
return b;
pi = pigpio.pi()
if not pi.connected:
exit()
e = pi.event_callback(pigpio.EVENT_BSC, i2c)
pi.bsc_i2c(I2C_ADDR) # Configure BSC as I2C slave
time.sleep(600)
e.cancel()
pi.bsc_i2c(0) # Disable BSC peripheral
pi.stop()
本文标签: I2C Slave respond to registry read on Raspberry Pi with Python using pigpio packageStack Overflow
版权声明:本文标题:I2C Slave respond to registry read on Raspberry Pi with Python using pigpio package - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744251167a2597255.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论