Interrupt not working?


Closed Thread
Results 1 to 13 of 13

Hybrid View

  1. #1
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154

    Default Re: Interrupt not working?

    Code:
    PortD =  %00000000
    PORTD = %00000000               ; set to PORTD low
    Are you sure that's enough?


    Seriously, I've seen several comments about both TX and RX pins should be set to input in TRIS. USART then takes control and decides what they should be.


    Code:
    CCP2MX_ON_3H
    Do you really need that feature enabled?

    Robert

  2. #2
    Join Date
    Jun 2011
    Location
    Philippines
    Posts
    223

    Default Re: Interrupt not working?

    Hi Robert, thanks for giving the time to look onto the codes...I will try to check on it and see what will happen...

    Regards,
    tacbanon

  3. #3
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,116

    Default Re: Interrupt not working?

    Leave the GSM aside for a while and test you program with a terminal.

    Then just type on the keyboard what you expect your PIC to receive and see if that works.

    Ioannis

  4. #4
    Join Date
    Jun 2011
    Location
    Philippines
    Posts
    223

    Default Re: Interrupt not working?

    @Ioannis
    I have the following code below that works when sending to the SerialComm...
    Code:
     '::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
                         'Hserin with Darryl Taylor's Instant Interrupts
     '::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    asm
        __CONFIG    _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
        __CONFIG    _CONFIG1H, _FOSC_HSPLL_HS_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
        ;__CONFIG    _CONFIG2L, _PWRT_ON_2L & _BOR_ON_2L  & _BORV_2_2L  & _VREGEN_ON_2L   
        __CONFIG    _CONFIG2H, _WDT_OFF_2H 
        __CONFIG    _CONFIG3H, _MCLRE_ON_3H & _LPT1OSC_OFF_3H & _PBADEN_OFF_3H & _CCP2MX_ON_3H 
        __CONFIG    _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _ICPRT_OFF_4L  & _XINST_OFF_4L & _DEBUG_OFF_4L 
    endasm
    
            
            
            DEFINE OSC 48       
            DEFINE HSER_RCSTA 90h ' enable serial port, 
            DEFINE HSER_TXSTA 20h  ' enable transmit,                  
            DEFINE HSER_BAUD 9600
            DEFINE HSER_CLOERR  1 ' automatic clear overrun error  
            
            TRISC  = %10000000    ' PORTC.7 is the RX input, PORTC.6 is the TX output
                                  
        
        '   Serial communication definition
        '   ===============================
            '
      ADCON1 = %00001111      'Set up ADCON1 register no matter what you're doing!!!!!!
    '::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    
    INCLUDE "MODEDEFS.BAS"       ' Include Shiftin/out modes
    INCLUDE "DT_INTS-18.bas"     ' Base Interrupt System
    INCLUDE "ReEnterPBP-18.bas"  ' Include if using PBP interrupts
    '::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
        '   Variable definition
    '::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    PortB = %00000000
    TRISB = %00000000        
    RCIF       VAR     PIR1.5     ' Receive  interrupt flag (1=full , 0=empty)
    TXIF       VAR     PIR1.4     ' Transmit interrupt flag (1=empty, 0=full)
    led        var     PORTC.0
    led1        var     PORTC.1
    holdoff    var     word
    SerialData var     byte
    SerialInput var    byte[50]
    PortB = 0
    c var byte
    i var byte
    c = 0
    clear
    
            '((((((((((((((((((((((((((((((((((((((()))))))))))))))))))))))))))))))))))))))
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler   RX_INT,    _Getbytes,    PBP,  no
        endm
        INT_CREATE               ; Creates the interrupt processor
    ENDASM
    
    @   INT_ENABLE  RX_INT     ; enable RX_INT interrupts
    
    
            '((((((((((((((((((((((((((((((((((((((()))))))))))))))))))))))))))))))))))))))
                       ' Subroutine to slow loop down some and toggle heartbeat
            '((((((((((((((((((((((((((((((((((((((()))))))))))))))))))))))))))))))))))))))
    Mainloop:
     c = 0
            for holdoff = 1 to 100
            pause 1
            next holdoff
            toggle led           'toggle led every loop for heartbeat  
           
            goto Mainloop
    
    
            '((((((((((((((((((((((((((((((((((((((()))))))))))))))))))))))))))))))))))))))
               'ISR for RX_int interrupt 
            '((((((((((((((((((((((((((((((((((((((()))))))))))))))))))))))))))))))))))))))
    
    Getbytes:
           
           While RCIF = 1     ' clear the buffer
           c = c + 1
           'HSEROUT ["Process "] 
           HSERIN 100,error,[Serialdata] ' take it
           HSEROUT [Serialdata] ' take it out
           SerialInput[c] = Serialdata        
           select case Serialdata          ' What to do with that data???                                
               case "^"            ' User selection = 1
                    HSEROUT ["Goto Sub Process "] ' take it out
                    gosub displaydata
           End select         
           Wend
           
           toggle led       'led to confirm program went to RX ISR
    
    @ INT_RETURN
    
    
    error:
          Toggle led1
    @ INT_RETURN
     end
     
     displaydata:
            for i = 1 to c
             Hserout [SerialInput[i]]
            next i
            
     return
    Then I tried to insert GSM related one block of code at a time but the same result (triggers interrupt only once--upon bootup)..

    >>>tacbanon

  5. #5
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,605

    Default Re: Interrupt not working?

    Some random thoughts:
    The TX interrupt flag gets cleared by the hardware when the buffer is emptied - which it is by reading it so Reset Flag=NO is correct.

    Perhaps you're overflowing the buffer?
    When you're "emulating" the GSM-module by sending characters manually from the terminal your sending them quite slowly - if you're sendig them one by one as you are typing them. When you then plugin the GSM-module it'll send the same string (hopefully) at the same baudrate as you did manually but the time between each character is a lot shorter so the time the ISR has to process each character is shorter.

    I see that you have a HSEROUT ["Process"] in the ISR, things like that WILL overflow the buffer because your sitting in a loop spitting out the word 'Process' (7 bytes) while more might be comming in. The TX-buffer is only one byte deep so the program will have to put in the 'P' then wait for it to go out, put in the 'r', then wait for it to go out and so. Not untill it has put the last 's' in the Tx-buffer will it continue. In the meantime bytes are still trying to get into the Rx-buffer which is only 2 bytes deep - the buffer will likely overflow.

    Now, I see that you've commented the above line out which is good but it illustrates the issue I'm trying to get at perfectly.


    Also, I'm not sure if it's intentionally but you're resetting the counter (c) each time thru the main loop so if the mainloop startover in the middle of a string it will start overwriting itself. I think that what you want is to reset (c) at the end of DisplayData routine, and possible in the Error routine.

    Finally, at the beginning of the program, try inserting a lengthy pause to allow the PIC and the GSM-module to power up properly then make sure the USART buffer is clear and the interrupt flag reset - then enable the interrupt. If the GSM module has an enable input or something tie that to an output on the PIC so you can keep it disabled untill you're ready.

    /Henrik.

  6. #6
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154

    Default Re: Interrupt not working?

    Is that too much stuff going on inside ISR?

    What if you simplify usart logic until you get things working as expected?

    Do you really need byte-by-byte reception? Can you get away with a fixed length message?

    My interrupt routine looks like this:
    Code:
    ReceiveInterrupt:
      HSERIN 50,No232,[DEC5 PicIn.byte1, DEC5 PicIn.byte0, DEC1 CommandIn, _
                       STR DataIn1\24, STR DataIn2\24,                     _
                       DEC5 CheckSumIn.byte1, DEC5 CheckSumIn.byte0]
      RS232Flag = StateTrue
    No232:
    @ INT_RETURN
    I check in main loop if RS232Flag was set, and then do all the processing there.

    Robert

  7. #7
    Join Date
    Jun 2011
    Location
    Philippines
    Posts
    223

    Default Re: Interrupt not working?

    Thank you Henrik for explaining it well and giving me ideas how to trace the steps the codes is doing.
    and thank you Robert for sharing your code...I will try them out.

    regards,
    tacbanon

  8. #8
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,116

    Default Re: Interrupt not working?

    For sending a string of keystrokes instead of typing and having a delay, as Henrik spoted, try this terminal program:

    https://sites.google.com/site/termin...attredirects=0

    It can accept a string of characters and then you hit send to send it as it would your GSM device.

    Ioannis

Similar Threads

  1. SERIN Not Working, SEROUT Working
    By cc1984 in forum Serial
    Replies: 11
    Last Post: - 26th October 2010, 19:16
  2. confused problem with interrupt in a working program
    By illuminator4 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 14th November 2008, 17:01
  3. ON INTERRUPT not working
    By Russ Kincaid in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 12th April 2008, 13:41
  4. PIC to PC not working
    By The Master in forum Serial
    Replies: 5
    Last Post: - 30th October 2007, 04:34
  5. Replies: 0
    Last Post: - 27th August 2004, 07:20

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts