I have written application with UART1 receive data from BARCODE SCANNER and UART2 receive and send data to control PC.
Both of them should work with Interrupt routine. UART2 working well all time, never fail.
Uart1 receive EAn13 with 0x0d and 0x0A as delimiter code looks like 932710120001 + control chr +0x0D 0x0A
PIC32 read this data each second time, and OERR_bit is set each second time. Why?
Anybody having working example of UART1 interrupt want to share is welcome. I spend days on this.
radni1 and radni2 are strings[200]
thanks,
Damir
Code: Select all
sub procedure UART1_INT() iv IVT_UART_1 ilevel 6 ics ICS_AUTO 'komunikacija s SCANNEROM
' Do we have uart rx interrupt request?
if U1STA.OERR = 1 then
U1STA.OERR = 0
end if
received1= UART1_Read() 'prijem sa serijskog ulaza
receive1[brojslova1] = received1 'kopiranje u receive buffer CHAR
if received1=13 then 'ako je CR ascii 13 hex 0D
receive1[brojslova1]=13
radni1[brojslova1]=13 'kopiranje u radni
'radni[brojslova+1]=0x00
goto preskoci1
end if
if received1=10 then 'ako je LF ascii 10 hex 0A
if brojslova1<5 then 'ovo je samo da onemogucim CR i LF same u bufferu
brojslova1=0
radni1[0]=0x00
goto kraj1
end if
receive1[brojslova1]=10
radni1[brojslova1]=10
radni1[brojslova1+1]=0x00
ready1=1
primljeno1=1
goto kraj1
end if
radni1[brojslova1]=received1 'kopiranje u string radni
preskoci1:
inc (brojslova1)
kraj1:
U1RXIF_bit =0 ' Set U1RXIF to 0
end sub
sub procedure UART2_INT() iv IVT_UART_2 ilevel 7 ics ICS_AUTO 'komunikacija s PC-om
' Do we have uart rx interrupt request?
received2=UART2_Read() 'prijem sa serijskog ulaza
receive2[brojslova2] = received2 'kopiranje u receive buffer CHAR
if received2=36 then ' ako je $ asci 36 hex 24
radni2=""
brojslova2=0
receive2[brojslova2]=36
radni2[brojslova2]=36 'kopiranje u radni
goto preskoci2
end if
if received2=35 then ' ako je # asci 35 hex 23
receive2[brojslova2]=35
radni2[brojslova2]=35 'kopiranje u radni
goto preskoci2
end if
if received2=13 then 'ako je CR ascii 13 hex 0D
receive2[brojslova2]=13
radni2[brojslova2]=13 'kopiranje u radni
'radni[brojslova+1]=0x00
goto preskoci2
end if
if received2=10 then 'ako je LF ascii 10 hex 0A
receive2[brojslova2]=10
radni2[brojslova2]=10
radni2[brojslova2+1]=0x00
ready2=1
primljeno2=1
goto kraj2
end if
radni2[brojslova2]=received2 'kopiranje u string radni
preskoci2:
inc (brojslova2)
kraj2:
U2RXIF_bit =0 ' Set U1RXIF to 0
end sub
Code: Select all
'Initialization of UART1 interrupt..............
U1IP0_bit = 0 ' set interrupt
U1IP1_bit = 1 ' priority
U1IP2_bit = 1 ' to 6
U1IS0_bit = 1 'Sub Priority 11 = 3
U1IS1_bit = 1
U1STA.URXISEL0 = 0 '00 = one char, 01 = 3, 11 = 4
U1STA.URXISEL1 = 0 'gen Int when 1 chars in buffer
U1EIE_bit = 0 'Turn off error detection
U1RXIF_bit=0 ''UART2 IF=0
U1RXIE_bit=1 'enable UART2 INTERRUPT RX
U1TXIE_bit=0 'enable UART2 INTERRUPT RX
received1=uart1_read() 'just to clear UART buffer
received1=uart1_read() 'just to clear UART buffer
received1=uart1_read() 'just to clear UART buffer
received1=uart1_read() 'just to clear UART buffer
'---------------------------------------------------------------------------------------------------------------------------------------
radni1=""
'Initialization of UART2 interrupt..............
U2IP0_bit = 1 ' set interrupt
U2IP1_bit = 1 ' priority
U2IP2_bit = 1 ' to 7
'U2IS0_bit = 1 'Sub Priority 11 = 3
'U2IS1_bit = 0
U2STA.URXISEL0 = 0 '00 = one char, 01 = 3, 11 = 4
U2STA.URXISEL1 = 0 'gen Int when 1 chars in buffer
U2EIE_bit = 0 'Turn off error detection
U2RXIF_bit=0 'UART2 IF=0
U2RXIE_bit=1 'enable UART2 INTERRUPT RX
U2TXIE_bit=0
received2=UART2_read() 'just to clear UART buffer
radni2=""