I2C slave?
I2C slave?
Looking at docs and source it seems ESP32 port does not support I2C slave mode? Pyboard seems to have support. Are there any plans on implementing it in ESP32 port in nearby future?
Re: I2C slave?
I2C slave is supported in esp-idf.
I'm planning to add hardware I2C slave support in my Micropython port the next month.
I'm planning to add hardware I2C slave support in my Micropython port the next month.
Re: I2C slave?
Hi Loboris;I2C slave is supported in esp-idf.
I'm planning to add hardware I2C slave support in my Micropython port the next month.
You mentioned that you were going to add the I2C Slave Mode, is this likely to happen any time soon ?
Thanks
Re: I2C slave?
I played around with with esp-idf and created a couple of I2C slaves. They seem to work well. Only problem is though, that since ESP32 has hardware I2C implementation and there is only two I2C busses the slave can only listen at two I2C addresses. I do not know if there is a way around this other than creating a software I2C slave implementation.
In any case I also would be interested this supported in Micropython.
In any case I also would be interested this supported in Micropython.
Re: I2C slave?
Hi;
I know this is a very old post, but you mentioned that you managed to get a slave working on the ESP32 ?
Was this using micropython ??
Or does anybody else have a software implementation for an I2C Slave / Peripheral that they would not mind sharing ??
I dont want to do this on a pyboard.
I know this is a very old post, but you mentioned that you managed to get a slave working on the ESP32 ?
Was this using micropython ??
Or does anybody else have a software implementation for an I2C Slave / Peripheral that they would not mind sharing ??
I dont want to do this on a pyboard.
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: I2C slave?
See this doc. Crucially, from this doc,
The Pyboard or similar STM based boards are currently the only targets supporting I2C slave mode. Consequently at least one end of the interface (known as theInitiator) must be a Pyboard or other board supporting the pyb module. The Responder may be any hardware running MicroPython and supporting machine.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: I2C slave?
Thanks, yes I am aware that the pyboard is the only device with built in slave mode.
But I am referring to a software implementation of this, probably bit banging.
But I am referring to a software implementation of this, probably bit banging.
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: I2C slave?
I'm not aware of one. This is an issue which crops up fairly regularly. Even the Pyboard's hard slave mode is difficult to use:
The last resort might be to use threading.
An interesting project. Rather akin to soft UARTs, often promised but seldom delivered. Tougher than they look. I don't think I'll be doing it
I think this concurrency issue would affect software implementations: the master can initiate at any time but the slave needs to be able to get on with other things. There are a few solutions. You might invent another signal, where the master asserts a pin which interrupts the slave and puts it into blocking receive mode, perhaps via micropython.schedule. You might use uasyncio to poll the interface - but this would only work at very low clock rates. Or you might write an interrupt driven slave. Probably the best approach but quite hard to do as each ISR needs to return fast.There is a timing issue in that the I2C master requires that the slave be ready before it initiates a transfer. Further, in the MicroPython implementation, a slave which is ready will block until the transfer is complete.
The last resort might be to use threading.
An interesting project. Rather akin to soft UARTs, often promised but seldom delivered. Tougher than they look. I don't think I'll be doing it
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: I2C slave?
OK, I thought that I would try the pyboard as a slave and esp32 as master:
PYB Slave
ESP32 Master
This works, but how do I go about having the slave reply ?
PYB Slave
ESP32 Master
What I want to do is for the slave to reply to the master with a value that was determined from the byte address that the master sent.
PYB Slave
Code: Select all
data = i2c_slave.recv(1)
print(data)
Code: Select all
i2c_master.writeto(0x0b,b'X')
PYB Slave
Code: Select all
data = i2c_slave.recv(1)
i2c_slave.send(data)
print(data)
Code: Select all
print(i2c_master.readfrom_mem(0x0b,0XFF,1))
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: I2C slave?
The doc I referenced describes a way to make a bidirectional interface between a Pyboard and an I2C master using Pyboard I2C slave mode. The interface behaves like a full duplex stream. All the code is there.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.