Menu

Hardware I2C stops program running

Help
Peter
2017-08-12
2017-08-13
  • Peter

    Peter - 2017-08-12

    I have the code below, and it doesn't do anything. No flashing LEDs, nothing on the GLCD.

    #chip 16F18326, 32
    #config FEXTOSC_OFF
    #include <glcd.h>
    
    'Generated by PIC PPS Tool for Great Cow Basic
    'PPS Tool version: 0.0.5.10
    'PinManager data: v1.45
    '
    'Template comment at the start of the config file
    '
    #startup InitPPS, 85
    
    Sub InitPPS
    
    'Module: MSSP1
    RC3PPS = 0x18    'SCL1 > RC3
    RC4PPS = 0x19    'SDA1 > RC4
    
    End Sub
    
    'Flash LED to show chip is running
    Repeat 5
    Pulseout PORTC.1, 250 ms
    Wait 500 ms
    End Repeat
    
    'Setup Hardware I2C
    #define HI2C_DATA PORTC.4
    #define HI2C_CLOCK PORTC.3
    'I2C pins need to be input for SSP module when used on Microchip PIC device
    Dir HI2C_DATA in
    Dir HI2C_CLOCK in
    'MASTER MODE
    HI2CMode Master
    
    'Define GLCD Hardware settings
    #define GLCD_TYPE GLCD_TYPE_SSD1306
    #define GLCD_I2C_Address 0x78
    
    GLCDInit
    Wait 1 s
    GLCDCLS
    GLCDPrint(0,0,"Hello")
    
    'Turn LED on to show it is complete
    set PORTC.1 On
    

    If I comment out the HI2C setup (not the PPS bit), the LED flashes then stays on. The GLCD is blank.
    If I use software I2C, the LED works and the GLCD works.

    Any ideas?

    Currently using the 0.97.01 2017-02-20 compiler.

     

    Last edit: Peter 2017-08-12
  • Anobium

    Anobium - 2017-08-13

    Please talk me through how the PPSTool came up with those settings. What editing did you do? You have the latest PPSTool and the latest XML dataset (I can see this from the code) but the actual code in your program for PPS is not correct.

    So, rather than have me just tell you the answer - can you recreate using PPSTool and then compare the PPS code generated.

    Anobium

    P.S. Are you using MPLAB-IPE to program?

     
  • Peter

    Peter - 2017-08-13

    I'd aready tried the exact code from PPSTool without any luck:

    #startup InitPPS, 85
    
    Sub InitPPS
    
            'Module: MSSP1
            RC3PPS = 0x0018    'SCL1 > RC3
            SSP1CLKPPS = 0x0013    'RC3 > SCL1 (bi-directional)
            RC4PPS = 0x0019    'SDA1 > RC4
            SSP1DATPPS = 0x0014    'RC4 > SDA1 (bi-directional)
    
    End Sub
    

    However the problem is with this line:
    #define HI2C_DATA PORTC.4
    If I comment it out the LED flashes etc., if it's uncommented nothing happens.
    Changing the pin doesn't make a difference either.

    Another way to get the code to run, is to comment out everything to do with the GLCD (GLCDInit, GLCDCLS and GLCDPrint).

    And yes, I'm using IPE to program,

     

    Last edit: Peter 2017-08-13
  • Anobium

    Anobium - 2017-08-13

    This code works. I have just logged into my home remotely and this is a test program that could be in the next release. I know this works - I just adapted to ensure the code is your code.

    #chip 16F18326, 32
    #Config WRT_OFF, CPD_ON, MCLRE_ON, FEXTOSC_OFF, CLKOUTEN_OFF    'These configs = User non-votatile protection off (WRT), Data non-votatile protection off (CPD), MCLR pin function enablesd, External oscillator not enabled and clockout function is disables ( enable portc.5 to I/O port).
    
    #include <glcd.h>
    
        'Generated by PIC PPS Tool for Great Cow Basic
        'PPS Tool version: 0.0.5.9
        'PinManager data: v1.36.1
        '
        'Template comment at the start of the config file
        '
        #startup InitPPS, 85
    
        Sub InitPPS
    
                'Module: MSSP1
                RC3PPS = 0x0018    'SCL1 > RC3
                SSP1CLKPPS = 0x0013    'RC3 > SCL1 (bi-directional)
                RC4PPS = 0x0019    'SDA1 > RC4
                SSP1DATPPS = 0x0014    'RC4 > SDA1 (bi-directional)
    
        End Sub
        'Template comment at the end of the config file
    
    'Flash LED to show chip is running
    DIR PORTC.1 OUT
    Repeat 5
    Pulseout PORTC.1, 250 ms
    Wait 500 ms
    End Repeat
    
    'Setup Hardware I2C
    #define HI2C_DATA PORTC.4
    #define HI2C_CLOCK PORTC.3
    'I2C pins need to be input for SSP module when used on Microchip PIC device
    Dir HI2C_DATA in
    Dir HI2C_CLOCK in
    'MASTER MODE
    HI2CMode Master
    
    'Define GLCD Hardware settings
    #define GLCD_TYPE GLCD_TYPE_SSD1306
    #define GLCD_I2C_Address 0x78
    
    GLCDCLS
    GLCDPrint(0,0,"Hello")
    
    'Turn LED on to show it is complete
    
    DO
    
      PORTC.1 =!PORTC.1
      wait 50 ms
    
    LOOP
    
     
  • Anobium

    Anobium - 2017-08-13

    Working solution. See attached.

    I would have 2.2k pullsup on the i2c bus on SDA and SCL

     
  • Peter

    Peter - 2017-08-13

    I've tried your New14.gcb with and without the latest hwi2c.h - neither work!
    I had several versions of GCB installed which may/may not have been messed with, so I deleted them all and downloaded a fresh version of 0.97-01 but that didn't help.

    It's not an electrical problem with the board, otherwise the software I2C wouldn't work. There are resistors on the SDA and SCL lines.

    Having looked through previous projects, I can't find any occasions where I've used HWI2C so I guess I've never had any luck with it.

    This can wait until you're back off your holidays.

     
    • Anobium

      Anobium - 2017-08-13

      I will send you a hex file. I can access remotely.   Normal email address?

       
      • Peter

        Peter - 2017-08-13

        Yes, normal email is fine.

         
  • Anobium

    Anobium - 2017-08-14

    Please try https://sourceforge.net/p/gcbasic/code/HEAD/tree/GCBASIC/trunk/include/glcd_SSD1306.h

    I spotted the fix in the release note for the next release.

    371    Fix      SDD1306   Added delay to allow display to power up fully befor initalization
                                  Clear display before DisplayON to hide garbage at POR / initalization
    
     
    • Peter

      Peter - 2017-08-16

      That fixed the problem and HI2C is working now! I can write to/refresh the SSD1306 at speeds never seen before using #define HI2C_BAUD_RATE 400
      I'm not sure why adding the delay and clearing the display would stop code executing any further but it works so I'll just accept it :)

       

Log in to post a comment.