• AVR Freaks

Hot!Use of IIC on PIC24FJ64GA002

Author
MTSPIKE
Starting Member
  • Total Posts : 39
  • Reward points : 0
  • Joined: 2017/05/10 05:46:22
  • Location: 0
  • Status: offline
2019/07/08 13:29:39 (permalink)
0

Use of IIC on PIC24FJ64GA002

I'm trying to use IIC communication with the PIC24FJ64GA002.  Specifically the intention is to use the PIC24FJ64GA002 as Master, and communicate with a TI TMP102 temperature sensor, then subsequently send acquired temperature readings from the TMP102 to a Sparkfun 7-Segment display.
 
In the following discussion, note that I’ve placed both the temperature sensor and 7-segment display on a small breadboard which I connect to either the PIC24128GA010 on explorer 16 board, or b to the PIC24FJ64GA002 on 16-Bit 28P Starter Demo Board.  
 
I have a program that works just fine when I use it with PIC24FJ128GA010 on the Explorer 16 board.  Beyond fact that temperature readings are successfully communicated to the 7-Segment display, using an oscilloscope I can see Test book SDA and SCL signals on lines.  Presently, it does not work with the PIC24FJ64GA002; no readings on 7-Segment display, SCL is Stuck At Zero and SDA is Stuck at One.
 
I've not used the Peripheral Pin Select (PPS) of the PIC24FJ64, but I don't think that is an issue when using IIC.  I say that in part because neither Table 10-2 nor Table 10-3 of the PIC24FJ64GA004 Family data sheet mention IIC as a Selectable input or output source.  Further, in Chapter 16 of the Data Sheet, REGISTER 16-1 says when I2CEN = 1 Enables the I2Cx module and configures the SDAx and SCLx pins as serial port pins.
 
I saw mention on the Forum of potential problems with IIC1 from the PIC24FJ64GA002, so I switched over to IIC-2, but still have same problem.     
 
MTSPIKE
 
 
#1

8 Replies Related Threads

    ric
    Super Member
    • Total Posts : 23172
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: Use of IIC on PIC24FJ64GA002 2019/07/08 15:17:06 (permalink)
    5 (1)
    I2C1 on the PIC24FJ64GA002 is shared with JTAG pins, so you need to disable JTAG in the config words.
    SDA2 and SCL2 on that part are shared with analog pins. Have you switched them to digital mode?
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #2
    BobAGI
    Super Member
    • Total Posts : 1715
    • Reward points : 0
    • Joined: 2011/03/09 00:04:35
    • Location: Texas and Sweden
    • Status: offline
    Re: Use of IIC on PIC24FJ64GA002 2019/07/09 00:42:02 (permalink)
    0
    I needed to use I2C on a PIC24FJ256GB206 chip a number of years ago to interface to an EEPROM chip and had big problems until I reverted to a bit-bang approach.
    Here is an earlier mention of this I posted in March 2017.
    In this thread I also have posted further links to advice regarding bitbang of I2C.
    The big advantage is that you can use any I/O pin for this, no need to enable the on-board subsystem.

    --
    Bo B
    Sweden & Texas
     
    #3
    MTSPIKE
    Starting Member
    • Total Posts : 39
    • Reward points : 0
    • Joined: 2017/05/10 05:46:22
    • Location: 0
    • Status: offline
    Re: Use of IIC on PIC24FJ64GA002 2019/07/09 08:21:22 (permalink)
    0
    ric and BobAGI,
     
    Thank you both for your feedback, I truly appreciate it.
    In the following discussion, "Data Sheet" refers to the PIC24FJ64GA004 Data Sheet (DS39881E)
     
    ric,
     
    1) JTAG is disabled.  That is, bit 14 of Config Word 1 = 0 (See Data Sheet, REGISTER 24-1)
     
    2) As for switching to Digital Mode, I had not done that so I went ahead and switched to Digital Mode on all bits, at least I think I did; AD1PCFG = 0xffff;  (See Data Sheet, REGISTER 25-5),   please correct me if I'm mistaken here.  At any rate, I still have same problem, SCL is Stuck At Zero and SDA is Stuck at One.
     
    I believe there may be an issue with the specific PIC24FJ64GA002 IC I have, which I will explain at the bottom.    First however I would appreciate, if you have the time, to see if my thinking outlined below is correct.  (NOTE: The issue with the PIC24FJ64GA002 IC does not appear to apply to I2C2 which is why I switched from I2C1 to I2C2.) 
     
    Since the intention is for the PIC24FJ64GA002 to serve as an IIC Master, the SCL pin should always be an output, and the SDA pin would either be an output when sending data such as an IIC address, or an input when receiving data from the IIC sensor.  In looking at Figure 10-1 of the "Data Sheet", and contemplating SCL, I would assume that Output Enable of the Tri-State driver would always be enabled for SCL, and that the Output Data going to the Tri-State driver would be the Peripheral Output Data, specifically the SCL stream.  The I/O pin for SCL2 would be pin 7 of the PIC24FJ64GA002 (See pg. 2 of Data Sheet).
     
    When contemplating SDA, and again looking at Figure 10-1, when SDA is sending data such as an IIC address, the Output Enable would enable the Tri-State driver and the Peripheral Output Data (i.e., IIC address) would be routed to the Tri-State driver input.  When SDA is receiving data such as data from an IIC Temperature sensor, the Output Enable would be set so that the Tri-State drive is in "Tri-State" i.e., high impedance, and the data in I/O pin is routed thru Schmidt Trigger to Input Data then on to "Peripheral Input Data". The I/O pin for SDA2 would be pin 6 of the PIC24FJ64GA002 (See pg. 2 of Data Sheet).
     
    Now, in looking at Figure 10-1 of the Data Sheet, I'm of an opinion that the "Peripheral Module Enable" bit going to the Multiplexers will, in essence be set for the Peripheral operation when I2C2CON bit 15 is set to 1, See REGISTER 16-1 of Data Sheet.  The Data Sheet indicates that when this bit is set to 1, Enable I2C2 module and configure the SDA2 and SCL2 pins as serial ports, that is pins 6 & 7 respectively.
     
    Well, I mentioned that there may be an issue with the PIC24FJ64GA002 that I have.  Apparently I have an early version of the chip.  A "PIC24FJ64GA004 Family Silicon Errata and Data Sheet Clarification" has been issued (DS80000470J).  However, this document indicates to me that I2C2 does not have the problem.  So, I'm still stuck as I cant get I2C2 to function.
     
    Any input would be appreciated.
     
    MTSPIKE
     
    PS:  I plan to order new PIC24FJ64GA002 IC's, however as I mention above I don't think the potential IC issue pertains I2C2, and if so, I will still be stuck.
     
    #4
    BobAGI
    Super Member
    • Total Posts : 1715
    • Reward points : 0
    • Joined: 2011/03/09 00:04:35
    • Location: Texas and Sweden
    • Status: offline
    Re: Use of IIC on PIC24FJ64GA002 2019/07/09 10:23:12 (permalink)
    0
    Did you look at my linked post at all? It has a complete source for an i2c module, which will work with ANY two I/O lines....
     

    --
    Bo B
    Sweden & Texas
     
    #5
    MTSPIKE
    Starting Member
    • Total Posts : 39
    • Reward points : 0
    • Joined: 2017/05/10 05:46:22
    • Location: 0
    • Status: offline
    Re: Use of IIC on PIC24FJ64GA002 2019/07/09 11:28:07 (permalink)
    0
    BobAGI,
     
    I will have to take a look at it closer, and perhaps try to implement.
     
    Thank you,
     
    MTSPIKE
    #6
    MTSPIKE
    Starting Member
    • Total Posts : 39
    • Reward points : 0
    • Joined: 2017/05/10 05:46:22
    • Location: 0
    • Status: offline
    Re: Use of IIC on PIC24FJ64GA002 2019/07/25 12:35:31 (permalink)
    4 (1)
    ric and BobAGI,
     
    Thank you again for your help, and I wanted to let you know about the following.  I suspect you may have understood this, but it took me a while to get it thru my head.
     
    A means of using I2C2 on the PIC24FJ64GA002 has been found, Microchip Support helped.  It turns out that the SDA2 and SCL2 pins, which are also AN4 and AN5 respectively must be configured as digital BEFORE the I2C2 module is enabled.  That is, the following will work:
     
    AD1PCFG = 0x30;      // Needs to be set AN4 and AN5 as digital pins before init
    I2C2CONbits.I2CEN = 1;   // enable module.
     
    The following will not work:
     
    I2C2CONbits.I2CEN = 1;   // enable module.
    AD1PCFG = 0x30;      // Needs to be set AN4 and AN5 as digital pins before init
     
    This is discussed in Microchip document DS70000195G, pg. 18, Section 4.1, Second sentence.  Specifically it says:
     
    "When the module is enabled, assuming no other module with higher priority has control, the module will assume control of the SDAx and SCLx pins."
     
    I probably read that sentence multiple times, but my brain was not able to connect the dots.  
     
    The sequence above that works was not needed for the PIC24FJ128GA010 that I had working for over a year, but it is needed for the PIC24FJ64GA002.   The SDA2 and SCL2 pins on the PIC24FJ128GA010 are not shared with other internal peripherals, but they are on the PIC24FJ64GA002.
     
    Thanks again,
     
    MTSPIKE
     
     
     
     
    #7
    MBedder
    Circuit breaker
    • Total Posts : 6773
    • Reward points : 0
    • Joined: 2008/05/30 11:24:01
    • Location: Zelenograd, Russia
    • Status: offline
    Re: Use of IIC on PIC24FJ64GA002 2019/07/25 13:19:59 (permalink)
    5 (1)
    Conclusion: the RTFM won again LoL
    #8
    ric
    Super Member
    • Total Posts : 23172
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: Use of IIC on PIC24FJ64GA002 2019/07/25 13:21:58 (permalink)
    5 (1)
    Mike L French
    ...
    It turns out that the SDA2 and SCL2 pins, which are also AN4 and AN5 respectively must be configured as digital BEFORE the I2C2 module is enabled.  That is, the following will work:

    My standard practice is to set all pins to the correct status
    (output state, direction, analog/digital), as soon as possible after power-on, and certainly BEFORE enabling any peripherals, so I would never even consider enabling the peripheral first.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #9
    Jump to:
    © 2019 APG vNext Commercial Version 4.5