CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Problem using INT_RDA2 with PIC18F66K80

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ronewart



Joined: 02 Aug 2008
Posts: 8

View user's profile Send private message Visit poster's website

Problem using INT_RDA2 with PIC18F66K80
PostPosted: Fri Apr 18, 2014 2:06 pm     Reply with quote

Having problems getting the EUSART2 interrupt to work on PIC18F66K80. Am trying to communicate between two PIC18F66K80s using EUSART2. Am using a very simple query protocol between the two PIC chips. The code is working fine when using EUSART1, but when I physically move the signal and associated uart port setup from UART1 to UART2, INT_RDA to INT_RDA2, the RDA2 does not start the interrupt. When using UART1, INT_RDA works fine. Can physically see a clean RS232 signal of good level on RX2.

UART SETUP IN .h header file
Code:

#use delay(clock=16000000)
#use rs232(uart2,xmit=PIN_E7,rcv=PIN_E6,enable=PIN_G1,baud=9600,bits=8,parity=N,stop=1,stream=pintf,errors)
   

INTERRUPT HANDLER IN .c   source file
#int_RDA2      // this interrupt works fine when using UART1 and #INT_RDA
void RDA2_isr(void)
{
   output_bit(Led0GrnA,1); // !! flash scope pin if byte received 4/8/14
   output_bit(Led0GrnA,0);
   // this entry when  byte is received via RS-232 pintf
   proc_pintf(); // process pintfooth I/O
}

ENABLING  OF RDA2 INTERRUPT DURING INITIALIZATION IN .c  source file
   enable_interrupts(INT_RDA2); // !! for test of interface only 4/8/14
   enable_interrupts(INT_TIMER0);   // for Timer0 3/1/13
   enable_interrupts(GLOBAL);   

Am using PCWHD compiler version 5.016

Any suggestions / recommendations appreciated. Thanks.
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Fri Apr 18, 2014 3:52 pm     Reply with quote

Hi,

No one else has replied, so I'll take a shot at the problem even though it's not a PIC I've ever used. I notice that you specify both 'UART2' and the UART #2 pin numbers in your #use rs232 directive. Try to get rid of the pin numbers or the 'UART2' keyword, don't use both. I also notice that you have defined an 'Enable' pin. Are you really using some sort of RS485 tranceiver, such as the MAX485?

Does this really work for UART1, including the 'Enable'? Same hardware, just moving three wires (Tx, Rx, Enable)?

One other thing I just noticed. You never actually read the character in the RDA2 interrupt. This is required for the interrupt to be cleared.

John
ronewart



Joined: 02 Aug 2008
Posts: 8

View user's profile Send private message Visit poster's website

PostPosted: Fri Apr 18, 2014 5:52 pm     Reply with quote

John,
Thanks for you suggestion. I will try deleting the Pin numbers in the #use_rs232 directive. I am using the PIC chip's defined RX and TX pins, which worked fine for UART1. That same syntax does not work for UART2.
Yes, I am using an rs485 transceiver, and yes, the Enable works perfectly to enable the transmitter at the correct time on UART1. The transceiver defaults to the HI state when no enabled, so there is a very clean transition between bytes, with no spurious glitches.
For the test, I only moved Tx from TX1 to TX2, and the Rx from RX1 to Rx2. For the test, I left the enable on the same pin for both the UART1 test which works, and the UART2 test which does not work.
The proc_pintf() does indeed read the character in the RDA2 interrupt. My problem is that I can never get the RD2 interrupt routine to execute. I put a scope test in the RDA2 routine to toggle a bit and output to a pin, and it never occurs.
Thanks. Ron
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Fri Apr 18, 2014 8:23 pm     Reply with quote

Hi Ron,

There was something in the archives about a similar issue with UART 2 on a chip in the same family. PCM programmer posted a work-around for a compiler issue. That was some versions ago, so my guess is it's been fixed?

I'd create two identical programs, one with UART 1 and one with UART 2, and the compare the .lst file for each. That should basically tell you if the compiler is creating the same code for each case, with only the UART differences.

BTW, it's pretty unusual to jump out of the interrupt to read the received character. Why do you do it that way? Do you have some good reason?

John
ronewart



Joined: 02 Aug 2008
Posts: 8

View user's profile Send private message Visit poster's website

PostPosted: Tue Apr 22, 2014 5:19 am     Reply with quote

John,
Your first comment fixed my INT_RDA2 problem, and it started to work. I removed the "xmit=PIN_E7,rcv=PIN_E6" from the #use rs232 statement. It is now:
Code:
#use delay(internal=16000000)
#use rs232(UART2, baud=9600,parity=N,bits=8,stream=pintf,enable=PIN_G1,errors)

Thanks for the help.

Also, I had no good reason for reading the character outside the #INT_RDA2 routine. I changed that to read the character inside the interrupt, and flag for subsequent processing.

Thanks John!
Ron
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Wed Apr 23, 2014 8:59 am     Reply with quote

Hi Ron,

Glad to hear it's now working for you!

For really robust serial communications, I recommend that you take a look at the CCS example program 'ex_SISR.c', which demonstrates how to implement an interrupt-driven circular receive buffering system for incoming serial data. It's a bit of work to get just right, but in the long run it's well worth the effort!!

Thanks,

John
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group