View previous topic :: View next topic |
Author |
Message |
DanX Guest
|
Processing data from a RF module |
Posted: Tue Jun 06, 2006 3:10 pm |
|
|
Whenever the transmitter is not transmitting, I get alot of garbage from my RX module. I'm sending an ascii message and it looks like this
UUU + (manchester encoded byte or 16bit)+UUU.
Is using Kbhit to poll for incoming serial data a good idea in this case? I tried it and it seems to freeze up my pic.
I'm trying to intercept my ascii message, parse it and decode the manchester encoded byte. |
|
|
danX Guest
|
|
Posted: Tue Jun 06, 2006 3:15 pm |
|
|
the thing making it hard is all the garbage characters going into the pic. THe pic seems overwhelm or something.
Right now i'm just trying to see if I can intercept the message and prints it to the screen. No decoding is done.
Code: | #include <16F88.h>
#device adc=8
#fuses XT,NOWDT,PROTECT,NOBROWNOUT,PUT,NOMCLR
#use delay (clock=4000000)
#use rs232(baud=14400, xmit=PIN_B5, rcv=PIN_B2)
#define uint8 char
#define uint16 long
uint16 man_encode(uint8 unenc);
uint8 man_decode(uint16 enc);
char string[20];
int receive_error=0;
main()
{
uint16 encoded=0;
uint8 decoded=0;
while(1)
{
if(kbhit()&& (getc()=='U'))
{
gets(string);
}
printf(string);
output_high(PIN_B4);
delay_ms(500);
output_low(PIN_B4);
delay_ms(500);
}
}
uint16 man_encode(uint8 unenc) {
uint8 odd_byte,even_byte,temp;
odd_byte=unenc&0xAA;
temp=(~unenc&0xAA)>>1;
odd_byte=odd_byte|temp;
even_byte=unenc&0x55;
temp=(~unenc&0x55)<<1;
even_byte=even_byte|temp;
return((uint16)odd_byte<<8)|even_byte;
}
uint8 man_decode(uint16 enc) {
uint8 odd_byte,even_byte,temp;
odd_byte=(uint8)(enc>>8);
if((odd_byte&0xAA)^((~odd_byte&0x55)<<1)) {
receive_error=1;
return(0);
} else odd_byte&=0xAA;
even_byte=(uint8)enc;
if((even_byte&0x55)^((~even_byte&0xAA)>>1)) {
receive_error=1;
return(0);
} else even_byte&=0x55;
receive_error=0;
return(odd_byte|even_byte);
}
|
|
|
|
DanX Guest
|
|
Posted: Tue Jun 06, 2006 3:17 pm |
|
|
My message
UUU + (manchester encoded byte or 16bit)+UUU
does have a '\r' at the end. |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1907
|
|
|
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Tue Jun 06, 2006 4:17 pm |
|
|
Have you thought about using the RDA interrupt instead of trying to poll for characters inside of main()? That's what the hardware's there for. |
|
|
DANX Guest
|
|
Posted: Tue Jun 06, 2006 4:54 pm |
|
|
"forum/viewtopic.php?t=23953"
how can this code work without using manchester encoding? Maybe for expensive modules that doesn't require DC balance?
The module that i'm using require DC balance signal |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1907
|
|
Posted: Tue Jun 06, 2006 5:07 pm |
|
|
DANX wrote: | "forum/viewtopic.php?t=23953"
how can this code work without using manchester encoding? Maybe for expensive modules that doesn't require DC balance?
The module that i'm using require DC balance signal |
Try it first. If it doesn't work, then do a pseudo-manchester type of transmission by inserting "U" between each character you send. Discard the "U"s in the receiver.
Long story short: don't try to reinvent the wheel. |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
|
|