I2C Slave mode support?

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

Moderators: utzig, lbednarz, tfAteba, barthess, RoccoMarco

User avatar
HDKLog
Posts: 41
Joined: Thu Aug 18, 2016 12:36 am
Been thanked: 2 times

Re: I2C Slave mode support?

Postby HDKLog » Sun Aug 21, 2016 8:57 pm

In chibios all hal drivers have "hal_" prefix i just replaced content and including file names but I have several errors

Code: Select all

make -j1 all
Compiling hal_i2c_lld.c
../../ChibiOS/os/hal/ports/STM32/LLD/I2Cv1/hal_i2c_lld.c: In function 'i2c_lld_serve_event_interrupt':
../../ChibiOS/os/hal/ports/STM32/LLD/I2Cv1/hal_i2c_lld.c:934:14: error: macro "qEvt" requires 2 arguments, but only 1 given
   qEvt(0x0000);
              ^
../../ChibiOS/os/hal/ports/STM32/LLD/I2Cv1/hal_i2c_lld.c:934:3: error: 'qEvt' undeclared (first use in this function)
   qEvt(0x0000);
   ^
../../ChibiOS/os/hal/ports/STM32/LLD/I2Cv1/hal_i2c_lld.c:934:3: note: each undeclared identifier is reported only once for each function it appears in
../../ChibiOS/os/hal/ports/STM32/LLD/I2Cv1/hal_i2c_lld.c:137:19: warning: large integer implicitly truncated to unsigned type [-Woverflow]
   i2cQ[i2cI].code=(posn); i2cQ[i2cI].state=(i2cp->mode); i2cQ[i2cI].param=(info); }
                   ^
../../ChibiOS/os/hal/ports/STM32/LLD/I2Cv1/hal_i2c_lld.c:938:1: note: in expansion of macro 'qEvt'
 qEvt(0x9999,0);
 ^
make: *** [build/obj/hal_i2c_lld.o] Error 1

:|

steved
Posts: 770
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 10 times
Been thanked: 122 times

Re: I2C Slave mode support?

Postby steved » Sun Aug 21, 2016 9:59 pm

It's a little while since I worked on any of my code using I2Cv1; looks like the later compilers pick up errors better!

Simple fix; in line 127 of i2c_lld.c, change it to:

Code: Select all

#define QEVENTS 0


This disables a debugging feature of the driver (which should probably be disabled normally anyway).

User avatar
HDKLog
Posts: 41
Joined: Thu Aug 18, 2016 12:36 am
Been thanked: 2 times

Re: I2C Slave mode support?

Postby HDKLog » Sun Aug 21, 2016 10:29 pm

Still have Errors, looks like you define that function with 2 arguments and miss second argument when use it... , yes i use latest Eclipse Neon 4.6.0 and Chibios 3.0 from Github repository

Code: Select all

make -j1 all
Compiling hal_i2c_lld.c
../../ChibiOS/os/hal/ports/STM32/LLD/I2Cv1/hal_i2c_lld.c: In function 'i2c_lld_serve_event_interrupt':
../../ChibiOS/os/hal/ports/STM32/LLD/I2Cv1/hal_i2c_lld.c:934:14: error: macro "qEvt" requires 2 arguments, but only 1 given
   qEvt(0x0000);
              ^
../../ChibiOS/os/hal/ports/STM32/LLD/I2Cv1/hal_i2c_lld.c:934:3: error: 'qEvt' undeclared (first use in this function)
   qEvt(0x0000);
   ^
../../ChibiOS/os/hal/ports/STM32/LLD/I2Cv1/hal_i2c_lld.c:934:3: note: each undeclared identifier is reported only once for each function it appears in
../../ChibiOS/os/hal/ports/STM32/LLD/I2Cv1/hal_i2c_lld.c:137:19: warning: large integer implicitly truncated to unsigned type [-Woverflow]
   i2cQ[i2cI].code=(posn); i2cQ[i2cI].state=(i2cp->mode); i2cQ[i2cI].param=(info); }
                   ^
../../ChibiOS/os/hal/ports/STM32/LLD/I2Cv1/hal_i2c_lld.c:938:1: note: in expansion of macro 'qEvt'
 qEvt(0x9999,0);
 ^
make: *** [build/obj/hal_i2c_lld.o] Error 1


I fixed this but have another Error now

Code: Select all

02:30:45 **** Incremental Build of configuration Default for project F401_Nucleo_I2C_Slave ****
make all
../../ChibiOS/os/common/startup/ARMCMx/compilers/GCC/rules.mk:221: target `build/obj/crt0_v7m.S' doesn't match the target pattern
../../ChibiOS/os/common/startup/ARMCMx/compilers/GCC/rules.mk:221: target `build/obj/chcoreasm_v7m.S' doesn't match the target pattern
make: arm-none-eabi-gcc: No such file or directory
Compiling
make: *** [build/obj/crt0_v7m.S] Error 1

steved
Posts: 770
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 10 times
Been thanked: 122 times

Re: I2C Slave mode support?

Postby steved » Mon Aug 22, 2016 1:40 pm

That looks like a more general ChibiOS issue; possibly a missing path in the makefile or similar. Or maybe you are mixing code versions - I'm not sure whether the github repository is absolutely up to date; the master is the SVN repository. And things gradually change.
It might be better to download the latest released software, rather than trunk, unless there's a brand new feature you need.
It might also be worth downloading Chibistudio if you can, since that's preconfigured to 'just work'.

User avatar
HDKLog
Posts: 41
Joined: Thu Aug 18, 2016 12:36 am
Been thanked: 2 times

Re: I2C Slave mode support?

Postby HDKLog » Mon Aug 29, 2016 5:33 pm

I cant use Chibistudio, Im on mac, thanks anyway for provided code, i Implemented my own driver and merged it with I2Cv1 in ChibiOS 3.0
and i think Github repository is up to date (https://github.com/ChibiOS/ChibiOS)

User avatar
alex31
Posts: 334
Joined: Fri May 25, 2012 10:23 am
Location: toulouse, france
Has thanked: 33 times
Been thanked: 46 times
Contact:

Re: I2C Slave mode support?

Postby alex31 » Wed Jul 12, 2017 12:52 pm

Hello, i dig out this one year old thread. I need I²C slave capabilities in a project that i begin now, what is the best solution -- I will use stable 17.6 chibios, RT, on a STM32F303RE (I2CV2) -- to add I²C slave to 17.6 stable ?

using the I2C_Master_Slave.zip archive on page 7 of this thread (which will overwrite i2c source of 17.6 distribution) ?

Thanks for any advice
Alexandre

steved
Posts: 770
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 10 times
Been thanked: 122 times

Re: I2C Slave mode support?

Postby steved » Wed Jul 12, 2017 1:20 pm

Latest source in this thread should still work no problems. You might have to change some of the file names to begin "hal_"; that should be obvious when you add the code.

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

Re: I2C Slave mode support?

Postby eblot » Mon Dec 11, 2017 5:37 pm

Hi All,

I'm using an STM32L432 to implement an I2C slave.

I've downloaded the latest version for ChibiOS (v17.6.3), and merge the latest
I2Cslave source (from page 7), then renamed the files are recommended (hal_...).

It builds Ok, and I've neen able to make the STM32 to start communicating as a
slave with a remote I2C master.

However, after a 1-byte write (Master->Slave) and a 2-byte read (Slave->Master)
sequence, the I2Cslave does not seem to receive any other data.

I've checked with a Saleae logic analyser: a new 3-byte I2C frame is sent as
expected from the master, and the STM32 slave acknowleges all the 3 bytes, but
that's it, the I2CSlaveMsg.processMsg is no longer called.

I've enabled the debug traces in hal_i2c_lld.c to see if I could get some
useful info (see below).

The I2C slave I'm trying to emulate follows a common communication scheme over
I2C. The slave supports many registers.

To write to one (or more) registers, the master should first write the register
address (1 byte), followed with the actual data (each register is 2-byte long).
2-byte data packets may be repeated to write to subsequent registers in the
slave, until a STOP condition is generated.

To read from one (or more) register(s), the master should first write the
register address (1 byte), then issue a repeated start condition and read the
register content (2 bytes). The read may be repeated to read subsequent
registers from the slave, until a STOP condition is generated.


Here is the captured sequence with the logic analyser:

Code: Select all

Time [s], Analyzer Name, Decoded Protocol Result

0.000004000000000,I2C,Setup Write to [0x6C] + ACK
0.000065300000000,I2C,0x02 + ACK

0.000790100000000,I2C,Setup Read to [0x6D] + ACK
0.000866000000000,I2C,0x80 + ACK
0.000912500000000,I2C,0x7F + NAK

0.001505400000000,I2C,Setup Write to [0x6C] + ACK
0.001566700000000,I2C,0x02 + ACK
0.001620700000000,I2C,0x28 + ACK
0.001672200000000,I2C,0x2D + ACK

Here is the qEvent queue:

Code: Select all

00: 82->02 01 01FF   new receive buffer set
01: 80->02 01 0000   new reply set
02: 04->02 01 0000   Address match

03: 13->02 01 01FF   address match - receive
04: 14->02 02 0000   start slave receive operation
05: 04->02 02 0000   Address match
06: 07->02 02 0000   Recovery from untidily finished previous transaction [repeated start cond?]

07: 12->02 02 01FF   address match - send
08: 16->02 02 0000   start slave transmit operation
09: 02->02 04 0000   transfer complete received
10: CC->02 04 0000   clearing down after transmission - triggered by NAK received (usually valid)
11: 05->02 04 0000   STOP received

12: 04->02 01 0000   Address match
13: 13->02 01 01FF   address match - receive
14: 14->02 02 0000   start slave receive operation
15: 05->02 02 0000   STOP received

16: 00->00 00 0000


On the I2Cslave client API,
1. rxMsg.processMsg() is called once (with 1 byte data payload), then
2. replyMsg.processMsg() is called once (when TX to master complete I believe)
but that's it, I would have expected to observe:
3. rxMsg.processMsg() to be called with a 3-byte data payload

Is there some explicit "reset" to perform after each request?

For now, I only configure the slave with:

Code: Select all

   i2cStart();
   i2cSlaveConfigure();
   i2cMatchAddress();


while the .processMsg only update the .body and .size members of their respective
I2CSlaveMsg instance.

Thanks,
Manu

BTW: is there any chance that whatever valid I2CSlave implementation eventually gets merged into the upstream repository?

User avatar
Giovanni
Site Admin
Posts: 13527
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 861 times
Been thanked: 743 times
Contact:

Re: I2C Slave mode support?

Postby Giovanni » Mon Dec 11, 2017 6:26 pm

hi,

eblot wrote:BTW: is there any chance that whatever valid I2CSlave implementation eventually gets merged into the upstream repository?


Unlikely shot term, problem is support not code.

Giovanni

steved
Posts: 770
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 10 times
Been thanked: 122 times

Re: I2C Slave mode support?

Postby steved » Mon Dec 11, 2017 7:03 pm

Have you caught up with this thread? There's an example which might help pin down the problem.


Return to “General Support”

Who is online

Users browsing this forum: No registered users and 4 guests