HSERIN and XOUT command


Closed Thread
Results 1 to 21 of 21

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default

    Thank you Joe and Steve,
    Pins RB1(Rx) and RB2(Tx) are used to service the serial connection with the Xbee module. Xout uses pin RB6; Xin uses pin RB4 and zerocrossing is on pin RB6. Here the code:

    Code:
    INCLUDE "Modedefs.bas"
    INCLUDE "DT_INTS-14_2.bas"     ; Base Interrupt System
    INCLUDE "ReEnterPBP.bas"     ; Include if using PBP interrupts
    
    CMCON   = 7
    
    TrisA = %00000000
    TrisB = %00110010
    PortA = 0
    
    DEFINE OSC 10
    
    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
    DEFINE HSER_SPBRG 64  ' 9600 Baud @ 10MHz, 0,16%
    DEFINE HSER_CLROERR 1 ' Clear overflow automatically
    
    XbDtr       var PortB.0
    XbRts       var PortB.3
    XbSlp       var PortA.3       
    
    Pwr         var PortA.0
    Led         var PortA.1
    Buz         var PortA.2
    
    X10Rx       var PortB.4
    ZCrox       var PortB.5
    X10Tx       var PortB.6
    TxEnable    var PortB.7
    
    high Pwr
    high XbSlp
    low TxEnable
    low XbRts
    Low XbDtr
    
    A0          var Byte
    House       var byte
    Unit        var Byte
    Job         var Byte
    Decode      var byte
    Pass        var byte
    
    Rdata       var Byte[10]
    
    HouseKey    var word 
    
    '--------------------------- Rx DT interrupt definition -------------------
    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
    
    '-------------------------------------------------------------------------
    
    gosub Buzzer
     
    
    Main:
    pause 1
    If Rdata[0]=250 then loop
    goto main
    
    Getbytes:
    Hserin 100,ErrorFlag,[str Rdata\9]
    High led
    
    If Rdata[0]=36 then 
    House = ((Rdata[4]-48)*10) + (Rdata[5]-49) 
    Unit = ((Rdata[6]-48)*10) + (Rdata[7]-49)
    Decode = Rdata[8]-48
    If decode = 1 then Job = 18 : Pass = 1
    If decode = 2 then Job = 26 : Pass = 1
    If decode = 50 then Job = 20: Pass = 1
    If decode = 51 then Job = 28: Pass = 1
    gosub TxCommand
    endif
    Pass=0
    Low led
    @ INT_RETURN
    
    ErrorFlag:
    RCSTA.4 = 0
    RCSTA.4 = 1
    Pass=0
    low led
    @ INT_RETURN
    
    TxCommand:
    If Pass=0 then return
    High TxEnable 
    pause 1
    Xout X10Tx,Zcrox,[House\Unit,House\Job]
    low TxEnable 
    
    
    Buzzer:
    high buz
    pause 20
    low buz
    return
    
    Loop:
    xin X10Rx,ZCrox,[Housekey]
    hSerout ["H: ",#Housekey.byte1,13,10]
    hserout ["K: ",#Housekey.byte0,13,10]
    goto loop

    Now the code works with the exception of HSEROUT that I was anable to get it to work in the "Main" loop. I had to make the trick to jump in a secondary loop "LOOP" to have it working, but if I re-enter the "LOOP" the second time then HSEROUT doesn't work anymore. There must be something effecting the USART setting using Xin and Xout command.

    I should mention once again that pic16F628 is working @ 3.3 Volts. No compilation errors without Modedefs.bas file.

    Any tip will be welcome!

    Al.
    Last edited by aratti; - 10th May 2009 at 00:51.
    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

    Hi Aratti,

    This could be a problem.

    In the Main loop, actually Loop:, there is an XIN statement that runs on every loop. Then if you receive data in the interrupt handler, the TxCommand is called which does an XOUT. The XOUT could potentially be triggered in the middle of the XIN. Possibly leaving XIN waiting for something it will never receive.

    That could keep the HSEROUT's from being executed.

    If you set a "flag" in the interrupt handler when it receives data, then do the XOUT in the main loop when it sees the flag, it won't try to do both XIN and XOUT at the same time.

    Added: You may also need to have the RX interrupt receive bytes 1 at a time instead of a full string, to keep it from interfereing with the XIN to begin with.

    hth,
    Last edited by Darrel Taylor; - 10th May 2009 at 03:23. Reason: Added:
    DT

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


    Did you find this post helpful? Yes | No

    Default No luck

    Hi Darell, thank you for your answer. I did try your suggestion without any luck.
    In doing these changes I came to the conclusion that Xin command is the problem, infact simply removing Xin from the code and Txing numbers with a For/Next loop everything work fine. As soon as I enable Xin the problem is back again.

    At this time it seems I have got only one bullet left "use two pics" one for Xin and one for Xout.

    Al.
    Last edited by aratti; - 10th May 2009 at 19:13.
    All progress began with an idea

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


    Did you find this post helpful? Yes | No

    Default

    I did try your suggestion without any luck.
    Did you also change the RX handler to receive only 1 byte at a time? Waiting for a whole string takes a LONG time.

    And, have you tried the XIN without the interrupts? Is XIN working at all?
    You can add a Timeout to XIN, in case it's not receiving anything.

    Is the XIN supposed to be running continuously in a loop, or as a response to the 250 command?
    If it was in response to the command, it's more likely that incoming data will not occur again in the middle of the XIN.
    <br>
    DT

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


    Did you find this post helpful? Yes | No

    Default

    Did you also change the RX handler to receive only 1 byte at a time?
    Yes I did But it doesn't work very well. A command must be sent twice or three times to be executed, while with the whole string method commands are all decoded and executed correctly at the first time. Very likely my code is not so efficient as the whole string.

    Here the code used: (Where : RxBuffer VAR PIR1.5)
    Code:
    Getbytes:
    A0=0
    While RxBuffer=1 
    Hserin 100,ErrorFlag,[Rdata[A0]]
    A0=A0+1
    Wend
    @ INT_RETURN

    And, have you tried the XIN without the interrupts? Is XIN working at all?
    Yes with "SERIN2/SEROUT2" did work, not with "HSERIN/HSEROUT". But as you can understand, I need to jump out from Xin loop when an X10 command is received via Xbee in order to service it with the Xout command.


    Is the XIN supposed to be running continuously in a loop, or as a response to the 250 command?
    Xin is supposed to continuouly scan the main for X10 commands coming in from the different sources capable to issue such a command. The incoming data will be used to update a memory area containing the status of various lamps and appliances (On/Off).

    Al.
    All progress began with an idea

  6. #6
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    how about get rid of the timeout label and the IF-THEN?
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  7. #7
    Join Date
    Dec 2005
    Posts
    1,073


    Did you find this post helpful? Yes | No

    Default

    As written, Xin is blocking. You need a timeout and jump_to_label.

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