I2C Init

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
graemec
Posts: 11
Joined: Thu Dec 24, 2009 10:26 pm

I2C Init

Post by graemec »

Hi,
I have an instance of the I2C init macro hanging the program in HW. I want to perform a write to an external I2C eeprom 24LC256 but it doesn't get past the I2C init macro. Everything works ok in the simulator. When should the init macro be run? Right at the start of the program or just before the I2C start macro? Any ideas? I'm running version 4.2.3.58 and Im using a 18f4620 @ 20MHz. Thanks
PS If I run just the full I2C routine separate from the main program it works in HW also....

G

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: I2C Init

Post by Benj »

Hello,

You should be able to call the init function at any time without causing lockups.

Are you using the hardware or software I2C?

Also do you have external pull up resistors connected to the 2 signal lines? These will probably need to be around 4.7K.

graemec
Posts: 11
Joined: Thu Dec 24, 2009 10:26 pm

Re: I2C Init

Post by graemec »

Hi Benj
I do have the external pull ups at exactly 4k7 and I'm using the onboard I2C of the 18F4620.
I've experimented a little...
1) To make things simpler and to make sure I had no stack overflow issues I exported my I2C eeprom write macro from the main program and added some markers so I'd know where it was hanging and recompiled.
2) Ran the program and as before it got stuck at the I2C init component macro.
3) Moved the I2C init component macro to the very start of the main program and it now it does not lockup.

So it would appear that it does make a difference where you call the I2C init.

Any ideas on understanding what's causing the lock up?

G

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: I2C Init

Post by Benj »

Looking at the code there is nothing in the init function that could be blocking the code from running.

In the Start function there is however a while command that could potentially cause a block if the sspcon2 register is not updated correctly or becomes corrupted.

Maybe try switching to the software (bitbanged) mode if the lockups become a recurring problem.

Migght be worth putting your program onto the forum to see if we can replicate the problem here and get to the route of what is going wrong.

graemec
Posts: 11
Joined: Thu Dec 24, 2009 10:26 pm

Re: I2C Init

Post by graemec »

Hi Ben,
Here are two files. One works fine, the other locks up at the I2C init macro. The only difference is the position of the I2C init component macro. Both run ok in the simulation.
dm4_i2c_4620_lockup.fcf is the one with the lockup.
I'm using a 18F4620 @ 20MHz with a 24LC256 connected directly to the controller with 4k7 pullups on the SDA and SCL lines.
Thanks
Graeme
dm4_i2c_4620_lockup.fcf
(14.46 KiB) Downloaded 263 times
dm4_i2c_4620_test.fcf
(14.36 KiB) Downloaded 275 times

graemec
Posts: 11
Joined: Thu Dec 24, 2009 10:26 pm

Re: I2C Init

Post by graemec »

Hi Ben,
Have you looked into this I2C init issue any further?
Since my last post I've tried a different controller (18F4520), different memory (24LC02), different clock (4MHZ) and a different board.
In all cases I'm able to cause problems by moving the I2C init macro (corrupt data or lockups)
The place the I2C init Macro seems to work best ( doesn't lockup) is if it is the very first macro of the main program but even then something is not quite right.
In my application the first time I call a page read of the I2C eeprom it works ok but subsequent attempts to call the read routine either for the same or another memory address of the I2C eeprom cause a lockup of the controller this time at the I2C start Macro. FYI writing to the I2C eeprom works fine without problems.
Is there anything in the chip config that would cause problems?
Please let me know something.
Graeme

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: I2C Init

Post by Benj »

Hello Graeme,

Sorry I've not had chance to look at it yet I spend my weekend concentrating on the bug in the FAT16 component.

I don't think this is a configuration problem it must just be a set of specific events thats go together to form a crash. I will try and have a look at the cause of the problem as soon as I get some free time.

Post Reply