go away spammer

Author Topic: Sending packets of data through RF UART  (Read 27484 times)

0 Members and 1 Guest are viewing this topic.

Offline airman00Topic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 3,650
  • Helpful? 21
  • narobo.com
    • Narobo.com - Mechatronics and related
Sending packets of data through RF UART
« on: October 16, 2008, 04:56:38 AM »
This has  been troubling me for quite a while

I have a RF Tx/Rx pair that act as a UART link.  I want to send a packet of 2 bytes and have it receive it and process it . I've tried it over and over but it doesn't seem to work!   I know the UART is working because if I have it check for only one byte continuously it will get it ( its not interference because when I change the data value to turn on different LEDs it works)

I checked the baud and its correct(both set to use 2400) . The receiver's MCU is an ATmega168 running at 8mhz , the transmitter's MCU is the Axon micocontroller running at 16mhz.

Here is some simple code for receiving a packet of only two bytes  . The yellow LED turns on sometimes but the red is never on.

Code: [Select]
while(1){
RADDR = getByte(); // get address byte
data = getByte(); // get data byte

if (RADDR == 1) // check if address byte is equal to 1
  {                       
yellow_on; // turn on yellow LED
if (data == 49) // Check if the received data is equal to 49
{
red_on;
}
   }
}
The getByte() subroutine is as follows:
Code: [Select]
int getByte(void)
{
    while((UCSR0A&(1<<RXC0)) == 0);        // Wait until a byte has been received
   return UDR;  // Return received data
}

On the transmitter end all that I am doing is this :
Code: [Select]
while(1)
{
uart0SendByte(1);
uart0SendByte(49);
delay_ms(10);
}
« Last Edit: October 16, 2008, 05:00:08 AM by airman00 »
Check out the Roboduino, Arduino-compatible board!


Link: http://curiousinventor.com/kits/roboduino

www.Narobo.com

Offline dunk

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 1,086
  • Helpful? 21
    • dunk's robot
Re: Sending packets of data through RF UART
« Reply #1 on: October 16, 2008, 06:13:24 AM »
most RF RX/TX pairs are optimised for manchester encoding. http://en.wikipedia.org/wiki/Differential_Manchester_encoding
in short, it is good practice when deailing with RF signals to transmit an even number of "1"s and "0"s.
this means your power output level is the same no matter what value you are transmitting. it also provides some form of error checking.

it dose mean it's not as simple as just connecting your UART to your TX module though.

to confirm this is the problem you are facing try transmitting "10101010" via the UART and see if that gets through.

i started documenting my solution to the issue but never finished it.
you can have a look here if you are willing to put up with my spelling mistakes and an unfinished format: http://mrdunk.googlepages.com/rflinkbetweenavrs .


dunk.

Offline airman00Topic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 3,650
  • Helpful? 21
  • narobo.com
    • Narobo.com - Mechatronics and related
Re: Sending packets of data through RF UART
« Reply #2 on: October 16, 2008, 06:16:37 AM »
I found this if it helps anyone
http://winavr.scienceprog.com/example-avr-projects/running-tx433-and-rx433-rf-modules-with-avr-microcontrollers.html 

@dunk
Thanks! I'm going to to try it out now
Check out the Roboduino, Arduino-compatible board!


Link: http://curiousinventor.com/kits/roboduino

www.Narobo.com

Offline airman00Topic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 3,650
  • Helpful? 21
  • narobo.com
    • Narobo.com - Mechatronics and related
Re: Sending packets of data through RF UART
« Reply #3 on: October 16, 2008, 06:18:03 AM »
also dunk
how well did your RF link work using your solution? How much range did you get (approximately)?

Did you make your Manchester Encoder function already? Or should I make my own and post it online?
« Last Edit: October 16, 2008, 06:48:44 AM by airman00 »
Check out the Roboduino, Arduino-compatible board!


Link: http://curiousinventor.com/kits/roboduino

www.Narobo.com

Offline dunk

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 1,086
  • Helpful? 21
    • dunk's robot
Re: Sending packets of data through RF UART
« Reply #4 on: October 16, 2008, 07:55:48 AM »
Quote
how well did your RF link work using your solution? How much range did you get (approximately)?
i have not explored the range fully.
the RF modules i'm using are rated up to 1km and there was this one time when the wind decided it was taking my plane for a joyride i got close to that distance without loss of signal.
so i guess i'm saying you should get close to the rated distance of your RF modules.

Quote
Did you make your Manchester Encoder function already? Or should I make my own and post it online?
yea. made it. see below.
not particularly pretty but fairly human readable.
mine is not the full spec Manchester Encoding as it does not send the UART start bits compliment but it is close enough to work with my RF modules. i'd imagine it will work for yours too.

so in the comments in the following code a "nibble" is half a byte.
either the first 4 bits or the last 4.

TX:
Code: [Select]
        // **** Data. low nibble then high nibble to make full bite. ****
        // each data byte sent as pesudo manchester encoding so every bit is followed by inverse of the same bit.
        // this means every byte of data will need 2 byes to be transmitted on the UART.
        for (n=0;n<4;n++){                              // loop through low nibble of data2
                if(data & (1<<n)){                     
                        temp |= (1<<(n*2));            // set bit on n.
                        temp &= ~(1<<((n*2)+1));       // and set inverse of bit on n+1.
                }
                else{
                        temp &= ~(1<<(n*2));
                        temp |= (1<<((n*2)+1));
                }
        }
        UARTout(temp);                                 // transmit low nibble

        for (n=0;n<4;n++){                              // loop through high nibble of data2
                if(data & (1<<(n+4))){               
                        temp |= (1<<(n*2));            // set bit on n
                        temp &= ~(1<<((n*2)+1));       // and set inverse of bit on n+1
                }
                else{
                        temp &= ~(1<<(n*2));
                        temp |= (1<<((n*2)+1));
                }
        }
        UARTout(temp);                                 // transmit high nibble

RX:
Code: [Select]
        temp=0x00; c=0;cc=0;
        while ((!c) & (cc< UART_timeout) & (!error)){     // wait for low nibble to arrive on UART
                c = UARTin();
                cc++;
        }

        for (n=0;n<8;n+=2){
                if((c & (1<<n)) != (c & (1<<(n+1)))) {  // make sure n is opposite of n+1 (fake manchester encoding.)
                        if (c & (1<<n)){
                                temp |= 1<<(n/2);
                        }
                        else{
                                temp &= ~(1<<(n/2));
                        }
                }
                else{                                   // bit n not opposite of n+1. (ie. corruption has occured.)
                        error=1;                        // set error flag
                        //n=9;                            // and stop for loop.
                }
        }


        c=0;cc=0;
        while ((!c) & (cc< UART_timeout) & (!error)){      // wait for high nibble to arrive on UART
                c = UARTin();
                cc++;
        }

        for (n=0;n<8;n+=2){
                if((c & (1<<n)) != (c & (1<<(n+1)))) {
                        if (c & (1<<n)){
                            temp |= 1<<((n/2)+4);
                        }
                        else{
                           temp &= ~(1<<((n/2)+4));
                        }       
                }
                else{                                   // bit n not opposite of n+1. (ie. corruption has occured.)
                        error=1;                        // set error flag
                }
        }


dunk.

Offline airman00Topic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 3,650
  • Helpful? 21
  • narobo.com
    • Narobo.com - Mechatronics and related
Re: Sending packets of data through RF UART
« Reply #5 on: October 16, 2008, 08:20:40 AM »
thank you very much !

can someone explain what UART_timeout is?

EDIT:
Is this
Code: [Select]
while ((!c) & (cc< UART_timeout) & (!error)){     // wait for low nibble to arrive on UART
                c = UARTin();
                cc++;
        }

the equivalent of this:
Code: [Select]
while((UCSR0A&(1<<RXC0)) == 0);        // Wait until a byte has been received
   return UDR;  // Return received data
« Last Edit: October 16, 2008, 11:36:07 AM by airman00 »
Check out the Roboduino, Arduino-compatible board!


Link: http://curiousinventor.com/kits/roboduino

www.Narobo.com

Offline izua

  • Supreme Robot
  • *****
  • Posts: 682
  • Helpful? 0
    • izua electronics
Re: Sending packets of data through RF UART
« Reply #6 on: October 16, 2008, 11:38:55 AM »
use RXC0 checking instead of a timeout.
Check out my homepage for in depth tutorials on microcontrollers and electronics.

Offline dunk

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 1,086
  • Helpful? 21
    • dunk's robot
Re: Sending packets of data through RF UART
« Reply #7 on: October 16, 2008, 04:53:51 PM »
nope.
for my application i didn't want to use RXC0.
it is possible the preceding byte is in fact interference and there is no 2nd byte coming.
for that reason i increase cc every iteration of the while loop and if it ever reaches the value in UART_timeout then it continues (and flags an error when the encoding check fails).

what is missing from my RX code snippet is i actually started by sending and at the RX end testing for a start bit.
if you were going to use this code as is you would need to strip out the UART_timeout from the first nibble so the program waits there indefinitely..
you'd still want a timeout on the 2nd nibble though in case interference caused the code to pass the first nibble in error.


dunk.

Offline airman00Topic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 3,650
  • Helpful? 21
  • narobo.com
    • Narobo.com - Mechatronics and related
Re: Sending packets of data through RF UART
« Reply #8 on: October 16, 2008, 04:56:13 PM »
what should the timeout value be?

and also the data byte in my application has a possibility of only 125 values. Nothing more than that . Would it make sense to just use a long list of preprogrammed defines and each define having the Manchester-encoded byte.

How many possible  combinations are there in binary( 8bits) that have an equal number of 1s and 0s ? 
« Last Edit: October 17, 2008, 01:59:03 PM by airman00 »
Check out the Roboduino, Arduino-compatible board!


Link: http://curiousinventor.com/kits/roboduino

www.Narobo.com

Offline airman00Topic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 3,650
  • Helpful? 21
  • narobo.com
    • Narobo.com - Mechatronics and related
Re: Sending packets of data through RF UART
« Reply #9 on: October 18, 2008, 06:28:51 PM »
How many possible  combinations are there in binary( 8bits) that have an equal number of 1s and 0s ? 
Let me just answer my own question here.

I asked on VBforums for code to generate the appropriate numbers and it turns out there are 70 combinations. I guess I have to do Manchester Encoding( unless I reduce the number of possible values , which would probably happen anyways)

Here is the code in VB6 for those who want it: http://www.vbforums.com/showpost.php?p=3359427&postcount=7
« Last Edit: October 18, 2008, 06:30:15 PM by airman00 »
Check out the Roboduino, Arduino-compatible board!


Link: http://curiousinventor.com/kits/roboduino

www.Narobo.com

Offline dunk

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 1,086
  • Helpful? 21
    • dunk's robot
Re: Sending packets of data through RF UART
« Reply #10 on: October 19, 2008, 03:45:39 AM »
Quote
what should the timeout value be?
obviously it depends on your clock speed and baud rate.
i found mine by trial and error. (start high so it definitely only times out when there is an error and decrease the value until it stops working properly.)

Quote
How many possible  combinations are there in binary( 8bits) that have an equal number of 1s and 0s ? 
i'm afraid you don't have this part quite right yet. my initial description of manchester encoding was too limited.
so for manchester encoding each bit bust be followed by it's compliment. (ie if you send a "1" the next bit must be a "0" and vice versa.) this gives 16 possible combinations.

i'm not saying you need true manchester encoding. it depends what your RF modules will do.

on the RF modules i was using the binary number 11110000 would not work.
11011011 would work 75% of the time.
11010100 would always work (even though it's not manchester encoded).
i implemented manchester encoding partly because of the built in error checking.

if you just want a lookup table with 125 values i suggest you start testing 8 bit numbers and seeing which ones work. while there would not have been 125 values for my RF modules there may be for yours.

question: have you confirmed you can send a number like 10101010 yet?
it would be worth checking this is indeed your problem.


dunk.

Offline airman00Topic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 3,650
  • Helpful? 21
  • narobo.com
    • Narobo.com - Mechatronics and related
Re: Sending packets of data through RF UART
« Reply #11 on: October 19, 2008, 07:13:53 AM »

question: have you confirmed you can send a number like 10101010 yet?
it would be worth checking this is indeed your problem.
yep I sent that byte and it got it perfectly

whats interesting to note is that almost all of the "noise" values had an equal number of 1s and 0s.

Another thing which I might try is to constantly send a dummy byte ( it has no function , except keep the Rx on tune) and then once I need to send the real data it will pick it up right away. From my tests it seems that if I do this there will be minimal noise.

My applications demand got even lower. I need to send a color code to a receiver which shows that color on a RGB LED. So I guess I'll test out the 70 binary numbers my VB program generated and find the 45 best that work.
 I will test it out as follows :
Code: [Select]
Do a for loop (transmit a certain amount of times) for each of the values
Send dummy byte a few times to mark a change in byte
Change the byte sent and do a for loop
Repeat for all the bytes (0-255 or maybe I should just do the 70 numbers generated by the VB program?)
Check out the Roboduino, Arduino-compatible board!


Link: http://curiousinventor.com/kits/roboduino

www.Narobo.com

Offline airman00Topic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 3,650
  • Helpful? 21
  • narobo.com
    • Narobo.com - Mechatronics and related
Re: Sending packets of data through RF UART
« Reply #12 on: October 19, 2008, 12:21:15 PM »
he he

I upped the voltage on the transmitter from 5V to 12V. It now gets literally everything - from 0 to 255.
I did some tests(the for loop of sending numbers from 0 to 255) from the 1st floor of my house to the second floor and it got everything I sent to it.

 I'm all about eliminating error , so do you think I should do Manchester Style bytes anyways, just in case I might have some sort of error?

Here is the link to the Tx/Rx pair by the way : http://www.sparkfun.com/commerce/product_info.php?products_id=7816
Is that specific pair manchester encoding optimized?

Check out the Roboduino, Arduino-compatible board!


Link: http://curiousinventor.com/kits/roboduino

www.Narobo.com

Offline airman00Topic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 3,650
  • Helpful? 21
  • narobo.com
    • Narobo.com - Mechatronics and related
Re: Sending packets of data through RF UART
« Reply #13 on: October 19, 2008, 08:39:01 PM »
I have another issue

OK heres my setup now : Transmitter is running the following code and sending a packet continuously
Code: [Select]
dummy = 99;
RADDR = 68;
data = 17;
checksum = RADDR + data;

while(1)
{
delay_ms(1);
uart0SendByte(dummy);
delay_ms(1);
uart0SendByte(RADDR);
delay_ms(1);
uart0SendByte(data);
delay_ms(1);
uart0SendByte(checksum);
}

The receiver is receiving the values from the receiver and right away sending it through USB to my terminal windows

In the terminal window I see crap values for a while and then all of sudden the correct bytes are seen except that they are each shown too many times. A packet is supposed to be [ 99,68,17,85] . What happens is that each byte of that packet is copied multiple times so its like [99,99,99......99,68,68,68...... , etc.]

It also seems like the packet is getting received backwards. look at the log below, its received in the following order 85,17,68,99
Anyone know how to fix this and have a proper byte sent?

Here is the log of the values sent through USB ( note that values are in decimal )
EDIT : Log removed since it was too long and is shown later on in this post
« Last Edit: October 23, 2008, 05:46:11 PM by airman00 »
Check out the Roboduino, Arduino-compatible board!


Link: http://curiousinventor.com/kits/roboduino

www.Narobo.com

Offline dunk

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 1,086
  • Helpful? 21
    • dunk's robot
Re: Sending packets of data through RF UART
« Reply #14 on: October 20, 2008, 01:12:51 PM »
are you sure your program at the receiver end is pausing until it receives a new character rather than just reading what's in the buffer?
that would not explain the order being reversed though....

i'd try a program like this at the transmitter end if i was looking for weird timing issues:
Code: [Select]
while(1){
   for(t = 0; t < 255; t++){                             // increase number of ms between TXs.
      for(i = 0; i < 255; i++){                            // print a string of values from 0 to 255. (easier to see a pattern this way.)
         uart0SendByte(t);
         delay_ms(t);
         uart0SendByte(i);
         delay_ms(t);
      }
   }
}


dunk.

Offline airman00Topic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 3,650
  • Helpful? 21
  • narobo.com
    • Narobo.com - Mechatronics and related
Re: Sending packets of data through RF UART
« Reply #15 on: October 20, 2008, 01:37:48 PM »
i tried what you said dunk and I got these numbers

Quote
225
232
7
7
7
5
8
8
24
30
8
8
49
55
8
8
74
EDIT: shortened for content
« Last Edit: October 23, 2008, 05:46:46 PM by airman00 »
Check out the Roboduino, Arduino-compatible board!


Link: http://curiousinventor.com/kits/roboduino

www.Narobo.com

Offline airman00Topic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 3,650
  • Helpful? 21
  • narobo.com
    • Narobo.com - Mechatronics and related
Re: Sending packets of data through RF UART
« Reply #16 on: October 20, 2008, 02:46:30 PM »
When the transmitter runs this code:

Code: [Select]
while(1){
SendByte(15);   // 0F in hex
SendByte(16);  // 10 in hex
 }

The macro for SendByte was recommended by AVRfreaks so that way its not AVRlib dependant
Code: [Select]
void SendByte(char c) {
  while (!(UCSR0A & (1<<UDRE0)));
  UDR0 = c;
}

I get all the packets and then all of a sudden it just shows FF  (255 in decimal ) and occasionally the proper bytes pop up among the FF.

Is this an error because of the transmitter? or maybe its from the receiver which is just taking in bytes and sending it through USB
Receiver uses this code:
Code: [Select]
while(1)
{
data = uart0GetByte();
uart1SendByte(data);
}

Heres a log of what happens
Code: [Select]
0F 10 0F 10 0F 10 0F 10 0F 10 0F 10 0F 10 0F 10 0F 10 0F 10 0F 10 0F 10 0F 10 0F 10 0F 10 0F 10 0F 10 0F 10 0F 10 0F 10 0F 10 0F 10 0F 10 0F 10 0F 10 0F 10 0F 10 0F 10 0F 10 0F 10 0F 10 0F 10 0F 10 0F 10 0F 10 0F 10 0F 10 0F 10 0F 10 0F 10 0F 10 0F 10 0F 10 0F 10 0F 10 0F 10 0F 10 0F 10 0F 10 0F 10 0F 10 0F 10 0F 10 0F 10 0F 10 0F 10 0F 10 0F 10 0F 10 0F 10 0F 10 0F 10 0F 10 0F 10 0F 10 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF 0F FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF 10 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF 0F FF FF                                                       
Check out the Roboduino, Arduino-compatible board!


Link: http://curiousinventor.com/kits/roboduino

www.Narobo.com

Offline dunk

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 1,086
  • Helpful? 21
    • dunk's robot
Re: Sending packets of data through RF UART
« Reply #17 on: October 20, 2008, 06:03:03 PM »
and what if you keep that receive program and just repeatedly send 0xAA ?
(ie, binary 10101010)

dunk.

Offline airman00Topic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 3,650
  • Helpful? 21
  • narobo.com
    • Narobo.com - Mechatronics and related
Re: Sending packets of data through RF UART
« Reply #18 on: October 21, 2008, 06:23:46 PM »
and what if you keep that receive program and just repeatedly send 0xAA ?
(ie, binary 10101010)

dunk.
then i get only 0xAA and no FF ( which is 255)

Any idea why the FF pops up when I send two bytes?

« Last Edit: October 21, 2008, 06:24:18 PM by airman00 »
Check out the Roboduino, Arduino-compatible board!


Link: http://curiousinventor.com/kits/roboduino

www.Narobo.com

Offline dunk

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 1,086
  • Helpful? 21
    • dunk's robot
Re: Sending packets of data through RF UART
« Reply #19 on: October 22, 2008, 02:34:29 AM »
sounds like you are back to the issue with the module needing to send manchester encoded data.

try sending a series of manchester encoded bytes and seeing if you have problems with that.
this is the full series:
01010101
01010110
01011001
01011010
01100101
01100110
01101001
01101010
10010101
10010110
10011001
10011010
10100101
10100110
10101001
10101010


dunk.

Offline airman00Topic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 3,650
  • Helpful? 21
  • narobo.com
    • Narobo.com - Mechatronics and related
Re: Sending packets of data through RF UART
« Reply #20 on: October 22, 2008, 05:50:12 PM »
tried what you said dunk , I still get the FF
Check out the Roboduino, Arduino-compatible board!


Link: http://curiousinventor.com/kits/roboduino

www.Narobo.com

Offline airman00Topic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 3,650
  • Helpful? 21
  • narobo.com
    • Narobo.com - Mechatronics and related
Re: Sending packets of data through RF UART
« Reply #21 on: October 22, 2008, 05:59:09 PM »
Here is some more details on the FF section

OK so after it receives the code correctly a few times then it starts to go into this:
Quote
FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF 55 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF 65 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF 95 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF A5 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF 55 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF 65 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF 95 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF A5 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF 55 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF 65 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF 95 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF A5 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF 55

Please note that between each correct byte there is an equal number of FF.  There are exactly 40 FF between each correct byte . Anybody know why?
Check out the Roboduino, Arduino-compatible board!


Link: http://curiousinventor.com/kits/roboduino

www.Narobo.com

Offline dunk

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 1,086
  • Helpful? 21
    • dunk's robot
Re: Sending packets of data through RF UART
« Reply #22 on: October 23, 2008, 03:21:33 AM »
so it works properly for 10101010 but not any other sequence?
weird. i'm out of ideas.

what happens if you reset your transmitter circuit while it's doing the FF sequence?

what happens if you reset your receiver circuit while it's doing the FF sequence?

what happens if you stop transmitting for a while then restart in the program at the transmitter end?
does it work for a while then revert to your FF pattern?


dunk.

Offline airman00Topic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 3,650
  • Helpful? 21
  • narobo.com
    • Narobo.com - Mechatronics and related
Re: Sending packets of data through RF UART
« Reply #23 on: October 23, 2008, 05:49:59 AM »
so it works properly for 10101010 but not any other sequence?

no it works fine whenever I send only one byte over and over. When I start sending more than one byte at a time , it starts with the FF.

As for your other questions I'm gonna try it out now.
Check out the Roboduino, Arduino-compatible board!


Link: http://curiousinventor.com/kits/roboduino

www.Narobo.com

Offline airman00Topic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 3,650
  • Helpful? 21
  • narobo.com
    • Narobo.com - Mechatronics and related
Re: Sending packets of data through RF UART
« Reply #24 on: October 23, 2008, 08:34:06 AM »
I figured it out a bit
I wrote my own routines for each of the GetByte and SendByte and the result was that I eliminated the FF. The reason for the FF was that each time the byte was read it was empty and returned a -1 -- which is shown FF in a character.

Here is my SendByte routine
Code: [Select]
void SendByte(char c) {
  while (!(UCSR0A & (1<<UDRE0)));  // wait until you are able to send a byte
  UDR0 = c;
}

Here is my getbyte routine
Code: [Select]
int GetByte0(void)
{
    while((UCSR0A&(1<<RXC0)) == 0); // wait until a byte is received
    return UDR0;
}


« Last Edit: October 23, 2008, 05:48:20 PM by airman00 »
Check out the Roboduino, Arduino-compatible board!


Link: http://curiousinventor.com/kits/roboduino

www.Narobo.com

Offline airman00Topic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 3,650
  • Helpful? 21
  • narobo.com
    • Narobo.com - Mechatronics and related
Re: Sending packets of data through RF UART
« Reply #25 on: October 23, 2008, 05:25:12 PM »
I did some more tests and it looks like  I get 138 correct 4 byte packets ( in correct order) in 30 seconds . Thats 552 bytes in 30 seconds and 18.4 bytes per second(147.2 bits per second).
I did another test , but this time for 1 minute long - in 1 minute it received the reverse packet ( 5A,59,56,55)   252 times - approximately the same values as my 30 second test.
Please note that I am running this at 2400 baud.

Btw the reason the test above had such good accuracy was because all the bytes received were received backwards - meaning the correct packet I intended to send was
Code: [Select]
SendByte(data1);  //55
SendByte(data2);  //56
SendByte(data3);  //59
SendByte(data4);  //5A

Issue #2:But in my log I received 5A, 59, 56, 55!  How come I'm getting it backwards???


Issue #3: Listen to this scenario - the transmitter is on and supposed to be sending (55,56,59,5A) . Now I turn on the receiver and it gets that whole reverse packet nonsense . Now I turn off the receiver and turn it back on. It keeps getting that nonsense . I turn it off and on once more ( note that the transmitter is still on) and it gets reverse character and reverse packet! Meaning now the correct packet is received as {A5 95 65 55 }

Part of my log:
Quote
65 A5 55 A5 65 95 65 55 A5 65 95 65 55 A5 65 95 65 55 A5 65 55 A5 55 A5 95 55 65 55 A5 95 55 65 55 A5 95 65 A5 55 A5 95 65 A5 55 A5 95 65 A5 55 A5 95 65 A5 95 A5 95 65 55 95 A5 95 65 55 95 A5 95 65 55 95 A5

Issue #4: Occasionally after turning on and off the receiver portion - but leaving the transmitter on and transmitting - I receive the hex number 69 instead of A5 . Note that this is only when I get the packets in reverse character and reverse packet
« Last Edit: October 23, 2008, 05:58:42 PM by airman00 »
Check out the Roboduino, Arduino-compatible board!


Link: http://curiousinventor.com/kits/roboduino

www.Narobo.com

Offline airman00Topic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 3,650
  • Helpful? 21
  • narobo.com
    • Narobo.com - Mechatronics and related
Re: Sending packets of data through RF UART
« Reply #26 on: October 23, 2008, 07:22:24 PM »
Quote
I did some more tests and it looks like  I get 138 correct 4 byte packets ( in correct order) in 30 seconds . Thats 552 bytes in 30 seconds and 18.4 bytes per second(147.2 bits per second).
Please note that in that test I got the reverse packet - A5 95 65 55  not the correct packet

Quote
Issue #4: Occasionally after turning on and off the receiver portion - but leaving the transmitter on and transmitting - I receive the hex number 69 instead of A5 . Note that this is only when I get the packets in reverse character and reverse packet
This means that each time an A5 is usually seen it is replaced by hex number 69. The A5 never shows up in that case
I can't seem to find the relationship between A5 and 69 - I dunno why it would be replaced.
« Last Edit: October 23, 2008, 07:33:36 PM by airman00 »
Check out the Roboduino, Arduino-compatible board!


Link: http://curiousinventor.com/kits/roboduino

www.Narobo.com

Offline airman00Topic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 3,650
  • Helpful? 21
  • narobo.com
    • Narobo.com - Mechatronics and related
Re: Sending packets of data through RF UART
« Reply #27 on: October 23, 2008, 08:31:18 PM »
I changed my transmit code to this:
Code: [Select]
SendByte(0);  //0  - a dummy byte that we don't care if its lost
SendByte(data1);  //55
SendByte(data2);  //56
SendByte(data3);  //59
SendByte(0);  //0  - a dummy byte that we don't care if its lost

Adding in a dummy byte of 0 basically fixed all my issues  - but I still don't know why those issues came up.
Also changed all baud rates to 4800.

I now get a correct 3 byte packet 586 times in 30 seconds - or 19.5 bytes per second. Total of 5307 bytes sent in 30 seconds and 1758 of those bytes were correct packets - so I guess 33% accuracy for a 3 byte packet - which kind of sucks.

Anything I can do to improve this accuracy even more?
« Last Edit: October 23, 2008, 08:36:12 PM by airman00 »
Check out the Roboduino, Arduino-compatible board!


Link: http://curiousinventor.com/kits/roboduino

www.Narobo.com

Offline dunk

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 1,086
  • Helpful? 21
    • dunk's robot
Re: Sending packets of data through RF UART
« Reply #28 on: October 24, 2008, 03:08:53 AM »
you should be getting far better speeds than that.

rather than send a 0x00 byte between packets what if you send no byte at all?
try putting a few ms pause between packets.

also, i presume you have tried putting a delay between bytes?

the module datasheet should tell you the optimum baud rate for the modules.
this value will *probably* be for manchester encoded data so half the value your UART is sending at.

let me know if you want to try my full RC firmware just to see if your modules behave any differently with my code.
i don't see why they would though. i can't see anything particularly different we are doing with the timing other than i have a delay between packets.


dunk.

Offline airman00Topic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 3,650
  • Helpful? 21
  • narobo.com
    • Narobo.com - Mechatronics and related
Re: Sending packets of data through RF UART
« Reply #29 on: October 24, 2008, 02:27:31 PM »
Heres what I tried, and here is my results (all tests were run at 4800 bps)

For the following combinations I the transmission is really crappy and I get less than 300 3 byte packets in 30 seconds.
0,55,56,59,0  with 10ms delay after each packet, with 5ms delay after each byte, with 3ms delay after each byte, with no delay at all
0,55,56,59 with 10ms delay after each packet, with 5ms delay after each packet ,with 5ms delay after each byte, with 3ms delay after each byte, with no delay at all

So far the best I've gotten is this combination :
0,55,56,59,0 with 5ms delay after each packet  and 852 correct 3 byte packets in 30 seconds  - 28.4 packets per second  == 85.2 bytes per second - still pretty crappy

I'm going to experiment with different delay times after each packet.


Datasheets are provided on this page for my receiver and transmitter : http://www.sparkfun.com/commerce/product_info.php?products_id=7816

Thanks dunk.
Check out the Roboduino, Arduino-compatible board!


Link: http://curiousinventor.com/kits/roboduino

www.Narobo.com

 


Get Your Ad Here