I am attempting to establish serial communications with UART1 or 2
on a PIC24HJ64GP502. MPLAB IDE v8.76 and c30 v3.30.
I am using a MAX232 and serial-USB converter to a Win-7
PC running hyperterm (9600-N-8-1). If I pull the PIC and jumper
pins 21 and 22 together I get a proper echo on the PC, so the
connectivity is good too/from the PIC.
Current program does nothing but try to receive a character, increment a
counter and turn on a led.
Transmit from PIC to PC works fine, but I can't get the receive side to
respond
at all. I have U1RX_IN mapped to RP10/pin 21 and can see clean data from
the PC directly on pin 21 of the PIC with my oscilloscope.
When running the program the Error LED does not get turned on,
(other than by an initial spurious character on startup) i.e. no
framing or overrun errors detected nor does the received character
counter get incremented except on startup.
When I halt the program it is looping in the receive
loop with the watch window showing:
BRGVAL = 0xEE (238)
U1STA = 0x0100
U1MODE = 0xC000
U1RXREG = 0
RPINR18 = 0x1F0A
In the more complex version of the code I've tried BRGVALs from
226 to 253 (the points at which hyperterm fails to correctly receive the
startup prompt) at 9600 baud. Also tried 2400, 19200, 57600, and 115200 baud.
Also tried uart2.
I've read both the datasheet and Section 17 of the Family Reference
Manual and can't see anything I'm doing wrong. The code is essentially
the polling example from Section 17 with the changes/additions
required for a 24HJ (PPS mapping and FRC=7.37 MHz).
My code is below.
What am I doing wrong?
TIA
to unsubscribe, go to http://www.yahoogroups.com and follow the instructions
PIC24HJ64GP502 UARTs will not receive
Started by ●September 26, 2011
Reply by ●December 10, 20122012-12-10
Not sure if this is an issue in your code but I always forget to set the
pin's TRIS register for input...
//Make the Serial RX pin an input
TRISCbits.TRISC5=1;
Are you turning on the UART's Continuous Receive?
//Setup the USART BRGH=0; SYNC=0; BRG16=0; SPBRGQ; SPEN=1; //Turn on the
UART TXEN=1; //Enable Transmit CREN=1; //Enable continous recieve.
Also, I poll for input a bit differently. I used the UART interrupt flag
but handle it in normal code, not an interrupt handler... Like this.
if (RCIF) { Input=RCREG; switch (Input) { case 's': case 'S':
GetSetPoint(); break; case 'q': case 'Q': Serial_Prints("Current
Temperature: "); TC=MeasuredTemperature/10; Serial_Print_UInt(TC);
PutC('.'); PutC(48+(MeasuredTemperature-(10*TC))); Serial_Prints("C\n\r");
break; case 'b': case 'B': GetBandGap(); break; } }
Hope this helps.
-Demolitron
pin's TRIS register for input...
//Make the Serial RX pin an input
TRISCbits.TRISC5=1;
Are you turning on the UART's Continuous Receive?
//Setup the USART BRGH=0; SYNC=0; BRG16=0; SPBRGQ; SPEN=1; //Turn on the
UART TXEN=1; //Enable Transmit CREN=1; //Enable continous recieve.
Also, I poll for input a bit differently. I used the UART interrupt flag
but handle it in normal code, not an interrupt handler... Like this.
if (RCIF) { Input=RCREG; switch (Input) { case 's': case 'S':
GetSetPoint(); break; case 'q': case 'Q': Serial_Prints("Current
Temperature: "); TC=MeasuredTemperature/10; Serial_Print_UInt(TC);
PutC('.'); PutC(48+(MeasuredTemperature-(10*TC))); Serial_Prints("C\n\r");
break; case 'b': case 'B': GetBandGap(); break; } }
Hope this helps.
-Demolitron