• AVR Freaks

AnsweredPIC18F46K22 UART2 Handler issue

New Member
  • Total Posts : 23
  • Reward points : 0
  • Joined: 2018/11/21 00:35:48
  • Location: 0
  • Status: offline
2019/05/19 06:30:02 (permalink)

PIC18F46K22 UART2 Handler issue

Hello, I'm working with a module I should be sending and receiving from, via UART2. 
I send the commands and it works fine, the problems comes when I am supposed to receive data from module in the interrupt. I am receiving nothing. 
My LED should be blinking everytime I receive any character via UART2 handler. everything I receive via the serial monitor while testing but nothing happens. 
here are the  the main functions that could affect the problem : 

void Interrupts_Init(void)
RCONbits.IPEN= 0x01; //Enable priority level on Interrupts
INTCONbits.GIE_GIEH= 0x01; //enable all high priority interrupts
INTCONbits.PEIE_GIEL=0x01; //enable all low priority interrupts
PIE3bits.RC2IE = 0x01; //EUSART2 Receive Interrupt enabling
IPR3bits.RC2IP=0x01; //EUSART2 receive is high priority
void UART2_Initialization(void)
BAUDCON2bits.BRG16=0x01; //16-bit baud rate generator is used
TXSTA2bits.BRGH=0x00; //low speed baud rate
SPBRG2=103; SPBRGH2=0; //value to generate 9600 Baud Rate at 16MHz with minimum error
TRISDbits.RD6= 0;
TRISDbits.RD7= 1;
TXSTA2bits.SYNC=0x00; //Asynchronous mode
RCSTA2bits.SPEN= 0x01; // serial port enabled
RCSTA2bits.CREN= 0x01; //Enable continuous receive
TXSTA2bits.TXEN=1; //enable transmit
void interrupt High_Priority(void)

if(PIR3bits.RC2IF==1 && PIE3bits.RC2IE == 0x01)
GSM_Response[counter]= RCREG2;
post edited by CantFindName - 2019/05/19 06:40:22
  • Total Posts : 1880
  • Reward points : 0
  • Joined: 2012/01/16 12:01:07
  • Location: Second star on the right, straight on till morning
  • Status: offline
Re: PIC18F46K22 UART2 Handler issue 2019/05/19 07:34:58 (permalink) ☼ Best Answerby CantFindName 2019/05/20 00:17:42
+3 (3)
UART2 Rx for your chip is on pin RD7, which also has analog input functionality that must be disabled.
Reference: PORTD Registers section of the I/O Ports chapter of the Data Sheet.

Recommend you get into the habit of using LATB rather than PORTB register to manipulate LED bits.  It may not make a difference in this particular program, but you will thank me later when you get to more "interesting" applications.  Reference: About a gazillion posts on this forum (and elsewhere): Search "read-modify-write" or "RMW"
post edited by davekw7x - 2019/05/19 07:46:21

Attached Image(s)

Sometimes I just can't help myself...
Jump to:
© 2020 APG vNext Commercial Version 4.5