Page 12 of 12
Re: I2C Slave mode support?
Posted: Mon May 09, 2022 5:00 pm
by Edoardo1982
gab wrote:Is there a working i2c-slave code for stm32f103? I'm trying many variants published in this topic, but no one working

Please help me!
Hi, this is my chibios203 supporting I2C slave,
https://github.com/elombardi82/chibios203Demo is under testhal/STM32/STM32F4xx/I2C-MASTER_SLAVE
Re: I2C Slave mode support?
Posted: Mon May 30, 2022 7:01 pm
by gab
Sorry for late answer. Bellissimo! Ok. I can see RX events!
i2c-scan works.
Some questions:
"I2CDx.reply_required" - when this flag toggled on?
My test sketch on arduino UNO, connected to my board:
----
Wire.beginTransmission(0x18); // 0x18 - my device addr.
Wire.write(1);
Wire.endTransmission();
////---- I see in this place, that my board catch i2c addr. Ok.
Wire.requestFrom(0x18, 1);
while(Wire.available() == 0){ ////// ----- this music will be forever...

delay(10);
}
int c = Wire.read();
Serial.print(c);
----
Re: I2C Slave mode support?
Posted: Wed Jul 06, 2022 1:14 pm
by steved
I've never used the F103; IIRC I last used I2Cv1 slave code on the F4, which I stopped using a long time ago. AFAIK that should work on F103 as well.
I last updated ChibiOS 19.1.3 (not sure how well it was tested), and have attached the updated files from there.
The test harnesses I used are posted somewhere way back, possibly on this thread.
Re: I2C Slave mode support?
Posted: Thu Jul 28, 2022 7:06 pm
by yiancar
I know this is a very old long thread but would like to ask why this seems not to be making it into upstream?:)
Cheers,
Yiangos
Re: I2C Slave mode support?
Posted: Sun Jul 31, 2022 9:26 am
by steved
yiancar wrote:I know this is a very old long thread but would like to ask why this seems not to be making it into upstream?:)
I suspect because the code could do with a good cleanup after several people have updated and extended it. I've long felt that the V2 code is over-complicated, but since it works reliably for me I haven't had the time and inclination to touch it.
Also, the method of receiving data chosen by the original author may not suit everyone (I2C receive is tricky because you have a limited time to respond)
Re: I2C Slave mode support?
Posted: Mon Aug 01, 2022 12:07 am
by yiancar
steved wrote:yiancar wrote:I know this is a very old long thread but would like to ask why this seems not to be making it into upstream?:)
I suspect because the code could do with a good cleanup after several people have updated and extended it. I've long felt that the V2 code is over-complicated, but since it works reliably for me I haven't had the time and inclination to touch it.
Also, the method of receiving data chosen by the original author may not suit everyone (I2C receive is tricky because you have a limited time to respond)
Cheers Steved thank you for the reply.
Is there a chance I could get a TL;DR regarding which versions of ChibiOS it works with and which st chips it supports? maybe also some gotchas that people should be aware of?
Re: I2C Slave mode support?
Posted: Mon Aug 01, 2022 5:28 pm
by steved
All but the most recent ST devices use one of two I2C hardware blocks, each with its own driver. (So I2CV1, I2CV2). You can tell which by looking at the device-specific make file - look in the directories under \os\hal\ports\STM32 (for 20.3.4, anyway).
Judging by the minimal work involved in porting the I2CV2 slave driver forward, moving I2CV1 from Chibi 19 to Chibi 20 should largely be a matter of modifying the various files in the zip which I posted.