Go Down

Topic: I2C write function doesn't seem to work (Read 260 times) previous topic - next topic

witch359

I'm using code right out of the library example:

Code: [Select]
#include <Wire.h>

byte val = 0;

void setup()
{
  Wire.begin(); // join i2c bus
}

void loop()
{
  Wire.beginTransmission(44); // transmit to device #44 (0x2c)
                              // device address is specified in datasheet
  Wire.write(val);             // sends value byte 
  Wire.endTransmission();     // stop transmitting

  val++;        // increment value
  if(val == 64) // if reached 64th position (max)
  {
    val = 0;    // start over from lowest value
  }
  delay(500);
}



However, I'm only seeing the first block of data on the scope:
- Start bit
- 7 bit address is correct
- write bit (0)
- NACK (nothing attached to the bus right now)
- Stop bit.

 See attached.

This seems like a simple library to use, so what am I doing wrong? Thanks.


pylon

Quote
- Start bit
I don't know where you see the start bit in that picture because there is none. I2C doesn't have a start bit but a start condition and a stop condition.

Quote
This seems like a simple library to use, so what am I doing wrong? Thanks.
You're doing nothing wrong, it's everything as expected. If you expect something else you should define your expectations. The "val" byte is not sent because no device acknowledged the address signaling. Attach a device that acknowledges that address and the "val" value will be sent.

Go Up