i2c transmission success!

[ element14 shabaz i2c code ] [ Tektronix MSO 2014 ]

[ R-PI > I2C > Arduino ] [ Level Shifters ] <– use for shield

20150309-001123.jpgPull up resistors can be skipped. The transitions are more curvy in this case.

If we do want to pull up, 1.2 kohm to 3.3 V seems to work well. Transitions get sharper. I also mistakenly plugged in 1k (SCL) and 100 ohm (SDA) resistors, which do seem to transmit the data, but we get an I/O failure after sending the address and the first byte (only “e” shows up on arduino’s serial…)

Pulling up to 5V seemed to mess everything up, but after some resets / “default setup” on the oscilloscope, things seemed to start working again! I almost felt like I had burnt something.

Using i2c-1 on Debian. Didn’t have to configure anything special (read: the missing i2c-1).

BBB P9.19 -> Uno A5 (SCL)
BBB P9.20 -> Uno A6 (SDA)

Arduino configured as a slave receiver:

// Wire Slave Receiver
// Originally by Nicholas Zambetti &amp;lt;http://www.zambetti.com&amp;gt;
//Edited slightly to print all char to Arduino's serial

// Demonstrates use of the Wire library
// Receives data as an I2C/TWI slave device
// Refer to the &amp;quot;Wire Master Writer&amp;quot; example for use with this

// Created 29 March 2006

// This example code is in the public domain.

#include &amp;lt;Wire.h&amp;gt;

void setup(){
  Wire.begin(5);                // join i2c bus with address #4
  Wire.onReceive(receiveEvent); // register event
  Serial.begin(9600);           // start serial for output

void loop(){

// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany){
  while(1 &amp;lt; Wire.available()){ // loop through all but the last
    char c = Wire.read(); // receive byte as a character
    Serial.print(c);         // print the character
  char x = Wire.read();    // receive byte as an integer
  Serial.print(x);         // print the integer

i2cdetect on BBB works just fine:

Screen Shot 2015-03-08 at 11.34.49 PMHere’s what we ran on the BBB:

#include &amp;lt;stdio.h&amp;gt; 
#include &amp;lt;linux/i2c.h&amp;gt;
#include &amp;lt;linux/i2c-dev.h&amp;gt;
#include &amp;lt;sys/ioctl.h&amp;gt;
#include &amp;lt;fcntl.h&amp;gt;
#include &amp;lt;errno.h&amp;gt;
#include &amp;lt;time.h&amp;gt;
//#include &amp;quot;i2cfunc.h&amp;quot;

int i2c_open(unsigned char bus, unsigned char addr){
  int file;
  char filename[16];
  sprintf(filename,&amp;quot;/dev/i2c-%d&amp;quot;, bus);
  if ((file = open(filename,O_RDWR)) &amp;lt; 0){
    fprintf(stderr, &amp;quot;i2c_open open error: %s\n&amp;quot;, strerror(errno));
  if (ioctl(file,I2C_SLAVE,addr) &amp;lt; 0){
    fprintf(stderr, &amp;quot;i2c_open ioctl error: %s\n&amp;quot;, strerror(errno));

int i2c_write(int handle, unsigned char* buf, unsigned int length){
  if (write(handle, buf, length) != length){
    fprintf(stderr, &amp;quot;i2c_write error: %s\n&amp;quot;, strerror(errno));

int main() {
    unsigned char bus = 1;
    unsigned char addr = 0x05;
    int handle = i2c_open(bus, addr);
    unsigned int length = 5;
    unsigned char buf[length];
    int success = i2c_write(handle, buf, length);
    printf(&amp;quot;We should see %d: %d\n&amp;quot;, length, success);
    return 0;

And here’s what happens if we mess around with our buffer’s size (that is, if you only fix some bytes on the buffer, some fun things start happening…)

Screen Shot 2015-03-08 at 10.27.29 PM


One thought on “i2c transmission success!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s