When trying to send and receive using a PIC18F97J60 and MAX232 using a program written with the C18 compiler, I am only able to transmit data. For receiving, I have tried at least 50 methods but none are working. I even tried the software on multiple micro-controller boards to check for a hardware problem but none of the boards ever receive anything. I believe that the following items are correct:
- My clock is perfect at 41.6667MHz
- My baud generation is perfect
- My hardware is OK (some other IIIrd party hex code able to receive also)
- My host PC, its COM port, and the serial cable are OK
Can anyone guide with probable areas I may be missing?
------------------ FURTHER CLARIFICATIONS -------------------------------------------
Thanks Olin for helping, you are great man. Sorry for not putting my question correctly. Please note:
I was trying to do serial I/O to write a boot loader for the PIC18F97J60 myself as my vendor's supplied boot loader stops sending/receiving with PCloader software after a partial user application hex download. It also ensures that RS232 port is able to both send and receive. Moreover, Microchip's boot loader described in AN1310 also stucks on receiving data.
My sample application (a bootloader) is able to transmit but never receives anything. I'm in soup: either I need a new boot loader or my application must work. I have never faced such a problem in my 12 years of development and I am feeling like a fool.
Other details as you requested are as follows:
- I had 10-12 PIC18F97J60 cards with MAX232 on C6/C7 for Serial I/O. The problem is the same for all boards (of different batches).
- I wish to do 9600 baud, 8 bit, no parity, 1 stop, no handshake, no interrupt data exchange with RealTerm (Better Than Hyperterminal - Displays HEX Code).
- My clock and baud rate calculations are perfect for 41.6667MHz. I have set
OSCTUNE = 0x40
andBAUDCON = 1084
. I am able to receive perfectly on the PC with RealTerm. - My program not able to receive anything on the PIC but able to transmit.
- I tried polling as well as interrupt but nothing works.
Snippet of code is as follows:
void putchar(unsigned char Char)
{
//Wait for (TSR==1)
while(TXSTA1bits.TRMT!=1);
//Trasmit Current Data
TXREG1= Char;
//Wait for (TSR==1)
while(TXSTA1bits.TRMT!=1);
}
void putstr(unsigned char *String)
{
do
{
putchar((*String));
}while(*String++);
//CR
putchar(CR);
//LF
putchar(LF);
}
void main(void)
{
unsigned char RS232[] = "RS-232";
OSCTUNE = 0x40;
TXSTA1 = 0x24;
RCSTA1 = 0x90;
BAUDCON1=0x08;
SPBRGH1=0x04;
SPBRG1=0x3C;
while(1)
{
putstr(RS232);
Delay10KTCYx(200);
if(PIR1bits.RC1IF == 1)
{
MYChar = RCREG1; //*** No OERR & FERR present, RC1IF never gets set ***
}
}
}