|
|
View previous topic :: View next topic |
Author |
Message |
Guest
|
RS232 problems |
Posted: Wed Feb 25, 2009 4:42 pm |
|
|
I am using a PIC 16F886 with an internal oscillator. My compiler is PCM 4.086. I can't seem to get serial communications to work with anything but a PICKit2 serial monitor. I don't need speed, 300 baud would be fine.
I suspected a timing issue, but I checked with an analog scope and also the PicKit logic analyzer and the timing looks right on. I also wrote a program to blink an LED once per minute and it only lost 3 seconds in 45 minutes.
One PC program I tested with said I had a framing error. Hyperterminal either prints nothing or garbage. The character 'U' usually prints fine. I have also tried printing to a serial LCD, but that doesn't work either. The PICKit serial tool works great, however.
Does anyone have any ideas? Can the INTOSC work for slow serial rates? I sure thought it would.
Here is my code:
Code: |
#include <16F886.H>
#fuses INTRC_IO,NOWDT,NOPROTECT,NOLVP
#use delay(clock=8000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, bits=8, parity=N, stop=1, ERRORS)
#byte OSCTUNE = 0x90
void main()
{
OSCTUNE=0x00;
while(1) {
//putc(0xAA); //0b10101010
//putc(0x55); //0b01010101
putc('a');
delay_ms(1000);
}
}
|
Thanks for any help,
Bill |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
how about this - working ?? |
Posted: Wed Feb 25, 2009 5:08 pm |
|
|
Code: |
#include <16f886.h>
#FUSES NOPROTECT,NOMCLR,INTRC_IO,NOWDT,NODEBUG,NOLVP,NOIESO,NOFCMEN,PUT,NOWRT,NOFCMEN,NOBROWNOUT,
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS )
#use delay( clock=8000000,INTERNAL )
set_tris_c (3); // 00000011 low = C0,C1 are inputs
main() {
for (;;) {
printf ( "Hi!\r\n");
delay_ms(1000);
}
}
// this outputs to hyper term as long as i care to let it run
// how bout for you ?
|
|
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Wed Feb 25, 2009 5:19 pm |
|
|
If the internal oscillator has a speed error it will apply equally to all baud rates. You can't get away with a looser clock at lower speeds. To see if it is a clock speed problem try adjusting your #use delay speed. Try 3% faster or 3% slower and see if the comms start to make sense. You can make a test program that prints several lines at slightly different speeds and see what the low and high limits are.
Then read the datasheet about clock accuracy. If you are not at 5V and 25C the internal oscillator is crap. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
Guest
|
|
Posted: Wed Feb 25, 2009 5:35 pm |
|
|
It prints to the PICKit UART tool, but nothing in Hyperterminal. I notice that you use the INTOSC also, so it must be OK for you.
I did have to move the #use delay before the #use rs232 in your example to get it to compile. Also, for some reason, I had to comment out the set_tris_c() function. I don't think these are issues.
I'm starting to think I've got a bad RS232-TTL converter, but I cannot get a serial LCD with TTL input to work either.
Thanks,
Bill |
|
|
Guest
|
|
Posted: Wed Feb 25, 2009 6:10 pm |
|
|
The internal osc is rated +-2% at 0-85C at 5 Vdd. That seems reasonable to me. A 104 uSec bit could vary from 102 to 106 uSec. This works out to a max error of 21 uSec per char.
Of course, in my application, the serial link is an occasional setup tool. My control scheme does not depend on it. If it did, I would probably have designed in an oscillator. |
|
|
Guest
|
|
Posted: Wed Feb 25, 2009 7:03 pm |
|
|
I've been playing with baud rates for hours, to no avail. I did try the plus and minus 3% just now to be thorough, but no help. I am pretty sure that it is not a baud rate issue. It measure surprisingly close each time I try. |
|
|
|
|
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
|