Wire.endTransmission

Hello!

I'm trying to communicate wit a motor driver circuit (MD03) using an I2C bus.

The program always get stuck on the Wire.endTransmission. I've seen a fe topict about this but the only solid tip to solve this is what tek2 is suggesting in this thread: Bug with TWI/i2c and Atmega168 - Bugs & Suggestions - Arduino Forum
The only problem: The line SIGNAL... does not exist in the twi.c, at least not in my setup.

Using arduino 1.0.5, windows 7, arduino mega 2560

Any new ideas?

Forgot the code, I commented most of the lines to isolate the problem.

/**
 * Perform a basic test to verify communication with the MD03 motor
 * controller.  It simply reads the software revision register
 * and prints it to the serial port.
 */
#include <Wire.h>
 
/**
 * Define some useful constants.
 */
#define MD03_ADDRESS 0xB0 // The address of the MD03 motor controller
#define MD03_COMMAND_REG 0x00
#define MD03_STATUS_REG 0x01
#define MD03_SPEED_REG 0x02
#define MD03_ACCELERATION_REG 0x03
#define MD03_TEMPERATURE_REG 0x04
#define MD03_MOTOR_CURRENT_REG 0x05
#define MD03_SOFTWARE_REV_REG 0x07
 
byte counter;
 
void setup() {
  Wire.begin(); // Initialize the I2C bus
  Serial.begin(115200); // Initialize the serial bus
  counter = 0;
}
 
void loop() {
  byte revision;
 
  /*
   * Tell the MD03 which register we want to read.
   */
  Wire.beginTransmission(MD03_ADDRESS); // Start communicating with the MD03
  Wire.write(MD03_SOFTWARE_REV_REG);     // Send the address of the register that we want to read
  Wire.endTransmission();
 
  //Wire.requestFrom(MD03_ADDRESS, 1);   // Request one byte of data from the MD03
  //while(Wire.available() < 1);         // Busy wait while there is no byte to receive
  //revision = Wire.read();           // Reads the byte as an integer
 
  Serial.println("test1");
  Serial.println(revision, DEC);
 
  delay(1000); // Do this at approx 1Hz
}

Wire.endTransmission() returns a value
can you check it?

void loop() {
  byte revision;
 
  /*
   * Tell the MD03 which register we want to read.
   */
  Wire.beginTransmission(MD03_ADDRESS); // Start communicating with the MD03
  Wire.write(MD03_SOFTWARE_REV_REG);     // Send the address of the register that we want to read
  int rv = Wire.endTransmission();
  Serial.print("rv: ");
  Serial.println(rv);

  //Wire.requestFrom(MD03_ADDRESS, 1);   // Request one byte of data from the MD03
  //while(Wire.available() < 1);         // Busy wait while there is no byte to receive
  //revision = Wire.read();           // Reads the byte as an integer
 
  Serial.println("test1");
  Serial.println(revision, DEC);
 
  delay(1000); // Do this at approx 1Hz
}

Thanks for the reply.

I will test it tonight, but I doubt that I can see the value, since the line after the Wire.endTransmission command is currently
Serial.println ("test1"), and i don't get anything in the serial monitor, but when I comment the Wire.endTransmission line I get a "test" and a "0" in the serial monitor...

I don't know if the change in the Wire.endTransmission line makes any difference to this though, so I will try.

Those reports are about 4 years old.

The Wire.endTransmission actually does the whole transmission. The start and write just set up an internal buffer. If the endTransmission fails it is probably something electrical. Do you have pull-up resistors?

I connected it according to this sketch Arduino Examples 50V 20A Motor Driver
(except no LCD and I use the arduino mega 2560 and pin 20-21)

So, trial and error.

I finally found a short on the SCL line. The slave card (MD03) had a short from the SCL pin to GND. So With a spare card I got the Wire.endTransmission command to work properly (at least without stopping the program)

Now I’m stuck on the while loop in the next part, while(Wire.available() <1)

Am I right to assume that my arduino gets no response from the “target” and therefore never exits the loop. Does anyone have any ideas what to look for here?

Can you run the I2C scanner on this page please, and report what it prints?

So, with some troubleshooting, some loud screams of anger and a lot of patience, I got the communication to work.

Thanks for the help!

The next step in the project is of a different nature and will probably be better put in another forum, but I'll come back with more questions here if needed.