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

Problem on receiving RS232 data using hardware USART
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
puppie7777



Joined: 09 Jun 2004
Posts: 25
Location: Monterey, CA

View user's profile Send private message

Problem on receiving RS232 data using hardware USART
PostPosted: Tue Aug 23, 2005 12:40 am     Reply with quote

Hi, there,
i got a very confusing problem. I am sure that the data reached my pic RECV pin (i use a transmitter circuit to tap out and dump to pc COM port, i can see all the data correctly), but my kbhit() and getc() wont work, it only receives some 0s data even when kbhit() returns TURE. (if i tie the Trasmit and Recv pin togther to do a loop back check, whatever i sent i can receive correctly).
My RS232 is connecting to a GSM modem(i m sure that the modem got send out "OK" and it did reach my pic recv PIN when i send "AT", but pic can not collect the data by using getc()). Is it possible due to my hardware circuit design? Is it relative to voltage level of modem receive and transmit?

Thanks!
Ttelmah
Guest







PostPosted: Tue Aug 23, 2005 4:33 am     Reply with quote

If you have a scope, check the voltage level on the pin. The default 'receive' input voltage for the idle state (high), is 0.8 of the supply voltage. The 'high' input for a MAX232 (assuming this is what you are using to drive the link to the PC), is only about 2v. You will get 'data ready' going true every character time, so long as the voltage is below the required level, and will always receive '0'. Depending on your circuit, you need to add either a pull-up, or a buffer, to get the rqquired level.

Best Wishes
arunb



Joined: 08 Sep 2003
Posts: 492
Location: India

View user's profile Send private message Send e-mail

RE:
PostPosted: Wed Aug 24, 2005 2:07 am     Reply with quote

Hi,

I don't think you can use getc() function to receive a string like "OK", for this you need to use gets().

getc() only receives a single character, whereas gets() an entire string...

Also use INT_RDA , it is more effective..

thanks
arun
puppie7777



Joined: 09 Jun 2004
Posts: 25
Location: Monterey, CA

View user's profile Send private message

PostPosted: Mon Aug 29, 2005 9:31 pm     Reply with quote

Ttelmah wrote:
If you have a scope, check the voltage level on the pin. The default 'receive' input voltage for the idle state (high), is 0.8 of the supply voltage. The 'high' input for a MAX232 (assuming this is what you are using to drive the link to the PC), is only about 2v. You will get 'data ready' going true every character time, so long as the voltage is below the required level, and will always receive '0'. Depending on your circuit, you need to add either a pull-up, or a buffer, to get the rqquired level.

Best Wishes


Thanks for ur reply. Actually, from the RX and TX pin to my modem module, it is still in the TTL level, so i didnt use transiever at all.
One more thing i have confirmed is that if i connect to a transmit circuit with a Max232 and then to a modem terminal, all my source code works very fine. That is why it made me so confused.
puppie7777



Joined: 09 Jun 2004
Posts: 25
Location: Monterey, CA

View user's profile Send private message

Re: RE:
PostPosted: Mon Aug 29, 2005 9:35 pm     Reply with quote

arunb wrote:
Hi,

I don't think you can use getc() function to receive a string like "OK", for this you need to use gets().

getc() only receives a single character, whereas gets() an entire string...

Also use INT_RDA , it is more effective..

thanks
arun


Thanks for ur reply, i have tried all of them include gets() and using INT_RDA interrupt service routine. It remains the same problem. which is that i can not read the data from the PIC, but i can sniffer out and dump to comm port to pc... This problem still remain unsolved. Hope to get some more opnions from u guys...
Thanks!
asmallri



Joined: 12 Aug 2004
Posts: 1635
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

Re: RE:
PostPosted: Mon Aug 29, 2005 10:07 pm     Reply with quote

Quote:
Thanks for ur reply, i have tried all of them include gets() and using INT_RDA interrupt service routine. It remains the same problem. which is that i can not read the data from the PIC, but i can sniffer out and dump to comm port to pc... This problem still remain unsolved. Hope to get some more opnions from u guys...
Thanks!


Could you state the problem a little more clearly (hint: pretend you don't know the problem and read the problem description to yourself).
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
ckielstra



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

View user's profile Send private message

PostPosted: Tue Aug 30, 2005 12:54 am     Reply with quote

Your problem description is indeed not very clear, but I've got an idea what your problem might be. First let me confirm the following:
1) You are using the hardware UART of the PIC?
2) Your program is working when using a MAX232 to a PC?
3) This same program fails when voltage levels are changed to TTL by removing the MAX232?

If yes to all the above, then remember that the MAX232 is not only a voltage level converter but also a signal inverter.
When communicating at TTL-levels to an external device you have to add either a hardware inverter to the signal path or use the software UART which has an INVERT option.
puppie7777



Joined: 09 Jun 2004
Posts: 25
Location: Monterey, CA

View user's profile Send private message

PostPosted: Tue Aug 30, 2005 3:49 am     Reply with quote

Thank you, ckielstra!
ckielstra wrote:
Your problem description is indeed not very clear, but I've got an idea what your problem might be. First let me confirm the following:
1) You are using the hardware UART of the PIC?
2) Your program is working when using a MAX232 to a PC?
3) This same program fails when voltage levels are changed to TTL by removing the MAX232?


Yes, You are right.

ckielstra wrote:
If yes to all the above, then remember that the MAX232 is not only a voltage level converter but also a signal inverter.
When communicating at TTL-levels to an external device you have to add either a hardware inverter to the signal path or use the software UART which has an INVERT option.


Thank you so much. But my pic is not connecting to external device. My pic is actually directly connect to the pins of "Tx, Rx, CTS, RTS, IGT" of siemens modem module. And the module is able to connect to the GSM network after i supplied the pulse wave to the IGT pin (as stated in the datasheet of siemens modem, the LED blinking shows the connection to GSM network). and then when my pic send "AT" command to it, the "OK" data can reach my receive pin of pic18f452 (i sniffer out the data, they are correct), but my pic can not capture them, seems there aways an error of "Overrun".
Have u got any idea of that?
Thank you!
puppie7777



Joined: 09 Jun 2004
Posts: 25
Location: Monterey, CA

View user's profile Send private message

PostPosted: Tue Aug 30, 2005 3:50 am     Reply with quote

Thank you, ckielstra!
ckielstra wrote:
Your problem description is indeed not very clear, but
1) You are using the hardware UART of the PIC?
2) Your program is working when using a MAX232 to a PC?
3) This same program fails when voltage levels are changed to TTL by removing the MAX232?


Yes, You are right.

ckielstra wrote:
If yes to all the above, then remember that the MAX232 is not only a voltage level converter but also a signal inverter.
When communicating at TTL-levels to an external device you have to add either a hardware inverter to the signal path or use the software UART which has an INVERT option.


Thank you so much. But my pic is not connecting to external device. My pic is actually directly connect to the pins of "Tx, Rx, CTS, RTS, IGT" of siemens modem module. And the module is able to connect to the GSM network after i supplied the pulse wave to the IGT pin (as stated in the datasheet of siemens modem, the LED blinking shows the connection to GSM network). and then when my pic send "AT" command to it, the "OK" data can reach my receive pin of pic18f452 (i sniffer out the data, they are correct), but my pic can not capture them, seems there aways an error of "Overrun".
Have u got any idea of that?
Thank you!
puppie7777



Joined: 09 Jun 2004
Posts: 25
Location: Monterey, CA

View user's profile Send private message

PostPosted: Tue Aug 30, 2005 3:57 am     Reply with quote

Hi, asmallri,
Thank you also!
ckielstra



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

View user's profile Send private message

PostPosted: Tue Aug 30, 2005 5:56 am     Reply with quote

Quote:
when my pic send "AT" command to it, the "OK" data can reach my receive pin of pic18f452 (i sniffer out the data, they are correct), but my pic can not capture them, seems there aways an error of "Overrun".
You still don't give us a lot to work with. Posting a small test program would help. Maybe your UART stalled because of a Rx buffer overflow? Have you tried adding the ERRORS directive to your #use RS232 line?
puppie7777



Joined: 09 Jun 2004
Posts: 25
Location: Monterey, CA

View user's profile Send private message

PostPosted: Tue Aug 30, 2005 7:47 pm     Reply with quote

Hi,ckielstra,
Thanks. I have tried the ERRORS but still doesnt work. The code is really as simple as standard one:
Code:

#use rs232(baud=115200, parity=N, BITS=8, xmit=TXD2, rcv=RXD2)

#byte RCSTA = 0xFAB   //Note: Memory Address for PIC18F452
#byte PIR1  = 0xF9E   //Note: Memory Address for PIC18F452

#bit RCIF = PIR1.5
#bit OERR = RCSTA.1                //Overrun Error bit
#bit CREN = RCSTA.4               //Continuous Receive Enable bit (1=enable)

//------------------------------------------------------------------------------
short kbhit_sms(void)
{
   if( OERR ){                   //If overrun error occurs
      CREN = 0;                   //CREN cleared
      CREN = 1;                   //CREN enabled
   }
   return RCIF;                   //RCIF returned
}

//------------------------------------------------------------------------------
//Get a single byte from receive PIN of PIC within tout time
char getSmsByte(long tout)       //every tout count is 1ms
{
   char   r=0;
   long   i;
   char   j;
   timeout=1;
   for (i=0; i<tout; i++)
   {
      for (j=0; j<200; j++)
      {
         if (kbhit_sms())
         {             //When byte received, kbhit_sms=1
            r=getc();
            timeout=0;
            return r;
         }
         else
         {
            delay_us(5);
         }
      }
   }
   return r;
}

And i have ajusted the delay timing in receiving for different values, sometimes the kbhit() can return TRUE, but still got all null characters.
I have tried to use the interrupt mode to receive the data, it doesnt work either!
arunb



Joined: 08 Sep 2003
Posts: 492
Location: India

View user's profile Send private message Send e-mail

RE:
PostPosted: Sat Sep 03, 2005 5:11 am     Reply with quote

Hi,

To determine the problem you will have to check if the PIC behave s correctly,for this you will have to proceed step by step.

1. Have you enabled the INT_RDA interrupts,??
2. Have you written the isr handler for this.
3. In case you have done all this, we first ensure the interrupt is called,
4. Have you enabled the watchdog timer ?? If so are you reseting the timer..?


For this you have the following options, in the isr for the INT_RDA interrupt , write to any location of the internal EEPROM, before starting clear the contents of the location.

The logic behind this is simple, if the interrupt occurs, the EEPROM location will contain the written data, this you can verify by reading the EEPROm location from your programmer.

You could also wire up a LED, so that when the interrupt is called the LED lights up.

alternatively use a PC to send a single character to your PIC, then record this character to the internal EEPROM, this way you can determine where the problem lies.

thanks
arunb
Guest








PostPosted: Sat Sep 03, 2005 6:43 am     Reply with quote

puppie7777 wrote:

Quote:
Thank you so much. But my pic is not connecting to external device. My pic is actually directly connect to the pins of "Tx, Rx, CTS, RTS, IGT" of siemens modem module.


I�m not understand clearly your description. You mentioned that your PIC is directly
connected to pins Tx, Rx, CTS, RTS. If you are using CTS and RTS, I assume
that you know that this control signals are for hardware handshaking and must be
RS232 level compatible.

Siemens modems usually includes a complete 16C550 compatible serial ports
(comm signals + control signals) that can be configured with jumpers.
Could you pls tell us a full description of the modem comm port conection with the PIC ?


Humberto
puppie7777



Joined: 09 Jun 2004
Posts: 25
Location: Monterey, CA

View user's profile Send private message

PostPosted: Mon Sep 05, 2005 3:54 am     Reply with quote

Quote:

Siemens modems usually includes a complete 16C550 compatible serial ports
(comm signals + control signals) that can be configured with jumpers.
Could you pls tell us a full description of the modem comm port conection with the PIC ?


Quote:

1. Have you enabled the INT_RDA interrupts,??
2. Have you written the isr handler for this.
3. In case you have done all this, we first ensure the interrupt is called,
4. Have you enabled the watchdog timer ?? If so are you reseting the timer..?


Hi, Humberto,
Thank you so much for ur reply. I am using Siemens modem MODULE NOT modem TERMINAL, it is a TTL level connection.

Hi, arunb,
Thanks for ur reply too. Now my problem was solved. All my ISR or polling routines works fine. It is a hard ware design problem, finally i found that the Siemens modem module works at TTL voltage level of 4.3v, just pull down the voltage to 4.3v at the RX pin. It works so nicely...

Thank you all!
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