I2C Slave mode support?

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

Moderators: barthess, RoccoMarco, utzig, lbednarz, tfAteba

mstanisz
Posts: 3
Joined: Fri Jan 19, 2018 7:30 pm

Re: I2C Slave mode support?

Postby mstanisz » Fri Jan 19, 2018 7:58 pm

Hey all,

I've merged the latest (Chibi_I2C_Slave_17.6.3.zip) into my code for my STM32F37xx. I've read through this post and a few others and have 4 similar examples for an I2C slave test. I'm currently trying to port the F401_Nucleo_I2C_Slave example. Using an Aardvark as my master, I can see it transmitting to the STM32 and getting an acknowledge back, but the default echo functionality of my example code isn't working.

Could someone point me to the best example currently for getting the slave code up and running that's similar to my device?

Cheers!
Matt

steved
Posts: 558
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 4 times
Been thanked: 61 times

Re: I2C Slave mode support?

Postby steved » Fri Jan 19, 2018 10:03 pm

The slave example for the F051 from this thread should work - by using the core code with a make file intended for the F401, the I2CV1 driver will be automatically selected - no need to do anything special.
I'm mostly using the slave code on an F407 with a non-ST processor as master, without any problem.

mstanisz
Posts: 3
Joined: Fri Jan 19, 2018 7:30 pm

Re: I2C Slave mode support?

Postby mstanisz » Sat Jan 20, 2018 12:21 am

Hey steved,

Actually, I started with your F051 example first. I've integrated it back into my code, but I'm getting a similar response. Perhaps I'm misinterpreting the demo code, but if I perform a I2C write and then an I2C read with my master, I should get the data back from the echoRx routine, correct?

Currently here's what I get:

I2C Write (addr) 0x55
I2C Read (addr) 0x2D

Performing an I2C read displays the "I2c poll" message from the monitor thread denoting that I'm sending the "initialReply" response instead of the "echoRx" response. I get an ACK from the I2C slave on the write, but I don't ever see the debug "I2c TxRx" message, so I suspect I'm not entering the messageProcessor code for some reason.

Any help's appreciated,
Matt

steved
Posts: 558
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 4 times
Been thanked: 61 times

Re: I2C Slave mode support?

Postby steved » Sat Jan 20, 2018 9:23 am

Memory's rather hazy on how all that works, but IIRC you get different responses dependent on whether you do write-->repeated start-->read or if the write and read are separate operations. I think that's what the comment near the top of commsthread.c means. Essentially it boils down to whether the communication is treated as a single transaction, or two effectively independent transactions. It sounds as if you're doing two independent transactions.

If you've got enough bits, maybe try and use an ST device as master as well to prove the point.

mstanisz
Posts: 3
Joined: Fri Jan 19, 2018 7:30 pm

Re: I2C Slave mode support?

Postby mstanisz » Mon Jan 22, 2018 11:42 pm

After poking around the LLD files and commsthread a bit, it seems like there was an issue where txPtr and txBody were not receiving the same data from rxBody. I removed txPtr portion and did a memcpy() from rxBody into txBody in the messageProcessor() function and now it all looks good. If time allows, I'll try to poke around with the sample code some more, but at this point looks like I'm all good to start adding in my command processor :)

Matt

msichal
Posts: 2
Joined: Thu Oct 04, 2018 9:10 am

Re: I2C Slave mode support?

Postby msichal » Thu Oct 04, 2018 10:25 am

I'm using files from Chibi_I2C_Slave_17.6.3.zip on custom board with STM32L433.
Only effect I'm able to see is the error handler working. If the transaction finishes successfully (eg. a write), data is stored in RX buffer, but RX callback is not being run.
I'm using a slightly modified example from shd (commsthread.c).

Any ideas why RX callback (I2CSlabeMsgCB, in this case - messageProcessor function) might not be executed?
It is properly configured with i2cSlaveConfigure. I2C peripherial seems to be properly configured as well.

Other thing is - if the error callback is ever called, the error comes out as: I2cError: 0000 , which doesn't seem to make a lot of sense to me.

Any help?

eblot
Posts: 16
Joined: Fri Dec 08, 2017 5:33 pm
Been thanked: 1 time

Re: I2C Slave mode support?

Postby eblot » Mon Nov 12, 2018 10:48 am

msichal wrote:Other thing is - if the error callback is ever called, the error comes out as: I2cError: 0000 , which doesn't seem to make a lot of sense to me.
Any help?


Hi msichal,

I'm (successfully) using some variation of the I2C slave implementation w/ STM32L432.
I'm not 100% sure which variation it was as I tried several of them, but I think it was viewtopic.php?f=2&t=1502&start=60#p26532. Anyway I hacked it a bit.

I noticed the same issue lately. I'm not sure your issue is the same, but the original code was using
i2cp->errors to retrieve errors, where the application should use i2cSlaveErrors(i2cp) when slave mode is used.

I cannot move to ChibiOS 18.x on this project, as the base code has changed quite a bit since this version, and I have no time to work on the port. I hope I2C slave mode gets integrated upstream at some point.

HTH,
Manu

msichal
Posts: 2
Joined: Thu Oct 04, 2018 9:10 am

Re: I2C Slave mode support?

Postby msichal » Tue Nov 13, 2018 5:20 pm

Thanks for the reply.
Finally I just wrote my own 'driver' - very simple state machine working without any chibios I2C drivers.

Pretty much all you need to do is to create handlers for a few interrupts and use a simple state machine to handle common interrupt flags/situations.

I recommend that approach - saves a lot of time and makes writing working i2c slave possible in a few hours without playing around with drivers from chibios/cubeHAL/etc.

steved
Posts: 558
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 4 times
Been thanked: 61 times

Re: I2C Slave mode support?

Postby steved » Wed Nov 28, 2018 3:47 pm

I've just updated the I2CV2 slave driver for ChibiOS 18 (just as 19 is on the horizon!), and also made a few changes to reflect problems I encountered on the 32L071 - re-ordering bits of code, rather than changing the fundamentals. Not tested on other processors yet, but don't anticipate problems. It would be straightforward to back-port the changes to earlier Chibi versions.
I'm unlikely to port the I2CV1 driver, but there are very few changes involved (mostly systime_t becomes sysinterval_t, IIRC)
Attachments
Chibi_18_I2CV2_Slave.zip
(29.16 KiB) Downloaded 6 times


Return to “General Support”

Who is online

Users browsing this forum: No registered users and 5 guests