Problem with multiple interrupts


Closed Thread
Results 1 to 8 of 8

Hybrid View

  1. #1
    Join Date
    May 2008
    Location
    Italy
    Posts
    825

    Default Problem with multiple interrupts

    Dear friends, I am trying to make two pic16F88 to serially communicate between them.

    Pic_A Pic_B

    portB.6 (Tx) >-------------------------> portB.7 (Rx)

    portB.7(Rx) <-------------------------< portB.6(Tx)


    To be sure to have a reliable communication, I am using DT int on portB.0 to activate serial transmission as per the code below.

    Code:
    INCLUDE "Modedefs.bas"
    INCLUDE "DT_INTS-14_3.bas"   ; Base Interrupt System
    INCLUDE "ReEnterPBP.bas"     ; Include if using PBP interrupts
    
    ANSEL = 0
    CMCON = 7
    OPTION_REG.6 = 1 
    
    TrisA = %00010000
    TrisB = %10000101
    PortA = 0
    
    DEFINE OSC 8
    
    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 20h ' Enable transmit, BRGH = 0
    DEFINE HSER_SPBRG 12  ' 9600 Baud @ 8MHz, 0,16%
    DEFINE HSER_CLROERR 1 ' Clear overflow automatically
    
    
    SCall       var     PortB.3
           
    PwrL        var     PortA.0
    PwrM        var     PortA.1
    
    Led         var     PortA.2
    Buz         var     PortA.3
    
    STx         var     PortB.6
    SRx         var     PortB.7
    
    ZCrox       var     PortA.4
    X10Tx       var     PortB.1
    TxEnable    var     PortB.4
    
    low TxEnable
    low SCall
    input SRx
    high STx
    
    A0              var Byte
    DataFlag        var byte    
    House           var byte
    Unit            var Byte
    Job             var Byte
    
    Rdata           var Byte[30]
    
    Flag0           var dataflag.0
    Flag1           var DataFlag.1   ' Hserin interrupt channel
    Flag2           var dataFlag.2   ' PortB.0 interrupt channel
    Flag3           var DataFlag.3
    Flag7           var dataFlag.7
    
    
    '-------------------- Rx & PB0 DT interrupt definition -----------------
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?       
            INT_Handler    RX_INT,   _Getbytes,     PBP,  yes
            INT_Handler    INT_INT,  _DataReady,    PBP,  yes        
        endm
        INT_CREATE               ; Creates the interrupt processor
    ENDASM
    
    @     INT_ENABLE  RX_INT     ; enable RX_INT interrupts
    
    '----------------------------------------------------------------------
    
    gosub Buzzer
    low led
    A0=0
    DataFlag=0
    
    pause 500
    hserout ["System Ready",10,13]
    
    Main:
    
    pause 1
    
    IF Rdata[0] = 36 and Flag0 = 1 then 
    
    High led
    
    If Rdata[1] = 49 then
    House = ((Rdata[4]-48)*10) + (Rdata[5]-49)  ' X10 house value 
    Unit = ((Rdata[6]-48)*10) + (Rdata[7]-49)   ' X10 Unit value
    
    Flag7 = 0
    If Rdata[8] = 49 then Job = 18 : Flag7 = 1
    If Rdata[8] = 50 then Job = 26 : Flag7 = 1
    If Rdata[8] = 98 then Job = 20: Flag7 = 1
    If Rdata[8] = 99 then Job = 28: Flag7 = 1
    if Flag7 = 0 Then Skip00
    
    High TxEnable                               ' enable X10 transmission
    pause 1                                     ' delay before X10 Tx
    Xout X10Tx,Zcrox,[House\Unit,House\Job]     ' X10 transmission
    low TxEnable                                ' disable X10 Transmission
    
    goto Skip00
    Endif
    
    If Rdata[1] = 52 then     ' intra system comand
    
    If Rdata[8] = 250 then gosub Power01 
    If Rdata[8] = 240 then gosub Power02
    If Rdata[8] = 230 then gosub Modem01 
    If Rdata[8] = 220 then gosub Modem02
    
    goto Skip00
    endif
    
    If Rdata[1] = 51 then     ' intra system communication
    High Scall
    Pause 10
    serout2 STx,84,5,[str Rdata\30]
    Low Scall
    
    goto Skip00
    endif
    
    IF Rdata[1] = 57 and Flag2 = 1 then        ' send out via wifi string recived
        hserout [str Rdata\30]
    endif
    
    Skip00:                                     ' reset main pointers & flag
    
    Rdata[0] = 0
    Rdata[1] = 0
    Rdata[2] = 0
    Rdata[8] = 0
    Flag0 = 0
    Flag1 = 0
    Flag2 = 0
    A0=0
    
    gosub buzzer
    Low led
    endif
    
    goto Main
    
    
    Getbytes:                                   ' Rx interrupt data from Xbee module
    hserin 100, Nodata, [Str Rdata\9]
    Flag0 = 1 
    @ INT_RETURN
    
    Nodata:
    Flag0 = 0
    Flag1 = 1
    @ INT_RETURN
    
    DataReady:                                  ' Intracom interrupt data from chip
    hserout ["PB0 Interrupt"]  ' this message never show up
    Flag0 = 0
    Flag1 = 0
    Flag2 = 0
    serin2 STx,84,500,JumpOut,[str Rdata\30]
    Flag2 = 1
    Flag0 = 1
    Loop:
    if PortB.0 = 1 then Loop
    @ INT_RETURN
    
    JumpOut:
    Flag0 = 0
    Flag1 = 0
    Flag2 = 0
    Flag3 = 1
    @ INT_RETURN
    
    Power01:
    hserout ["PowerLine Off",10,13]
    pause 1
    low PwrL
    return
    
    Power02:
    hserout ["PowerLine On",10,13]
    pause 1
    high PwrL 
    return
    
    Modem01:
    hserout ["Modem Off",10,13]
    pause 1
    low PwrM
    return
    
    Modem02:
    hserout ["Modem On",10,13]
    pause 1
    high PwrM 
    return
    
    Buzzer:
    high buz
    pause 20
    low buz
    return

    The Rx interrupt works fine, while the portB.0 interrupt doesn't work at all, so I am anable to get data transfer between the two pics.

    There must be something wrong but I am anable to find it! Any help will be greatly appreciated.

    Al.
    Last edited by aratti; - 31st May 2009 at 11:54.
    All progress began with an idea

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Probably just need to ...
    Code:
    @     INT_ENABLE  INT_INT
    DT

  3. #3
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    Yes Darell that was the missing part! Thank you very much indeed for the help.

    Al.
    All progress began with an idea

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


    Did you find this post helpful? Yes | No

    Default

    Sniff sniff,I smell something interesting here.

    If I may ask, what are you cooking? Wifi was the trigger to be curious!

    Ioannis

  5. #5
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    Ioannis , The project is called "Home Automation to the maximum possible extent" naturally I am doing it in my house, and as you can imagine from the title, the project is in continuos evolution.

    At present, I have almost all the appliances; lamps and blinders controlled via X10, plus 16 digital inputs to control various sensors, and 16 digital outputs to control non X10 devices.

    So far, I can control and monitor my house in several ways (PC; SMS; Timers and local keypads), I am working to be able to do it also via web.

    Al.
    All progress began with an idea

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


    Did you find this post helpful? Yes | No

    Default

    Nice Al.

    Most control are trivial I believe although some care is needed in the design. Web is the most impressive one.

    Good luck in the project.

    I am also doing something similar with Zigbee devices for local communication and am looking for the web thing later (now our 3rd kid is coming, so...)

    Ioannis

Similar Threads

  1. 16F946 Instant Interrupts problem
    By jderson in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 14th April 2009, 22:20
  2. General Question About Multiple Interrupts
    By grzeh666 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 31st August 2008, 17:09
  3. Darrel Taylor Interrupts I2C Problem
    By dcorraliza in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 26th March 2008, 02:13
  4. Handeling multiple Interrupts
    By BobSpencerr in forum General
    Replies: 15
    Last Post: - 1st March 2007, 01:12
  5. Turning on & off multiple interrupts
    By elec_mech in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 30th June 2005, 17:50

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