|
|
View previous topic :: View next topic |
Author |
Message |
litoman Guest
|
Multiple RS232 ports problem |
Posted: Mon Apr 18, 2005 2:17 pm |
|
|
Somebody Knows what is wrong in this program?I`m going crazy...
Only works interrupts for P_Nuevo in the external interrupts..???? what happend in RDA interrupt.
This is my code...
in .h:
#include <16F876.h>
#device adc=8
#device *=16
#use delay(clock=10000000)
#fuses NOWDT,HS, PUT, NOPROTECT, BROWNOUT, NOLVP, NOCPD, NOWRT, NODEBUG
#use rs232(baud=9600,parity=N,xmit=PIN_C5,rcv=PIN_B0,bits=8,stream=P_Nuevo)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=P_Viejo)
in .c file:
#include "D:\Trabajo\Interfaz Paneles\Interfaz_Comunicaciones.h"
/******************************************************************************/
#define BUFFER_SIZE 30
BYTE buffer[BUFFER_SIZE];
BYTE next_in = 0;
BYTE next_out = 0;
/************* INTERRUPCION DEL PUERTO SERIE PANEL VIEJO **********************/
#int_rda
RDA_isr()
{
int t;
buffer[next_in]=fgetc(P_Viejo);
t=next_in;
next_in=(next_in+1) % BUFFER_SIZE;
if(next_in==next_out)
next_in=t; // Buffer lleno !!
}
#define bkbhit (next_in!=next_out)
BYTE bgetc()
{
BYTE c;
while(!bkbhit) ;
c=buffer[next_out];
next_out=(next_out+1) % BUFFER_SIZE;
return(c);
}
/******************************************************************************/
#define BUFFER_SIZE2 30
BYTE buffer2[BUFFER_SIZE2];
BYTE next_in2 = 0;
BYTE next_out2 = 0;
/************* INTERRUPCION DEL PUERTO SERIE PANEL NUEVO **********************/
#int_EXT
EXT_isr()
{
int t2;
buffer2[next_in2]=fgetc(P_Nuevo);
t2=next_in2;
next_in2=(next_in2+1) % BUFFER_SIZE2;
if(next_in2==next_out2)
next_in2=t2; // Buffer lleno !!
}
#define bkbhit2 (next_in2!=next_out2)
BYTE bgetc2()
{
BYTE c2;
while(!bkbhit2) ;
c2=buffer2[next_out2];
next_out2=(next_out2+1) % BUFFER_SIZE2;
return(c2);
}
void main()
{
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
ext_int_edge(H_TO_L);
enable_interrupts(INT_EXT);
enable_interrupts(int_rda);
enable_interrupts(GLOBAL);
fprintf(P_Viejo,"Probando Panel Viejo");
fprintf(P_Nuevo,"Probando Panel Nuevo");
while(1)
{
fprintf(P_Viejo,"\r\n\Running...\r\n");
// The program will delay for 10 seconds and then display
// any data that came in during the 10 second delay
do {
delay_ms(10000);
fprintf(P_Viejo,"\r\nBuffered data => ");
while(bkbhit)
putc( bgetc() );
} while (TRUE);
}
} |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Apr 18, 2005 3:11 pm |
|
|
Your problem is in the putc() statement below. You are using two
serial streams, so all rs232 functions must specify the stream.
You also need to use the fputc() function instead of putc(), because
only fputc() allows you to specify the stream.
Code: | do {
delay_ms(10000);
fprintf(P_Viejo,"\r\nBuffered data => ");
while(bkbhit)
putc( bgetc() );
} while (TRUE); |
|
|
|
litoman Guest
|
Multiple RS232 Ports |
Posted: Mon Apr 18, 2005 10:32 pm |
|
|
OK,but the problem is not in the transmision.The problem is in the reception:the #int_RDA not execute it�s code never.The problem must be in the
#use rs232(baud=9600,parity=N,xmit=PIN_C5,rcv=PIN_B0,bits=8,stream=P_Nuevo)
If I delete this then #int_RDA execute without problems. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Apr 18, 2005 10:54 pm |
|
|
After making the changes that I specified, I compiled your code with
PCM vs. 3.223. The #int_rda code worked OK.
What is your version of the compiler ? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Apr 18, 2005 11:04 pm |
|
|
To make it very clear, the changes that I did are shown in bold, below:
do {
delay_ms(10000);
fprintf(P_Viejo,"\r\nBuffered data => ");
while(bkbhit)
fputc(bgetc(), P_Viejo);
} while (TRUE); |
|
|
litoman Guest
|
Multiple RS232 ports |
Posted: Mon Apr 18, 2005 11:46 pm |
|
|
I have the version 3.222 but i have compile in the 3.216 too. |
|
|
litoman Guest
|
Multiple RS232 ports |
Posted: Mon Apr 18, 2005 11:55 pm |
|
|
This is my new code.
Code: | while(1)
{
if(bkbhit)
{
fputc(bgetc(),P_Nuevo);
}
if(bkbhit2)
{
fputc(bgetc2(),P_Viejo);
}
} |
It only detect bkbhit2. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Apr 19, 2005 12:06 am |
|
|
I installed PCM vs. 3.222 and tested your code with a PICDEM2-Plus
board. There are a few differences between the PICDEM2-Plus and
your board, but they're not important. It has a 16F877 instead of
a 16F876. It's running at 4 MHz instead of 10 MHz. I made those
changes to your code, so it would run on my board.
I also made the change shown in bold below.
do {
delay_ms(10000);
fprintf(P_Viejo,"\r\nBuffered data => ");
while(bkbhit)
fputc(bgetc(), P_Viejo);
} while (TRUE);
It worked very well. I connected the serial port on the PicDem board
to COM1 on my PC. (This is the hardware serial port, which uses pins
C6 and C7 on the PIC). I programmed the 16F877 with my ICD2.
Then I clicked the button in MPLAB vs. 7.10, to release the PIC from reset.
Then I typed in a few words from my keyboard. After a delay of several
seconds, it displayed this on the terminal window:
Probando Panel Viejo
Running...
This is a test
Buffered data => This is a test
-------------
Note:
The terminal program is set to echo characters to the terminal window
when they are typed in. That's why you see the "This is a test" line
after the "Running...." line.
--------------
If you made the change to the putc() line that I posted, and it still
doesn't work, then I think you may have a hardware problem.
Check the wiring on your board. Check if the MAX232 chip is working
properly. |
|
|
litoman Guest
|
Multiple RS232 port |
Posted: Tue Apr 19, 2005 1:39 am |
|
|
Thank you,but it seems to be a problem with the compiler.In the version 3.184 work OK. |
|
|
|
|
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
|