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

Rx Tx
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
arys



Joined: 09 Mar 2007
Posts: 31

View user's profile Send private message

Rx Tx
PostPosted: Thu Jan 10, 2008 8:44 pm     Reply with quote

Hi, I think this is a stupid question. I dont know how to start or test my HW/SW. I want to control few task from serial port of the PC.
I'm using 16f8X and max232 as interface to serial port. Do you guys know how? or just tell me the link or what ever, so I could do something. may be jjust want to light up LED.
Many thanks.
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Fri Jan 11, 2008 8:22 am     Reply with quote

Do you know how to write a program that sends "Hello World" out the PIC serial port? That is often the first program one writes when learning a new processor or compiler.
_________________
The search for better is endless. Instead simply find very good and get the job done.
jji



Joined: 11 Jan 2008
Posts: 7

View user's profile Send private message

PostPosted: Tue Jan 15, 2008 1:43 am     Reply with quote

I'm interested about this too. I'm using 16f690 and have built a serial level converter from max232.

If there is some short tutorial, which would show a simple example how to read/write data from serial line I would be interested to hear about it. Simple getc/putc doesn't seem to work (I get some random data from PIC and can't write anything to it).
arys



Joined: 09 Mar 2007
Posts: 31

View user's profile Send private message

PostPosted: Tue Jan 15, 2008 2:10 am     Reply with quote

You can go throgh this link. very useful. its work.

http://www.ccsinfo.com/forum/viewtopic.php?t=32831&highlight=getc
jji



Joined: 11 Jan 2008
Posts: 7

View user's profile Send private message

PostPosted: Tue Jan 15, 2008 3:08 am     Reply with quote

Actually the provided example didn't work for me. Could be hardware problem as there were on the thread. I'll double check that first.
arys



Joined: 09 Mar 2007
Posts: 31

View user's profile Send private message

PostPosted: Tue Jan 15, 2008 3:14 am     Reply with quote

may be you have to check your circuit between PC-max232-PIC.
you may check it in the net or you can find it here :

http://www.sparkfun.com/commerce/present.php?p=BEE-4-UART

then go through the link I post before. Its work. Because I prove it by myself. If not, try ask others.
HOHOHAHA



Joined: 13 Apr 2007
Posts: 24

View user's profile Send private message AIM Address

PostPosted: Tue Jan 15, 2008 3:26 am     Reply with quote

connect the 1uf in MAX232 properly... ie the + and - sign of the capacitors...this may be the only problem...I think...
jji



Joined: 11 Jan 2008
Posts: 7

View user's profile Send private message

PostPosted: Tue Jan 15, 2008 3:33 am     Reply with quote

I used these instructions for the max232. I understood it should work.
jji



Joined: 11 Jan 2008
Posts: 7

View user's profile Send private message

PostPosted: Tue Jan 15, 2008 6:27 am     Reply with quote

Ok, i checked the max232 part and it should be ok. After testing it I get decent replies from PIC but there is some strange behaviour. The code I'm using follows:
Code:

char c = '0';
int i = 0b00000001;
...
while(1)
  {
   putc('a');
   DELAY_MS(1000);
   OUTPUT_C(i);
   c = getc(); 
   putc(c);
   i*=2;
  }


Now it looks like there is some sort of echoing going on. I get "61 00 61" (hex) from PIC, i.e. the letter 'a' two times with null between and after running the second led is on, not the first as I would expect. Looks like the letter PIC sends is somehow read by it and sent to PC again. Also I'm not able to send anything to PIC.

If I add putc('b') after sending letter 'a' my terminal client receives "61 62 00 61 62" in hex.

Any ideas?
ckielstra



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

View user's profile Send private message

PostPosted: Tue Jan 15, 2008 6:56 am     Reply with quote

One possible explanation is that your code is having startup problems. You assume the receive buffer is empty on program start but this might not be the case.
Try adding the following code just before your while loop:
Code:
delay_ms(10);      // Allow environment to 'stabilize'
while( kbhit() )   // Read all pending data from the UART
{
  getc();
}


Quote:
Also I'm not able to send anything to PIC.
This is very strange when you can send data to the PC. Double check your hardware, especially the Tx line from PC to the Rx pin of the PIC and everything in between. A LED breakout box is very helpful to search these type of errors.
jji



Joined: 11 Jan 2008
Posts: 7

View user's profile Send private message

PostPosted: Tue Jan 15, 2008 7:39 am     Reply with quote

ckielstra wrote:
You assume the receive buffer is empty on program start but this might not be the case.


Yep, this solved the echoing issue. Thanks!


ckielstra wrote:
Double check your hardware, especially the Tx line from PC to the Rx pin of the PIC and everything in between. A LED breakout box is very helpful to search these type of errors.


I changed capacitors just for trying but no effect. Could the Max232 be broken in this way?

If nothing helps I'll build another serial level converter from scratch. This is first time I'm building anything like this and could simply be some stupid mistake I have made with hw.
ckielstra



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

View user's profile Send private message

PostPosted: Tue Jan 15, 2008 8:15 am     Reply with quote

Quote:
I changed capacitors just for trying but no effect. Could the Max232 be broken in this way?
Everything is possible... but unlikely in this case as the capacitors are used in generating the transmit voltages and are not used in the receive part where you have problems. The RS232 standard is quiet robust, it is not easy to break the driver chips.

Try connecting a led with 180 Ohm series resistor from the Rx input of the PIC to ground. Do you see the led light up when you transmit data from the PC to the PIC?

Post your:
- chip number
- compiler version number
- #use rs232 line
jji



Joined: 11 Jan 2008
Posts: 7

View user's profile Send private message

PostPosted: Wed Jan 16, 2008 2:06 am     Reply with quote

ckielstra wrote:
Try connecting a led with 180 Ohm series resistor from the Rx input of the PIC to ground.


Unfortunately I don't have resistor/led in hand. I'll buy some first aid- collection of miscallenius electronics.

ckielstra wrote:
- chip number
- compiler version number
- #use rs232 line


Compiler: PCM version 4.062
Use rsr232 (current version, I have tried changing it): #use rs232(baud=9600, xmit=PIN_B7, rcv=PIN_B5, ERRORS)
With chip number you mean 16F690? This is "Pickit2 started kit" with CCS compiler.

Terminal clients I'm using are Terminal v1.9 (Br@y) and Hercules.
jji



Joined: 11 Jan 2008
Posts: 7

View user's profile Send private message

PostPosted: Fri Jan 18, 2008 2:41 am     Reply with quote

Interesting. If I disconnect the external power source for max232 there is no problems reading from PIC, but if it is attached I'll get garbace again. Looks like it has something to do with the problems.
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Sun Jan 20, 2008 5:47 am     Reply with quote

Quote:
Interesting. If I disconnect the external power source for max232 there is no problems
reading from PIC

The MAX232 doesn't need any external power source. Is has a built in pump-switching
DC/DC voltage converter to generate the required levels for RS232.

Regarding your garbage character problem, I hope the following links will help you:
http://www.ccsinfo.com/faq.php?page=rs232_errors
http://www.ccsinfo.com/faq.php?page=pic_to_pc
http://www.ccsinfo.com/faq.php?page=multiple_rs232


Humberto
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