I2C Slave mode support?

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

User avatar
Edoardo1982
Posts: 24
Joined: Thu Aug 03, 2017 8:39 am
Has thanked: 10 times
Been thanked: 20 times

Re: I2C Slave mode support?

Post 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/chibios203
Demo is under testhal/STM32/STM32F4xx/I2C-MASTER_SLAVE
gab
Posts: 17
Joined: Wed Sep 23, 2020 1:05 pm
Been thanked: 1 time

Re: I2C Slave mode support?

Post 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);
----
steved
Posts: 834
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 12 times
Been thanked: 138 times

Re: I2C Slave mode support?

Post 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.
Attachments
I2CV1.7z
(18.04 KiB) Downloaded 501 times
yiancar
Posts: 14
Joined: Fri Jan 04, 2019 11:26 am
Has thanked: 1 time

Re: I2C Slave mode support?

Post 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
steved
Posts: 834
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 12 times
Been thanked: 138 times

Re: I2C Slave mode support?

Post 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)
yiancar
Posts: 14
Joined: Fri Jan 04, 2019 11:26 am
Has thanked: 1 time

Re: I2C Slave mode support?

Post 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?
steved
Posts: 834
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 12 times
Been thanked: 138 times

Re: I2C Slave mode support?

Post 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.
Post Reply