Menu

16F18313 RX interrupt not working

Help
Rox
2018-05-31
2018-06-01
  • Rox

    Rox - 2018-05-31

    Please help! tried on interrupt ans sub interrupt, but both not working..what is missing on my code?

    ' ----- Configuration
      #chip 16f18313, 4
      #config fextosc_off,
      #option Explicit
    '
      TRISA = 0b00000100
      PORTA = 0b00000100
    '
    ' Variables
    
     dim Length         as Byte
     dim Buffer(16)     as Byte
     dim wFlags           as Word
    
     '
     ' Defines/ Alias
     #Define fInt10mS     wflags.0
    
         'Generated by PIC PPS Tool for Great Cow Basic
        'PPS Tool version: 0.0.5.19
        'PinManager data: v1.65.2
        '
        #startup InitPPS, 85
    
        Sub InitPPS
            UNLOCKPPS
    
                'Module: EUSART
                RXPPS = 0x0002    'RA2 > RX
                RA5PPS = 0x0014    'TX > RA5
    
            LOCKPPS
        End Sub
    '
         'USART settings - these MUST be set after the PPS settings
        #define USART_BAUD_RATE 9600
        #define USART_BLOCKING
        #define USART_TX_BLOCKING
    
    '    RC1STA     = 144 ; Enable continuous receive
    '    TX1STA     = 36  ; Enable transmit
    '
    ' Hardware settings
    ' I/O Directions
      dir porta.4 out
      dir porta.2 in
    ' Timer0, Prescaler 1:64; TMR0 Preload = 100; Actual Interrupt Time : 9.984 ms
      InitTimer0 Osc, PS0_64
      t0con0 = 0b10010000            '16 bit, postscaler=1:1
      t0con1 = 0b01100110
    
      TMR0h   = 0xd8
      tmr0l = 0xf0
    
      set porta.4 on
      pause 500
      set porta.4 off
    
      On Interrupt Timer0Overflow Call T0int
     ' On Interrupt UsartRX1Ready Call readUSART
    
    '
      intcon = 0b11000000
      HSerPrint " PIC 16f18313"
    ' ========== [ Main Loop ]==============
      Do
        if fInt10mS Then
          fint10ms = 0
          HardSer
        end if
      Loop
      '
    '========== [Sub Routines ]===========
    '
    sub Interrupt
    '--- USART Interrupt
      if RC1STA.1 or RC1STA.2 Then  'if usart error clear the error flag
        RC1STA.4 = 0
        RC1STA.4 = 1
      end if
      '
      if pir1.5 Then              'RX Interrupt
        Buffer(Length) = HSerReceive1    'rcreg
        hserprint Buffer(length)
        Length = Length + 1
    '    if Length = 16 Then length = 0
        porta.4 = !porta.4
      end if
    End sub
      '
    sub T0int   'Timer 0 causes interrupt
    '  If pir0.5 Then
    '     pir0.5 = 0
         TMR0h   = 0xd8
         tmr0l = 0xf0
         fInt10mS = 1
    
    '  End If
    
    End sub
    '
    Sub HardSer
    ' HSerPrint " PIC 16f18313"
    ' HSerSend 13  ' "Carriage Return"
    ' HSerSend 10  ' "Line Feed"
    
    End sub
    
     
  • Rox

    Rox - 2018-05-31

    my timer 0 is working fter some debugging, harware TX also OK, but RX is the problem.
    Thanks,

     
  • Anobium

    Anobium - 2018-05-31

    I am looking at the code.

    Cut the code to something we can work with please. So, just the essential code that you think will show the issue. I am currently confused - lots of stuff commented out including the interrupt.

    This will help us help you.

     
  • Rox

    Rox - 2018-05-31

    The problem is the RX interrupt doesn't triggerrs.

    ' ----- Configuration
      #chip 16f18313, 4
      #config fextosc_off,
      #option Explicit
    '
    ' Variables
    
     dim Length         as Byte
     dim Buffer(16)     as Byte
     dim wFlags           as Word
    
     '
     ' Defines/ Alias
     #Define fInt10mS     wflags.0
    
         'Generated by PIC PPS Tool for Great Cow Basic
        'PPS Tool version: 0.0.5.19
        'PinManager data: v1.65.2
        '
        #startup InitPPS, 85
    
        Sub InitPPS
            UNLOCKPPS
    
                'Module: EUSART
                RXPPS = 0x0002    'RA2 > RX
                RA5PPS = 0x0014    'TX > RA5
    
            LOCKPPS
        End Sub
    '
         'USART settings - these MUST be set after the PPS settings
        #define USART_BAUD_RATE 9600
        #define USART_BLOCKING
        #define USART_TX_BLOCKING
    '
    ' Hardware settings
    ' I/O Directions
      dir porta.4 out
      dir porta.2 in
    ' Timer0, Prescaler 1:64; TMR0 Preload = 100; Actual Interrupt Time : 9.984 ms
      InitTimer0 Osc, PS0_64
      set porta.4 on
      pause 500
      set porta.4 off
    
      On Interrupt Timer0Overflow Call T0int
     ' On Interrupt UsartRX1Ready Call readUSART
    
    '
      intcon = 0b11000000
      HSerPrint " PIC 16f18313"
    ' ========== [ Main Loop ]==============
      Do
        if fInt10mS Then
          fint10ms = 0
          HardSer
        end if
      Loop
      '
    '========== [Sub Routines ]===========
    '
    sub Interrupt
    '--- USART Interrupt
      if RC1STA.1 or RC1STA.2 Then  'if usart error clear the error flag
        RC1STA.4 = 0
        RC1STA.4 = 1
      end if
      '
      if pir1.5 Then              'RX Interrupt
        Buffer(Length) = HSerReceive1    'rcreg
        hserprint Buffer(length)
        Length = Length + 1
    '    if Length = 16 Then length = 0
        porta.4 = !porta.4
      end if
    End sub
      '
    sub T0int   'Timer 0 causes interrupt
         TMR0h   = 0xd8
         tmr0l = 0xf0
         fInt10mS = 1
    End sub
    '
    Sub HardSer
     HSerPrint " PIC 16f18313"
     HSerSend 13  ' "Carriage Return"
     HSerSend 10  ' "Line Feed"
    
    End sub
    
     
  • Rox

    Rox - 2018-05-31

    Ok ill try those sample program.

    Thanks you.

     
  • Moto Geek

    Moto Geek - 2018-05-31

    Just a quick look, but it seems like your ' On Interrupt UsartRX1Ready Call readUSART is commented out, so it won't cause an interrupt. Aslo I don't think you need the

    if pir1.5 Then

    end if

    You don't need to check the RCIF in this subroutine because it was called by the On Interrupt already.

    As usual, I could be wrong, but...

    Let us know...

     
    • Rox

      Rox - 2018-06-01

      I tried the On Interrupt with the "If pir1.5 then.. Commented.
      tried Sub Interrupt with the "If pir.5 then..
      Added the line ansel = 0 to disaable ADCs
      changed the RX pin to default pin RA1

      nothing work.
      ill just set aside this chip and use an old and tested PIC.

       
      • Anobium

        Anobium - 2018-06-01

        The code in the Help) - did that work? We should ensure the serial RX is working first - which was the issue you started with.

         
  • Moto Geek

    Moto Geek - 2018-05-31

    Also try changing the name of the RX subroutine from "Interrupt" to "readUSART".

    maybe???

     

Log in to post a comment.