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

Modems and PIC code...

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







Modems and PIC code...
PostPosted: Thu Jun 05, 2003 2:38 pm     Reply with quote

Has anyone got any code on interfacing with a serial modem. I have tried , but the modem starts dialing and then disconnects for some reason. Something is not right with the way I handle the control lines. Any ideas?

Thanks
Kevin
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515052
Regan
Guest







Re: Modems and PIC code...
PostPosted: Thu Jun 05, 2003 6:41 pm     Reply with quote

:=Has anyone got any code on interfacing with a serial modem. I have tried , but the modem starts dialing and then disconnects for some reason. Something is not right with the way I handle the control lines. Any ideas?
:=
:=Thanks
:=Kevin

It may not be the control lines. Use the appropriate AT commands to tell the modem to ignore the control lines before dialing.

Remember, don't send any data to the modem in between sending your ATD...<CR> string and the modem completing a connection (modem will respond with a CONNECT message at this point). If you do, most modems will immediately abort the connection.

Regan.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515057
Kevin Howell
Guest







Re: Modems and PIC code...
PostPosted: Fri Jun 06, 2003 6:56 am     Reply with quote

:=:=Has anyone got any code on interfacing with a serial modem. I have tried , but the modem starts dialing and then disconnects for some reason. Something is not right with the way I handle the control lines. Any ideas?
:=:=
:=:=Thanks
:=:=Kevin
:=
:=It may not be the control lines. Use the appropriate AT commands to tell the modem to ignore the control lines before dialing.
:=
:=Remember, don't send any data to the modem in between sending your ATD...<CR> string and the modem completing a connection (modem will respond with a CONNECT message at this point). If you do, most modems will immediately abort the connection.
:=
:=Regan.

Something has to happen with RTS because if I dont toggle it before sending a command, the modem doesn't respond. Would I be able to get away with tx , rx and gnd?

Thanks
Kevin
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515064
Pete Smith
Guest







Re: Modems and PIC code...
PostPosted: Sat Jun 07, 2003 6:41 am     Reply with quote

:=:=:=Has anyone got any code on interfacing with a serial modem. I have tried , but the modem starts dialing and then disconnects for some reason. Something is not right with the way I handle the control lines. Any ideas?
:=:=:=
:=:=:=Thanks
:=:=:=Kevin
:=:=
:=:=It may not be the control lines. Use the appropriate AT commands to tell the modem to ignore the control lines before dialing.
:=:=
:=:=Remember, don't send any data to the modem in between sending your ATD...<CR> string and the modem completing a connection (modem will respond with a CONNECT message at this point). If you do, most modems will immediately abort the connection.
:=:=
:=:=Regan.
:=
:=Something has to happen with RTS because if I dont toggle it before sending a command, the modem doesn't respond. Would I be able to get away with tx , rx and gnd?

It's worked for me in the past. I did a remote video surveilance system, which used a PIC16F877, and a 56k modem, to dial in and send greyscale pictures to a central machine.

What I did, was to tie together pins 7&8 (CTS & RTC IIRC), and make sure pins 5 & 9 are connected together too (not sure why, I've just always done it!).

HTH

Pete.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515084
Gerrit
Guest







Re: Modems and PIC code...
PostPosted: Sat Jun 07, 2003 9:48 am     Reply with quote

Hello Pete,

I have had a question for a simular system.

Can you share source idee for hardware etc.

I need 1-5 frames per second and i wanrt to use a internet
connection 256 kB bandwidth.

Any help is welcome


Please e-mail me prived.

Regards,

Gerrit

:=:=:=:=Has anyone got any code on interfacing with a serial modem. I have tried , but the modem starts dialing and then disconnects for some reason. Something is not right with the way I handle the control lines. Any ideas?
:=:=:=:=
:=:=:=:=Thanks
:=:=:=:=Kevin
:=:=:=
:=:=:=It may not be the control lines. Use the appropriate AT commands to tell the modem to ignore the control lines before dialing.
:=:=:=
:=:=:=Remember, don't send any data to the modem in between sending your ATD...<CR> string and the modem completing a connection (modem will respond with a CONNECT message at this point). If you do, most modems will immediately abort the connection.
:=:=:=
:=:=:=Regan.
:=:=
:=:=Something has to happen with RTS because if I dont toggle it before sending a command, the modem doesn't respond. Would I be able to get away with tx , rx and gnd?
:=
:=It's worked for me in the past. I did a remote video surveilance system, which used a PIC16F877, and a 56k modem, to dial in and send greyscale pictures to a central machine.
:=
:=What I did, was to tie together pins 7&8 (CTS & RTC IIRC), and make sure pins 5 & 9 are connected together too (not sure why, I've just always done it!).
:=
:=HTH
:=
:=Pete.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515085
Kevin Howell
Guest







Re: Modems and PIC code...
PostPosted: Sun Jun 08, 2003 2:14 am     Reply with quote

:=:=:=:=Has anyone got any code on interfacing with a serial modem. I have tried , but the modem starts dialing and then disconnects for some reason. Something is not right with the way I handle the control lines. Any ideas?
:=:=:=:=
:=:=:=:=Thanks
:=:=:=:=Kevin
:=:=:=
:=:=:=It may not be the control lines. Use the appropriate AT commands to tell the modem to ignore the control lines before dialing.
:=:=:=
:=:=:=Remember, don't send any data to the modem in between sending your ATD...<CR> string and the modem completing a connection (modem will respond with a CONNECT message at this point). If you do, most modems will immediately abort the connection.
:=:=:=
:=:=:=Regan.
:=:=
:=:=Something has to happen with RTS because if I dont toggle it before sending a command, the modem doesn't respond. Would I be able to get away with tx , rx and gnd?
:=
:=It's worked for me in the past. I did a remote video surveilance system, which used a PIC16F877, and a 56k modem, to dial in and send greyscale pictures to a central machine.
:=
:=What I did, was to tie together pins 7&8 (CTS & RTC IIRC), and make sure pins 5 & 9 are connected together too (not sure why, I've just always done it!).
:=
:=HTH
:=
:=Pete.

Hi Pete,

Thanks for the info, but I need some more clarity on the connection to the modem from the PIC. Do I connect only Tx and Rx and GND between the two devices and then just tie CTS & RTC together at the plug of modem or does the CTS of the modem have to be connected to the RTC of the PIC? I simple wiring diagram would help a lot. Was the code for your project in CCS and if so would it be possible to have some of the code?

Thanks
Kevin
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515090
Pete Smith
Guest







Re: Modems and PIC code...
PostPosted: Tue Jun 10, 2003 4:20 am     Reply with quote

:=:=:=Something has to happen with RTS because if I dont toggle it before sending a command, the modem doesn't respond. Would I be able to get away with tx , rx and gnd?
:=:=
:=:=It's worked for me in the past. I did a remote video surveilance system, which used a PIC16F877, and a 56k modem, to dial in and send greyscale pictures to a central machine.
:=:=
:=:=What I did, was to tie together pins 7&8 (CTS & RTC IIRC), and make sure pins 5 & 9 are connected together too (not sure why, I've just always done it!).
:=
:=Thanks for the info, but I need some more clarity on the connection to the modem from the PIC. Do I connect only Tx and Rx and GND between the two devices and then just tie CTS & RTC together at the plug of modem

Yes.

:= or does the CTS of the modem have to be connected to the RTC of the PIC?

No.

:= I simple wiring diagram would help a lot. Was the code for your project in CCS and if so would it be possible to have some of the code?

The code was written for CCS C. It's so simple, it's almost not worth posting, but here you go anyway!

This is interesting. According to my code, I was actually using the DTR line on the modem, to tell it that I (the data terminal) was ready.

This code was written over 3 years ago, so I'm a bit rusty :-)

Basically, it toggles the DTR line to the modem, to "wake it up". I then send ATZ. If the modem's attached and working, it replies with "OK".

I then sent ATDT[phone number]. There will be one of 4 responses to this... BUSY, CONNECT, NO CARRIER and NO DIALTONE.
Once the PIC receives "CONN", it exits the routine, and you effectively have an ASCII serial link connected via a MODEM.

HTH

Pete.

void dial_out(void) // The modem dial routine
{
int init,dial; // temporary variable storage

output_low(DTR); // Enable the modem

dial=0; // Set dial to 0
while (dial != 2) // So long as we haven't received "CONNECT"
{
init=0; // set fail state active
output_high(DTR); // diable the modem
delay_ms(200);
output_low(DTR); // Enable the modem

while (init != 1) // So long as we haven't received "OK"
{
flush_buffer(); // clear the input buffer
delay_ms(200);
printf("ATZ\%c",13); // Initialise the modem
strcpy(check_1,"OK"); // These are the responses we expect
init=wait_for(5,2,1); // 2 characters, 5 sec wait, 1 check

delay_ms(1000); // wait one second
}

flush_buffer(); // clear the input buffer
printf("ATDT0123456789\%c",13);
strcpy(check_1,"BUSY"); // These are the responses we expect
strcpy(check_2,"CONN"); // back from the modem.
strcpy(check_3,"NO C");
strcpy(check_4,"NO D");
dial=wait_for(60,4,4); // 4 chars, 30 sec, 4 words check
}
}


int wait_for(int wait_time,int size,int no_to_check)// The "Wait For" routine
{
char temp; // Temporary storage
int result=0;
char minibuf[8];
int srchlen;
int loop;
char tempc;

expired_time=0;
wanted_timer=wait_time;
onesecondtimer=32;

setup_counters(RTCC_INTERNAL,RTCC_DIV_256); // We want RTC running at 1/256 of main clock = 7812 times/sec
enable_interrupts(RTCC_ZERO); // Interrupt on RTCC wrapping round
enable_interrupts(int_rda);
enable_interrupts(GLOBAL); // and turn on all interrupts.

srchlen=size; // Define the search string length

*(minibuf+size)=0; // Put a terminator at end of search

while ((result==0) && (!expired_time)) // While we don't have a result, or timer hasn't expired
{
temp=bgetc(); // grab more data from buffer

for (loop=0;loop<(srchlen-1);loop++) // Move through the search string
{
*(minibuf+loop)=*(minibuf+1+loop); // move data left
}
*(minibuf+srchlen-1)=temp; // And put the new data at the end

if (no_to_check>0) // If we're checking 1 or more
{
temp=strncmp(minibuf,check_1,3); // then compare the string with 1st input
if (temp == 0) // if it passes, then
{
result=1; // note the result
}
}

if (no_to_check>1) // If we're checking 2 or more
{
temp=strncmp(minibuf,check_2,3); // then compare the string with 2nd input
if (temp == 0)
{
result=2; // note the result
}
}

if (no_to_check>2) // If we're checking 3 or more
{
temp=strncmp(minibuf,check_3,3); // then compare the string with 3rdinput
if (temp == 0)
{
result=3; // note the result
}
}

if (no_to_check>3) // If we're checking 4 or more
{
temp=strncmp(minibuf,check_4,3); // then compare the string with 4th input
if (temp == 0)
{
result=4; // note the result
}
}
}

disable_interrupts(RTCC_ZERO); // Stop Interrupt on RTCC wrapping round
enable_interrupts(int_rda);
enable_interrupts(GLOBAL); // and turn on all interrupts.

return(result);
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515141
Kevin Howell
Guest







Re: Modems and PIC code...
PostPosted: Tue Jun 10, 2003 1:36 pm     Reply with quote

:=
:=:=:=:=Something has to happen with RTS because if I dont toggle it before sending a command, the modem doesn't respond. Would I be able to get away with tx , rx and gnd?
:=:=:=
:=:=:=It's worked for me in the past. I did a remote video surveilance system, which used a PIC16F877, and a 56k modem, to dial in and send greyscale pictures to a central machine.
:=:=:=
:=:=:=What I did, was to tie together pins 7&8 (CTS & RTC IIRC), and make sure pins 5 & 9 are connected together too (not sure why, I've just always done it!).
:=:=
:=:=Thanks for the info, but I need some more clarity on the connection to the modem from the PIC. Do I connect only Tx and Rx and GND between the two devices and then just tie CTS & RTC together at the plug of modem
:=
:=Yes.
:=
:=:= or does the CTS of the modem have to be connected to the RTC of the PIC?
:=
:=No.
:=
:=:= I simple wiring diagram would help a lot. Was the code for your project in CCS and if so would it be possible to have some of the code?
:=
:=The code was written for CCS C. It's so simple, it's almost not worth posting, but here you go anyway!
:=
:=This is interesting. According to my code, I was actually using the DTR line on the modem, to tell it that I (the data terminal) was ready.
:=
:=This code was written over 3 years ago, so I'm a bit rusty :-)
:=
:=Basically, it toggles the DTR line to the modem, to "wake it up". I then send ATZ. If the modem's attached and working, it replies with "OK".
:=
:=I then sent ATDT[phone number]. There will be one of 4 responses to this... BUSY, CONNECT, NO CARRIER and NO DIALTONE.
:=Once the PIC receives "CONN", it exits the routine, and you effectively have an ASCII serial link connected via a MODEM.
:=
:=HTH
:=
:=Pete.
:=
:=void dial_out(void) // The modem dial routine
:={
:= int init,dial; // temporary variable storage
:=
:= output_low(DTR); // Enable the modem
:=
:= dial=0; // Set dial to 0
:= while (dial != 2) // So long as we haven't received "CONNECT"
:= {
:= init=0; // set fail state active
:= output_high(DTR); // diable the modem
:= delay_ms(200);
:= output_low(DTR); // Enable the modem
:=
:= while (init != 1) // So long as we haven't received "OK"
:= {
:= flush_buffer(); // clear the input buffer
:= delay_ms(200);
:= printf("ATZ\%c",13); // Initialise the modem
:= strcpy(check_1,"OK"); // These are the responses we expect
:= init=wait_for(5,2,1); // 2 characters, 5 sec wait, 1 check
:=
:= delay_ms(1000); // wait one second
:= }
:=
:= flush_buffer(); // clear the input buffer
:= printf("ATDT0123456789\%c",13);
:= strcpy(check_1,"BUSY"); // These are the responses we expect
:= strcpy(check_2,"CONN"); // back from the modem.
:= strcpy(check_3,"NO C");
:= strcpy(check_4,"NO D");
:= dial=wait_for(60,4,4); // 4 chars, 30 sec, 4 words check
:= }
:=}
:=
:=
:=int wait_for(int wait_time,int size,int no_to_check)// The "Wait For" routine
:={
:= char temp; // Temporary storage
:= int result=0;
:= char minibuf[8];
:= int srchlen;
:= int loop;
:= char tempc;
:=
:= expired_time=0;
:= wanted_timer=wait_time;
:= onesecondtimer=32;
:=
:= setup_counters(RTCC_INTERNAL,RTCC_DIV_256); // We want RTC running at 1/256 of main clock = 7812 times/sec
:= enable_interrupts(RTCC_ZERO); // Interrupt on RTCC wrapping round
:= enable_interrupts(int_rda);
:= enable_interrupts(GLOBAL); // and turn on all interrupts.
:=
:= srchlen=size; // Define the search string length
:=
:= *(minibuf+size)=0; // Put a terminator at end of search
:=
:= while ((result==0) && (!expired_time)) // While we don't have a result, or timer hasn't expired
:= {
:= temp=bgetc(); // grab more data from buffer
:=
:= for (loop=0;loop<(srchlen-1);loop++) // Move through the search string
:= {
:= *(minibuf+loop)=*(minibuf+1+loop); // move data left
:= }
:= *(minibuf+srchlen-1)=temp; // And put the new data at the end
:=
:= if (no_to_check>0) // If we're checking 1 or more
:= {
:= temp=strncmp(minibuf,check_1,3); // then compare the string with 1st input
:= if (temp == 0) // if it passes, then
:= {
:= result=1; // note the result
:= }
:= }
:=
:= if (no_to_check>1) // If we're checking 2 or more
:= {
:= temp=strncmp(minibuf,check_2,3); // then compare the string with 2nd input
:= if (temp == 0)
:= {
:= result=2; // note the result
:= }
:= }
:=
:= if (no_to_check>2) // If we're checking 3 or more
:= {
:= temp=strncmp(minibuf,check_3,3); // then compare the string with 3rdinput
:= if (temp == 0)
:= {
:= result=3; // note the result
:= }
:= }
:=
:= if (no_to_check>3) // If we're checking 4 or more
:= {
:= temp=strncmp(minibuf,check_4,3); // then compare the string with 4th input
:= if (temp == 0)
:= {
:= result=4; // note the result
:= }
:= }
:= }
:=
:= disable_interrupts(RTCC_ZERO); // Stop Interrupt on RTCC wrapping round
:= enable_interrupts(int_rda);
:= enable_interrupts(GLOBAL); // and turn on all interrupts.
:=
:= return(result);
:=}
EXCELLENT!!! What wonders simple code can do for the uninformed! How did you figure out the DTR line wakes up the modem. This is exactly what my problem was. The modem sometimes didn't respond and this must have been the reason. Thanks a stack! I haven't tried testing my code again, but I am sure this was the problem.

Thanks a lot for your help. It really is appreciated...

Kevin
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515150
Pete Smith
Guest







Re: Modems and PIC code...
PostPosted: Wed Jun 11, 2003 9:42 am     Reply with quote


:=EXCELLENT!!! What wonders simple code can do for the uninformed! How did you figure out the DTR line wakes up the modem. This is exactly what my problem was. The modem sometimes didn't respond and this must have been the reason.

Chances are that I did the same, and couldn't get the modem to wake up (this _is_ 3 years ago now!), so I'll have had a trawl around, and found that by taking DTR low, you can re-set the modem.

Glad it was some help anyway!

Pete.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515160
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