I2C Slave Driver

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

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
User avatar
HDKLog
Posts: 45
Joined: Thu Aug 18, 2016 12:36 am
Has thanked: 1 time
Been thanked: 3 times

I2C Slave Driver

Post by HDKLog »

Hello!
I'm working on project where I2C Slave functionality is required. As I found in this forum and in documentation there is no support for I2C Slave mode so i had to implement it by myself. Im working with STM32F446RE microcontroller, but I think my API is abstract enough to be ported on other microcontrollers.

here is modified driver files and example of it usage:
os.zip
I2C slave driver
(15.69 KiB) Downloaded 492 times

main.c.zip
I2C slave exemple
(1.45 KiB) Downloaded 524 times


Don't forget to define STM32_I2C_SLAVE_ENABLE in halconf.h

Code: Select all

/**
 * @brief   Enables I2C slave mode.
 */
#if !defined(STM32_I2C_SLAVE_ENABLE) || defined(__DOXYGEN__)
#define STM32_I2C_SLAVE_ENABLE       TRUE
#endif


I know some developers would like to have separated I2C Slave driver but i think it is better to extend existing I2C driver because some Master code can be reused for Slave mode.

For my application it works well but feel free to make any suggestions and/or corrections.
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: I2C Slave Driver

Post by Giovanni »

Hi,

Thanks for the code, is this based on the driver already proposed by genosensor or a whole new implementation?

Giovanni
User avatar
HDKLog
Posts: 45
Joined: Thu Aug 18, 2016 12:36 am
Has thanked: 1 time
Been thanked: 3 times

Re: I2C Slave Driver

Post by HDKLog »

I started from learning genosensor version but found it too complicated for simple I2C Slave applications so i made my own. I just extended existing I2Cv1 LLD driver, and simplified I2C Slave interface. I even used DMA which was preconfigured in "i2cStart" function. For most I2C Slave applications you just need to setup driver, give it address to match and wait until master will start Transmission or Reception of data. when master will do it, corresponding callback will be called from ISR and you will decide there what to do... For data Transmission you can just set up DMA and start sending data. When driver receives data it stores it in DMA (which you set up at start), until STOP detected and call Data Reception callback.
Post Reply