View previous topic :: View next topic |
Author |
Message |
colin_turner99
Joined: 24 Nov 2005 Posts: 7
|
16F88 RS232 Error |
Posted: Fri May 05, 2006 9:51 am |
|
|
Hi All
Please can you help me
I have a 16F88 with a Timer driven software serial routine
my code is a follows
Code: |
#use rs232(baud=9600,parity=N,xmit=PIN_B4,rcv=PIN_B1,bits=8,stream=RADIO2)
#int_TIMER2 // Radio 2 Ping Pong Buffer
void TIMER2_isr()
{
if (kbhit(Radio2))
{
Radio2Char=fgetc(Radio2);
radio2_flag_bufferfull=1;
}
setup_timer_2(T2_DIV_BY_1,4,10);
if (Radio2_flag_bufferfull==1)
{
radio2_flag_bufferfull=0;
fprintf(Radio2, "%d", Radio2Char);
}
|
But all i get from the serial port is bad data
for example if i send a K i get 25 chars rx from the pic?????
If i disable the Timer2 the TX of the serial all works ok
I have the same code running on a 16F876A with no problems
Please help
Colin |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Fri May 05, 2006 10:36 am |
|
|
Pls could you tell us whatīs the reason to expect a char just arriving inside the #int_TIMER2 "time window" ?
Why you didnīt use the built-in hardware UART ?
baud=9600,parity=N,xmit=PIN_B5,rcv=PIN_B2
Humberto |
|
|
colin_turner99
Joined: 24 Nov 2005 Posts: 7
|
|
Posted: Sat May 06, 2006 10:37 am |
|
|
Hi I am also using the Hardware port for RS232 as well
The window should be the time for 1 char to be sent at 9600
The code works on a 16F876A with no problems
Colin |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Sat May 06, 2006 1:58 pm |
|
|
Your code shows that you are trying to receive a char at regular intervals, not to transmit. To do it in such way you should synchronize the timer with an event coming from the transmitter or use the edge detecting capabilities of the INT_EXT module.
For a software UART you should use kbhit() prior to getc() to test if a char is arriving.
Humberto |
|
|
|