Hi,
I'm using a PIC16F628A USART to communicate with my SE T610 GSM. MikroC compiler.
Circuit:

How program works - when RB0 goes high, uC transmits "at" command to my GSM and it responds "OK". I've included a char compare routine to see if the response is indeed "OK". And it works - if it receives chars
O,
K,
\n or
\r the LED turns on.
My problem - I'm trying to use the exact same program and circuit (with appropriate pin adjustments, of course) with my PIC18F4520 and PIC16F887 but it doesn't work.
Transmittion works fine, I've tried "atd" command instead of "at", and GSM makes a call, which means transmission is ok. And uC also receives something back, because interrupt does occur (i've tested it), but when I compare incoming chars, none of them are what they are supposed to be ("OK\n\r").
I've also connected the GSM to my PC directly and tested it using putty to make sure it's not GSMs fault. It works perfectly.
Voltage levels of Tx and Rx pins are correct, I've also tried different Fosc's and baudrates, but couldn't make it work. Unfortunatley I don't have an access to any oscilloscope to check what am I actually receiving.
I don't understand why it works on 16F628A, but not on other two PICs. I suspect it has something to do with USART configuration. I've read all 3 datasheets but it seems to me nothing should change regarding USART init.
I would really appreciate any help.
Code from PIC16F887, where I'm using PORD intead of PORTB I/O:
volatile unsigned char uart_rd = 0; // serial input byte (RCREG)
unsigned int b = 0;
// UART Initialization
void uartinit()
{
UART1_Init(9600); // initialize UART module at 9600 bps
Delay_ms(100); // let it stabilize
PIE1.B5 = 1; // turn on USART interrupt bit RCIE
}
// UART Interrupt: Receive character
void interrupt()
{
if (PIR1.B5) // if interrupt occurs - if RCIF = 1(RCREG full)
{
uart_rd = RCREG; // read incoming byte (character)
if (uart_rd == 79) PORTD.B1 = 1; //if incoming byte is "O", turn on LED
PIR1.B5 = 0; // reset RCIF flag bit to 0
}
}
// Main program
void main()
{
uartinit();
INTCON = 0b11000000; // enable PEIE and GIE interrupts
ADCON1 = 0b0111; // configure all pins as digital
TRISD = 0b01;
PORTD = 0b00;
while (1)
{
if ((PORTD.B0 == 1) && (b == 0)) // if input goes high
{
b = 1; // set flag, so this if loop is disabled in future
UART1_Write_Text("at"); // phones response should be "OK"
UART1_Write(13); // \r
}
}
}