Basic question about I2C on Photon

I’m trying to interface my Photon ( firmware 0.6.0-rc2 prerelease and 0.5.3) with a 24AA32A E2PROM using I2C. I’m having a hard time sending data over with I2C. It seems I haven’t configured the bus correctly.

So I’ve set up a minimal code example to simplify:

void setup() {
	Wire.setSpeed(CLOCK_SPEED_100KHZ); 
	Wire.begin();   
}

void loop() {
	Wire.beginTransmission(3); // transmit to slave device #3
   
	if( Wire.endTransmission() != 0 ){ 
	 Wire.begin() ;     /* re-init the i2c */
	}
	delay(2000);
}

This is what I’m seeing with my oscilloscope:

So although I’m sending a 3, the oscilloscope decodes it as a 6.

What could be the problem? I’m using 4.7kOhm pullups to VDD.

I’d say this is due to the fact that this 3 is the 7bit address of the device, which will be left-shifted one bit to “add” the read/write bit to have the 8bit read or write address.

https://docs.particle.io/reference/firmware/photon/#begintransmission-

2 Likes

Thanks ScruffR for the reply! So This means the info sent is 3 and it’s also what the oscilloscope sees. The I2C library padds a 0 for the 7th bit which means a /Write. I see.

Hmm, actually you pass 3, but the library shifts that (multiplies by 2) and adds 0 (write) or 1 (read) to make up the byte that will be transmitted, and so the osc will see 6.

1 Like