CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

issues with the pic to send and receive serially

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
madtoilet



Joined: 02 Apr 2008
Posts: 36

View user's profile Send private message

issues with the pic to send and receive serially
PostPosted: Wed Apr 23, 2008 6:14 pm     Reply with quote

I know that there are a couple of topics on this and i've been looking through them but i'd like to know if there are any thoughts on why this code isn't working
Code:



#include <18f4550.h>



#fuses HS,NOWDT,NOPROTECT, NOLVP
#use delay(clock=4mhz)



void receive_text(void);

byte number[11]="5 ";

void main()
{

output_low(PIN_B6);
delay_ms(500);
output_high(PIN_B6);
delay_ms(2000);
output_low(PIN_B6);
//output_b(0x00);
delay_ms(20000);
 receive_text();

}

void receive_text(void)
{
#use rs232(baud=4800, bits=8, parity=N, stop=1, xmit=PIN_C6, rcv=PIN_C7, stream=GSM, ERRORS)
unsigned char temp[70];
byte ch =0;
int count=0;
int count2=10;
int count3=0;

fprintf(GSM,"AT+CMGF=1\r\n");
delay_ms(100);
//20 spots to first number
fprintf(GSM,"AT+CMGR=2\r\n");  //Read SMS at location 1
     delay_ms(3000);



//output_high(PIN_B3);
if(kbhit())
      output_high(PIN_B3);

start:
ch = fgetc(GSM);
     if(ch == '5' || ch == 0x35){
         output_high(PIN_B0);
               while(count2 !=0){
               ch = fgetc(GSM);
               number[count2] = ch;
               count2--;
                  }
            if(ch == '\r')
                  break;
     }


count3++;
if(count3 == 40){
      goto breaker;}


goto start;

breaker:
break;

/*
fprintf(GSM, "AT+CMGD=1\r\n");//delete sms at location 1
delay_ms(10);
*/

}


the main thing i want is for it to see the number '5' in the text. I know there is a number 5 in there when i checked it on the pc.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Wed Apr 23, 2008 7:20 pm     Reply with quote

Code:
fprintf(GSM,"AT+CMGR=2\r\n");  //Read SMS at location 1
     delay_ms(3000);
How much time do you think it will take before the phone sends the response?
Let's assume this will take less than your 3 seconds then the small buffer in the PIC's UART will store the first three characters before overflowing and ignoring all other incoming data. Most likely the the first data received is 'OK\n', so the buffer has overflown and locked even before the SMS data is sent to the PIC.

I suggest you use another mechanism for receiving the data based on interrupts, for an example see the file ex_sisr.c in the CCS Example directory.
madtoilet



Joined: 02 Apr 2008
Posts: 36

View user's profile Send private message

PostPosted: Thu Apr 24, 2008 3:02 pm     Reply with quote

hey,

thanks. I'm now applying the buffer to my code. One of my concerns is that if in my rs232 setting i have 'stream=GSM', can i still use

c = bgetc();

to obtain my information or do i have to change my buffer to work with the stream?
madtoilet



Joined: 02 Apr 2008
Posts: 36

View user's profile Send private message

PostPosted: Thu Apr 24, 2008 4:41 pm     Reply with quote

this is what my code looks like now

Code:

#include "G:\Senior Project\base2\base2.h"
  #include <string.h>
#fuses HS,NOWDT,NOPROTECT, NOLVP
  #use delay(clock=4mhz)
  //#include <lcd.h>

#define BUFFER_SIZE 32
BYTE buffer[BUFFER_SIZE];
BYTE next_in = 0;
BYTE next_out = 0;


#int_rda
void serial_isr() {
   int t;

   buffer[next_in]= getc();
   t=next_in;
   next_in=(next_in+1) % BUFFER_SIZE;
   if(next_in==next_out)
     next_in=t;           // Buffer full !!
}

#define bkbhit (next_in!=next_out)

BYTE bgetc() {
   BYTE c;

   while(!bkbhit) ;
   c=buffer[next_out];
   next_out=(next_out+1) % BUFFER_SIZE;
   return(c);
}

void receive_text(void);
void test_gsm(void);
char number[11]="5 ";


void main()
{

   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(FALSE);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   enable_interrupts(int_rda);
   enable_interrupts(global);
   setup_low_volt_detect(FALSE);
   setup_oscillator(False);

output_low(PIN_B6);
delay_ms(500);
output_high(PIN_B6);
delay_ms(2000);
output_low(PIN_B6);
//output_b(0x00);
delay_ms(2000);
 receive_text();
//test_gsm();


}

void receive_text(void)
{
#use rs232(baud=4800, bits=8, parity=N, stop=1, xmit=PIN_C6, rcv=PIN_C7, stream=GSM, ERRORS)
unsigned char temp[70];
byte ch =0;
int count=0;
int count2=10;
int count3=0;

fprintf(GSM,"AT+CMGF=1\r\n");
delay_ms(100);
//20 spots to first number
fprintf(GSM,"AT+CMGR=2\r\n");  //Read SMS at location 1
     delay_ms(1);

output_low(PIN_B0);
//output_high(PIN_B3);


while(TRUE){
start:
ch = bgetc();
     if(ch == '5' || ch == 0x35){
         output_high(PIN_B0);
               while(count2 !=0){
               ch = bgetc();
               number[count2] = ch;
               count2--;
                  }
            if(ch == '\r')
                  break;
     }
}

count3++;
if(count3 == 40){
      goto breaker;}


goto start;

breaker:
break;

/*
fprintf(GSM, "AT+CMGD=1\r\n");//delete sms at location 1
delay_ms(10);
*/

}


the gotos and the breaker: parts were for trouble shooting.

i'm having trouble figuring out what could be wrong. It's still not seeing the character that i want.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group