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

RS485 enable pin - manual or automatic (strange behaviour)

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



Joined: 27 Aug 2012
Posts: 23

View user's profile Send private message

RS485 enable pin - manual or automatic (strange behaviour)
PostPosted: Tue Aug 28, 2012 2:52 pm     Reply with quote

Hello my dear friends,

I have another freaky question.

I'm trying to write a simple communication between PC and PIC.

communication diagram is below:

PC <-> MAX232 <-> MAX485 <-> ........<->MAX485<->PIC
I use a RTC signal from PC as an enable pin.

I have two very simple programs:

FIRST
Code:

#include <16F628A.h>
#include <F628.h>

#fuses XT, NOPROTECT, NOCPD, NOLVP, NOWDT, NOBROWNOUT, PUT
#use delay(clock=4M)
#use rs232(baud=9600, xmit=PIN_B2, enable=PIN_B3, rcv=PIN_B1, errors, stream=PC)
void main()
{
   fprintf(PC,"test_1");
   fprintf(PC,"test_2\r\n");
   fprintf(PC,"test_3\r\n\r\n");
   fputc('a',PC);
   fputc('b',PC);
   fputc('c',PC);
   fputc('d',PC);
}




SECOND
Code:


#include <16F628A.h>
#include <F628.h>

#fuses XT, NOPROTECT, NOCPD, NOLVP, NOWDT, NOBROWNOUT, PUT
#use delay(clock=4M)
#use rs232(baud=9600, xmit=PIN_B2, rcv=PIN_B1, errors, stream=PC)
void main()
{
   output_high(PIN_B3);
   fprintf(PC,"test_1");
   fprintf(PC,"test_2\r\n");
   fprintf(PC,"test_3\r\n\r\n");
   fputc('a',PC);
   fputc('b',PC);
   fputc('c',PC);
   fputc('d',PC);
   output_high(PIN_B3)
}



the only difference is that FIRST has enable pin option in "#use rs232" and SECOND has not and i use manual output_high before sending some bytes and output_low after sending.


look what PC received:

FIRST
Code:

test_1test_2
test_3

abcd


SECOND
Code:

test_1test_2
test_3

ab


why I dint receive "cd"?

can anyone answer me?


also when the code is:
Code:

void main()
{
   output_high(PIN_B3);
   fprintf(PC,"test_2");
   output_low(PIN_B3);
}

and i use manual output_high and output_low i receive only:
Code:
test

so again last 2 characters are missing

Best regards
Lisek
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Aug 28, 2012 3:05 pm     Reply with quote

The PIC goes to sleep. CCS puts a SLEEP at the end of main().
Put a while(1); at the end of main() to prevent this problem.
lisek_lichu



Joined: 27 Aug 2012
Posts: 23

View user's profile Send private message

PostPosted: Tue Aug 28, 2012 3:25 pm     Reply with quote

PCM programmer wrote:
The PIC goes to sleep. CCS puts a SLEEP at the end of main().
Put a while(1); at the end of main() to prevent this problem.



this is not a problem

Code:

void main()
{
   output_high(PIN_B3);
   fprintf(PC,"test_2");
   output_low(PIN_B3);
   while(TRUE);
}


this code do exactly the same

PC received:
Code:

test


also 2 last characters missing

when I use enable option in #use rs232 this problem disappears. So what is the cause of this behaviour?


Lisek
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Tue Aug 28, 2012 6:05 pm     Reply with quote

Why did you start a new thread on this issue? You've already got the the same problem being discussed in your original thread.

John
SherpaDoug



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

View user's profile Send private message

PostPosted: Wed Aug 29, 2012 6:24 am     Reply with quote

If you are using a hardware UART the fprintf() function only puts the bytes into the UART buffer. You are disabling the 485 driver while the UART is still clocking out serial bits.

You should poll the UART busy flag to see when it is done before disabling the 485 driver.
_________________
The search for better is endless. Instead simply find very good and get the job done.
lisek_lichu



Joined: 27 Aug 2012
Posts: 23

View user's profile Send private message

PostPosted: Wed Aug 29, 2012 9:07 am     Reply with quote

ezflyr wrote:
Why did you start a new thread on this issue? You've already got the the same problem being discussed in your original thread.

John


Hello John, this is not the same problem. this is another thing i have found during my tests and I just don't want to put another thing into one thread.

Smile
Ttelmah



Joined: 11 Mar 2010
Posts: 19348

View user's profile Send private message

PostPosted: Wed Aug 29, 2012 12:03 pm     Reply with quote

It is tied up with the other thread. One poster had asked if the enable was being handled correctly, and the reply had already been posted in the other thread.

Keep the threads about one problem together.

Best Wishes
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