raushankumar586
Junior Member level 1
Hello Guys,
I want to implement interrupt driven communication between pic18f4520 and sim800 module, I partially succeed but stuck at one point form one week, let me show you code first :
ohk, now come to my issue...... upper main code is working , notice following code in main loop
instead of calling readit() here, I want to call readit() from my timer interrupt , so I made following change in interrupt and called readit() from there , I can see from oscilloscope at two at\r\nok\r\n is having approx 208ms separation
but this code is not working , means previously I was getting AT\r\nOK\r\n in my serial monitor but this time only ATATAT comming and that too stops after one or two seconds stops.
I want to implement interrupt driven communication between pic18f4520 and sim800 module, I partially succeed but stuck at one point form one week, let me show you code first :
Code:
void main(void) {
OSCCON = 0x72; // INTOSC frequency 8MHz
TRISBbits.RB7 = 0;
InterruptSetup();
Timer0Setup();
I2C_Master_Init(9600);
UART_Init(9600);
while (1) {
UART_Write_Text("AT\r\n");
__delay_ms(7);
readIt();
__delay_ms(200);
}
}
Code:
void interrupt interruptRoutine() {
if (PIR1bits.RCIF) {
nextChar = UART_Read();
if (nextChar == '\r') {
SimMsgReceived += 1;
} else if (bufferidx < strLen) {
buffer[bufferidx++] = nextChar;
buffer[bufferidx] = 0;
}
}
PIR1bits.RCIF = 0;
}
Code:
void readIt() {
if (SimMsgReceived <= 5) {
printToArduino(buffer);
SimMsgReceived = 0;
}
clearbuffer();
}
void clearbuffer() {
for (int i = 0; i < bufferidx + 1; i++) {
buffer[i] = 0;
}
bufferidx = 0;
}
void printToArduino(unsigned char *printOutput) {
I2C_Master_Start(); //Start condition
I2C_Master_WriteC(0x12); //7 bit address + Write (000001-0)(SELECT ADDRESS TO COMMUNICATE )
I2C_Master_WriteS(printOutput); //Write data
I2C_Master_Stop(); //Stop condition
}
ohk, now come to my issue...... upper main code is working , notice following code in main loop
Code:
while (1) {
UART_Write_Text("AT\r\n");
__delay_ms(7);
readIt();
__delay_ms(200);
}
instead of calling readit() here, I want to call readit() from my timer interrupt , so I made following change in interrupt and called readit() from there , I can see from oscilloscope at two at\r\nok\r\n is having approx 208ms separation
Code:
void interrupt interruptRoutine() {
if (timer0InterruptFired()) {
INTCONbits.TMR0IE = 1;
T0CON = 0x00; // using a 16 bit timer0 with pre-scaler 4
T0CONbits.PSA = 0;
TMR0H = 0xFC; // now having 1.6ms delay
TMR0L = 0x00;
Count++;
if (Count > 210) {
Count = 0;
readIt();
}
T0CONbits.TMR0ON = 1;
INTCONbits.TMR0IF = 0;
}
if (PIR1bits.RCIF) {
nextChar = UART_Read();
if (nextChar == '\r') {
SimMsgReceived += 1;
} else if (bufferidx < strLen) {
buffer[bufferidx++] = nextChar;
buffer[bufferidx] = 0;
}
}
PIR1bits.RCIF = 0;
}
// my timer setup function is following:
void Timer0Setup() {
INTCONbits.TMR0IF = 0;
INTCONbits.TMR0IE = 1;
T0CON = 0x00; // using a 16 bit timer0 with pre-scaler 4
T0CONbits.PSA = 0;
TMR0H = 0xFC;
TMR0L = 0x00;
T0CONbits.TMR0ON = 1;
}
but this code is not working , means previously I was getting AT\r\nOK\r\n in my serial monitor but this time only ATATAT comming and that too stops after one or two seconds stops.
Last edited: