Page 1 of 1

I2C Slave Driver

Posted: Sat Sep 03, 2016 12:13 pm
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 493 times

main.c.zip
I2C slave exemple
(1.45 KiB) Downloaded 525 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.

Re: I2C Slave Driver

Posted: Sat Sep 03, 2016 2:41 pm
by Giovanni
Hi,

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

Giovanni

Re: I2C Slave Driver

Posted: Sat Sep 03, 2016 3:34 pm
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.