raushankumar586
Junior Member level 1
- Joined
- Jun 26, 2017
- Messages
- 17
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 191
Stuck in ISR, RCIF is not Firing when uart with pic18f5420 and Sim800
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
Kindly help. ..
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
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 /* * 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. ..