Page 1 of 1
I2C master and slaves
Posted: Tue Oct 30, 2018 7:55 pm
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
Re: I2C master and slaves
Posted: Tue Oct 30, 2018 10:12 pm
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
Re: I2C master and slaves
Posted: Sun Nov 04, 2018 8:12 pm
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??
Re: I2C master and slaves
Posted: Sun Nov 04, 2018 9:59 pm
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
Re: I2C master and slaves
Posted: Mon Nov 05, 2018 2:07 pm
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?
Re: I2C master and slaves
Posted: Mon Nov 05, 2018 5:25 pm
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.
Re: I2C master and slaves
Posted: Tue Nov 06, 2018 6:38 pm
by JFinlayson
Where does flowcode set up the bits for I2C so I can check whats going on??
Re: I2C master and slaves
Posted: Tue Nov 06, 2018 10:48 pm
by JFinlayson
Yes I have pull up resistors 6k8 on both lines
Re: I2C master and slaves
Posted: Wed Nov 07, 2018 10:53 am
by LeighM
Hi,
You can change pins for the hardware channels too ...

- pin_change.jpg (57.88 KiB) Viewed 10234 times
Re: I2C master and slaves
Posted: Wed Nov 07, 2018 12:09 pm
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.
Re: I2C master and slaves
Posted: Wed Nov 07, 2018 12:23 pm
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.
Re: I2C master and slaves
Posted: Wed Nov 07, 2018 3:22 pm
by JFinlayson
Thanks!
It would be nice to know the problem and the solution.
Re: I2C master and slaves
Posted: Sun Nov 11, 2018 4:05 pm
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.
Re: I2C master and slaves
Posted: Sun Nov 11, 2018 8:35 pm
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.
Re: I2C master and slaves
Posted: Sun Nov 18, 2018 4:11 pm
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.
Re: I2C master and slaves
Posted: Wed Nov 28, 2018 6:31 pm
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

Re: I2C master and slaves
Posted: Thu Nov 29, 2018 12:17 pm
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.