![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
mle
Joined: 12 Sep 2003 Posts: 10
|
Modem reponse |
Posted: Tue Mar 09, 2004 11:07 am |
|
|
Hello,
I'm working with a PIC18F6520 and a TDK single chip modem (73M2901C). I am getting a strange reponse from the modem. If I send it any command at all it returns an "AT" and that's it. It still does this even if I turn off the "echo" command.
This is the test program I'm using, Can anyone help?
#include <18F6520.h>
#use delay(clock = 40000000)
#fuses HS,NOWDT,PUT,NOBROWNOUT,NOLVP
/****************PIC18F6520 Processor Register Definitions*************/
#BYTE PORTA = 0XF80 //PORTA - PIC18F6520
#BYTE PORTB = 0xF81 //PORTB - PIC18F6520
#BYTE PORTC = 0xF82 //PORTC - PIC18F6520
#BYTE PORTD = 0xF83 //PORTD - PIC18F6520
#BYTE PORTE = 0xF84 //PORTE - PIC18F6520
#BYTE PORTF = 0xF85 //PORTF - PIC18F6520
#BYTE PORTG = 0xF86 //PORTG - PIC18F6520
#BYTE TRISA = 0XF92 //TRISA - PIC18F6520
#BYTE TRISB = 0xF93 //TRISB - PIC18F6520
#BYTE TRISC = 0xF94 //TRISC - PIC18F6520
#BYTE TRISD = 0xF95 //TRISD - PIC18F6520
#BYTE TRISE = 0xF96 //TRISE - PIC18F6520
#BYTE TRISF = 0xF97 //TRISF - PIC18F6520
#BYTE TRISG = 0xF98 //TRISG - PIC18F6520
#define USART2 rs232(baud=9600, xmit=PIN_G1, rcv=PIN_G2) //SERIAL PORT
#define USART1 rs232(baud=2400, xmit=PIN_C6, rcv=PIN_C7) //TDK MODEM
#include <string.h>
void main(){
char c1,c2,c3,c4,c5;
#use USART2
delay_us(500);
printf("Modem Test\r\n"); // copy string
delay_ms(1000);
printf("Dialing 8583022 ...\r\n"); // copy string
while(!bit_test(TXSTA1,1)); //WAIT until TSR is empty
/***********Hold Modem in Reset**********/
bit_clear(TRISA,5);
bit_set(PORTA,5);
bit_set(TRISB,3); //Modem RI bit
bit_clear(TRISB,4); //Modem DTR bit
bit_clear(PORTB,4); //MODEM DTR
bit_set(TRISC,5); //MODEM DCD
bit_set(TRISC,2); //MODEM DSR
bit_set(TRISC,1); //MODEM CTS
bit_clear(TRISC,0); //MODEM RTS
bit_clear(PORTC,0); //MODEM RTS
delay_ms(500);
bit_clear(PORTA,5); //bring modem out of reset
delay_ms(500);
#use USART1 //use the modem usart port
delay_ms(500);
printf("ATE0%c%c",10,13);
delay_ms(500);
c1=getc(); //get message from modem
#use USART2 //switch back to serial port
putc(c1);
#use USART1 //use the modem usart port
c2=getc();
#use USART2 //switch back to serial port
putc(c2); /*******************PROGRAM STOPS HERE************/
#use USART1 //use the modem usart port
c3=getc();
#use USART2 //switch back to serial port
putc(c3);
#use USART1 //use the modem usart port
c4=getc();
#use USART2 //switch back to serial port
putc(c4);
printf("Done\r\n");
}//main
Thanks,
mle |
|
![](templates/subSilver/images/spacer.gif) |
Neutone
Joined: 08 Sep 2003 Posts: 839 Location: Houston
|
|
Posted: Tue Mar 09, 2004 11:14 am |
|
|
Use stream identifiers for the serial ports.
#define USART2 rs232(baud=9600, xmit=PIN_G1, rcv=PIN_G2) //SERIAL PORT
would be
#use rs232(baud=9600, xmit=PIN_G1, rcv=PIN_G2,stream=USART2) //SERIAL PORT
printf("Modem Test\r\n"); // copy string
would be
fprintf(USART2,"Modem Test\r\n"); // copy string |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Tue Mar 09, 2004 11:33 am |
|
|
First comment. This 'toggling' between the UARTs, looks likely to cause problems. Remember that a simple command, may well get more than a two character response, and so the UART connected to the modem, will allmost certainly overflow. Consider using the 'streams' ability, handling the receive events hardware UART in an interrupt handler, with a serial buffer.
I'd suspect the modem is not entering the 'command' state. Resetting the modem, may not ensure it is in the command state. Some modems wake up 'ready to receive', not in command, and it takes a software instruction to switch to the command state. More likely though, the AT command, must be the first character on the line, and if the RS232 signal was in an indeterminate state at this point, the modem would then go to the normal 'run' state, and echo back your sent data via the line. The chip would overflow after two characters, and since 'ERRORS' is not specified, will not be reset. and will hang at this point. Hence you will receive just the two characters in the hardware buffer, and then the system will hang.
Hence I'd use the 'soft' command to switch to the required state. This is normally a 1 second pause, followed by '+++', then another one second pause. Combined with switching to using a soft buffer on both TX/RX for both UARTs, this should get things working.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
mle
Joined: 12 Sep 2003 Posts: 10
|
|
Posted: Tue Mar 09, 2004 12:18 pm |
|
|
Thanks for the help.
I'm new to the streaming concept. If i use fprintf to transmit, what do I use to receive? I tried fscanf, but this wasn't recognized by ccs. This is how I changed the code. Is this what you meant?
#use rs232(baud=9600, xmit=PIN_G1, rcv=PIN_G2,stream = USART2) //SERIAL PORT
#use rs232(baud=2400, xmit=PIN_C6, rcv=PIN_C7,stream = USART1) //TDK MODEM
void main(){
char line1[500]; //string to receive messages from modem
delay_us(500);
fprintf(USART2,"Modem Test\r\n"); // copy string
delay_ms(1000);
while(!bit_test(TXSTA1,1)); //WAIT until TSR is empty
/***********Hold Modem in Reset**********/
bit_clear(TRISA,5);
bit_set(PORTA,5);
bit_set(TRISB,3); //Modem RI bit
bit_clear(TRISB,4); //Modem DTR bit
bit_clear(PORTB,4); //MODEM DTR
bit_set(TRISC,5); //MODEM DCD
bit_set(TRISC,2); //MODEM DSR
bit_set(TRISC,1); //MODEM CTS
bit_clear(TRISC,0); //MODEM RTS
bit_clear(PORTC,0); //MODEM RTS
delay_ms(500); //play around with this timing
bit_clear(PORTA,5); //bring modem out of reset
delay_ms(500);
//#use USART1 //use the modem usart port
delay_ms(1000);
fprintf(USART1,"+++%c%c",10,13);
delay_ms(1000);
fprintf(USART1,"ATE0%c%c",10,13);
fscanf(USART1, "%s",line1);
fprintf(USART2, "modem: %s \r\n",line1);
fprintf(USART2,"Done\r\n");
} |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Tue Mar 09, 2004 3:30 pm |
|
|
mle wrote: | Thanks for the help.
I'm new to the streaming concept. If i use fprintf to transmit, what do I use to receive? I tried fscanf, but this wasn't recognized by ccs. This is how I changed the code. Is this what you meant?
#use rs232(baud=9600, xmit=PIN_G1, rcv=PIN_G2,stream = USART2) //SERIAL PORT
#use rs232(baud=2400, xmit=PIN_C6, rcv=PIN_C7,stream = USART1) //TDK MODEM
void main(){
char line1[500]; //string to receive messages from modem
delay_us(500);
fprintf(USART2,"Modem Test\r\n"); // copy string
delay_ms(1000);
while(!bit_test(TXSTA1,1)); //WAIT until TSR is empty
/***********Hold Modem in Reset**********/
bit_clear(TRISA,5);
bit_set(PORTA,5);
bit_set(TRISB,3); //Modem RI bit
bit_clear(TRISB,4); //Modem DTR bit
bit_clear(PORTB,4); //MODEM DTR
bit_set(TRISC,5); //MODEM DCD
bit_set(TRISC,2); //MODEM DSR
bit_set(TRISC,1); //MODEM CTS
bit_clear(TRISC,0); //MODEM RTS
bit_clear(PORTC,0); //MODEM RTS
delay_ms(500); //play around with this timing
bit_clear(PORTA,5); //bring modem out of reset
delay_ms(500);
//#use USART1 //use the modem usart port
delay_ms(1000);
fprintf(USART1,"+++%c%c",10,13);
delay_ms(1000);
fprintf(USART1,"ATE0%c%c",10,13);
fscanf(USART1, "%s",line1);
fprintf(USART2, "modem: %s \r\n",line1);
fprintf(USART2,"Done\r\n");
} |
Look at the two example files, EX_STISR, and EX_SISR. These show how to implement serial transmit buffering, and receive buffering. In place of the getc, and putc functions in these, use fgetc, and fputc to talk to the respective streams. You probably only 'need' receive buffering (the need for transmit buffering will depend on what else the chip has to do at the same time).
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
mle
Joined: 12 Sep 2003 Posts: 10
|
|
Posted: Thu Mar 11, 2004 12:25 pm |
|
|
Hello,
I have changed my program to use streams and using a buffer for receiving info from the modem. I looked at the suggested example files for buffering and I implemented my receive buffer accordingly. Regardless of these modification, I am still getting the same result! The modem only returns 2 characters and they are always the first two characters that I send to it.
Please help!!
mle
Here's the most recent program:
#use rs232(baud=9600, xmit=PIN_G1, rcv=PIN_G2,stream = USART2) //SERIAL PORT
#use rs232(baud=2400, xmit=PIN_C6, rcv=PIN_C7,stream = USART1) //TDK MODEM
#include <string.h>
#define BUFFER_SIZE 50
BYTE buffer[BUFFER_SIZE];
BYTE next_in=0;
BYTE next_out=0;
#define NOT_FULL (next_in!=next_out)
#INT_RDA
void RDA_int(){
int t;
buffer[next_in]=fgetc(USART1);
t=next_in;
next_in=(next_in+1)%BUFFER_SIZE;
if(next_in==next_out)
next_in=t; //buffer is full
}
BYTE buff_getc(){
BYTE c;
while (!NOT_FULL);
c=buffer[next_out];
next_out=(next_out+1)%BUFFER_SIZE;
return (c);
}
void main(){
delay_us(500);
while(!TRMT2);
fprintf(USART2,"Modem Test\r\n"); // copy string
delay_ms(1000);
while(!bit_test(TXSTA1,1)); //WAIT until TSR is empty
/***********Hold Modem in Reset**********/
bit_clear(TRISA,5);
bit_set(PORTA,5);
bit_set(TRISB,3); //Modem RI bit
bit_clear(TRISB,4); //Modem DTR bit
bit_clear(PORTB,4); //MODEM DTR
bit_set(TRISC,5); //MODEM DCD
bit_set(TRISC,2); //MODEM DSR
bit_set(TRISC,1); //MODEM CTS
bit_clear(TRISC,0); //MODEM RTS
bit_clear(PORTC,0); //MODEM RTS
delay_ms(500); //play around with this timing
bit_clear(PORTA,5); //bring modem out of reset
delay_ms(500);
delay_ms(1000);
while(!TRMT1);
fprintf(USART1,"+++%c%c",10,13);
delay_ms(1000);
while(!TRMT1);
fprintf(USART1,"ATE0%c%c",10,13);
enable_interrupts(GLOBAL);
enable_interrupts(INT_RDA);
WHILE(1){
while(!TRMT2);
fprintf(USART2, "%c",buff_getc());
}
} |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|