Buy an Axon, Axon II, or Axon Mote and build a great robot, while helping to support SoR.
0 Members and 1 Guest are viewing this topic.
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; } } }
int getByte(void){ while((UCSR0A&(1<<RXC0)) == 0); // Wait until a byte has been received return UDR; // Return received data}
while(1) { uart0SendByte(1); uart0SendByte(49); delay_ms(10);}
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?
// **** 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
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 } }
while ((!c) & (cc< UART_timeout) & (!error)){ // wait for low nibble to arrive on UART c = UARTin(); cc++; }
while((UCSR0A&(1<<RXC0)) == 0); // Wait until a byte has been received return UDR; // Return received data
How many possible combinations are there in binary( 8bits) that have an equal number of 1s and 0s ?
what should the timeout value be?
question: have you confirmed you can send a number like 10101010 yet? it would be worth checking this is indeed your problem.
Do a for loop (transmit a certain amount of times) for each of the valuesSend dummy byte a few times to mark a change in byteChange 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?)
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);}
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); } }}
22523277758824308849558874EDIT: shortened for content
while(1){SendByte(15); // 0F in hexSendByte(16); // 10 in hex }
void SendByte(char c) { while (!(UCSR0A & (1<<UDRE0))); UDR0 = c;}
while(1) { data = uart0GetByte(); uart1SendByte(data); }
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
and what if you keep that receive program and just repeatedly send 0xAA ? (ie, binary 10101010)dunk.
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
so it works properly for 10101010 but not any other sequence?
void SendByte(char c) { while (!(UCSR0A & (1<<UDRE0))); // wait until you are able to send a byte UDR0 = c;}
int GetByte0(void){ while((UCSR0A&(1<<RXC0)) == 0); // wait until a byte is received return UDR0;}
SendByte(data1); //55SendByte(data2); //56SendByte(data3); //59SendByte(data4); //5A
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
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).
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
SendByte(0); //0 - a dummy byte that we don't care if its lost SendByte(data1); //55SendByte(data2); //56SendByte(data3); //59SendByte(0); //0 - a dummy byte that we don't care if its lost