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 support@ccsinfo.com

Error Read SMS or String from Uart

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



Joined: 24 Mar 2004
Posts: 53
Location: Portugal

View user's profile Send private message Send e-mail MSN Messenger

Error Read SMS or String from Uart
PostPosted: Fri Jul 09, 2004 6:00 pm     Reply with quote

Hello
my program read a String from Uart (hardware port), with Interrupt Int_rda, and #int_ext for PC programing.
I can't read the data incoming by Modem GSM on #int_rda.
When I test with hyperterminal all the system work fine but not with modem.
Only wanted to read the "RING" or "OK" from Modem and compare with existing String.
Thank You



some code:




Code:


#use delay(clock=16000000)
#use rs232(baud=1200, xmit=PIN_C6, rcv=PIN_C7, STREAM=COM_B)  //hardware
#USE RS232(BAUD=9600, XMIT=PIN_B1, RCV=PIN_B0, STREAM=COM_A)

//...

#int_rda              //read from COM_B
void vira()   

{
char c;

        c=fgetc(COM_B);

        if ((c>=' ')&&(c<='~'))
          { 
           buffer1[len] = c;
           len++;
          }
 
       if(c==0x0A ||c==0x0D) // I gues End Of String
        {
          bit_com_b=1;  // All OK
        }
      if(len >=  BUFFER_SIZE)
        {
          //bit_set(ModemFlag,RecErr);  // Something wrong !!
          disable_interrupts(INT_RDA); // Get out & ovoid reentrance
          len=0;
        }
        fputc(c, COM_A);//just for test arrive char
}


#int_ext
void seirala_isr()
{
       
        cmd=fgetc(COM_A);
        cmd=toupper(cmd);
        fputc(cmd, COM_A);
 }


//..
// now, read and compare with String "RING" or "OK"

read_eeprom_string(s, ROM_ackmodem, ROM_askmodem_SIZE);
           
      if (strncmp (buffer1, s, 5)==0)
            {
            fprintf(COM_A,"\r\nComutado\r\n");
            disable_interrupts(INT_RDA);//disable interrupt port b
            fprintf(COM_B,"AT+CMGR=1\n");
            delay_us( 1000 );
            enable_interrupts(INT_RDA);
            len=0;
            bit_com_b=0;
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jul 09, 2004 8:37 pm     Reply with quote

You didn't show your setup code for the soft USART.

Since you're using Pin B0 with INT_EXT, you need
to set the edge of the waveform which will cause the
interrupt. Since a start bit at the PIC is a logic Low Level,
you need to interrupt on the falling edge. The PIC defaults
to using the rising edge. That might explain why it doesn't
work. You need to put these lines near the start of main(),
as shown below.
Code:

#bit INTF_BIT = 0x0B.1  // This address is for the 16F877

void main()
{
output_float(PIN_B0);   // Set pin B0 as an input
output_high(PIN_B1);    // set pin B1 as an output
ext_int_edge(H_TO_L);  // Interrupt at beginning of Start bit

INTF_BIT = 0;    // Clear ext. int. flag before enabling interrupts

enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);


// Put other code here.


while(1);  // Prevent PIC from going to sleep
}
carlosma



Joined: 24 Mar 2004
Posts: 53
Location: Portugal

View user's profile Send private message Send e-mail MSN Messenger

PostPosted: Sat Jul 10, 2004 5:39 am     Reply with quote

Thank you

I think that my problem is not in Software Port, because this port just used for read char incoming PC. It works fine when test.
From hardware Port (C6, C7, use "int_rda") Only wanted to read the "RING" or "OK" from Modem and compare with existing String, but never read any char or string.

The program:

Code:

#include <16F876.h>
#fuses HS,NOPROTECT,NOWDT,NOLVP,PUT,NOBROWNOUT
#use delay(clock=16000000)
#use rs232(baud=1200, xmit=PIN_C6, rcv=PIN_C7, STREAM=COM_B)  //hardware
#USE RS232(BAUD=9600, XMIT=PIN_B1, RCV=PIN_B0, STREAM=COM_A)

//...

#int_rda              //read from COM_B modem GSM
void rda_isr()   

{
char c;

        c=fgetc(COM_B);

        if ((c>=' ')&&(c<='~'))
          { 
           buffer1[len] = c;
           len++;
          }
 
       if(c==0x0A ||c==0x0D) // I gues End Of String
        {
          bit_com_b=1;  // All OK
        }
      if(len >=  BUFFER_SIZE)
        {
          //bit_set(ModemFlag,RecErr);  // Something wrong !!
          disable_interrupts(INT_RDA); // Get out & ovoid reentrance
          len=0;
        }
        fputc(c, COM_A);//just for test arrive char
}


#int_ext                  //from com_A PC
void ext_isr()
{
       
        cmd=fgetc(COM_A);
        cmd=toupper(cmd);
        fputc(cmd, COM_A);
 }

void init_chip()
{
   delay_ms(500);
   //fprintf(COM_B, "AT+CSCA?\n");
   delay_ms(1500);
   fprintf(COM_B, "AT+CMGF=1\n");
   muda_linha();
   delay_ms(500);
   fprintf(COM_B, "AT+CMGD=0,1\n");
   muda_linha();
   delay_ms(2000);
   fprintf(COM_B, "AT+CNMI=1,1\n");
   muda_linha();
   delay_ms(500);
   
   output_float(PIN_B0);   // Set pin B0 as an input NEW
   output_high(PIN_B1);//NEW
   ext_int_edge( H_TO_L );   // Sets up EXT   
   
   setup_adc_ports(No_Analogs);
   setup_timer_0(RTCC_INTERNAL | RTCC_DIV_32);
   enable_interrupts(int_timer0); // Enable timer0 interrupt
   
   enable_interrupts(int_timer1);
   setup_timer_1 (T1_INTERNAL);
     set_timer1(65200);
   enable_interrupts(int_ext);
   enable_interrupts(INT_RDA);
   enable_interrupts(GLOBAL);
}

void main()
{
static boolean led2, led;
      init_ext_eeprom();

    init_chip();

 while(1)
   {

     //..
     // now, read and compare with String "RING" or "OK"

      read_eeprom_string(s, ROM_ackmodem, ROM_askmodem_SIZE);
           
      if (strncmp (buffer1, s, 5)==0)
            {
            fprintf(COM_A,"\r\nComutado\r\n");
            disable_interrupts(INT_RDA);//disable interrupt port b
            fprintf(COM_B,"AT+CMGR=1\n");
            delay_us( 1000 );
            enable_interrupts(INT_RDA);
            len=0;
            bit_com_b=0;

    //..
     
      if(cmd=='W')
      {
         
         //char string[ROM_SMTP_SIZE];
         disable_interrupts(INT_EXT);
        fprintf(COM_A, "\r\nSMTP: ");
         get_string(string, ROM_SMTP_SIZE);
         write_eeprom_string(string, ROM_SMTP, ROM_SMTP_SIZE);


    }
}


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