- Joined
- Jul 4, 2009
- Messages
- 16,572
- Helped
- 5,158
- Reputation
- 10,349
- Reaction score
- 5,226
- Trophy points
- 1,393
- Location
- Aberdyfi, West Wales, UK
- Activity points
- 140,153
// adjust this to the length of the longest response + 1
#define BUFFERSIZE 20
// this is the ISR
void __interrupt() ISR(void)
{
if(PIR1bits.RCIF)
{
if(RCSTAbits.OERR)
{
RCSTAbits.CREN = 0;
RCSTAbits.CREN = 1;
}
else
{
ByteReceived = RXREG;
gsmFlag = 1;
}
}
// this is in your main loop
if(gsmFlag)
{
if(ByteReceived == '+') GSMindex = 0; // start of message found
if(ByteReceived == '\n') STAT = !STAT; // or whatever you want to do with the data
else
{
if(GSMindex < BUFFERSIZE)
{
GSMbuff[GSMindex++] = ByteReceived;
GSMbuff[GSMindex] = 0;
}
}
}
Code:if(GSMindex < BUFFERSIZE) { GSMbuff[GSMindex++] = ByteReceived; GSMbuff[GSMindex] = 0; }
else
{
GSMindex = 0;
}
There is no harm done but no advantage in that Andre as the overflowing data is lost anyway. The array pointer gets reset to zero by the next string arriving. It is there just in case an unterminated or over-length string arrives so it doesn't overflow the buffer.With the addition of an 'otherwise' option...
There is no harm done but no advantage in that Andre as the overflowing data is lost anyway. The array pointer gets reset to zero by the next string arriving. It is there just in case an unterminated or over-length string arrives so it doesn't overflow the buffer.
Brian.
/******************************************************************************/
/* Files to Include */
/******************************************************************************/
#include <xc.h> /* XC8 General Include File */
#include <stdint.h> /* For uint8_t definition */
#include <stdbool.h> /* For true/false definition */
#include "system.h" /* System funct/params, like osc/peripheral config */
#include "user.h" /* User funct/params, such as InitApp */
#include "lcd.h" /* LCD functions*/
#include "usart.h" /* Serial Port Functions*/
/******************************************************************************/
/* User Global Variable Declaration */
/******************************************************************************/
unsigned char pass[MAX_PASS_LEN],regPhoneNumber[MAX_PHONE_LEN+1],regIbId[MAX_IBID_LEN];
/******************************************************************************/
/* Main Program */
/******************************************************************************/
void main(void){
unsigned char temp,data;
unsigned long timeout = 1500000;
/* Initialize I/O and Peripherals for application */
InitApp();
STAT = false;
lcd_clear();
lcd_goto(0X00);
lcd_puts("GSM Debug");
lcd_goto(0X40);
temp = 3; //three retries
do{
lcd_goto(0X00);
lcd_puts("ATE0 SENT...");
lcd_goto(0X40);
data = gsmTest();
flushGsmBuff();
lcd_putXnum(data);
lcd_putch(',');
if(data)
break;
temp--;
}while(!data);
lcd_goto(0X40);
lcd_puts("WAITING FOR SMS");
putstr("AT+CMGF=1\r");
__delay_ms(1000);
putstr("AT+CMGD=0\r");
__delay_ms(1000);
putstr("AT+CNMI=2,2,0,0,0\r");
__delay_ms(1000);
PIR1bits.RCIF = 0;
PIE1bits.RCIE = 1;
INTCONbits.PEIE = 1;
INTCONbits.GIE = 1;
lcd_clear();
lcd_goto(0x00);
GSMindex = 0;
gsmFlag = 0;
while(1){
if(gsmFlag){
STAT = true;
while(1){
if(GSMbuff[GSMindex - 1] == EOD){
gsmFlag = 0;
break;
}
if(GSMindex >= MAX_BUF_LEN)
break;
timeout --;
if(!timeout)
break;
}
STAT = false;
lcd_putch('*');
__delay_ms(500);
PIE1bits.RCIE = 0;
lcd_clear();
lcd_goto(0X00);
temp = GSMindex;
GSMindex = 0;
while(GSMindex < temp){
lcd_putch(GSMbuff[GSMindex]);
GSMindex ++;
if(GSMindex%60 == 0){
lcd_goto(0X54);
}
else if(GSMindex%40 == 0){
lcd_goto(0X14);
}
else if(GSMindex%20 == 0){
lcd_goto(0X40);
}
}
lcd_putXnum(temp);
GSMindex = 0;
timeout = 1500000;
gsmFlag = 0;
}
}
}
during the lcd printing i am disabling the interrupt, i am not expecting any reception in this time, is there any problem with that?What does the line " PIE1bits.RCIE = 0;" do? I can't see any point in disabling serial interrupts at that place in the program.
Brian.
Problem: your serial link is entirely missing from the schematic - how are we to diagnose a possible electrical problem when it isn't even shown.
Brian.
Disabling RCIE is not a problem but it isn't necessary and you need to re-enable it before any more serial data can be received.
The reason I wanted the full schematic is we could not tell what kind of interface was on the GSM module, some have RS232 interfaces which are incompatible with the PIC TX and RX pins. As the picture shows CTS and RTS pads connected directly to the SIM900 I think we can assume it does not have an intermediate interface to the row of pins on the right. I presume you are using those pins and not the 'D' connector.
Next question: you seem to be running the PIC from a 7805 regulator so it has a 5V VCC. The SIM900A will be destroyed by applying 5V, it has an absolute maximum supply of 4.5V and typically runs from 4V. Are you sure the voltage levels between them are compatible?
Brian.
The problem was not my in my code, or in my hardware ( conceptually). And also in GSM. The problem was GSM module is working on 3.3 -3.9v logic. I thought that pic can handle this. But it producing an FERR error. So I added a buffer between GSM tx and PIC Rx.For the benefit of others reading this forum, please tell us what you found was wrong.
Brian.
* or wrong voltage levels.
--> but you don't give none of the above informations.
hai,
I am reading the return back from a GSM Module (SIM900A) using PIC18f452, the module is AE GSM MODULE. the problem is when I am connecting the GSM module through the ft232 module by serial GSM modem is working, and also my program is also OK, but when I am connecting to the AE GSM MODULE the program is not getting the return back. anyone has faced similar problems and can anyone give any clues.
8-O8-O
Please read the question Technowiz, it relates to a PIC18F452 connecting to a GSM module, there is no mention of Arduino at all.According to me your issue related to, while programming Arduino uses serial ports to load program from the Arduino IDE. If these pins are used in wiring, the program will not be loaded successfully to Arduino. So you have to disconnect wiring in Rx and Tx each time you burn the program to Arduino. When the program get loaded successfully, you need to reconnect these pins and hopefully, your system gets started.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?