Menu

PIC18F27K40 - hanging issue

2019-09-23
2019-09-23
  • Joseph Realmuto

    Joseph Realmuto - 2019-09-23

    RESOLVED; See https://sourceforge.net/p/gcbasic/discussion/1073404/thread/a51df16ea3/#b58a The root cause in the K40 microcontroller.

    I haven't been around for a while but I recently started playing with PICs again. Anyway, I decided to substitute a PIC18F27K40 for a PIC18F2420 I was using for a project. I had a little difficulty with PPS but eventually got the program to work, at least up until the point where it reads from EEPROM. At that point, it just hangs and does nothing. If I comment out the lines using EPRead and EPWrite all is well.

    P.S. I recently modified the SSD1331 driver for faster character writes and also added the graphic acceleration routines. I also made a working SSD1351 driver for those nice 128x128 full color OLED displays now available on eBay. I'll start another thread on those later but for now I want to see if this problem can be resolved. I even resorted to writing my own EPRead and EPWrite routines straight from the data sheet but it didn't fix the problem:

    Sub EPRead ( EE_ADDR As word, EE_DATA As byte )
    
     BCF NVMCON1, NVMREG0
     BCF NVMCON1, NVMREG1
     MOVF EE_ADDR, W
     MOVWF NVMADRL
     MOVF EE_ADDR_H, W
     MOVWF NVMADRH
     BSF NVMCON1, RD
     MOVF NVMDAT, W
     MOVWF EE_DATA
    
    End Sub
    
    Sub EPWrite ( EE_ADDR As word, EE_DATA As byte )
    
     BCF NVMCON1, NVMREG0
     BCF NVMCON1, NVMREG1
     MOVF EE_ADDR, W
     MOVWF NVMADRL
     MOVF EE_ADDR_H, W
     MOVWF NVMADRH
     MOVF EE_DATA, W
     MOVWF NVMDAT
     BSF NVMCON1, WREN
     BCF INTCON, GIE
     MOVLW 55h
     MOVWF NVMCON2
     MOVLW AAh
     MOVWF NVMCON2
     BSF NVMCON1, WR
     BTFSC NVMCON1, WR
     BRA $-2
     BSF INTCON, GIE
     BCF NVMCON1, WREN
    
    End Sub
    
     

    Last edit: Anobium 2019-09-23
  • Anobium

    Anobium - 2019-09-23

    Crikey. ASM. That is serious.

    K40 is pretty stable but versions of compiler please? Simply look at the top of the ASM file - this shows what I need.

     
  • Joseph Realmuto

    Joseph Realmuto - 2019-09-23

    0.98.<<>> 2017-12-21

    I also tried it with the latest release ( 0.98.06 2019-06-12 (Windows 32 bit) ). Same issues.

     
  • Anobium

    Anobium - 2019-09-23

    Can you create source code with the minimum code using the standard library that reproduces the issue? The code should be the minimum number of lines... nothing huge. Then, I have your baseline which I can test here.

     
  • Joseph Realmuto

    Joseph Realmuto - 2019-09-23

    This is about as simple as I can get:

    ;Chip Settings
      #chip PIC18F27K40,4.194304
      #config FEXTOSC=XT, RSTOSC=EXTOSC_4PLL, BOREN=OFF, MCLR=ON, CSWEN = ON
      #include <glcd.h>
    
        'Generated by PIC PPS Tool for Great Cow Basic
        'PPS Tool version: 0.0.5.15
        'PinManager data: v1.65.1
        '
        'Template comment at the start of the config file
        '
        #startup InitPPS, 85
    
        Sub InitPPS
    
                'Module: MSSP1
                RC5PPS = 0x0010    'SDO1 > RC5
                RC4PPS = 0x0010    'SDA1 > RC4
                SSP1DATPPS = 0x0014    'RC4 > SDA1 (bi-directional)
                RC3PPS = 0x000F    'SCL1 > RC3
                SSP1CLKPPS = 0x0013    'RC3 > SCL1 (bi-directional)
                SSP1SSPPS = 0x0017    'RC7 > SS1
    
        End Sub
        'Template comment at the end of the config file
    
    ; ----- Define Hardware settings
    
      #define GLCD_DC PORTC.6
      #define GLCD_CS PORTC.7
      #define GLCD_RESET PORTC.2
      #define GLCD_DO PORTC.5
      #define GLCD_SCK PORTC.3
      #define SSD1351_HardwareSPI
    
    ; ----- Define GLCD Hardware settings
      #define GLCD_TYPE GLCD_TYPE_SSD1351
    
     'GLCD selected OLED font set.
      #define GLCD_OLED_FONT
      GLCDfntDefaultsize = 1
    
    ;Variables
    Dim data_index As byte
    
    
    'I/O ports
    dir PORTA.0 out
    dir PORTA.1 out
    dir PORTA.2 out
    'dir PORTA.3 out
    dir PORTA.4 in
    dir PORTA.5 in
    dir PORTB.0 in
    dir PORTB.1 out
    dir PORTB.2 out
    dir PORTB.3 out
    dir PORTB.4 out
    dir PORTB.5 out
    dir PORTB.6 out
    dir PORTB.7 out
    dir PORTC.0 in
    dir PORTC.1 out
    dir PORTC.2 out
    dir PORTC.5 out
    dir PORTC.6 out
    dir PORTC.7 out
    '
    '
    Main:
    
    OSCCON1 = 0x20
    
    Lamptest
    
    EPRead 0, data_index
    
    Lamptest
    
    Sub LampTest
     GLCDCLS
     SendCommand_SSD1351(SSD1351_Set_Display_All_On)
     wait 1 s
     SendCommand_SSD1351(SSD1351_Set_Display_All_Off)
     SendCommand_SSD1351(SSD1351_Reset_To_Normal_Display)
     FOR num3 = 0 to 127 step 8
      GLCDPrint ( 0, num3, "012345678901234567890")
     NEXT
     wait 1 s
    End Sub
    

    The program should go through the lamptest routine twice. It hangs after going through it once, which means the EPRead line is causing the problem.

     

    Last edit: Joseph Realmuto 2019-09-23
  • Anobium

    Anobium - 2019-09-23

    I was thinking this. Does the work? Does the LED light/port go high?

    #chip PIC18F27K40
    
    
    wait 2 s
    dir porta.1 out
    porta.1  = 0
    
    EPRead 0, data_index
    
    porta.1  = 1
    

    And, I thought the issue is with EPwrite. Where is that in you example code? But, first does EPRead lock up?

     
  • Anobium

    Anobium - 2019-09-23

    I was thinking this. Does the work? Does the LED light/port go high?

    #chip PIC18F27K40
    
    
    wait 2 s
    dir porta.1 out
    porta.1  = 0
    
    EPRead 0, data_index
    
    porta.1  = 1
    

    And, I thought the issue is with EPwrite. Where is that in you example code? But, first does EPRead lock up?

     
  • Joseph Realmuto

    Joseph Realmuto - 2019-09-23

    That seems to work, which is weird. I didn't put EPWrite in the example code because the problem occurred at the first instance of EPRead. It also occurred when I commented out anything using EPRead but kept stuff in using EPWrite. Both seem to cause the program to fail.

    It might be an issue with my chip configuration.

     
  • Anobium

    Anobium - 2019-09-23

    Yes, looks that way. Get rid of all the tweaks. Work thru from the code below to isolate the issue.

    #chip PIC18F27K40
    
    'Module: EUSART1
    RC6PPS = 0x0009    'TX1 > RC6
    
    'USART settings
    #define USART_BAUD_RATE 9600
    #define USART_TX_BLOCKING
    
    
    wait 2 s
    Epwrite 0,0x55
    EPRead 0, data_index
    
    HSerPrintCRLF 2
    HSerPrint data_index
    HSerPrintCRLF 2
    
     
  • Joseph Realmuto

    Joseph Realmuto - 2019-09-23

    Question: How can I visually see if anything is working using that code?

    I tried running my test program with no PPS assignments and software SPI. Same result. It hangs after EPRead. Evidently PSS isn't causing the problem.

    I also tried running it with no config files, software SPI, and just the #chip PIC18F27K40 line. Same thing except it executes the first few commands in the second lamptest routine, but not the part where it writes characters. It looks like EPRead is changing something which keeps the print routines from working.

    At least this is telling us EPRead (and probably EPWrite) aren't causing the chip to hang. They're just jamming up the GLCD routines in some way.

     
  • Anobium

    Anobium - 2019-09-23

    at rev of the chip do you have?

     
  • Joseph Realmuto

    Joseph Realmuto - 2019-09-23

    a002

     
  • Joseph Realmuto

    Joseph Realmuto - 2019-09-23
     
    • Anobium

      Anobium - 2019-09-23

      Yes. but, we have already sorted that in initsys a while ago.

      But, do investigate using the new .h file attached.

       
  • Joseph Realmuto

    Joseph Realmuto - 2019-09-23

    Just tried the new eeprom.h. Same thing. It looks like I might have to abandon the K40 for this particular project.

     
  • Anobium

    Anobium - 2019-09-23

    Send me the whole project. New glcds etc. It will be ok, hopefully.

     
  • Joseph Realmuto

    Joseph Realmuto - 2019-09-23

    Sent to your .anobium address.

     
  • Anobium

    Anobium - 2019-09-23

    The root cause is the K40 itself. The errata shows the error regarding EEProm usage.

    The fixes are: Update to EEPROM.H and an update to the compiler. The update caches the EEProm addressing bits - handled now with EEPROM.h and the interrupt handler.

     

Log in to post a comment.