Page 1 of 1

I2C problem

Posted: Fri Feb 10, 2012 2:03 pm
by djm2
Hi there

Was wondering if anyone could give any ideas to help me solve this problem?

I am using a easypic6 development board, PIC18f4685, 4MHz, 10K pull up resistors on I2C bus and flowcode 5

this compass sensor - http://www.robot-electronics.co.uk/htm/cmps10doc.htm
and this LCD - http://www.robot-electronics.co.uk/htm/Lcd03tech.htm

I have attached a simple program that reads the heading from the compass sensor via I2C. I have also written code for the LCD to work which also works over the I2C bus. The LCD is working great!

Here are my observations this far -
  • Nothing connected to SDA or SCL - works great I can see the data and the clock!
    LCD connected to SDA/CSL works great!
    If I connect the gyro nothing works. Data line is pulled low and the clock remains high. If I disconnect the gyro still nothing happens to get it to work again I have to disconnect the gyro from the bus and then turn the PIC off and on again. I have tried connecting the device once the PIC is powered up and also powering the whole lot up at the same time with the same result.
    Power LED flashes on gyro when powering up.
I have checked and double checked that SDA/SCL are connected correctly to the gyro/PIC. I found that as soon as the gyro is connected my program seems to stop working - I have an LED that flashes each time it goes around the loop and this stops flashing. I have found that if I reset the PIC it seems to give a bit of a burst of I2C and then stops almost as if it is getting stuck somewhere on the first pass of the code.

I was working on this yeserday and someone the sensor would work sometimes - I could not figure out what caused it to work/not work. Sometimes just reprogramming it with the same .hex file cause it to work again. I have attached some screen shots of how it should have looked - which it did sometimes and then other times the data line would remain pulled low however it worked in cycles ie one time it works OK the next not and so on.

David

Re: I2C problem

Posted: Fri Feb 10, 2012 2:42 pm
by Steve
Hi David,

Are you also a user of Flowcode V4 and are you able to check to see if the same problem exists with V4?

Thanks,
Steve.

Re: I2C problem

Posted: Fri Feb 10, 2012 3:07 pm
by JohnCrow
Hi David

I have used the CMP03 robot electonics compass modules. Think the one you are using can detect if the module is tilted.

Have a look at my posts these are in FC4, but I have had them work in FC5
Don't think I had any issues converting them, but at work at the monent so dont have access to my PC

http://www.matrixmultimedia.com/mmforum ... ass#p25899

Re: I2C problem

Posted: Fri Feb 10, 2012 3:28 pm
by djm2
Hi there

Thanks for your replies. I dont have V4 this is the first version of flowcode I have used. I checked to see if it was possible to use the free version but I dont believe the I2C component is available in this version.

Yeah its a new module and looks pritty good very similar to the one you used but with the tilt compensation. I opened up your example and my code seems to be very similar minus the LCD and the small register address changes.

David

Re: I2C problem

Posted: Fri Feb 10, 2012 9:18 pm
by petesmart
Hi,

I am using a CMPS10 with i2c at present on V5. Originally built on V4, converted to V5 ok...

When I get a moment I will have a look at your code, in the mean time some basic questions,

What is the value of the i2c Phillip resistors?

What is the speed of the i2c bus, 100hz?

Back soon

Pete

Re: I2C problem

Posted: Sat Feb 11, 2012 11:12 am
by djm2
Hi there

Yes you are correct I have it running at 100Hz. Not really sure what you mean by the I2C Phillip resistor? But I do have a 10k pull up resistor on both the SDA and SCL line.

David

Re: I2C problem

Posted: Sat Feb 11, 2012 12:57 pm
by dazz
Hi
As your not sure if its the cmps10 or your code go here
http://www.robot-electronics.co.uk/htm/ ... amples.htm download the cmps09 zip, connect your circuit as per the diagram, open the hex file in the zip you downloaded in ppp, change the chip and the config to your chip also enable internal external switchover and the failsafe clock moniter switch LVP to off , and save that hexfile (click apply then save) give it another name then set up your ep6 board as per diagram above and try it. if it give the same errors ie locking up then look around the module etc. If it works then recheck your flowcode etc.

hope it helps

Re: I2C problem

Posted: Sun Feb 12, 2012 10:42 pm
by djm2
Hi there

I did have a look at this however, it is an example using the serial comminication method with the device rather than I2C.

Basically I know the I2C hardware is fine because it works with an LCD display fine on the same bus. I changed the code for the LCD to work with the compass module. Disconnect the PIC turn the hardware on and both lines are pulled high with the compass connected to the hardware.

Sometimes I can get it to work which is the really weird thing. After ages playing about with it I noticed a strange pattern -

After programming my program would appear not to run. Turn the hardware off unplug the crystal and turn back on. Depending on the clock settings it may work but slowly. Then turn the hardware off again. Connect the crystal back up and turn back on. Then it works! If I then turn the hardware off and back on again it doesnt work again! This is the only consistance I have found however, sometimes (not very often) it will work first time after programming it.

I need to try with a different PIC/different type of PIC to see if it is the same with other devices or not but I have not have much time this weekend to play about too much.

David

Re: I2C problem

Posted: Mon Feb 13, 2012 2:09 pm
by petesmart
Hi ,

try this example... its for a 16f877A, it should work on your chip, just change the target.. Note it has an LCD attached to read out the angle.

BTW drop your pull up resisitors to 1.8k ( recommened by phillips) for 100khz... its possibly a contributor to your insatbility, depending on your rig of course

see how you go :)

best

Pete
compass i2C 16F877A_1.fcf
cmps09 test file with LCD
(15.09 KiB) Downloaded 480 times

Re: I2C problem

Posted: Wed Feb 15, 2012 12:00 am
by djm2
Hi there

I have to give you a massive thankyou Pete! Tried out your code and it worked! I made some minor changes to my code to make it pritty much identical to your code but my updated version still would not work. I tried copying the blocks over to a new file and then it worked. I was trying to work out if it was maybe the config settings but then my computer froze. Tried to restart it and the hard drive is now an ex hard drive :-(

With your code and my updated code (copied to a new file) the I2C worked great. I turned the hardware on and off repeatedly and each time it started up with no problems. When I get a new hard drive I guess I can start to try and figure out where the problem lay.

Once again thank you for your help!

David

Re: I2C problem

Posted: Wed Feb 15, 2012 3:36 pm
by petesmart
No problem... I could not get your code to work either... Did not spend too much time on it too figure out what was going on....glad it worked for you.


Best

Pete

Re: I2C problem

Posted: Thu Feb 16, 2012 10:34 am
by Dan81
Hello David

In your Flowchart, the return value (acknowledge) of the "Transmit Byte" macro is empty.
May be, it is cause of the problem.

Daniel