I2C master and slaves

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

Moderator: Benj

Post Reply
JFinlayson
Posts: 93
Joined: Mon Sep 23, 2013 4:33 pm
Has thanked: 5 times
Been thanked: 6 times
Contact:

I2C master and slaves

Post by JFinlayson »

Hi anybody got any demo software for I2C with one master and several slaves, as I am having problems communicating with slaves.

Thanks
The older the boy the bigger the toy

mnf
Valued Contributor
Valued Contributor
Posts: 1188
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: I2C master and slaves

Post by mnf »

I tried briefly to get this to work (although I wanted to actually create an i2c 'loop')

See http://www.matrixtsl.com/mmforums/viewt ... 71&t=20043 - which has some code that allowed a 'Master' (in this case Arduino) to transmit to multiple slaves. The sender /receiver did eventually work - and allowed the master to send to 2 (tested) or (theoretically) more slaves. Don't forget your pull-ups.

See also:
http://www.matrixtsl.com/mmforums/viewt ... =7&t=20254

Where Leigh posts at alternate definition file for the 328p MCU which should allow use of the TWI interrupt. Which would perhaps make for nicer code (although I couldn't get this to work :-( - couldn't find the interrupt - so had obviously done something wrong. I was just experimenting here)

Martin

JFinlayson
Posts: 93
Joined: Mon Sep 23, 2013 4:33 pm
Has thanked: 5 times
Been thanked: 6 times
Contact:

Re: I2C master and slaves

Post by JFinlayson »

Playing with I2C in Flowcode 7, using slave on my new BL080 with the stock PIC16F18877, cant seem to get any results, reading the slave status always produces 128 if slew rate control is disabled as expected. but enabling SMBus does not change this value it should. Sending data from an explorer 16 in I2C master mode does not change the status return it stays at 128 if slew rate is disabled and 0 in slew rate is enabled.
Both boards are set up with I2C settings the same ie. baud 100Khz and channel 1 hardware.

any idea why??
The older the boy the bigger the toy

JFinlayson
Posts: 93
Joined: Mon Sep 23, 2013 4:33 pm
Has thanked: 5 times
Been thanked: 6 times
Contact:

Re: I2C master and slaves

Post by JFinlayson »

Why is I2C hardware pins different between Master and Slave??
and different than the datasheet??
For PIC16F18877.
I think the I2C component for this chip is changing wrong bits etc, but even in software mode, I can not get slave or master to receive or transmit anything. oscilloscope shows no clock or data on selected I2C lines for this device.
but ok on explorer16 board
The older the boy the bigger the toy

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: I2C master and slaves

Post by LeighM »

Hi,
The SDA and SCL pins are selectable via the Remap properties. See the drop down list.
Could you post your test projects?
Do you have pull-up resistors?

JFinlayson
Posts: 93
Joined: Mon Sep 23, 2013 4:33 pm
Has thanked: 5 times
Been thanked: 6 times
Contact:

Re: I2C master and slaves

Post by JFinlayson »

I have included the test program, I have been trying many things with the I2C out and in.
In Flowcode 7 hardware channel 1 is data on C1 and clock on C7 for this chip. But for I2C master the pins are C2 and B2 respectively.
Datasheet says for I2C channel 1 is C3 for Clock and C4 for data. that's for the stock 16F18877 supplied with BL080.

so looks like a mix up of pins, and when I select software and choose pins same result nothing out or in on I2C.

BL080Combotest.fcfx
(16.11 KiB) Downloaded 274 times
BL080Combotestout.fcfx
(15.86 KiB) Downloaded 260 times
The older the boy the bigger the toy

JFinlayson
Posts: 93
Joined: Mon Sep 23, 2013 4:33 pm
Has thanked: 5 times
Been thanked: 6 times
Contact:

Re: I2C master and slaves

Post by JFinlayson »

Where does flowcode set up the bits for I2C so I can check whats going on??
The older the boy the bigger the toy

JFinlayson
Posts: 93
Joined: Mon Sep 23, 2013 4:33 pm
Has thanked: 5 times
Been thanked: 6 times
Contact:

Re: I2C master and slaves

Post by JFinlayson »

Yes I have pull up resistors 6k8 on both lines
The older the boy the bigger the toy

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: I2C master and slaves

Post by LeighM »

Hi,
You can change pins for the hardware channels too ...
pin_change.jpg
pin_change.jpg (57.88 KiB) Viewed 8703 times

JFinlayson
Posts: 93
Joined: Mon Sep 23, 2013 4:33 pm
Has thanked: 5 times
Been thanked: 6 times
Contact:

Re: I2C master and slaves

Post by JFinlayson »

This does not work for this device, I would like to know where settings are made in the code of flowcode7. does not matter what I do I can not get an output on I2C for this device but I can with Explorer 16 using flowcode. and with 32bit PIC but with BL080 NO output on I2C.
The older the boy the bigger the toy

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 master and slaves

Post by Benj »

Hello,

We recently discovered that hardware I2C on the 16F18877 is not working as it should in FC8. This is probably also the case in v7.

I know it was well tested previously so hopefully the fix should be fairly simple.

I'll have a look for you and see if I can find the root cause of the problem.

JFinlayson
Posts: 93
Joined: Mon Sep 23, 2013 4:33 pm
Has thanked: 5 times
Been thanked: 6 times
Contact:

Re: I2C master and slaves

Post by JFinlayson »

Thanks!
It would be nice to know the problem and the solution.
The older the boy the bigger the toy

JFinlayson
Posts: 93
Joined: Mon Sep 23, 2013 4:33 pm
Has thanked: 5 times
Been thanked: 6 times
Contact:

Re: I2C master and slaves

Post by JFinlayson »

I must be doing something wrong, I can't get I2C to work on pic18F4455 either. I await your assessment of what is wrong.
No output on oscilloscope on clock or data lines.
The older the boy the bigger the toy

JFinlayson
Posts: 93
Joined: Mon Sep 23, 2013 4:33 pm
Has thanked: 5 times
Been thanked: 6 times
Contact:

Re: I2C master and slaves

Post by JFinlayson »

Ok tried to output on I2C with 16 bit PIC24 no joy nothing out.
Then tried a PIC32MX and it outputs fine on both SCL and SDA in master mode.
However Slave mode does not work on 32bit device as compiler wont accept declarers.
The older the boy the bigger the toy

JFinlayson
Posts: 93
Joined: Mon Sep 23, 2013 4:33 pm
Has thanked: 5 times
Been thanked: 6 times
Contact:

Re: I2C master and slaves

Post by JFinlayson »

OK been away and checked things when I came back and I found fault with a SIL on board which affects some pins, so need to start again. ignore previous mails.
Also checked datasheet against assigned pins for I2C and produced the below. I see that there is no software I2C functionality in Flowcode 8.
and that pin assignment for PIC18877 pins are wrong.
Attachments
I2C.xlsx
(10.43 KiB) Downloaded 169 times
The older the boy the bigger the toy

JFinlayson
Posts: 93
Joined: Mon Sep 23, 2013 4:33 pm
Has thanked: 5 times
Been thanked: 6 times
Contact:

Re: I2C master and slaves

Post by JFinlayson »

Ok Just got back to I2C stuff and the new Flowcode 8 and my new BL080 programmer, and I am happy to say all is working as expected with I2C.

Great :P
The older the boy the bigger the toy

JFinlayson
Posts: 93
Joined: Mon Sep 23, 2013 4:33 pm
Has thanked: 5 times
Been thanked: 6 times
Contact:

Re: I2C master and slaves

Post by JFinlayson »

Hi everything works in new board BL080 with PIC18F6280, However PIC16F18877 that comes with board throws up errors.
First error during compile
C:\ProgramData\MatrixTSL\FlowcodeV8\CAL\PIC\PIC_CAL_I2C.c: FC_CAL_I2C_Master_Init_1()
256: = 21;
C:\Program Files (x86)\Flowcode\Compilers\pic\batch\pic_xc8_comp.bat reported error code 1.

This looks like errors with cal_i2c :Supplementary defines.
The older the boy the bigger the toy

Post Reply