Two or more Hserin inside a ISR


Closed Thread
Results 1 to 4 of 4
  1. #1
    Pedro Pinto's Avatar
    Pedro Pinto Guest

    Default Two or more Hserin inside a ISR

    Hello
    I again
    Want change my code to use Darrel Interupts like this:
    My questions is, when it jump to a serial communication interrupt service routine, after the first Hserin, can i wait of a second Hserin in the Interrupt routine?
    Thanks for help
    Best regard
    Pedro

    ' Initialize USART
    TRISC = %10111111 ' Set TX (PortC.6) to out, rest in
    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 20h ' Enable transmit, BRGH = 0
    DEFINE HSER_SPBRG 103 ' 2400 Baud @ 16MHz, 0.17%
    ''DEFINE HSER_SPBRG 25 ' 9600 Baud @ 16MHz, 0.16%
    DEFINE HSER_CLROERR 1 ' Clear overflow automatically
    '
    INCLUDE "modedefs.bas"
    INCLUDE "DT_INTS-18.bas" ' Base Interrupt System
    INCLUDE "ReEnterPBP-18.bas" ' Include if using PBP interrupts
    '
    ASM
    INT_LIST macro
    INT_Handler RX_INT, _IntRx, PBP, yes
    endm
    INT_CREATE
    ENDASM
    @ INT_ENABLE RX_INT


    Main:
    low transmite 'MAX 487 in reception mode
    make anything
    Goto main
    end


    intrx:
    HSERIN 850,rxfail,[wait ("P"), dec2 func, dec3 board, dec3 dumy]

    If (func = 20) and (machine = board) then 'is the data for this board?
    low transmite 'MAX 487 in reception mode

    'second Hserin in this ISR, ???? can that work?
    HSERIN 250,rxfail,[wait ("G"),hex2 rtchr,hex2 rtcmin,hex2 rtcyear,hex2 rtcmonth,hex2
    rtcdate,hex4 obrs,hex2 rtcday,hex2 daylight]
    rtcsec = $00

    Gosub settime

    high transmite 'set MAX 487 in transmit mode
    Hserout ["dumi",";",hex2 rtchr,";",hex2 rtcmin,";",hex2 rtcyear,";",hex2 rtcmonth,";",hex2
    rtcdate,";",hex4 obrs,";",hex2 rtcday,13,10]
    low transmite 'set MAX 487 in reception mode again
    goto RXfail
    Endif

    RXfail:
    @ INT_RETURN

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    can i wait of a second
    You probably could but why.
    Get in and out of the ISR as quick as possible. Do the IF/THEN stuff outside of the ISR and let the ISR pick up the second set of data. Other wise you might end up missing data someplace.
    Dave
    Always wear safety glasses while programming.

  3. #3
    Pedro Pinto's Avatar
    Pedro Pinto Guest


    Did you find this post helpful? Yes | No

    Default

    Hello mackrackit
    I have this run without interrupts, and now want like i said use Darrel interrupt solution
    This is the simplified code that i use, apreciate any help how to do this with interrupt routine
    Thanks
    Best regards
    Pedro

    maq = 114 'board number
    The PC send example: P20114123


    main:
    gosub blink 'not important
    gosub progboard
    goto main


    blink: only to see that the program runs
    ' led blink 2x
    return


    progboard:
    vezes = 0
    low transmite 'set MAX 487 in receive mode
    repeted: 'manual timeout
    vezes = vezes + 1
    if vezes > 15 then final
    SERIN2 rx_485,bmode,250,repeted,[wait ("P"),dec2 func,dec3 board,dec3 dumy] 'receive commands to execute
    '
    high led 'to see that receive a command
    Pause 500
    low led
    '
    if (func = 20) and (maq = board) then 'test if it is for this board to set on board RTC
    low transmite 'set MAX 487 in receive mode
    vezes = 0
    repetec: 'manual timeout
    vezes = vezes + 1
    if vezes > 20 then final
    low transmite 'set MAX 487 in receive mode
    'receive the data to set the realtime clock
    SERIN2 rx_485,bmode,250,repetec,[wait ("G"),hex2 rtchr,hex2 rtcmin,hex2 rtcyear,hex2 rtcmonth,hex2 rtcdate,hex4 obra,hex2 rtcday,hex2 daylight]
    rtcsec = $00
    '
    toggle led
    Gosub settime 'set the RTC on the board
    '
    pause 100
    rtchr = 0:rtcmin = 0:rtcyear = 0:rtcmonth = 0:rtcdate = 0:rtcday = 0
    pause 100
    segu_daylight = daylight 'backup
    '
    Gosub gettime 'read the board RTC after setting
    '
    pause 10
    vezes = 0
    repeteb: 'timeout manual
    vezes = vezes + 1
    if vezes > 40 then final
    low transmite 'set MAX 487 in receive mode
    Serin2 rx_485,bmode,250,repeteb,[wait ("R")]
    '
    HIGH transmite 'set MAX487 in transmit mode
    pause 2000 'important
    '
    'send received data back to PC to test if the on board RTC it correct set
    serout2 tx_485,bmode,["dumi",";",hex2 rtchr,";",hex2 rtcmin,";",hex2 rtcyear,";",hex2 rtcmonth,";",hex2 rtcdate,";",hex4 obra,";",hex2 rtcday,13,10]
    return
    endif 'if func = 20
    '
    ' ******************* Test if new data available for the PC *****************
    'The PC scan sequencialy all boards on the network for new data
    If (func = 30) and (maq = board) and (reg_completo = 1) then 'test if the request of data is for this board

    tmp0 = 0:tmp1 = 0:tmp2 = 0:tmp3 = 0:tmp4 = 0:tmp5 = 0:tmp6 = 0:tmp7 = 0:tmp8 = 0:tmp9 = 0:tmp10 = 0
    tmp11 = 0:tmp12 = 0:tmp13 = 0:tmp14 = 0:tmp15 = 0:tmp_tecn = 0
    'get the data from the CPU Eeprom to send to the PC
    read 10,tmp0
    read 11,tmp1
    read 12,tmp2
    read 13,tmp3
    read 14,tmp4
    read 15,tmp5
    read 16,tmp6
    read 17,tmp7
    read 18,tmp8
    read 19,tmp9
    read 20,tmp10
    read 21,tmp11
    read 22,tmp12
    read 23,tmp13
    read 24,tmp14
    read 25,tmp15
    read 26,tmp_tecnH
    read 27,tmp_tecnL
    '
    'make a simple checksum
    som = tmp0 + tmp1 + tmp2 + tmp3 + tmp4 + tmp5 + tmp6 + tmp7 + tmp8 + tmp9 + tmp10 + tmp11 + tmp12 + tmp13 + tmp14 + tmp15 + tmp_tecn
    '
    HIGH transmite 'set MAX487 in transmit mode
    pause 2000 '### important
    serout2 tx_485,bmode,["dumi",";",hex2 tmp0,";",hex2 tmp1,";",hex2 tmp2,_
    ";",hex2 tmp3,";",hex2 tmp4,";",hex2 tmp5,_
    ";",hex2 tmp6,";",hex2 tmp7,";",hex2 tmp8,_
    ";",hex2 tmp9,";",hex2 tmp10,";",hex2 tmp11,_
    ";",dec3 tmp12,";",dec3 tmp13,";",dec3 tmp14,_
    ";",hex2 tmp15,";",hex4 tmp_tecn,";",dec som,13,10]
    '
    low transmite 'set MAX 487 in receive mode
    vezes = 0
    repete: 'manual timeout
    vezes = vezes + 1
    if vezes > 36 then final
    SERIN2 rx_485,bmode,250,repete,[WAIT ("OK"),dec3 board] 'receive confirmation from PC that data OK
    if board = maq then
    toggle led 'only for debug
    endif
    endif

    final:
    return

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    I think the way I would do this is to have the ISR read any serial data into an array, the check the array for "P", "G", or "R" and act accordingly.

    You will have to use the USART (HSERIN). And it will pretty much be a complete re-write of what you have now...
    Dave
    Always wear safety glasses while programming.

Members who have read this thread : 1

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