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

Problems with RS232

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



Joined: 07 May 2004
Posts: 20

View user's profile Send private message

Problems with RS232
PostPosted: Wed Aug 25, 2004 2:05 pm     Reply with quote

Im having problems with getc specifically. I can putc a character and have no problems. But when i try a putc(getc()); I get out output that looks like a clock signal. When i depress a key i see the signal on the line over the clock like signal. My code looks like this

#include<16F819.h>
#use delay(8000000)
#use rs232(baud 19200,XMIT=PIN_A1,RCV=PIN_A0)


void main()
{
setup_adc_ports(NO_ANALOGS);

while(true)
{
putc(getc());
}
}

Worse yet when i use printf, it seems to work alright but, my code in my java applet is looking for a byte. If i use printf i get a bunch of junk back. Anyway i could use printf to only print in single bytes? Or am i missing something with the putc. Thanks in advance guys.
Bryan
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Aug 25, 2004 2:30 pm     Reply with quote

I can't really tell anything from your program because it's typed in code.
There may be things that are wrong, but I need to see them for real.
You need to paste in a program right out of MPLAB or the CCS IDE.

Also post the version of your compiler.


For example, I tested this program for a 16F877 with PCM vs. 3.188
and it works fine.

Code:
#include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)
#use rs232(baud=9600, xmit=PIN_B1, rcv=PIN_B0)

void main()
{

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

}
 
Ttelmah
Guest







PostPosted: Wed Aug 25, 2004 2:53 pm     Reply with quote

One comment that leaps to mind, is to look carefully at the wiring. remember you need a ground connection as well as the two data connections. The comment bout 'seeing a clock signal', to me suggests something somewhere is floating. The fact that A0, is immediately adjacent to the clock pin, makes me suspect something like capacitive coupling between the pins, and no ground connection between the units, which would give the visible clock signal you describe.
Putc(getc()), will work fine if the hardware is right, but with a major 'caveat'. Characters being received, _must_ have at least one character time between them. You are using the 'software' UART (since the chip you mention does not have a hardware UART), which means that while sending a character, the chip will not be listening to the input line. If this is not possible, consider switching to a pin compatible chip (like the 16F628), which has got the hardware UART - remember though you will then have to use pins B1 and B2.

Best Wishes
BMaxwell



Joined: 07 May 2004
Posts: 20

View user's profile Send private message

Here is the info you requested
PostPosted: Wed Aug 25, 2004 3:05 pm     Reply with quote

The compiler version is 3.148. The code from the actual c file reads like this

#include <16F819.H>


#use delay(clock=8000000)
#use rs232(baud=19200, xmit=PIN_A1, rcv=PIN_A0,RESTART_WDT)


void main()
{
setup_adc_ports( NO_ANALOGS );

while(TRUE){

putc(getc()); //this is the problem
//putc('A'); this works fine by itself


}

}

Thanks in advance guys.
Bryan
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Aug 25, 2004 3:46 pm     Reply with quote

1. You still need to show your #fuses statement, or list the config bits
settings that you're using with your programmer.

2. How are you testing this ? Are just typing in characters from the PC's
keyboard, or is some other device sending characters to the PIC ?
If so, as Ttelmah says, is there any time delay between characters ?
BMaxwell



Joined: 07 May 2004
Posts: 20

View user's profile Send private message

Answer to your questions
PostPosted: Thu Aug 26, 2004 10:39 am     Reply with quote

1. You still need to show your #fuses statement, or list the config bits
settings that you're using with your programmer.

Osc - HS, Watchdog timer - disabled, Power up timer - disabled, Mclr - RA5, Brownout detect -enabled, Low Voltage Program- enabled, Data EE Read Protect - disabled, Flash Power - disabled, Background debugger mode - enabled , CCP - ccp on rb2.

2. How are you testing this ? Are just typing in characters from the PC's
keyboard, or is some other device sending characters to the PIC ?
If so, as Ttelmah says, is there any time delay between characters ?

I am testing this with an oscilliscope on my transmit line which is connected to a serial to ethernet converter. This system is then connected through ethernet to another computer. I have a java program that runs on the serial to ethernet converter which can read and write to the serial port. I basically have an input box and a output box. When i depress a key in the input box it is visbile on the oscilliscope. If i putc('U'); this is also visible and shows up correctly in my java program. I also have tried to use pin_a2 to be a dtr line. This didnt seem to change anything. When i use a printf(getc()); I dont have that clock like signal, however i get junk characters in my java program. Its very confusing to me, so it must be ultra to you guys. Thanks in advance for your thoughts.
Bryan
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Aug 26, 2004 11:34 am     Reply with quote

I would do three things:

1. If you're not using Low Voltage Programming, then disable it.

ie., change this:
Low Voltage Program- enabled
to this:
Low Voltage Program- Disabled

2. Since you're not using the WDT, then get rid of the Restart_wdt
parameter in your #use rs232() statement. Keep everything simple.

3. You've got a problem with your soft USART. Test and fix this
problem with HyperTerminal and Com1 on your PC. Test it
by slowing typing characters from the PC keyboard. Make sure
that local echo is turned off. Once you've got it working there,
then add your Ethernet box and your Java program, perferably
one at a time.
BMaxwell



Joined: 07 May 2004
Posts: 20

View user's profile Send private message

Hair pulling time!
PostPosted: Tue Aug 31, 2004 11:43 am     Reply with quote

Well I got the RS 232 to work with a MAX 233 chip in the basic RS232 mode. But when i use a basic 74S04 with the serial to ethernet converter, I got all the original problems. I dont think i can use the MAX 233 chip because the serial to ethernet is TTL levels, and the transmit of the MAX 233 is 7+ volts. I need to use this converter. Are there any other commands to or ways to communicate serially. If not i will be a 25 year old guy with no hair..... Thanks in advance for your thoughts.
Bryan
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Aug 31, 2004 11:52 am     Reply with quote

Post the manufacturer, part number, and website of the Serial
to Ethernet converter.
BMaxwell



Joined: 07 May 2004
Posts: 20

View user's profile Send private message

Here ya go PCM
PostPosted: Tue Aug 31, 2004 1:01 pm     Reply with quote

LanTronix - CoBox Micro C0-E1-11AA www.lantronix.com
I have tested this system by connection its ttl transmit and receive together and hyper terminaling to its 10001 port. This works fine the characters echo back. The problem is at the pic as far as I can tell. This is where im stuck because it seems to work without the converter. But the converter works itself so...... I have also slowed the speed. Before i was using 19200 for the serial, so i slowed this to 9600 with no effect at all. Sigh..... One other thing i noticed pcm. If I use a putc('a') now i get out a
'=' sign. This works out in binary like this 'a'=01100001
The '=' = 00111110. If you shift a over one bit and invert it almost equals the '=' sign. Exception being the last 1 bit. Not sure what this all means. Thanks once again for helping.
Bryan
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Aug 31, 2004 1:44 pm     Reply with quote

The Lantronix Cobox has two serial connectors, CON1 and CON2.

From the data sheet, it looks like CON1 can connect directly to a
serial port on a PC.

1. Why don't you try and emulate the PC with your PIC ?
Use the MAX233 chip and connect the RS-232 side to the
CON1 connector.

2. Another issue is handshaking. The Lantronix unit appears to use it.
I don't know if they have any appnotes on this, but you may need it.

3. Also, are we sure that when Lantronix says "TTL" that they really
mean it ? Is it possible that they really use CMOS levels ?
-----------
Edited to add a couple more comments:

A. Since you know your PC and Hyperterminal can talk to the Lantronix
unit, you could disable all handshaking within HyperTerminal, and
see if the connection still works. If so, then handshaking may not
be required.

B. If you can prove that handshaking is not required (at least for a
few characters sent at a keyboard typing rate), then you can connect
the PIC to the Lantronix unit with the MAX233. The PC will have the
equivalent of a MAX233 inside it. So you're changing as little as
possible from a known, proven working method when you do this.
You're just substituting the PIC for the keyboard. Put a one second
delay between characters when you send them out from the PIC.

I suppose, to check if it's working, you could compare the echoed
character to the one sent, and maybe turn on a LED for 1 second
to show that it worked. (Or create a 2nd serial port and send a
good or bad indication to the PC and read it with HyperTerminal).
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