I2C interface Problem with I/O port [Solved]

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 7.

Moderator: Benj

Post Reply
jim_g
Posts: 22
Joined: Tue Jan 13, 2015 12:47 pm
Has thanked: 6 times
Been thanked: 8 times

I2C interface Problem with I/O port [Solved]

Post by jim_g »

Hi

I am building some battery operated radio synchronised clocks for Christmas presents (and its getting close!). I abandonned this a couple of years ago because excessive clock time errors + the effects of noise + excessive coding complexity (especially the last one!) stopped it being fun. Now, with a new clock chip and better algorithms and coding clarity from Flowcode, its nearly finished.

I'm using the 18F45K22.

The clock has three seven-segment displays for time and other data; these are driven by I2C chips (PCF8577C) and these work fine. It also has an LED array that can display calendar and other data in BCD format; these are driven by I2C chips (PCA9555DB) and I cannot get data into them. The chips return a zero after they have been addressed suggesting to me that I am using the correct address. I have previously managed to have this interface working fine using Mikro C, using:
I2C2_Start();
I2C2_Wr(0b01000000); // send device address + Write (integrated circuit U5)
I2C2_Wr(0x02); // address of next word (portA output)
I2C2_Wr(IO0); // data output to bank 0
I2C2_Wr(IO1); // data output to bank 1
I2C2_Repeated_Start();
I2C2_Wr(0b01000010); // send device address + Write (integrated circuit U7)
I2C2_Wr(0x02); // address of next word
I2C2_Wr(IO2); // data output to bank 0
I2C2_Wr(IO3); // data output to bank 1
I2C2_Stop();

Loading from Flowcode into a known working MikroC-programmed clock also does not work (so its not the hardware).

I have completely re-written the program in Flowcode (attached), which has a test loop near the beginning of Main().
It all works except for the LED array.
The I2C code near the end of paintLCDDisplay() (to send data to the LCDs) and that near the end of collectMSFDateTimeCode() (loads date/time into the real time clock chip DS3231) both work fine.
The only real difference in structure is that the LED control uses I2C2, whereas the others use I2C1.

Can anyone help, please?

Jim
Attachments
ClockTest.fcfx
(159.11 KiB) Downloaded 308 times

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 interface Problem with I/O port

Post by Benj »

Hi Jim,

To check it's not an I2C channel 2 issue would you mind switching the LED_I2C component Channel property to software and see if this allows everything to work as expected. If this works then it proves there is something wrong with I2C2 on your device.

If switching to software makes no difference then it must be related to something else.

jim_g
Posts: 22
Joined: Tue Jan 13, 2015 12:47 pm
Has thanked: 6 times
Been thanked: 8 times

Re: I2C interface Problem with I/O port

Post by jim_g »

Hi Ben

Just the same result. I also changed one of the addresses in ledTest() to a known incorrect value.
With the correct address, TransmitByte returns 0
With the incorrect address it returns 1

There are "sensible" looking clock and data pulses

Regards

Jim

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 interface Problem with I/O port

Post by Benj »

Hi Jim,

Ok thanks,

Just to be sure it's not something we have already fixed would you mind updating to the latest version of Flowcode 7 and then applying the latest files from here.

http://www.matrixtsl.com/mmforums/viewt ... 63&t=18209

I'll have a look at the code and see if I can spot anything obvious.

jim_g
Posts: 22
Joined: Tue Jan 13, 2015 12:47 pm
Has thanked: 6 times
Been thanked: 8 times

Re: I2C interface Problem with I/O port

Post by jim_g »

Ben

I have inserted the new files and I can see the recent datestamps in the subdirectories. Help... about still declares 7.1.1.0 and Sept 28 though.

There is no change to the results after re-compiling.

Cheers

Jim

jim_g
Posts: 22
Joined: Tue Jan 13, 2015 12:47 pm
Has thanked: 6 times
Been thanked: 8 times

Re: I2C interface Problem with I/O port

Post by jim_g »

Ben

I have (re)discovered the problem. The PCA9555 defaults to an input device on switch-on. Resetting this fixes the problem.

Sorry to wast your time!

Cheers

Jim

Post Reply