View previous topic :: View next topic |
Author |
Message |
lisek_lichu
Joined: 27 Aug 2012 Posts: 23
|
RS485 enable pin - manual or automatic (strange behaviour) |
Posted: Tue Aug 28, 2012 2:52 pm |
|
|
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:
so again last 2 characters are missing
Best regards
Lisek |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Aug 28, 2012 3:05 pm |
|
|
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
|
|
Posted: Tue Aug 28, 2012 3:25 pm |
|
|
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:
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
|
|
Posted: Tue Aug 28, 2012 6:05 pm |
|
|
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
|
|
Posted: Wed Aug 29, 2012 6:24 am |
|
|
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
|
|
Posted: Wed Aug 29, 2012 9:07 am |
|
|
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.
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19541
|
|
Posted: Wed Aug 29, 2012 12:03 pm |
|
|
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 |
|
|
|