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 support@ccsinfo.com

A small rs232 receive issue

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



Joined: 30 Apr 2007
Posts: 64

View user's profile Send private message

A small rs232 receive issue
PostPosted: Wed Nov 28, 2007 7:09 am     Reply with quote

Hello i use this code to confirm that i can recieve the button i press ,with my pc keyboard,through Rs232.When i press No1 key on my keyboard i cant see an ok mesage on hyperterminal.I can see the message that the pic transimts on hyper terminal but the recieve function doesn't work.

PIC18f4620
compiler version 3.249

Code:


#use rs232(baud=9600, parity=N,xmit=PIN_C6 ,rcv=PIN_C7,bits=8)
.
.
.
//i have configured the c7 (Rx) pin as input

loop:
//  .
//  .
//  .

ready=kbhit();
if(ready==1)
{
   key=getc();
   if(key==49)     // 1 in ASCII
   printf("OK");
//  .
//  . 
//  .
goto loop;
}

Audi80



Joined: 07 Sep 2007
Posts: 41

View user's profile Send private message

PostPosted: Wed Nov 28, 2007 7:21 am     Reply with quote

Instead of using if(key==49) try using if(key=='1').

And to receive anything i would recomend you to use the communications interruptions. #INT_RDA
jojos



Joined: 30 Apr 2007
Posts: 64

View user's profile Send private message

PostPosted: Wed Nov 28, 2007 8:15 am     Reply with quote

Nothing happens.I 've tryed the key=='1' didnt't work.I tryed the int_rda and i can see that it never gets in this interrupt ,ike there is nothing coming from rs232 so to produce an interrupt(i have enabled the interrupt of rda).
Could it be any setting that i have to do in hyperterminal or it doesn't matter?
In hyper terminal i use ANSI emulation and i have tryed all of flow control options (None,Xon/Xoff,Hardware)
Audi80



Joined: 07 Sep 2007
Posts: 41

View user's profile Send private message

PostPosted: Wed Nov 28, 2007 9:14 am     Reply with quote

Here´s a simple example...
Code:
#include <16F876A.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
//////////////////////////////////////////////
char cartao[10];
int a=0;
char aux;
//////////////////////////////////////////////
void escreve();
//////////////////////////////////////////////

#int_rda
void serial_isr() {

   aux=getc();
   cartao[a]=aux;
   ++a;
   escreve();
   if(a==10){
      a=0;
   }
}

void main() {

   enable_interrupts(global);
   enable_interrupts(int_rda);
   while(true);

}
void escreve(){
   int i;
   for(i=0;i<strlen(cartao);++i){
      printf("%c",cartao[i]);
   }

}


Dont forget that you´ve got to put a while(true) in the main so that the pic never stops. And you have to check your cable pin 2 is rx and 3 tx. to use the Hyperterminal with this example just select your comX and set to restore defaults. Hope it helps!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Nov 28, 2007 1:49 pm     Reply with quote

To check if RS232 is working correctly, try a very simple test program.
In the following program, any character that you type on the PC keyboard
will be sent back to the PC and displayed in the terminal window. Make sure that you configure the terminal program to disable "local echo".
Code:

#include <18F4620.h>
#fuses XT,NOWDT,BROWNOUT,PUT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

//================================
void main(void)
{
char c;

while(1)
  {
   c = getc();
   putc(c);
  }

}
jojos



Joined: 30 Apr 2007
Posts: 64

View user's profile Send private message

PostPosted: Thu Nov 29, 2007 3:25 am     Reply with quote

Pcm i cant see anything on the screen of Hyperterminal.What could be wrong?.I can transmit but i cant recieve.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Nov 29, 2007 3:32 am     Reply with quote

Check all the connections in your MAX232 circuit.
jojos



Joined: 30 Apr 2007
Posts: 64

View user's profile Send private message

PostPosted: Thu Nov 29, 2007 5:27 am     Reply with quote

I checked all my connection they appear to be O.K.

Using the oscilloscope i can see in the Rx pin of the pic that when i press a button on the pc keyboard there are pulses of max. 2V,but from the Tx pin it doesn't appear anything.I would expect that form the putc(c); instruction there had to be something.
Are the 2volts pulses to low or they are the nominal voltage?
jojos



Joined: 30 Apr 2007
Posts: 64

View user's profile Send private message

PostPosted: Thu Nov 29, 2007 7:38 am     Reply with quote

Found the problem.The capacitor on pin 16 and pin 2 of the max232 has failed. Guess everything is possible Shocked

Thanks for the respond.
Ttelmah
Guest







PostPosted: Thu Nov 29, 2007 7:38 am     Reply with quote

jojos wrote:
I checked all my connection they appear to be O.K.

Using the oscilloscope i can see in the Rx pin of the pic that when i press a button on the pc keyboard there are pulses of max. 2V,but from the Tx pin it doesn't appear anything.I would expect that form the putc(c); instruction there had to be something.
Are the 2volts pulses to low or they are the nominal voltage?

The signal at PIC, should be _high_ when no data is arriving, and drop when data is received. It needs to be reaching at least 0.8*the PIC supply rail (4v, for a 5v PIC). 2v, would normally imply something is badly wrong, and if the data is positive going, something else is wrong as well...

Best Wishes
Ttelmah
Guest







PostPosted: Thu Nov 29, 2007 8:00 am     Reply with quote

I see the hardware problem was found, while I posted. :-)

Best Wishes
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