Hello, I am new to PIC, I am able to transmit through pic18f4520 and sim800 but could not able to receive it. I run debugger, program is stuck in ISR but RCIF is not fired at all. here are my codes
/*
* File: interruptSetup.c
* Author: Raushan
*
* Created on 23 June, 2017, 7:30 PM
*/
#include <stdio.h>
#include <stdlib.h>
#include "ConfigurationBits.h"
void InterruptSetup() {
T1CON = 0x01; //Configure Timer1 interrupt
PIE1bits.TMR1IE = 1;
RCONbits.IPEN = 0x01; // TMR1 high priority ,TMR1 Overflow Interrupt Priority bit
PIR1bits.TMR1IF = 0;
T0CON = 0X00;
INTCONbits.T0IE = 1; // Enable interrupt on TMR0 overflow
INTCON2bits.TMR0IP = 0x00;
T0CONbits.TMR0ON = 1;
INTCONbits.PEIE = 1; //periferal interrupt enable
INTCONbits.GIE = 1;
INTCON2 =0x00; // Set Falling Edge Trigger
}
/*
* File: uartSetup.c
* Author: Raushan @intellicar
* Created on 23 June, 2017, 6:14 PM
*/
#include "ConfigurationBits.h"
#include <pic18f4520.h>
char UART_Init(const long int baudrate) {
//SPBRG = (_XTAL_FREQ - baudrate * 16) / (baudrate * 16); //Writing SPBRG Register
SPBRG = 12; // set baud rate to 9600 baud (2MHz/(16*baudrate))-1
SYNC = 0; //Setting Asynchronous Mode, ie UART
RCSTAbits.SPEN = 1; // enable USART// got effected
RCSTAbits.CREN = 1; // enable continous receiving
PIE1bits.RCIE = 1;
TXSTAbits.TXEN = 1; //Enables Transmission
TXSTAbits.BRGH = 1; // high baud rate mode
TRISCbits.RC7 = 1; //Rx
TRISCbits.RC6 = 0; //Tx
PIE1bits.TXIE = 1;
if (RCSTAbits.FERR = 1) {
RCSTAbits.CREN = 0; // enable continous receiving
RCSTAbits.CREN = 1; // enable continous receiving
}
if (RCSTAbits.OERR = 1) {
RCSTAbits.CREN = 0; // enable continous receiving
RCSTAbits.CREN = 1; // enable continous receiving
}
//BRG16 =1; //
return 1; //Returns 1 to indicate Successful Completion
}
/*
* File: work_23-06-17.c
* Author: Raushan
*
* Created on 23 June, 2017, 6:12 PM
*/
#include <stdio.h>
#include <stdlib.h>
#include <pic18f4520.h>
#include "ConfigurationBits.h"
#include "uartSetup.h"
#include "iterruptSetup.h"
#define STRLEN 512
char UART_Init(const long int baudrate);
void I2C_Master_Init(const unsigned long c);
void printToArduino(unsigned char *printOutput);
volatile unsigned char nextChar = '\n';
unsigned char buffer[STRLEN];
void main() {
OSCCONbits.IRCF = 0x55; // INTOSC frequency 2MHz
UART_Init(9600);
2C_Master_Init(9600);
UART_Write_Text("Setup complete");
printToArduino("Setup complete");
InterruptSetup();
while (1) {
UART_Write_Text("AT+BTPOWER=?\r\n");
__delay_ms(1000);
}
}
void interrupt interruptRoutine()
{
printToArduino("I am stuck here\n");
if (RCIF) {
nextChar = UART_Read();
printToArduino("This is Receive interrupt\n");
}
PIR1bits.RCIF = 0;
}
Kindly help. ..
/*
* File: interruptSetup.c
* Author: Raushan
*
* Created on 23 June, 2017, 7:30 PM
*/
#include <stdio.h>
#include <stdlib.h>
#include "ConfigurationBits.h"
void InterruptSetup() {
T1CON = 0x01; //Configure Timer1 interrupt
PIE1bits.TMR1IE = 1;
RCONbits.IPEN = 0x01; // TMR1 high priority ,TMR1 Overflow Interrupt Priority bit
PIR1bits.TMR1IF = 0;
T0CON = 0X00;
INTCONbits.T0IE = 1; // Enable interrupt on TMR0 overflow
INTCON2bits.TMR0IP = 0x00;
T0CONbits.TMR0ON = 1;
INTCONbits.PEIE = 1; //periferal interrupt enable
INTCONbits.GIE = 1;
INTCON2 =0x00; // Set Falling Edge Trigger
}
/*
* File: uartSetup.c
* Author: Raushan @intellicar
* Created on 23 June, 2017, 6:14 PM
*/
#include "ConfigurationBits.h"
#include <pic18f4520.h>
char UART_Init(const long int baudrate) {
//SPBRG = (_XTAL_FREQ - baudrate * 16) / (baudrate * 16); //Writing SPBRG Register
SPBRG = 12; // set baud rate to 9600 baud (2MHz/(16*baudrate))-1
SYNC = 0; //Setting Asynchronous Mode, ie UART
RCSTAbits.SPEN = 1; // enable USART// got effected
RCSTAbits.CREN = 1; // enable continous receiving
PIE1bits.RCIE = 1;
TXSTAbits.TXEN = 1; //Enables Transmission
TXSTAbits.BRGH = 1; // high baud rate mode
TRISCbits.RC7 = 1; //Rx
TRISCbits.RC6 = 0; //Tx
PIE1bits.TXIE = 1;
if (RCSTAbits.FERR = 1) {
RCSTAbits.CREN = 0; // enable continous receiving
RCSTAbits.CREN = 1; // enable continous receiving
}
if (RCSTAbits.OERR = 1) {
RCSTAbits.CREN = 0; // enable continous receiving
RCSTAbits.CREN = 1; // enable continous receiving
}
//BRG16 =1; //
return 1; //Returns 1 to indicate Successful Completion
}
/*
* File: work_23-06-17.c
* Author: Raushan
*
* Created on 23 June, 2017, 6:12 PM
*/
#include <stdio.h>
#include <stdlib.h>
#include <pic18f4520.h>
#include "ConfigurationBits.h"
#include "uartSetup.h"
#include "iterruptSetup.h"
#define STRLEN 512
char UART_Init(const long int baudrate);
void I2C_Master_Init(const unsigned long c);
void printToArduino(unsigned char *printOutput);
volatile unsigned char nextChar = '\n';
unsigned char buffer[STRLEN];
void main() {
OSCCONbits.IRCF = 0x55; // INTOSC frequency 2MHz
UART_Init(9600);
2C_Master_Init(9600);
UART_Write_Text("Setup complete");
printToArduino("Setup complete");
InterruptSetup();
while (1) {
UART_Write_Text("AT+BTPOWER=?\r\n");
__delay_ms(1000);
}
}
void interrupt interruptRoutine()
{
printToArduino("I am stuck here\n");
if (RCIF) {
nextChar = UART_Read();
printToArduino("This is Receive interrupt\n");
}
PIR1bits.RCIF = 0;
}
Kindly help. ..