[I2C] Wire library messages not sending

Hi All,

I’ve taken the dive into porting a c library from a PIC over to arduino (Feather m0) and having some issues with the i2c (wire) library. I’ve been sniffing the i2c bus with a bus pirate to keep track of the traffic going on and I’m able to connect to the part (an MCP39F521 energy monitor chip) at address 0xE8 but my messages will not send.

I think that the issue is in the filling of the internal buffer in the wire library. From the sniffer, I see that I am sending the first ID byte (which the part ACKs) then the stop bit but nothing else. I can begin and end a transmission, but will not get any data into it (each .endTransmission() returns a 0 error code, meaning successful transmission. I’m obviously missing something. My code is actually trying to send a char array, but I am getting the same results with individual bytes.

unsigned char i;
	unsigned char * ptr;  // pointer to type power monitor datas

    // read 28 bytes @ 0x0002
    //SYSTEM_STATUS					0x0002 // b16 2
    //SYSTEM_VERSION				0x0004 // u16 2
    //VOLTAGE_RMS					0x0006 // u16 2
    //LINE_FREQUENCY				0x0008 // u16 2
    //ANALOG_INPUT_VOLTAGE			0x000A // u16 2
    //POWER_FACTOR					0x000C // s16 2
    //CURRENT_RMS					0x000E // u32 4
    //ACTIVE_POWER					0x0012 // u32 4
    //REACTIVE_POWER				0x0016 // u32 4
    //APPARENT_POWER				0x001A // u32 4
	const unsigned char ReadValues[] = { 0xA5, 0x08, 0x41, 0x00, SYSTEM_STATUS, 0x4E, 28, 0x5A };
	// send read command
	Wire.beginTransmission(BATTERY_POWMON); //BrSp (Arduino does not need the R/W flag)
	Serial.print("Wire.beginTransmissionReadOutputs( "); //Bs Debug
	Serial.println(BATTERY_POWMON, BIN); Serial.print(" Searching for device..."); //Bs Debug
	for (i = 0; i<sizeof(ReadValues); i++)

		Serial.print("Wire.write size_t: ");
		Serial.println(Wire.write((uint8_t*)ReadValues[i], 8));
		Serial.print("ReadValues[i]: "); Serial.println(ReadValues[i], HEX); Serial.println(ReadValues[i], BIN);//Bs Debug
	Serial.print("Wire.endTransmission() "); Serial.println(Wire.endTransmission()); //this will print the error code
										  // Errors:
										  //  0 : Success
										  //  1 : Data too long
										  //  2 : NACK on transmit of address
										  //  3 : NACK on transmit of data
										  //  4 : Other error

I have also tried individual bytes like this without success.

Wire.write((uint8_t)0x41); Serial.println(0x41, HEX);

Any thoughts?

Thoughts: - your snippet isn't sufficient to see what is going on. Post all your code. - don't put more than one statement per line. - it is not obvious to me that ReadValues is a valid command. The checksum appears to be wrong. I get 0x66. The example in the datasheet of that command requests 0x20 bytes and the checksum is 0x5E. Your request only differs by asking for 8 more bytes which means the checksum is 0x5E+8 = 0x66.