Hi I've been fiddeling a lot with getting a "serial-link" between to PICce512's using a RF-transmitter/receiver to work. I would greatly appreciate any help I could get :). I have written two simple functions that are supposed to work with each other, but they're not quite working :/ The protocol I intend to use is as simples as follows: [space period] - [high clock] (to indicate start of data) - [low clock] - [data clock] - [high clock] and it then repeats everything except the space preriod for as long as I send my data, which is currently 16 bits long. I use the freeware version of CC5X Watchdog timer is enabled for the sendning device and disabled for the receiving one. I use the internal RC-osciallator. //Martin Johansson Here is my code for the functions: Code for calling SendSerial looks like this: while (GPIO.5 == 1) // Check for sending condition { EnableTransmitter(); // Power-up the transmitter. Blink(); // Sound the alarm. for (i=0;i<10;i++) // Send the serial number 10 times. { delay_ms(10); SendSerial(); // Send the data. clrwdt(); // Keep WDT cleared while transmitting. //-------------------------------------------------------------------------- - // FUNCTION: SendSerial // PURPOSE: Send serial number indicating alarm condition. // ARGS: None. // RETURNS: None. // COMMENTS: //-------------------------------------------------------------------------- - void SendSerial() { uns8 BitNumber, BitToSend, test; uns16 DataOut, DataMask ; DataOut = SerialNumber; // First, put line high to indicate beginning of data GPIO.1 = 1; // Then, wait for some time clrwdt(); delay_us(500); // Now start the cycle of data transmission for(BitNumber=0; BitNumber < 16 ; BitNumber++) // 16 bits of data to be transfered. { //---First clock is low--- GPIO.1 = 0; clrwdt(); delay_us(500); //---Second clock is data--- //Create data mask for this bit DataMask=1; DataMask = DataMask << BitNumber; //Decide if current bit is 0 or 1 test = DataOut & DataMask; if( test > 0) GPIO.1 = 1; else GPIO.1 = 0; //Set data line according to serialnumber // GPIO.1 = BitToSend; //Wait for third clock clrwdt(); delay_us(500); //---The third clock is high--- GPIO.1 = 1; //Wait for third clock to expire clrwdt(); delay_us(500); } GPIO.1 = 0; // Set data line low again } and the functions that are supposed to receive data looks like this: /--------------------------------------------------------------------------- // FUNCTION: GetSerial // PURPOSE: Watches for data stream from receiver. // ARGS: None // RETURNS: TRUE, if matching serial number is received. // COMMENTS: //-------------------------------------------------------------------------- - int GetSerial() { uns8 i,BitNumber, temp1, temp2; uns16 ReceivedSerial, BitMask; ReceivedSerial = 0; // Init incoming data variable // Wait for data line to go low, which it _should_ do within 500us blink(); delay_ms(250); blink(); delay_ms(1000); for(i=0; i < 50; i++) { if(GPIO.2 == 0) // If data line goes low we continue break; delay_us(50); } if(i >= 50) return 0; //Data line has not gone low and we timeout (exit function, return 0) // Data line has gone low, we now have to decide whever or not we're in the beginning of transmission // A clock is approx 500us (probably more in reality) for(i=0; i < 200; i++) //We require line to be low at least 5ms for us to consider data { if(GPIO.2) break; delay_us(25); } if( i < 70 ) return 0; // Line was not low long enough, thus we exit // We have reached this far which means we're in the beginning of a "new" data transmission, hurra! delay_ms(400); blink(); delay_ms(400); while(!GPIO.2) ; // We wait for "Startbit" while(GPIO.2) ; // First clock is low, then comes data. for(BitNumber=0; BitNumber < 16; BitNumber++) { delay_us(750); // We should now be in the middle of the data clock // 500us for first low clock + 250 to get into the data clock // Here comes data, catch it! if(GPIO.2) { BitMask = 1; BitMask = BitMask << BitNumber; // Create bitmask according to a '1' ReceivedSerial = ReceivedSerial | BitMask; } // If data line was low, we do nothing with ReceivedSerial and continue delay_us(300); // Get into the third (low) clock while(GPIO.2) ; // Last clock is high! } // Receive next bit, or continue if buffer is full (16 bits are received) /* COMPARE */ temp1 = ReceivedSerial.low8; temp2 = SerialNumber.low8; if ( temp1 == temp2 ) { temp1=ReceivedSerial.high8; temp2=SerialNumber.high8; if(temp1 == temp2){ return 1; } else return 0; } else return 0; } The very (maybe too?) simple delay routines I use looks like this. void delay_us(uns16 num) { int b; for(b=0;buP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads