ChromeBit:
I have an ov7670 module and it communicates using a very similar protocol to i2c.
I've been trying to communicate with it using this code (obviously wire.begin and serial.begin are in setup)...
Wire.beginTransmission(0x21);
//delay(3000);
Wire.requestFrom(0x21,1); readvalue=Wire.read();
delay(300);
Serial.write(readvalue);
Wire.endTransmission();
And a bi-directional level shifter (the sensor uses 3v3 i2c whereas the arduino i2c is 5v).
I have connected the camera correctly, and given it a clock signal, however it still fails to respond to any communication. I have found that I can communicate between boards through the level shifter, so I know the level shifter is set up correctly.
Does anyone know what might be the problem? Do I need to disable the internal pull-up resistors, or will this make no difference if I'm using a level shifter?
You are mixing a Transmit and a receive call to WIRE.
Wire.beginTransmission(0x21);
//delay(3000);
Wire.requestFrom(0x21,1); readvalue=Wire.read();
delay(300);
Serial.write(readvalue);
Wire.endTransmission();
the following is a Wire transmit and a WIRE receive.
// WIRE.write example
WIRE.beginTransmission(0x21); // start a WRITE transaction to I2C device with Slave ID of 0x21
WIRE.write((uint8_t) 25); // add a single byte value (25 decimal) to the WIRE TX_buffer.
WIRE.endTransmission(true); // Actually send the TX_buffer to the Slave. Send an I2C STOP condition,
// releasing the I2C bus to allow other I2C Master's to use the bus,
WIRE.beginTransmission(0x21); // start a WRITE transaction to I2C device with Slave ID of 0x21
WIRE.write((uint8_t) 25); // add a single byte value (25 decimal) to the WIRE TX_buffer.
WIRE.endTransmission(false); // Actually send the TX_buffer to the Slave. DO NOT Send an I2C STOP condition,
// RETAIN control of the I2C bus, The next I2C operation will start with a REPEATED START condition.
// Some I2C device need a two part command to read a specific register.
// First you Write a register address, then you use a RepeatStart to Read the Register contents.
// Read Example
WIRE.requestFrom(0x21,1); // Request a single byte from slave 0x21
uint8_t readValue =WIRE.read();//
WIRE.beginTransmission(), WIRE.endTransmission() are only used to transmit to a slave device
WIRE.requestFrom() is only used to receive from a slave device.
Chuck.
Check out my Kickstarter Project Memory Panes an expansion RAM Shield for Mega2560's. It adds 1MB of RAM for those projects where 8KB is not enough.