Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

who is my modem communicating with ?

Status
Not open for further replies.

puneetnepsam

Junior Member level 3
Joined
Apr 27, 2009
Messages
26
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,478
who is my modem communicating with

--------------------------------------------------------------------------------

hi all,

i want to test whether my modem is responding to the AT commands or not?

suppose if i send the command "at+crsm=?"
it will send me the response "OK"

my modem is connected to the PIC24F through UART interface..

can anyone tell me how to proceed further...

should i have to send AT command from the code

if i write
buf[] = " at + cmgs=?"

and send it
sendUART(buf);

and if i do
buf1[] = receiveUART();

will i get the response in buf1[] buffer

Thanks
Puneet
 

avoid cr to lf in modem communication

Hai puneetnepsam
Please do avoid multiple postings of the same topic under diffrent sections. Good luck
 

how to get server to answer modem communication

pranam,,,

actually this topic belongs to both the communities...dat's y posted in both...
 

at+csim command format

puneetnepsam
If you get answers, you'll get it anywhere. Good luck
 

receive string buffer

puneetnepsam said:
--------------------------------------------------------------------------------
[...]
and if i do
buf1[] = receiveUART();

will i get the response in buf1[] buffer
[...]
Puneet
...not really, no.

You don’t really know when the data hits you so you can’t just decide: ”now I will receive data form UART”.
You’ll have to listen to it all the time (using interrupts), or at least most of the time (by polling).
Furthermore, this type of communication has hard- (as opposed to soft-) realtime requirements, meaning you’ll have to be there when the data (a character) comes, or you’ll just miss it and that will spoil all the fun.

I suggest implementing a double-port circular buffer for storing received bytes in the RX ISR (server-side), while consuming the data in the main loop of your program (client-side).
If you do it right, this method is guaranteed to deliver all the data you’ll ever need :p

Arthur
 
pic24f uart flush buffer

hi Arthur

i am devoloped this code......please spare some time and go through it........


#include "p24fj256gb110.h"
#include "serial.h"

int main()
{
unsigned char uIdx = 0;
const unsigned char send_AT_Cmd[]="AT+CSIM=?";
unsigned char rec_cmd[20];

init_uart();

for(uIdx = 0; send_AT_Cmd[uIdx] !='\0'; uIdx++ ) //send AT commands
{
SendUSART(send_AT_Cmd[uIdx]);
}

uIdx = 0;
for(uIdx = 0 ; uIdx < 20 ; uIdx++)
while(1)
{
rec_cmd[uIdx] = RecUSART();
if(!rec_cmd[uIdx])
break;
uIdx ++;
}
//send AT command
return 0;
}

am i will be able to receive the AT response from the modem in the rec_cmd register.......

circular port buffer means??
what changes i have to do
 

Re: modem communication

First of all, a circular buffer is e very nice construct that implements a buffer without an end. It’s ideal for situations like yours, when you want to temporary store messages of unknown, arbitrary size.
By double-port, I meant a buffer that you can independently access from two different sides (i.e. you have a “read” pointer on the client-side, and a separate “write” pointer on the server-side).
Read more here:

https://en.wikipedia.org/wiki/Circular_buffer

I don’t think your code will work.
At the transmitter side, I think you need a carriage-return (CR+LF) at the end of the AT string. If that’s the case, add “\r\n” at the end of your const AT string.
At the receiver side, regardless of how you implemented “RecUSART()”, it seems like you will either overwrite the answer, or overflow the buffer rather quickly. (Another unrelated observation is that, in embedded systems, the main loop should never end!)
Why don’t you just do something like this:
Code:
[...]

	init_uart();
	
	while(1)
	{// main loop should never be allowed to end!

	/* TODO: dummy read the RECV register to flush any previos chars, such as
	unsigned char dummy = SBUF;
	*/
	
	for(uIdx = 0; send_AT_Cmd[uIdx] !='\0'; uIdx++ ) //send AT commands 
	{ 
		SendUSART(send_AT_Cmd[uIdx]); 
	} 
	
	uIdx = 0;
	do
	{
		unsigned char ch = RecUSART();

		if(ch != '\r')
			rec_cmd[uIdx] = ch;
		else
			rec_cmd[uIdx] = '\0';	// put a string terminator NULL
		
		uIdx++;

	}while(ch != '\r' && uIdx < 20)
	
	/* TODO: here you should have a complete answer, minus the CRLF, or the
	buffer is full. Do whatever necessary with it before sending/reading some
	more */
	}

[...]
For this to work, your "RecUSART()" must not return until it gets a char in the UART's RECV register (whatever that is, i'm not familiar with PIC).

I must warn you that this is not good coding and it's purely for learning purposes!
This assumes that your code runs fast enough between your sending and until you are ready to store the received chars in the buffer (which is most likely true, but good coding should not need to assume that).
As soon as you add more things to do, this assumption si going to create problems.

I mention before that sending/receving should best be implemented with interrupts. Read some more on that because it's worth the effort.
I hope this helps.

Arthur
 

Re: modem communication

buddy, thanks for a very good reply

But the response of the modem contains...'OK'...and nothing else if i send the following AT command
"AT + CSIM"

then y i need to check for '\r'....i coouldnt get this thing...

can u please explain me in detail.....
i should include this thing in the sending string also?

Added after 14 minutes:

ok...are you saying like this:

int main()
{
unsigned char uIdx = 0;
const unsigned char send_AT_Cmd[]="AT+CSIM=?\r\n";
unsigned char rec_cmd[20];

init_uart();
while(1)
{// main loop should never be allowed to end!

/* TODO: dummy read the RECV register to flush any previos chars, such as
unsigned char dummy = SBUF;
*/

for(uIdx = 0; send_AT_Cmd[uIdx] !='\0'; uIdx++ ) //send AT commands
{
SendUSART(send_AT_Cmd[uIdx]);
}

uIdx = 0;
do
{
unsigned char ch = RecUSART();

if(ch != '\r')
rec_cmd[uIdx] = ch;
else
rec_cmd[uIdx] = '\0'; // put a string terminator NULL

uIdx++;

}while(ch != '\r' && uIdx < 20)

/* TODO: here you should have a complete answer, minus the CRLF, or the
buffer is full. Do whatever necessary with it before sending/reading some
more */
}
return 0;
}

BUT are you sure that in the response also caarriage return would be there?
 

Re: modem communication

No, I’m not sure you will get a carriage in return. I just assume you do to make this example work.

If you don’t get one, you will need some other method to figure out when the answer is completely received (such as when you see the RX-line idle for more than 2 characters, or something)., or just interpret the characters as they come, until they make sense...

Alternatively, you could command your device to give numeric answers (as opposed to text), which would be much easier to parse and interpret (you would then get "0" instead of "OK" and so on). Check your device’s spec. on how to do that.

At the transmit side however, you would need a string termination character (configurable on some devices, so check with the spec.) that is usually carriage return (and not with line feed as I previously thought). So just ‘\r’ (CR), and not ‘\n’ (LF) at the end of you AT commands.

Debug a little and try to adapt to the new problems; do some searches and use your brain more...
Good luck!

Arthur
 

Re: modem communication

thanks a lot buddy....ill try this method on my hardware....

thanks for the help
 

Re: modem communication

thanks arthur...

this method working...and i am also getting the carriage return in response...

:D
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top