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 1, 2  Next
 
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

AT Command Response Help
PostPosted: Tue Sep 09, 2008 4:11 pm     Reply with quote

I am trying to get a response through the serial port of my PIC18F452 from a EZURiO bluetooth developement board. I am simply sending the commands below to communicate with the hardware UART.

Code:

#include <18F452.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#include <LCD.C>
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=blue)

void setup( void )
{
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   enable_interrupts(INT_RDA);
   enable_interrupts(GLOBAL);
   setup_psp(PSP_DISABLED);
   setup_spi(FALSE);
   setup_wdt(WDT_OFF);
}

void main( void )
{
   setup();
   lcd_putc("\fAT\n");

   fprintf(blue,"AT\r");
   gets(rx_blue,blue);

   delay_ms(100);
   printf(lcd_putc,"%s",rx_blue);

   while(1);
}


I should get a response of OK, but I receive no response. The program never gets passes the gets() statement. I have read the documentation and used an emulator via the terminal on a PC to test this simple thing. I am checking with a PC terminal on what the PIC is sending out and Siow.exe is showing me 'ATZ\0D'.

The AT Command Guide says that: "All commands will be terminated by the carriage return character 0x0D, which is represented by the string <cr> in descriptions below and cannot be changed."

All I am using is the Tx,Rx, and GND to communicate with the bluetooth module. Am I missing something? Here is the dev kit I am playing with: http://www.ezurio.com/products/devkit/

Also, "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."
Ex:<cr,lf>OK<cr,lf>

Thanks for the help, let me know if I can offer more information.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Sep 09, 2008 4:21 pm     Reply with quote

Your program is incomplete.
1. It uses array 'rx_blue', but it's not declared.
2. It enables INT_RDA interrupts, but there is no interrupt service routine.
scaven92



Joined: 06 Oct 2006
Posts: 44

View user's profile Send private message

PostPosted: Tue Sep 09, 2008 4:32 pm     Reply with quote

Update:

I have another PC serial connection checking the same line as the PIC's RX and TX. When I run the program I receive 'AT\0D' printed in my terminal as expected and the bluetooth module should receive this too. After I run the program and receive no response, I connect the PC serial cable to the bluetooth module (without hitting any buttons) and I receive a response as follows in siow.exe:

Code:

\0A0D                                                                               
\0AOK\0D   


It is almost like the PC terminal is giving it a signal that its okay to send, which my PIC isn't. Does this help at all? It looks like the bluetooth module is receiving the data from the looks of it. Also I am using a male to male DB9 convertor which I made and I have crossed the TX/RX line which connects the bluetooth module to my MAX233.

PCM Programmer, sorry I cut and paste from a larger code, but I am now using the one I posted. I added the interupt enable, but never used it so lets take that out.

Code:

#include <18F452.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#include <LCD.C>
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=blue)

char rx_blue[16];

void setup( void )
{
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(FALSE);
   setup_wdt(WDT_OFF);
}

void main( void )
{
   setup();
   lcd_putc("\fAT\n");

   fprintf(blue,"AT\r");
   gets(rx_blue,blue);

   delay_ms(100);
   printf(lcd_putc,"%s",rx_blue);

   while(1);
}
ckielstra



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

View user's profile Send private message

PostPosted: Tue Sep 09, 2008 4:43 pm     Reply with quote

Code:
   gets(rx_blue,blue);
The CCS compiler is sloppy here. Correct syntax is:
Code:
   fgets(rx_blue,blue);
or
   gets(rx_blue);

Quote:
All responses from the blu2i device will have carriage return and linefeed characters preceding and appending the response.
Most likely the gets() in your program reads this first CR/LF combination. The returned string is empty (by design) and that's why you don't see a response.

Try something like:
Code:
void main( void )
{
   setup();
   lcd_putc("\fAT\n");

   fprintf(blue,"AT\r");

   while ()
   {
      fgets(rx_blue, blue);
      if (strln(rx_blue) > 0)
         printf(lcd_putc,"%s",rx_blue);
   }
}
scaven92



Joined: 06 Oct 2006
Posts: 44

View user's profile Send private message

PostPosted: Tue Sep 09, 2008 5:00 pm     Reply with quote

Good catch on the gets function.

I tried your recommendations using the main program below and received the same results. It prints AT to the lcd display and to the terminal and when i connect the PC RS232 cable to the module i receive the OK response. I have also verified that the bluetooth module is running at 9600 baud rate.

Code:

void main()
{
   int i = 1;

   setup();
   lcd_putc("\fAT\n");

   fprintf(blue,"AT\r");

   while (i)
   {
      fgets(rx_blue, blue);
      if (strlen(rx_blue) > 0)
      {
         printf(lcd_putc,"%s",rx_blue);
         i = 0;
      }
   }
   while(1);   
}


Last edited by scaven92 on Tue Sep 09, 2008 5:09 pm; edited 1 time in total
ckielstra



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

View user's profile Send private message

PostPosted: Tue Sep 09, 2008 5:03 pm     Reply with quote

Code:
   int i = 0;
...
   while (i)
The while loop is never entered...
scaven92



Joined: 06 Oct 2006
Posts: 44

View user's profile Send private message

PostPosted: Tue Sep 09, 2008 5:07 pm     Reply with quote

Oh god... Its getting late... Let me fix that
scaven92



Joined: 06 Oct 2006
Posts: 44

View user's profile Send private message

PostPosted: Tue Sep 09, 2008 5:08 pm     Reply with quote

Alright fixed the error, but still getting the same result.

Also, when I am looking at the PC RS232 terminal, I see the 'At\0D' being sent on the PIC's output. Then when I connect the PC RS232 connector from the PIC line to the bluetooth module it echo's (resends) the 'AT\0D' command and thats when I get the OK response. So the command may never get to the bluetooth module, does that sound right?


Last edited by scaven92 on Tue Sep 09, 2008 5:19 pm; edited 1 time in total
ckielstra



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

View user's profile Send private message

PostPosted: Tue Sep 09, 2008 5:18 pm     Reply with quote

It could be the cable to the bluetooth module. Check if you need a straight cable or a cross cable.

Which EZURIO module are you using?

How do you have the serial line drivers connected in your setup?

It's late here too. I'm off to bed now.


Last edited by ckielstra on Tue Sep 09, 2008 5:28 pm; edited 2 times in total
scaven92



Joined: 06 Oct 2006
Posts: 44

View user's profile Send private message

PostPosted: Tue Sep 09, 2008 5:23 pm     Reply with quote

I have a MAX233 connected to the bluetooth module and a MAX233 (its a MAX232 with caps inside) for a PC RS232 connector to view the PIC-to-Bluetooth communication.

I am using a male DB9 to male DB9 cable to connect the MAX232 Board to the bluetooth module. I checked the continuity and its untwisted.

The only pins I need are Pin 5 (GND), Pin 2 (Tx), and Pin 3 (Rx) correct?

I have my PIC running at 5V, I don't power the EZURiO module through it, I use the developement boards USB cable to power it.

Thank you very much for the help this evening, hopefully I can get this figured out by tomorrow.
scaven92



Joined: 06 Oct 2006
Posts: 44

View user's profile Send private message

PostPosted: Wed Sep 10, 2008 9:42 am     Reply with quote

I re-read the User Manual for the developement kit and found this from the FAQ...

Q: The cable between my host and the blu2i module has just RX, TX and GND. I get no responses from the blu2i module.

A: Pull the CTS line of the blu2i module to the asserted state (0V).

I did this by connecting wires between the connectors using only the TX, RX, and GND and grounded CTS through my breadboard, but I am still getting the same problem.

I am getting confused...
scaven92



Joined: 06 Oct 2006
Posts: 44

View user's profile Send private message

PostPosted: Wed Sep 10, 2008 11:45 am     Reply with quote

I have been playing around with it by using on the RX, TX, GND, and CTS pins.

When I connect a PC RS232 cable to the bluetooth module via these pins only, I can only receive data when I have the CTS pin HIGH (I'm using 5V). I am looking at this through Siow.exe terminal. I am communicating great with just that.

Then I connect the bluetooth module to my PIC using the same pins, where Pin2-Tx is hooked to Pin 5 of MAX233 and Pin2-Rx is hooked to Pin 4 of MAX233 and then Pin5-GND and Pin7-CTS is connected to 5V. I receive no data.

If I connect the PC RS232 using the same pins to the MAX233 and PIC the emulation works flawless.

Please help!!!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Sep 10, 2008 12:24 pm     Reply with quote

Quote:

Then I connect the bluetooth module to my PIC using the
same pins, where Pin2-Tx is hooked to Pin 5 of MAX233
and Pin2-Rx is hooked to Pin 4 of MAX233 and then
Pin5-GND and Pin7-CTS is connected to 5V. I receive no data.


On page 5 of Ezurio appnote AN008, it says that pin 2 of the DB-9
on the Ezurio module is an output pin. It's the Tx output data pin
for the module.
http://www.ezurio.com/files/00662.pdf

But on page 21 of the Max233 data sheet, the diagram on the right side
shows that pin 5 of the Max233 is an output pin.
http://datasheets.maxim-ic.com/en/ds/MAX220-MAX249.pdf
You have two output pins driving each other. You have Tx going to Tx.
That's not correct.

In your text above, you refer to both Tx and Rx as being on "Pin2"
of the Ezurio module. In fact, Txd goes out pin 2 of the DB9 on the
module. Rxd comes in on pin 3 of the DB9.


Do you have a common ground connection between the PIC board
and the Ezurio board ? Pin 5 on the DB9 on the Ezurio board should
be connected to Ground on the PIC board.
scaven92



Joined: 06 Oct 2006
Posts: 44

View user's profile Send private message

PostPosted: Wed Sep 10, 2008 2:43 pm     Reply with quote

I appologize, I entered it wrong above. The connection is Pin3-Rx.

You are correct about the Tx to Tx connection. I will have to cross the Tx and Rx line going from the bluetooth DB9 to the MAX233.

I am connecting Pin 7 on the DB9 to +5V. From my testing with a RS232 cable connected to a PC and wires connecting the RX, TX, GND, and CTS between the bluetooth DB9 and PC DB9 I found that CTS must be high for data to be received at the PC end. If I keep it low, then the data just waits and the moment I put 5V on the line the PC terminal receives all the data. When I connect it to the PC I keep the TX and RX untwisted, when its twisted to your recommendations it doesnt work.


Below are my connections on my breadboard (CURRENTLY)...
Code:

PIC Connections:
      RC6(Tx) connected to Pin2(T1IN) of MAX233
      RC7(Rx) connected to Pin3(R1OUT) of MAX233

MAX 233 Connections:
      Pin4(R1IN) of MAX233 connected to Pin2(Tx) of Bluetooth DB9
      Pin5(T1OUT) of MAX233 connected to Pin3(Rx) of Bluetooth DB9

Bluetooth DB9 Connections:
      Pins 1,4,6,8,9 are NOT CONNECTED
      Pin 2(Tx) connected to Pin4(R1IN) of MAX233
      Pin 3(Rx) of DB9 connected to Pin5(T1OUT) of MAX233
      Pin 5(GND) of DB9 connected to breadboard ground
      Pin 7(CTS) of DB9 connected to +5V of breadboard



The above connections have the errors fixed and it how I currently have it connected.

I tested it and received the response 'AT' on my LCD display. It appears my PIC has received a response, but it seems like an echo rather then the 'OK' response I should be receiving. Below, if I have strnlen(rx_blue) >0 I get the program hanging on the fgets().

I am using the main code below:
Code:

void main()
{
   setup();
   lcd_putc("\fAT\n");

   fprintf(blue,"AT\r");

   while (1)
   {
      fgets(rx_blue, blue);
      if (strlen(rx_blue) > 1)
     {
       lcd_putc("\fFound String    ");
       lcd_gotoxy(1,2);
       printf(lcd_putc,"%s",rx_blue);
       delay_ms(500);
     }
     else lcd_putc("\fWaiting...");
   }
}


Thanks for the help, I appreciate your taking the time!
Guest








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

Echo is on by default - it's in the EZUiRO docs...

You saw echo on your terminal right? Yep - that should have been a clue...

Turn echo off by sending - "ATE0"

Actually to init my modules I reset them with ATZ, then send ATE0 and whatever else I need to do to init the module...

HTH - Steve H.
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 1, 2  Next
Page 1 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