SOLVED: Wire library routine pulls SCL and SDA low but does not release ????

I have a compass from Parallax HMC6352 which I did'nt get to respond so this weekend I borrowed an oscilloscope from my job to see the timing. I am using the Arduino 2560 board.

The Parallax board has already 10k pullup and the pullup works just fine. Right now I have just connected the SCA and SCL to an external pullup of 2k to debug with my oscilloscope.

Immediately when I send the first command the SDA and SCL goes low and stays low ??? I would expect the clock and address to toggle sending out the info ...at least trying to connect. No matter if there is a I2C slave or not that cound hear what the master is sending.

After the Wire.begin(); in my setup I just call

Serial.println("DEBUG: START OF GetCompass1direction rountine"); Wire.beginTransmission(0x42); Wire.send("A"); Wire.endTransmission(); Serial.println("DEBUG: Halfway");

Right now both SDA and SCL are being pulled low and stays there... Have I forgot to initialize anything that is needed to be able to use the wire library with my 2560?

A beginners mistake?? Any ideas ?

thanks//Fredrik BTW: The pins works fine. I can use digitalWrite(); to make them toggle as expected

(deleted)

Try using an address of 0x21 instead.

See attached PDF for setup. :slight_smile:

I know that the adress should be 0x21 since Wire adds the bit depending on if your write or read.
That is not the issue here.

The SDA and SCL lines are not toggled at all ! Thats the issue. They are being pulled down to GND
when I try to send out something.

/Fred

I2C testing.pdf (346 KB)

Issue partly solved.

I called the routine from a Timer 2 interrupt.
MsTimer2::set(1000,Timer2interrupt); // 1000ms period gives a call at 1Hz to get the compass direction

When I removed all MsTimer2 code and just put the I2C call directly in a blank new sketch Loop
it worked ???
Yet I have not had the time to figure out why.
Anyone who knows if there could be any issues when setting the prescaler etc when one uses MsTimer2??

/Fred
See the picture with clear communication that I have attached.

I2C_NowWorking.jpg

The endTransmission goes into a couple of hard loops, relying on an interrupt to pull it out. If you are calling it from an interrupt service routine, and interrupts are disabled, then it will just loop forever.

I guess thats really whats happened.

Problem solved by setting a flag inside the MsTimer2 routine that is was time to do send data. In the main LOOP just checked that this flag was set and started the I2C communication from there.

I now also have added some more communication. The data read from I2C is now transmitted via USART1 up to my PC. Using the very simple Serial1.Print();

Serial1 is maybe simple but for us who just needs basic communication between different boards its very effective. I must say the Arduino world is making thoose standard things just flow.

Credit to all of you participating in Lib-writing and contributing in different ways

thanks/Fred