|
|
View previous topic :: View next topic |
Author |
Message |
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
questtion on a software RS232 and unused pin |
Posted: Tue Jan 04, 2005 5:39 pm |
|
|
Using a 16F877 @ 16 MhZ and CCS 3.214
Why would adding an unused pin to this program make it work.
Code: | #use rs232(baud=9600,xmit=PIN_A2,errors,invert,stream=DEBUG)
|
when changed to this
Code: | #use rs232(baud=9600,xmit=PIN_A2,rcv=PIN_A3,errors,invert,stream=DEBUG)
|
makes it work, ... but I don't use the rcv pin??
stream U13 is rcv serial data from another PIC (B0 tied to B0) without a pull up or anything.
Code: |
#include <16f877.h>
#device *=16
#case
#use delay(clock=16000000,RESTART_WDT)
#fuses hs,nowdt,noprotect,nolvp
#define VER_MAJOR 1
#define VER_MINOR 00
#use rs232(baud=9600,xmit=PIN_A2,rcv=PIN_A3,errors,invert,stream=DEBUG)
#use rs232(baud=9600,rcv=PIN_B0,errors,stream=U13)
#zero_ram
char getaddress(void);
void main(void)
{
int8 myaddr;
setup_adc_ports(NO_ANALOGS);
disable_interrupts(GLOBAL);
set_tris_a(0xFF);
set_tris_b(0xFF);
set_tris_c(0xFF);
set_tris_d(0xFF);
set_tris_e(0xFF);
//--------- START -------//
fprintf(DEBUG,"STARTING U11\n\r");
fprintf(DEBUG,"FIRMWARE VERSION %u.%02u\n\r",VER_MAJOR,VER_MINOR);
myaddr=getaddress();
fprintf(DEBUG,"MyAddr=%U or 0x%X\r\n",myaddr,myaddr);
while(TRUE)
{
;
}
}
char getaddress(void)
{
int8 addr[4];
do
{
if (kbhit()) addr[0]=fgetc(U13);//new value read into 0
if (kbhit()) addr[1]=fgetc(U13);//new value read into 1
if (kbhit()) addr[2]=fgetc(U13);//new value read into 2
if (kbhit()) addr[3]=fgetc(U13);//new value read into 3
fprintf(DEBUG,"%U %U %U %U\r\n",addr[0],addr[1],addr[2],addr[3]);
}while(addr[0]!=addr[1] ||
addr[0]!=addr[2] ||
addr[0]!=addr[3]);//look for 4 addr that are the same
return(addr[0]);
} |
with the extra RCV pin define my code works and a 0x131 is seen on stream U13. Without it I get a 17. ???/
The change is just in my debug code.
And somehow changes the data I see on stream U13.
This just doesn't make sense. |
|
|
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Tue Jan 04, 2005 5:59 pm |
|
|
--
Last edited by treitmey on Wed Jan 05, 2005 9:32 am; edited 1 time in total |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Wed Jan 05, 2005 2:31 am |
|
|
Your change making the code work is just coincidence, both versions are wrong.
Error 1: You are calling kbhit() without specifying which stream to use. From the manual: Quote: | If the stream parameter is not included, the function uses the primary stream used by getc(). | In your first version no I/O-pin is defined for your primary stream, resulting in undefined behaviour. The second version has the rx-pin defined, but for the wrong stream. Both versions shouldn't work....
Error 2: The kbhit() function is non-blocking, addr[0], 1, 2 and 3 are not synchronized and will (potentially) read garbage data.
Solution: Remove all kbhit() calls.
Code: | char getaddress(void)
{
int8 addr[4];
do
{
addr[0]=fgetc(U13);//new value read into 0
addr[1]=fgetc(U13);//new value read into 1
addr[2]=fgetc(U13);//new value read into 2
addr[3]=fgetc(U13);//new value read into 3
fprintf(DEBUG,"%U %U %U %U\r\n",addr[0],addr[1],addr[2],addr[3]);
}while(addr[0]!=addr[1] ||
addr[0]!=addr[2] ||
addr[0]!=addr[3]);//look for 4 addr that are the same
return(addr[0]);
} |
|
|
|
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Wed Jan 05, 2005 8:41 am |
|
|
Thanks for finding the error.
I don't use kbhit often. Should have know that would be the problem.
That was pretty obvious, I just needed to get away from the problem for a while. |
|
|
|
|
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
|