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

RS232 problems

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








RS232 problems
PostPosted: Wed Feb 25, 2009 4:42 pm     Reply with quote

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

View user's profile Send private message AIM Address

how about this - working ??
PostPosted: Wed Feb 25, 2009 5:08 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Feb 25, 2009 5:19 pm     Reply with quote

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








PostPosted: Wed Feb 25, 2009 5:35 pm     Reply with quote

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








PostPosted: Wed Feb 25, 2009 6:10 pm     Reply with quote

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








PostPosted: Wed Feb 25, 2009 7:03 pm     Reply with quote

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.
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