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

Serial communication between PIC18F4520 & PC

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



Joined: 07 Mar 2012
Posts: 34
Location: jalpaiguri, India

View user's profile Send private message

Serial communication between PIC18F4520 & PC
PostPosted: Sun Mar 23, 2014 8:17 am     Reply with quote

hi,

I am trying to send/receive data between PIC18F4520 & PC.
I am using the following code. but nothing is showing up in the hyper terminal.
Sad Sad

Code:
#include<18f4520.h>
#fuses NOWDT,HS,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600,UART1,ERRORS, parity=N,bits=8)   

void main(void)
{
   char a;
   delay_ms(20); //The capacitors in the MAX232 take a few mSec to charge
   printf("hello...\n.");
   while(1)   
   {
      a=getc();
      putc(a);   
  }   
}


I am using max-232. with 10uF capacitors. PLEASE HELP !! Sad
temtronic



Joined: 01 Jul 2010
Posts: 9226
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Mar 23, 2014 8:34 am     Reply with quote

I would remove the PIC to MAX232 connections (TX and RX). Simply 'loopback' the MAX232 TX and RX pins by connecting them to each other. Then press a key on the PC. It should be displayed on the PC screen.

If this works, it confirms the PC is operating, that Hyperterminal is configured and the MAX232 is OK.

If it doesn't, perhaps you've miswired the serial connections. Pin 2 is PC-rcv, pin 3 is PC-xmt. Also be sure pin 5 (ground) is connected to your PIC !

I don't see anything wrong with your program (a slightly modified CCS Example).

hth
jay
SubhamayS



Joined: 07 Mar 2012
Posts: 34
Location: jalpaiguri, India

View user's profile Send private message

MAX232 is ok
PostPosted: Tue Apr 01, 2014 2:56 am     Reply with quote

Hi,, Thanks for the reply.. Smile

temtronic wrote:
I would remove the PIC to MAX232 connections (TX and RX). Simply 'loopback' the MAX232 TX and RX pins by connecting them to each other. Then press a key on the PC. It should be displayed on the PC screen.

I have done the loopback test as you mentioned.. The MAX232 connection is OK.. Whatever I type on keyboard is displayed on hyper terminal window. Smile
temtronic wrote:
If it doesn't, perhaps you've miswired the serial connections. Pin 2 is PC-rcv, pin 3 is PC-xmt. Also be sure pin 5 (ground) is connected to your PIC !

this is the circuit I am using: http://www.filefactory.com/file/17izre3pxqfh/PIC-Serial1.jpg
the connection seem to be ok... but still I am not getting anything in the hyper terminal... Sad

another strange thing I noticed is that if I add an LED blinking code in the while loop of the above program... The LED is not responding at all... That means the while loop is getting stuck somewhere... but once I comment out the getc() putc() & printf() functions... the LED blinks... Sad or is it a compiler issue !!! I am using version 4.068.. please help !!


Last edited by SubhamayS on Tue Apr 01, 2014 4:33 am; edited 1 time in total
Ttelmah



Joined: 11 Mar 2010
Posts: 19513

View user's profile Send private message

PostPosted: Tue Apr 01, 2014 4:18 am     Reply with quote

As written, the code will sit waiting in 'getc' forever, until a character arrives. Hence the LED would stop if a character is not seen.
Obvious guess, would be that your connections are wrong, so it is not seeing the character....
Now when you did the loopback, you did test 'at the PIC', not at the Max232?. What you want to be doing is unplugging the PIC, and connecting PIN25 to pin 26 at the socket where the PIC normally sits. This then tests everything to the point where the PIC receives.
When you did the flash an LED test, did that flash at the right rate?. This is vital.
Do you have access to a scope?. If so, test the signal at pin 26 on the PIC. Is it sitting 'high' (4+v)?. Do you see activity here if you type characters on the PC?.
Do you have a meter?. With the unit switched off, physically check that pin 25 on the PIC, does connect to pin 11 on the MAX232, and to nowhere else. Similarly with pin 26 on the PIC to pin 12.

What you have typed _does work_ on a working PIC, with a working MAX232, so you have a wiring problem somewhere.
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Tue Apr 01, 2014 6:31 am     Reply with quote

Hi SubhamayS,

A little bit of 'tough love' here! What you call a 'strange thing' is actually normal behavior that is well documented in the CCS manual. Here is what the manual says about getc():

"This function waits for a character to come in over the RS232 RCV pin and returns the character. If you do not want to hang forever waiting for an incoming character use kbhit() to test for a character available."

My point is that learning to become a proficient CCS 'C' programmer demands that you actually become familiar with the various functions of the language, and the compiler. It's all (mostly) well documented if you just seek out the information!

Good luck!

John
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