|
|
View previous topic :: View next topic |
Author |
Message |
07arunsharma
Joined: 05 Mar 2012 Posts: 18 Location: India
|
Multiple Serial Port using PIC16F77A Problem?? |
Posted: Mon Jul 09, 2012 4:03 am |
|
|
I want to use two Serial Ports in a Single Controller.. Thats why i choose PIC16F877A having one Serial Port...
I read the CCS Help topics??
How can I use two or more RS-232 ports on one PICĀ®?
And Just Copy Paste its Code and program my Controller.. but it is neither working on hardware nor on proteus...
Pls help
Here is My Code
Code: |
#include<16f877a.h>
#use delay(clock = 20000000)
#fuses HS,NOWDT,NOPROTECT,NOBROWNOUT
#use RS232(BAUD=9600, XMIT=PIN_C6, RCV=PIN_C7, STREAM=COM_A)
#use RS232(BAUD=9600, XMIT=PIN_C4, RCV=PIN_C5 , STREAM=COM_B)
void main()
{
char c;
fprintf(COM_A,"Online-A\n\r");
fprintf(COM_B,"Online-B\n\r");
while(TRUE)
{
c = fgetc(COM_A);
fputc(c, COM_A);
fputc(c, COM_B);
}
}
|
Online A and Online B are Coming properly but when i type character in COM_A Nothing happens...
fgetc is not working
Pls help
Thanks in Advance _________________ Arun Sharma |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Mon Jul 09, 2012 4:56 am |
|
|
1) Add 'ERRORS' to the COM_A declaration. This _must_ always be present, when using the hardware UART, unless _you_ add your own code to handle UART errors. Without this, if characters arrive, and are not read, the receive part of the UART, _will_ hang.
2) Then double check your receive connections. Is pin C7, at the PIC, sitting close to 5v, when you do not send a serial character?. It needs to be (logic high). If not, without '1' the receive UART _will_ have hung. When you send a character this should be seen as a series of low pulses on this pin. You obviously have got the required hardware inversion on the transmit side (or Online-A, and Online-B wouldn't work). Have you got the other inversion on the receive side (other inversion since it also needs the voltage conversion from RS232 levels down to 5v, as opposed to the transmit conversion which needs conversion from 5v to RS232 levels).
You have proved the transmit wiring is OK, so your problem is on the receive side.
Best Wishes |
|
|
07arunsharma
Joined: 05 Mar 2012 Posts: 18 Location: India
|
|
Posted: Mon Jul 09, 2012 5:16 am |
|
|
Thanks for your reply...
My Code is working now after adding FORCE_SW
Code: | #use RS232(BAUD=9600, XMIT=PIN_C0, RCV=PIN_C1,FORCE_SW, STREAM=COM_A)
#use RS232(BAUD=9600, XMIT=PIN_C2, RCV=PIN_C3,FORCE_SW, STREAM=COM_B)
|
like this _________________ Arun Sharma |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Mon Jul 09, 2012 8:52 am |
|
|
Seriously, this almost certainly implies the hardware UART _was_ hung before.
FORCE_SW, does nothing on the second stream. It has to be software, because there is no UART hardware on these pins. So it was the hardware UART causing the problem. Only possible problem, is that the UART has become hung, because you did not have 'ERRORS', and the incoming line must have been low at some point (during boot up possibly, or if characters were arriving and unread, in the long delays implied by sending the 20 characters before starting to read).
Try again, with ERRORS on the first stream.
Seriously, having the hardware UART in use for the first stream, implies data can be received, and not missed on this stream. Otherwise if (for instance), you send two characters straight after one another now, the second will be lost.....
Best Wishes |
|
|
07arunsharma
Joined: 05 Mar 2012 Posts: 18 Location: India
|
|
Posted: Mon Jul 09, 2012 10:32 am |
|
|
Thanks for your reply....
But i think..
#use rs232 directive produces software uart
not hardware
unless we specify uart1 in that...
this is my personal belief not sure...
if i am wrong then correct me...
and if possible pls have a look at this link also
http://www.ccsinfo.com/forum/viewtopic.php?p=164505#164505 _________________ Arun Sharma |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Mon Jul 09, 2012 1:38 pm |
|
|
No.
#use RS232, generates hardware UART calls, _if you use the hardware pins_. Using 'UARTx, is a shortcut to say "use the hardware pins for UART 'x'".
Best Wishes |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9246 Location: Greensville,Ontario
|
|
Posted: Mon Jul 09, 2012 1:59 pm |
|
|
and..
get rid of Proteus !!
It is full of bugs,errors and faulty DRCs so you'll NEVER know if it's your program or Proteus that is at fault !! |
|
|
nailuy
Joined: 21 Sep 2010 Posts: 159
|
|
Posted: Mon Jul 16, 2012 4:31 pm |
|
|
Try to use this example:
Code: |
if(kbhit(PORT2)){
BUFER1=getc(PORT2);
putc(BUFER1,PORT1);
}
|
"kbhit" is command used in software or hardware buffer for receiving data RS232. If your program is much longer that 10 cycles of osc, maybe is not working. Try to read help from F1 or other topics. |
|
|
|
|
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
|