I2C problem

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

Post Reply
djm2
Posts: 18
Joined: Tue Jan 24, 2012 6:12 pm
Has thanked: 1 time
Contact:

I2C problem

Post 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
Attachments
compass code.zip
(104.33 KiB) Downloaded 345 times
Screenshots.zip
(158 Bytes) Downloaded 354 times

User avatar
Steve
Matrix Staff
Posts: 3418
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times
Contact:

Re: I2C problem

Post 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.

User avatar
JohnCrow
Valued Contributor
Valued Contributor
Posts: 1367
Joined: Wed Sep 19, 2007 1:21 pm
Location: Lincolnshire
Has thanked: 364 times
Been thanked: 716 times
Contact:

Re: I2C problem

Post 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
1 in 10 people understand binary, the other one doesn't !

djm2
Posts: 18
Joined: Tue Jan 24, 2012 6:12 pm
Has thanked: 1 time
Contact:

Re: I2C problem

Post 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

User avatar
petesmart
Valued Contributor
Valued Contributor
Posts: 395
Joined: Thu May 06, 2010 11:42 am
Location: Sydney, Australia
Has thanked: 187 times
Been thanked: 140 times
Contact:

Re: I2C problem

Post 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
sorry about that Chief!

djm2
Posts: 18
Joined: Tue Jan 24, 2012 6:12 pm
Has thanked: 1 time
Contact:

Re: I2C problem

Post 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

dazz
Posts: 1314
Joined: Sun Jan 15, 2012 3:15 pm
Has thanked: 474 times
Been thanked: 458 times
Contact:

Re: I2C problem

Post 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
To sign up to the V5 forum follow this link http://www.matrixmultimedia.com/forum_upgrades.php

djm2
Posts: 18
Joined: Tue Jan 24, 2012 6:12 pm
Has thanked: 1 time
Contact:

Re: I2C problem

Post 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

User avatar
petesmart
Valued Contributor
Valued Contributor
Posts: 395
Joined: Thu May 06, 2010 11:42 am
Location: Sydney, Australia
Has thanked: 187 times
Been thanked: 140 times
Contact:

Re: I2C problem

Post 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 400 times
sorry about that Chief!

djm2
Posts: 18
Joined: Tue Jan 24, 2012 6:12 pm
Has thanked: 1 time
Contact:

Re: I2C problem

Post 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

User avatar
petesmart
Valued Contributor
Valued Contributor
Posts: 395
Joined: Thu May 06, 2010 11:42 am
Location: Sydney, Australia
Has thanked: 187 times
Been thanked: 140 times
Contact:

Re: I2C problem

Post 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
sorry about that Chief!

User avatar
Dan81
Valued Contributor
Valued Contributor
Posts: 268
Joined: Sun Jan 15, 2006 4:07 pm
Location: Albi France
Been thanked: 60 times
Contact:

Re: I2C problem

Post 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

Post Reply