Clarify usage of UART_Set_Active and uart interrupt

General discussion on mikroBasic PRO for PIC32.
Post Reply
Author
Message
calixarene
Posts: 17
Joined: 03 Apr 2012 06:31

Clarify usage of UART_Set_Active and uart interrupt

#1 Post by calixarene » 03 Feb 2015 05:16

I would like to use two UART modules at the same time. If I am not using interrupt, I need to use UART_Set_Active() to switch back and forth between two modules to read the data like the manual said.

Code: Select all

UART_Set_Active(@UART1_Read, @UART1_Write, @UART1_Data_Ready, @UART1_Tx_Idle); ' set UART1 active
  uart1_rd = UART1_Read() ;        ' Read message through UART1

UART_Set_Active(@UART2_Read, @UART2_Write, @UART2_Data_Ready, @UART2_Tx_Idle); ' set UART2 active
  uart2_rd = UART2_Read() ;        ' Read through UART2

UART_Set_Active(@UART1_Read, @UART1_Write, @UART1_Data_Ready, @UART1_Tx_Idle); ' set UART1 active
  uart1_rd = UART1_Read() ;        ' Read message through UART1
......
Can I use interruput and Uart1_rd= U1RxReg to read the character so that I don't need to switch back and forth using the UART_Set_Active() procedure. UArt1 is only for listening the message without transmitting and so I don't need it for transmitting.

Code: Select all


sub procedure UART2interrupt() iv IVT_UART_2 ilevel 6 ics ICS_AUTO
  uart2_rd = UART2_Read()         ' read the received data
  U2RXIF_bit = 0
end sub

sub procedure UART1interrupt() iv IVT_UART_1 ilevel 6 ics ICS_AUTO
  if OERR_bit = 1 then 
     OERR_bit = 0      ' overrun error and clear it otherwise the port will be jammed
  end if 
  Uart1_rd = U1RxReg
  U1RXIF_bit = 0
end sub

 UART_Set_Active(@UART2_Read, @UART2_Write, @UART2_Data_Ready, @UART2_Tx_Idle)  ' set only once
 U1RXIE_bit = 1                       ' enable uart1 received interrupt
 U2RXIE_bit = 1                       ' enable uart2 received interrupt
Will this work? In addition, Do I need to check OERR_bit when using UART2_Read() function

Thanks for advice in advance.

User avatar
darko.minic
Posts: 747
Joined: 01 Dec 2014 11:10

Re: Clarify usage of UART_Set_Active and uart interrupt

#2 Post by darko.minic » 03 Feb 2015 15:14

Hello,

You can use UART1 and UART2 interrupts so you don't need to switch back and forth using the UART_Set_Active() procedure.
Also I can recommend you to check OERR_bit when you're using UART2_Read() function.

Regards,
Darko

calixarene
Posts: 17
Joined: 03 Apr 2012 06:31

Re: Clarify usage of UART_Set_Active and uart interrupt

#3 Post by calixarene » 04 Feb 2015 10:34

Noted and Thanks. :D

Post Reply

Return to “mikroBasic PRO for PIC32 General”