logo elektroda
logo elektroda
X
logo elektroda
REKLAMA
REKLAMA
Adblock/uBlockOrigin/AdGuard mogą powodować znikanie niektórych postów z powodu nowej reguły.

RS232 UART - jak zrobić przerwanie

TomekMus 11 Lis 2009 23:31 2498 4
REKLAMA
  • #1 7248490
    TomekMus
    Poziom 17  
    chcę zrobić coś takiego że:

    pętla główna
    do
    'jakieś działania zajmują czas różnie od 5min do 1 godz.
    
    ' i tu dopiero by było odbiór rs232 - to ZŁE bo aplikacja będzie oczekiwała 1godzine aż
    ' uC się zgłosi!!!
    loop


    jest stała i ciągle oblicza jakieś wartości i nie mogę jej zatrzymać.

    Jak zrobić przerwanie od odebranego znaku z uart'u
  • REKLAMA
  • Pomocny post
    #2 7248549
    pgnige
    Poziom 14  
    $regfile = "m8def.dat"
    $crystal = 8000000
    
    Enable Urxc
    On Urxc Rs232
    Enable Interrupts
    
    Do
    'Instrukcje w petli
    Loop
    End
    
    Rs232:
       'tutaj zostalo zgloszone przerwanie w Udr jest aktualna przeslana liczba
       Print Udr
    Return
  • REKLAMA
  • Pomocny post
    #3 7248556
    tmf
    VIP Zasłużony dla elektroda
    Przeczytac rozdzial w pdfie poswiecony obsludze UARTu ze szczegolnym uwzglednieniem przerwania od odbiornika UARTu? Albo napisac jasniej o co ci chodzi i w czym masz problem.
  • REKLAMA
  • Pomocny post
    #4 7248615
    xury
    Specjalista automatyka domowa
    Poczytaj helpa z Bascoma ale angielskiego. Szczególnie o:
    "Config serialin" z uwzględnieniem "BYTEMATCH" - to jest obsługa UART w przerwaniu uproszczona na maxa.
    Warto przejrzeć:
    https://www.elektroda.pl/rtvforum/topic1462271.html
    i jeszcze ten:
    https://www.elektroda.pl/rtvforum/topic1468629.html
  • #5 7395267
    adambehnke
    Poziom 24  
    To przykładowy kod tyle że dla Mega2560. Męczyłem się okropnie z uartami i ich przerwaniami a to takie proste.

    'micro                    : Mega2560
    
    'suited for demo          : yes
    
    'commercial addon needed  : no
    
    '-----------------------------------------------------------------------------------------
    
     
    
    $regfile = "m2560def.dat"                                   ' specify the used micro
    
    $crystal = 8000000                                         ' used crystal frequency
    
    $hwstack = 40                                               ' default use 32 for the hardware stack
    
    $swstack = 40                                               ' default use 10 for the SW stack
    
    $framesize = 40                                             ' default use 40 for the frame space
    
     
    
     
    
    '$timeout = 1000000
    
     
    
    'The M128 has an extended UART.
    
    'when CO'NFIG COMx is not used, the default N,8,1 will be used
    
    Config Com1 = 19200 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
    
    Config Com2 = 19200 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
    
    Config Com3 = 19200 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
    
    Config Com4 = 19200 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
    
     
    
    Enable Interrupts
    
    Config Serialin = Buffered , Size = 20
    
    Config Serialin1 = Buffered , Size = 20 , Bytematch = 65
    
    Config Serialin2 = Buffered , Size = 20 , Bytematch = 66
    
    Config Serialin3 = Buffered , Size = 20 , Bytematch = All
    
     
    
     
    
    'Open all UARTS
    
    Open "COM2:" For Binary As #2
    
    Open "COM3:" For Binary As #3
    
    Open "COM4:" For Binary As #4
    
     
    
     
    
    Print "Hello"                                               'first uart
    
    Dim B1 As Byte , B2 As Byte , B3 As Byte , B4 As Byte
    
    Dim Tel As Word , Nm As String * 16
    
     
    
    'unremark to test second UART
    
    'Input #2 , "Name ?" , Nm
    
    'Print #2 , "Hello " ; Nm
    
     
    
     
    
    Do
    
    Incr Tel
    
    Print Tel ; " test serial port 1"
    
    Print #2 , Tel ; " test serial port 2"
    
    Print #3 , Tel ; " test serial port 3"
    
    Print #4 , Tel ; " test serial port 4"
    
     
    
     B1 = Inkey()                                             'first uart
    
     B2 = Inkey(#2)
    
     B3 = Inkey(#3)
    
     B4 = Inkey(#4)
    
     
    
    If B1 <> 0 Then
    
        Print B1 ; " from port 1"
    
    End If
    
    If B2 <> 0 Then
    
        Print #2 , B2 ; " from port 2"
    
    End If
    
    If B3 <> 0 Then
    
        Print #3 , B3 ; " from port 3"
    
    End If
    
    If B4 <> 0 Then
    
        Print #4 , B4 ; " from port 4"
    
    End If
    
     
    
    Waitms 500
    
    Loop
    
     
    
     
    
     
    
    'Label called when UART2 received an A
    
    Serial1charmatch:
    
    Print #2 , "we got an A"
    
    Return
    
     
    
     
    
    'Label called when UART2 received a B
    
    Serial2charmatch:
    
    Print #3 , "we got a B"
    
    Return
    
     
    
     
    
    'Label called when UART3 receives a char
    
    Serial3bytereceived:
    
    Print #4 , "we got a char"
    
    Return
    
     
    
    End
    
     
    
    Close #2
    
    Close #3
    
    Close #4 





    Po skonfigurowaniu przerwanie jest dokładnie tu:

    'Label called when UART2 received an A
    
    Serial1charmatch:
    
    Print #2 , "we got an A"
    
    Return 


    Oczywiście na Mega2560 jest więcej jak jeden Uart więc należy w programie skonfigurować wg. własnego proca.
REKLAMA