Pages: [1]   Go Down
Author Topic: I2c always reads as 255  (Read 2149 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Sr. Member
****
Karma: 11
Posts: 330
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I currently have an ov7670 interfaced with an arduino mega. I have disabled the internal pullups by editing the wiring library (the ov7670 uses 3.3v) and have tried both a 1k and a 10k pullup resistor.By removing the 3.3v it gets stuck on  Wire.endTransmission(true); the ov7670 uses SCCB which should be compatilbe with i2c Here is my code
Code:
#include <Wire.h>
void setup()
{
  Serial.begin(9600);
  pinMode(13, OUTPUT);
  Wire.begin();
  Serial.println("I2C started");
  Wire.beginTransmission(0x21);
  Serial.println("Began");
  Wire.write(0x0D);
  Serial.println("written");
  Wire.endTransmission(true);
  Serial.println("ended");
  
  Wire.requestFrom(0x21, 1,true);
  //while (!Wire.available()) {}
  Serial.println("requested");
  unsigned char x=Wire.read();
  Serial.println(x);
  
}
void loop()
{
 digitalWrite(13,HIGH);
  delay(100);
  digitalWrite(13,LOW);
  delay(100);
}
« Last Edit: December 27, 2012, 12:16:50 am by Mr_arduino » Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17293
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What pin numbers are you using on your mega to wire to the I2C device? The mega uses different pin numbers then the 328p based boards for I2C.

Lefty

Logged

Offline Offline
Sr. Member
****
Karma: 11
Posts: 330
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

20 and 21 they are labeled SDA and SCL so I used those. It must be plugged in correct because when I remove power to the ov7670 It gets stuck at Wire.endTransmission(true); also when I uncomment while (!Wire.available()) {} it gets stuck there. Could 255 just be an error message?
Here is a picture if that will help.(click for larger)

Edit: I did a google search and it turns out that someone is having a similar issue http://www.mentby.com/dave-hylands/i2c-read-fails-but-write-works.html
Should I make a program that bitbangs sccb read?
« Last Edit: December 27, 2012, 12:20:49 pm by Mr_arduino » Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17293
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It's been quite a while sense I played with I2C, but I seemed to recall the a 255 return is what I would get if there was no response back from the device, for instance if you are sending the wrong device address for the attached device, or the device has no power applied. There is frequently addressing problems when dealing with 8 bit address some vendors refer to Vs the 7 bit address (no low order read/write bit sent) that the I2C library requires you to use.

Good luck;

Lefty
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 46
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi there,

You might want to try this library : http://dsscircuits.com/articles/arduino-i2c-master-library.html

It includes a scan function which can be very handy, I had a similar problem with an LCD panel the address supplied was not the address the device was actually set to.

The Scan function automatically prints to the serial monitor.

Code:

#include <I2C.h>

#define SD21 0x61

int x = 0;
int y = 0;
int z = 0;
int err_c = 0;

unsigned int ServoHigh, ServoLow;
unsigned int Servo_pos = 0;

void setup()
{
  I2c.begin();
  Serial.begin(9600);
  //configure device for continuous mode
  //I2c.write(SD21,0x02,0x00);
}

void loop()
{
  delay(3000); //give us time to open serial monitor
  // display I2C bus address info
  for (int i=0;i<1;i++)
  {
      I2c.scan();
  }
Logged

Global Moderator
Netherlands
Online Online
Shannon Member
*****
Karma: 216
Posts: 13672
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


There is a I2C scanner here - http://www.gammon.com.au/forum/?id=10896 - search for I2C scanner (about 80% near the end)
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Offline Offline
Sr. Member
****
Karma: 11
Posts: 330
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Both scanners say no devices found. I am going to write a bit-bang sccb function. How would I convert 5v to 3.3v (bit bang is not open drain like i2c) I only have some hex buffers and resistors do I need to buy a bi-directional level shifter?
Logged

Offline Offline
Edison Member
*
Karma: 3
Posts: 1001
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am going to write a bit-bang sccb function. How would I convert 5v to 3.3v (bit bang is not open drain like i2c)
Your bit-bang function better be open drain if you want it to be I2C compatible. The way to do this is to toggle the SCL/SDA pins between output low and input mode. Logic high (pin mode input) is then limited to your external pullup voltage.
Logged

Pages: [1]   Go Up
Jump to: