Dear All,
I've noticed that chibios I2C driver doesn't implement I2C slave mode. I need that mode for my hardware as it consists of several identical MCUs on one I2C bus.
I've implemented I2C slave functionality by myself. Unfortunately, I've done it only for one MCU type: STM32F10XXX as I have only it. And it must be it doesn't work quite well at the moment: it works for separate read and write requests but it doesn't support read after write at the moment due to some reason. Anyway, it seems to me it would be useful to share the code. Slave mode functionality by default is invisible and everything is as without it. But if one defines I2C_USE_SLAVE_MODE to be TRUE i2cSlaveIoTimeout() function could be used
At the moment slave IO procedure is asynchronous. It returns immediately after invocation. But I2C works continuously after the very first call. To change IO data it's necessary to call the same procedure with different in and out buffers. I'm not sure it is in the mainstream of "chibios" but I'm ready to adjust it if necessary.
I2C slave mode.
- Giovanni
- Site Admin
- Posts: 14895
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: I2C slave mode.
Hi,
Very interesting, I am moving this thread in the contributions forum, the API looks OK, please let us know if you make more developments about this.
Giovanni
Very interesting, I am moving this thread in the contributions forum, the API looks OK, please let us know if you make more developments about this.
Giovanni
Re: I2C slave mode.
Hi!
I'd like to share some thoughts related to I2C slave implementation. The problem is that with my I2C slave implementation "i2cMasterTransmitTimeout()" only transmits and can't receive anything afterwards. Reading a datasheet I noticed that it is expectable behavior and nothing could be improved. At least it looks so.
Reading documentation for my MCU I again and again pay attention on the following phrase: "To generate the Stop/Restart condition, software must set the STOP/START bit just after reading the second last data byte". This sentence is from "I2C master receiver" section. And stop/restart is mentioned only there.
From this I conclude that STM32F10X hardware "understands" I2C restart only when slave is in transmitting mode. And it also means that "i2cMasterTransmitTimeout()" with it's capability to read after write can't actually do that if slave is based on STM32F10X MCU as slave doesn't understand that (it understands write after read instead).
So it looks like the only possibility to read and write to I2C slave based on STM32F10X MCU is to use separate read and separate write requests. And it does work. I can "read" and "write" or "write" and "read" if both "read" and "write" are separate requests. In other words full requests with START, ADDRESS, DATA and STOP parts. Am I right? And does one have any idea about it?
And I'm sorry if I ask in wrong place!
I'd like to share some thoughts related to I2C slave implementation. The problem is that with my I2C slave implementation "i2cMasterTransmitTimeout()" only transmits and can't receive anything afterwards. Reading a datasheet I noticed that it is expectable behavior and nothing could be improved. At least it looks so.
Reading documentation for my MCU I again and again pay attention on the following phrase: "To generate the Stop/Restart condition, software must set the STOP/START bit just after reading the second last data byte". This sentence is from "I2C master receiver" section. And stop/restart is mentioned only there.
From this I conclude that STM32F10X hardware "understands" I2C restart only when slave is in transmitting mode. And it also means that "i2cMasterTransmitTimeout()" with it's capability to read after write can't actually do that if slave is based on STM32F10X MCU as slave doesn't understand that (it understands write after read instead).
So it looks like the only possibility to read and write to I2C slave based on STM32F10X MCU is to use separate read and separate write requests. And it does work. I can "read" and "write" or "write" and "read" if both "read" and "write" are separate requests. In other words full requests with START, ADDRESS, DATA and STOP parts. Am I right? And does one have any idea about it?
And I'm sorry if I ask in wrong place!
Re: I2C slave mode.
I2C slave mode update.
Implemented receive/transmit callback functions in order to know if io takes place and update data buffers.
Implemented receive/transmit callback functions in order to know if io takes place and update data buffers.
Re: I2C slave mode.
Dear all, I'm very sorry for so many fixes of just a couple of files but here is one more update.
Fixed I2C slave transfer mode.
Fixed I2C slave transfer mode.