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: 522
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 3 times
Been thanked: 52 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: 522
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 3 times
Been thanked: 52 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


Return to “General Support”

Who is online

Users browsing this forum: No registered users and 2 guests