View previous topic :: View next topic |
Author |
Message |
Mrinmoy Dey
Joined: 23 Jan 2018 Posts: 44
|
INT_RDA receive problem for PIC18F66K40 |
Posted: Mon Sep 30, 2019 4:05 am |
|
|
Hi,
I am using PIC18F66K40 for my project recently and I am unable to receive data using int_rda. I am using PIC microcontrollers with CCS compiler for last 2 years and successfully worked on int_rda of other three PIC microcontrollers of 18F series. But this time I can't make it work. Is there any special change of int_rda functionality in PIC18F66K40?? I think I can't initialize the interrupt properly. The hardware part is okay and the compiler I have used is v5.083. Any idea on this problem is urgently needed.. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9269 Location: Greensville,Ontario
|
|
Posted: Mon Sep 30, 2019 4:15 am |
|
|
You need to post a short, compilable program for us to look at !
I don't use that PIC, but does it have 'programmable pin select' ?
Does the PIC properly run a '1 Hz LED' program?
Have you got the hardware properly setup to the other RS232 device ?
Is the other RS232 device working ?
OK, I quickly looked at the datasheet (coffee wasn't ready. HAS to be Monday) and it has pinselectable pins... so you NEED to code them !! There's a 'sticky' up top that'll help. Just be sure that the pin you select IS the one for the UART you want !! That PIC has FIVE UARTS !! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19589
|
|
Posted: Mon Sep 30, 2019 6:09 am |
|
|
Yes.
Key thing is if you use #use rs232 without having done the #pin_select, the
compiler will generate software serial, so no INT_RDA.
Look at the sticky at the top of the forum for how to use #pin_select.
It is always safer to force the hardware UART to be used, so:
#USE RS232 (UART1, BAUD=115200, ERRORS)
Which 'forces' the compiler to generate hardware serial. Even better, if
you use this and have not #pin_selected the UART pins, the compiler
will then warn you that you have not done this. |
|
|
Mrinmoy Dey
Joined: 23 Jan 2018 Posts: 44
|
|
Posted: Wed Oct 09, 2019 5:07 am |
|
|
All your suggestions are valuable and new to me so I have tried to apply those at my best but it is still not working. Following the sticky, you have mentioned I modify my code -
For system configuration my code is -
Code: | #pragma device HIGH_INTS=TRUE
#pragma fuses ECH,WDT,NOPROTECT,NOBROWNOUT,NOFCMEN,NOPUT
#pragma use delay(clock=20000000,restart_wdt)
#PIN_SELECT U2RX=PIN_G2
#PIN_SELECT U2TX=PIN_G1
#USE RS232 (stream=CAMERA, UART2, BAUD=9600, bits=8, parity=N, stop=1, ERRORS, restart_wdt) |
For receiving data my code is below -
Code: | clear_interrupt(INT_RDA2);
enable_interrupts(INT_RDA2);
#INT_RDA2
void uart4_Rx_isr(void)
{
// Receive byte from camera.
g_ui8CAMDataRxBuffer[g_ui8CAMDataRxByteCount] = fgetc(CAMERA);
// Increment byte count.
g_ui8CAMDataRxByteCount++;
// Check receive byte count buffer overflow.
if(g_ui8CAMDataRxByteCount >= SIZE_CAM_DATA_RX_BUFF)
{
g_ui8CAMDataRxByteCount = 0;
}
// Clear interrupt.
clear_interrupt(INT_RDA2);
} |
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19589
|
|
Posted: Wed Oct 09, 2019 7:01 am |
|
|
clear_interrupt line not needed, inside the interrupt handler, nor is
'HIGH_INTS' unless you are using multiple priorities.
However most likely reason for it not working, is what else is on the pins.
Your pins potentially have the comparator 2 input on one of them
(this needs to be turned off), and both support analog inputs (these
need to be disabled before you can use a pin for digital I/O). |
|
|
Mrinmoy Dey
Joined: 23 Jan 2018 Posts: 44
|
|
Posted: Thu Oct 10, 2019 12:14 am |
|
|
@Ttelmah and @Temtronic
Thank you sir..Its working now. |
|
|
|