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

AT Command Response Help
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
scaven92



Joined: 06 Oct 2006
Posts: 44

View user's profile Send private message

PostPosted: Wed Sep 10, 2008 3:52 pm     Reply with quote

That's it! I got my OK response! Thanks everyone for their help, I guess I need to read the supplied docs with a better trained eye from now on.

I can finally move on to a second command...
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Sep 10, 2008 4:01 pm     Reply with quote

I assume you read this doc which says you must send three "caret"
characters to put the device into command mode (on page 6):
http://www.ezurio.com/files/00222.pdf
scaven92



Joined: 06 Oct 2006
Posts: 44

View user's profile Send private message

PostPosted: Wed Sep 10, 2008 5:11 pm     Reply with quote

Yes I have, I am actually going to set ATS536=1, so that I can enter remote command mode by entering '!!!'.
scaven92



Joined: 06 Oct 2006
Posts: 44

View user's profile Send private message

PostPosted: Thu Sep 11, 2008 1:10 pm     Reply with quote

I have another question for you. When I am requesting a register value, my code gets hung with either getc or gets.

For example, using the code below, everything works fine until I come down to:

Code:
fprintf(blue,"ATS536?\r");


After this statement I use fgetc() to request the response, which should be a number, then an 'OK'. I am receiving the number fine, but when I issue a command after this it hangs on the next fgets() command. As if there are still values the bluetooth module needs to send. There is, but I am not receiving them.

The response from the bluetooth module shown in Siow.exe is this...
Code:

\0A                                                                                 
\0A1\0D                                                                             
\0AOK\0D


The bluetooth manual says the command I am issuing has a response of the form <cr,lf>As Appropriate<cr,lf>OK<cr,lf> .

"All responses from the blu2i device will have carriage return and linefeed
characters preceding and appending the response. These dual character
sequences have the values 0x0D and 0x0A respectively and shall be
represented by the string <cr,lf> and cannot be changed."

It hangs after the while( kbhit() ) loop when I try and call fgetc. If I omit that part and go straight into the next instruction it also just hangs at the next fgets().

Here is my main code (Iam using the same stuff from before minus these changes.
Code:

void display_rxblue()
{
   fgets(rx_blue,blue);
   lcd_gotoxy(1,2);
   lcd_putc("                ");
   lcd_gotoxy(1,2);
   printf(lcd_putc,"%s          ",rx_blue);
   delay_ms(1000);
}

void main()
{
   char temp;
   int i =1;

   setup();

   lcd_putc("\fATS536=1        "); //Set Remote Command Mode On
   fprintf(blue,"ATS536=1\r");
   fgets(rx_blue,blue);
   display_rxblue();               //Received OK!!
   delay_ms(1000);

   lcd_putc("\fATS536=1        "); //Set Remote Command Mode On
   fprintf(blue,"ATS536=1\r");
   fgets(rx_blue,blue);
   display_rxblue();               //Received OK!!
   delay_ms(1000);

   lcd_putc("\fATS536?        "); //Set Remote Command Mode On
   fprintf(blue,"ATS536?\r");
   fgets(rx_blue,blue);       //Gets rid of first x0D
   display_rxblue();           //Gets my Number (WORKS)

   while( kbhit() )
   {
      lcd_gotoxy(10,1);
      temp = fgetc(blue);    //I receive x0A and x4F and thats it
      printf(lcd_putc,"%x",temp);
      delay_ms(1000);
   }
   temp = fgetc(blue);      //HANGS HERE, should be x4B!!!!
   lcd_gotoxy(10,1);
   printf(lcd_putc,"%x",temp);
   delay_ms(1000);

   temp = fgetc(blue);       //Should be x0D for completion of 'OK'
   lcd_gotoxy(10,1);
   printf(lcd_putc,"%x",temp);
   delay_ms(1000);

   lcd_putc("\fAT              "); //Set Remote Command Mode On
   fprintf(blue,"AT\r");
   display_rxblue();
   display_rxblue();
   delay_ms(1000);
   while(1);
}   


What am I overlooking? Sorry if the above is confusing.
ckielstra



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

View user's profile Send private message

PostPosted: Thu Sep 11, 2008 2:35 pm     Reply with quote

Quote:
I receive x0A and x4F and thats it
Sounds like the famous UART's receive buffer overflow.

In your while( kbhit )-loop you have a delay_ms(1000), in computer timing this is almost eternity. While delaying more characters will be received and the UART's receive buffer overflows. A nasty feature of the UART is that it stops receiving at a buffer overflow, you have to reset the error to make it receiving again. The UART receive buffer has a size of two characters and one byte currently being received.

The solution is two-fold:
1) Remove the delays so no received characters will be lost.
2) Add the 'ERRORS' keyword to your #use rs232 line. This will clear the receive buffer error flags on every call to getc.
scaven92



Joined: 06 Oct 2006
Posts: 44

View user's profile Send private message

PostPosted: Thu Sep 11, 2008 2:45 pm     Reply with quote

That makes alot of sense. I will give that a shot. I was using the delays for debugging purposes so that I can see whats going on through the LCD, but probably was the cause of my headache. I really need to invest in an ICD2 debugger.

It worked. I added the errors command and the removal of delays.

Another questtion, when I tried called fgets() in the while( kbhit() ), why did it still hang? It doesn't on the getc() call. Does gets() not clear the buffer error flag?
ckielstra



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

View user's profile Send private message

PostPosted: Thu Sep 11, 2008 3:49 pm     Reply with quote

scaven92 wrote:
Another questtion, when I tried called fgets() in the while( kbhit() ), why did it still hang? It doesn't on the getc() call. Does gets() not clear the buffer error flag?
If you look at the code generated for fgets, then you will see internally it calls getc() in a loop until 0x0D is received.

Without example code I can't tell why your fgets() failed. Did you specify the correct stream to read from?
scaven92



Joined: 06 Oct 2006
Posts: 44

View user's profile Send private message

PostPosted: Thu Sep 11, 2008 4:39 pm     Reply with quote

One last question, I am trying to go from Data mode (where data flows freely from point to point on Bluetooth) to local command mode. You have to enable it by typing '^^^'. When I do this with fprintf(blue,"^^^"); it does not work.I have tried fprintf(blue,"^^^\r") and get the same issue.

When I do it through the console I just enter ^^^ and dont have to hit enter or anything. Any ideas?

I'll take a look at my fgets routine and see why its not doing it correctly. In the mean time I have used fgetc.
ckielstra



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

View user's profile Send private message

PostPosted: Thu Sep 11, 2008 4:44 pm     Reply with quote

I don't know about the '^^^' sequence, check the manual.
If it is similar to the '+++' sequence in AT-modems than you have to have a 1 second of no data transmitted before and after the sequence:
- pause 1 second
- send '^^^'
- pause 1 second
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Sep 11, 2008 4:46 pm     Reply with quote

It's in this document (page 6):
http://www.ezurio.com/files/00222.pdf
scaven92



Joined: 06 Oct 2006
Posts: 44

View user's profile Send private message

PostPosted: Thu Sep 11, 2008 5:01 pm     Reply with quote

<Guard time><Esc Chr><Guard time><Esc Chr><Guard time><Esc Chr><Guard
time>

I need a delay between character sends.

The device is 100ms by default, does it hurt if the guard time is longer?
ckielstra



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

View user's profile Send private message

PostPosted: Thu Sep 11, 2008 5:40 pm     Reply with quote

scaven92 wrote:
The device is 100ms by default, does it hurt if the guard time is longer?
What do you think yourself?

Two hints:
1) The delay is there to distinguish from a normal data streams (no pause or a very short pause between characters).
2) How quick can you manually type the sequence?
justrain



Joined: 12 Nov 2008
Posts: 3

View user's profile Send private message

PostPosted: Wed Nov 12, 2008 3:33 pm     Reply with quote

Hey I'm doing a similar code for PIC18F4680 and have similar problems as you used to have about the Ezurio BT module not responding anything the PIC sends, so, as you have figured that problem out... could you tell me what was the problem? Just adding the ATE0 command was the solution?

thanks
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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