Pyboard as i2c slave won't work

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
unruhseth
Posts: 3
Joined: Sun Sep 30, 2018 1:56 am

Re: Pyboard as i2c slave won't work

Post by unruhseth » Wed Oct 03, 2018 3:19 am

I just tried the code from you guys and it works great. Thanks a lot. Now all I have to do is try to understand why it works and what I need to do to get the rest of the project done. 😀 But thanks for the help for now.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Pyboard as i2c slave won't work

Post by pythoncoder » Wed Oct 03, 2018 6:47 am

OutoftheBOTS_ wrote:
Wed Oct 03, 2018 2:52 am
...The Slave has to be constantly monitoring for data from the master or the master will receive a NACK. This sort of made it not useful, as the slave device can't really go off and do things or the master will get a NACK back...
The solution might be to add an extra link between master and slave, whereby the slave can raise an interrupt on the master. In terms of the communication protocol the slave would be "Active" and the master "Passive". "Passive" would prepare any data to be sent, set up a receive buffer, and wait for an interrupt. "Active" would periodically initiate communications by pulsing the line. The communication would then occur.

The point here is that the slave ("Active") is the participant which is liable to block for long periods, so you ensure that blocking is for the minimum possible time. The same could be achieved without the extra wire if Passive polled I2C.is_ready(addr), but this would have higher latency and be less efficient.

I'm interested in getting a uasyncio-friendly communications link working; I can feel an experiment coming on...
Peter Hinch
Index to my micropython libraries.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Pyboard as i2c slave won't work

Post by pythoncoder » Wed Oct 03, 2018 6:51 am

SpotlightKid wrote:
Tue Oct 02, 2018 2:35 pm
...
(Obviously, there are other, internal I2C slaves connected to I2C bus 1.)...
I think that's the accelerometer.

Thanks for that useful code sample :D
Peter Hinch
Index to my micropython libraries.

rhubarbdog
Posts: 168
Joined: Tue Nov 07, 2017 11:45 pm

Re: Pyboard as i2c slave won't work

Post by rhubarbdog » Wed Oct 03, 2018 7:33 am

I have an i2c thermometer/ humidity sensor.
It constantly waits for the master to write a command/register pair at which point it reacts taking a couple of milli seconds then returns to a read loop/ blocking read.
If your setting up your pyboard to be a slave it probably needs a dedicated thread to deal with the master slave comms and one to measure all your other sensors.

Post Reply