View previous topic :: View next topic |
Author |
Message |
rightbak
Joined: 16 Sep 2011 Posts: 10
|
I2C Slave problem |
Posted: Tue Oct 17, 2017 5:28 am |
|
|
I'm using a 16F15376 with compiler version v5.070.
I'm having problems setting up the device to configure the I2C module as a slave. The problem I am seeing is that it works correctly if I use MSSP1 but fails to work if I use MSSP2.
So for example, this code works as an I2C Slave using I2C1
Code: | #pin_select SCL1OUT = PIN_B1
#pin_select SCL1IN = PIN_B1
#pin_select SDA1OUT = PIN_B2
#pin_select SDA1IN = PIN_B2
#use i2c(SLAVE,I2C1,ADDRESS=0x10)
|
But essentially the same code using I2C2 fails to operate
Code: |
#pin_select SCL2OUT = PIN_B1
#pin_select SCL2IN = PIN_B1
#pin_select SDA2OUT = PIN_B2
#pin_select SDA2IN = PIN_B2
#use i2c(SLAVE,I2C2,ADDRESS=0x10)
|
I need to use the second module as the first is being used as an SPI interface on pins C3, C4 and C5 (MSSP2 cannot be reconfigured onto Port C)
I've tried various combinations of options for the #use statement (FORCE_HW, specifying the pins directly etc) but nothing seems to work.
I'm sure I've done something wrong here but cannot spot it. Thanks in advance for any help! |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9247 Location: Greensville,Ontario
|
|
Posted: Tue Oct 17, 2017 6:48 am |
|
|
There are several reserved addresses and pretty sure 0x10 is one of them..though that may not be a concern, yet....
Have you the correct pullups on the 2nd I2C bus ??
Have you tried PCM P's I2C scanner program from the code library ?
Might be a compiler bug, version please !
Jay |
|
|
rightbak
Joined: 16 Sep 2011 Posts: 10
|
|
Posted: Tue Oct 17, 2017 7:00 am |
|
|
The physical I2C lines come in to RB1 (Clock) and RB2 (Data) and I'm using the pin select #use statement to redefine which MSSP module is 'connected'. MSSP1 appears to work but MSSP2 doesn't - see code above. The I2C pullups don't change so must be correct for MSSP1 to work.
Compiler version is v5.070.
I haven't seen PCM's I2C scanner program. I'll see if I can find it.... thanks |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1911
|
|
Posted: Tue Oct 17, 2017 7:13 am |
|
|
I haven't used that PIC but from the PICs I have used that have featured the PPS functionality, sometimes not all peripherals can be remapped to all pins. Have you checked that MSSP2 can actually be remapped to those two particular pins? |
|
|
rightbak
Joined: 16 Sep 2011 Posts: 10
|
|
Posted: Tue Oct 17, 2017 7:17 am |
|
|
MSSP2's default location is RB1 and RB2 anyway so perhaps I don't need to re-map it at all? I did try without the #PIN_SELECT statements but it didn't compile.. |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1358
|
|
Posted: Tue Oct 17, 2017 8:03 am |
|
|
Since I2C1 works on the same pins but I2C2 does not, I would start out by dumping the listing (LST) file for both versions (working and not working) and see how the assembly compares. Perhaps a wrong address is used for I2C2. The datasheet should have all the addresses listed so you can quickly tell.
Also did you check the errata on the chip to make sure there wasn't a problem with I2C2? |
|
|
rightbak
Joined: 16 Sep 2011 Posts: 10
|
|
Posted: Tue Oct 17, 2017 8:45 am |
|
|
Problem resolved...
I still had the interrupt enabled for INT_SSP rather than INT_SSP2!
Once changed over, all working ok! Thanks for all your prompting... |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19553
|
|
Posted: Tue Oct 17, 2017 8:49 am |
|
|
We have all done something similar at some point.
It is the little things that become vital.... |
|
|
alan
Joined: 12 Nov 2012 Posts: 357 Location: South Africa
|
|
Posted: Tue Oct 17, 2017 9:00 am |
|
|
Which once again highlights the request that a small compilable program with the fault present be attached. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19553
|
|
Posted: Wed Oct 18, 2017 1:05 am |
|
|
That is also why often the act of producing the 'cut down' version will make you realise what is wrong.... |
|
|
|