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

Module Interface issues

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



Joined: 14 Jun 2011
Posts: 24
Location: St. Louis

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

Module Interface issues
PostPosted: Mon Jul 25, 2011 10:51 pm     Reply with quote

Hi All,
I am simply trying to communicate to a module that I send an AT command to and look for a response. The AT command is stored in EEPROM and I expect the AT command to be the reply from the module. I am comparing the AT command string and setting a result that will then turn on an LED. I have run this code with a Hyperterminal and it works fine but when I hook up to the module it does not. I put a sniffer on the comm and I see garbage go out. I believe it is how I am handling the strings - it has been 15+ years since I have done this stuff and slowly getting back into the game. I appreciate any help or advice on this.

One last question - is there a way to clear the RCV buffer upon boot up of the controller - the module sends data to say ready and I have no need for this information.

Thank you,
Jeff

Code:

#include <16F690.h>
#include <string.h>
#use delay (internal=4mhz)
#fuses INTRC_IO, NOMCLR, NOCPD
//#use rs232 (baud = 9600, xmit = PIN_C4,rcv = PIN_C5, ENABLE=PIN_C1, RETURN=PIN_C2, ERRORS, TIMEOUT=5000)
#use rs232 (baud = 9600, xmit = PIN_C4,rcv = PIN_C5, ENABLE=PIN_C1, ERRORS, TIMEOUT=5000, RESTART_WDT,DISABLE_INTS)

#rom 0x2100={78,65,77,69,32,48,48,58,48,55,58,101,48,58,100,54,58,101,48,58,52,50,13}  //Store address

// Global Variables
int8 *i, iresult = -1;
int BTPAIR_ADR[23];
int BTPAIR_MEM[23];
int BTPAIR_MI[23];
int BTPAIR_STC[10];
int BTPAIR_ST[30];

int BT_CHECK()
{
      for(i = 0; i < 22; i++)
       {
         printf("%c" read_eeprom(i));      //send AT command from EEPROM storage to module
         BTPAIR_MEM[i]= read_eeprom(i);
       }   
       *i = '\0';                //add null to end of string
     
     printf("\r");            //send carriage return to accept AT command
      strcpy (BTPAIR_MI, BTPAIR_MEM);      //copy string to string
      strncpy (BTPAIR_STC, BTPAIR_MI, 10);   //copy the first 10 characters of the string
      delay_ms(100);
      gets(BTPAIR_ST);            //get AT response from module
      BTPAIR_ST[30] = '\0';            //add null to end of string
      iresult=strncmp  (BTPAIR_STC, BTPAIR_ST, 10);   //compare the first 10 characters of the AT command sent to the return AT command
      return(iresult);
}

void main()
{
   strcpy(BTPAIR_MEM, "NAME 00:11:22:33:44:550");  //Initialize BTPAIR_MEM

      do
       {
         if ((input(PIN_A3) == 0) && iresult != 0)    //Swith intial on
         {
            BT_CHECK();                                //Check for BT In Range
            if (iresult == 0)                         //turn on LED if AT command sent is returned
               {while (input(PIN_A3) == 0)           
                  {
                   output_high(PIN_C0);   
                  }
               } 
         }
         else
         {  output_low(PIN_C0);                       //Turn OFF relay
            iresult = -1;                              //clear iresult
         }
       
    }
    while (TRUE);
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jul 25, 2011 11:07 pm     Reply with quote

Quote:
strcpy(BTPAIR_MEM, "NAME 00:11:22:33:44:550");

This string has 23 chars in it. Your arrays are only 23 chars long,
which means there is no room in the arrays for the 0x00 byte at the end.
Increase the size of your arrays by at least 1, to accomodate the null.
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