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

Software vs Hardware UART on PIC16f877a
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Oct 11, 2005 12:45 pm     Reply with quote

Thanks. It might be tonight or tomorrow morning before I can test this.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Oct 11, 2005 10:29 pm     Reply with quote

I looked at your PicBasic-Pro program. It's doing something quite
different than the character echo program in C. The PBP program
is reading an entire string and "camping on" the serial input pin (C7)
until that string is received. Then it outputs the entire string to
the Debug pin (D0).

That would certainly work, because it's not going to miss any incoming
characters.

I think if you just write up the same thing in C, it will work too.
ramans



Joined: 10 Oct 2005
Posts: 9

View user's profile Send private message

PostPosted: Wed Oct 12, 2005 12:47 pm     Reply with quote

Isn't that what the gets/puts C program we tried earlier did? that did not work.

-R
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Oct 12, 2005 12:56 pm     Reply with quote

I will test it later today in hardware and let you know.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Oct 13, 2005 1:54 am     Reply with quote

I think the problem is caused by a bug in the CCS library code for
a software UART when used with fgets(), and a high oscillator
frequency and a low baud rate. I think CCS is using the FSR
register as the MSB of an internal delay loop, and they're trashing it.
I'll report the bug to CCS as soon as I document it better.

As a work-around, you need to create your own version of
fgets() in code. I've done that in the sample program below.
The code as written just emulates fgets(), but it could be improved
so that a long input string doesn't blow past the end of the buffer.

I know this sample program doesn't fit your situation exactly,
since it uses the same baud rate for the gps and dbg streams.
But I don't have the splitter cable with me right now, and I'm
pretty sure I've found the bug and a work-around, so I'll post
this tonight.
Code:

#include <16F877A.H>
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 20000000)

#use rs232(baud=2400, xmit=PIN_C6, stream=DBG)
#use rs232(baud=2400, rcv=PIN_C7, stream=GPS)

//======================================
void main()
{
char c;   
char str[80];
char *ptr;

while(1)
  {

// The following code emulates the fgets() function,
// without causing the bug.

   ptr = str;      // Get pointer to start of string buffer

   while(1)
     {
      c = fgetc(gps);   // Get a char

      if(c == 0x0d)     // Is it a message terminator ?
         break;         // Break if so
      else
         *ptr++ = c;   // Otherwise, put char in buffer
     }

   *ptr = 0;           // If done, write string terminator

  // fgets(str, GPS);      // Comment this line out.

   fputs(str, DBG);

  }

}
ramans



Joined: 10 Oct 2005
Posts: 9

View user's profile Send private message

PostPosted: Thu Oct 13, 2005 5:28 pm     Reply with quote

Thanks I'll give this a try!
ramans



Joined: 10 Oct 2005
Posts: 9

View user's profile Send private message

PostPosted: Mon Oct 17, 2005 10:59 am     Reply with quote

Bingo! That works. Cool thank you, and let me know if you hear of a fix for the initial bug!
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 Previous  1, 2
Page 2 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