I am trying to make two raspberry pi communicate through I2C protocol. I got little information that how I can code as a master in C using i2c-dev.h. So my question is how to make one of my raspberry pi behave as slave ? I didn't find any information in internet, please help , and I am very new to I2C, if I am not giving enough details let me know. :)
Thank you
-
Has someone written such a GPIO workaround or a custom slave driver?– user7648Commented May 27, 2013 at 11:09
3 Answers
I'm new to RPi and don't know if it has a built-in I2c-slave.
If it doesn't you still can use GPIOs as inputs and implement a slave yourself by polling those GPIOs in software. The I2c-protocol is relatively easy to implement once understood.
A problem could be the real-time aspects if you're really sampling the I2c-bus yourself: to have an I2c-bus running at 100kHz you need at least read the GPIO used for SCL (clock) 200000 times per second ideally with a constant interval to not miss a cycle.
-
Hi @Patrick , Thanks for the idea :). As per the kernel Documentation/i2c/summary page It has told that .
At this time, Linux only operates I2C (or SMBus) in master mode; you can't use these APIs to make a Linux system behave as a slave/device, either to speak a custom protocol or to emulate some other device.
– duslaboCommented Mar 25, 2013 at 3:51
bcm2835 has support for I2C slave. Refer to section 11 of http://www.raspberrypi.org/wp-content/uploads/2012/02/BCM2835-ARM-Peripherals.pdf
Unfortunately, GPIO pin 19 (BSC slave CLK) was dropped. http://elinux.org/RPi_BCM2835_GPIOs
So, the built-in I2C slave cannot be used.
The new Raspberry Pi B+ Rev.1.2 has 40 GPIO-Pins and four pins are for the I2C-Slave mode
I had never tested:
PIN 12 (connected to GPIO18) mode ALT3 -> BSCSL_SDA/MOSI
PIN 35 (connected to GPIO19) mode ALT3 -> BSCSL_SCL/SCLK
PIN 38 (GPIO20) ALT3 -> BSCSL/MISO
PIN 40 (GPIO21) ALT3 -> BSCSL/CE_N
I hope it'll help you a little bit.