SparkFun Forums 

Where electronics enthusiasts find answers.

All things pertaining to wireless and RF links
By hookups1534
#25697
Hi all, i am new to the spark fun forum and have been reading alot. here is my problem, i am interfacing the RLP transmitter and reicever to two MC9S12DP256's through the SCI ports. i have been working at this for a while now and have been reseaching alot. i am pretty frustrated. i wrote and pieced together some software by reading this forum and using your guys ideas. The problem is i cant get them to communicate. The reciever gives nothing when i run the software. i transmit the data in a neverending loop and always recieve data in a never ending loop. i think my problem might be baud related. i am running the reciever at 24Mhz using the on chip PLL and the transmitter at 4Mhz off the boards crystal. Please help, i will give more info if anyone thinks they can help me. Does anyone have experience interfacing these to HCS12's . Also i have bought two nRF24L01's and plan to do those next after these modules communicate. Here is the trans, reci code. Thanks and please give any advice.
Code: Select all
//reciever main

#include "J_SCI0.h"
#include "DBug12.h"
#include "mc9s12dp256.h"
#include "pll.h"
#include "J_SCI1.h"


#define RDRF 0x20   // Receive Data Register Full Bit

unsigned char recieve(void) ;
unsigned char getData(void);

void main(void) { 
   
   
   unsigned char byte; 
   unsigned char test[3] = {0x59, 0x4A, 0xB2}; 
   unsigned char i; 

  // Setup reciever 

  PLL_Init();
  SCI0_Init();
  SCI1_Init();
  SCI0_OutString("Welcome to Reciever");
  SCI0_OutChar(CR);
  SCI0_OutChar(LF);


   while( 1 ) { // Loop, forever receiving data 
      
       
      i = 0; 
      while( i < 3) { 
	 
         if( (SCI1SR1 & RDRF) == 1)
	   { 
            byte = SCI1_InChar(); 
             
         
             
            if( byte != test[i] ) 
               break; 
             
            i++; 
         } 
      } //end inside while 
       
      if( i == 3 ) { 
        
         byte = getData(); // Should check for error (check i) 
  //       byte = getData(i); // Should check for error (check i) 
        

         SCI0_OutString("Data Recieved");
         SCI0_OutChar(CR);
         SCI0_OutChar(LF);


         SCI0_OutChar(byte);

      } //end if( i == 3 )
       
      
  
    } //end outside while


  
  


} 

/* ---- Get Data ---- */ 


unsigned char getData(void) { //was "unsigned char *error"
   unsigned char odd, even; 

   odd = SCI1_InChar(); 
   even = SCI1_InChar(); 
    
   if( (odd & 0xAA) ^ ((~odd & 0x55) << 1) ) { 
//      *error = 1; 
      return 0; 
   } else 
      odd &= 0xAA; 
   if( (even & 0x55) ^ ((~even & 0xAA) >> 1) ) { 
//      *error = 1; 
      return 0; 
   } else 
      even &= 0x55; 
    
//   *error = 0; 
    
   return odd | even; 
} 











//transmitter main

#include "J_SCI0.h"
//#include "DBug12.h"
#include "mc9s12dp256.h"
//#include "pll.h"
#include "J_SCI1.h"




/* * * 
 * Transmitter Code 
 */ 
void sendData(const unsigned char *data, const unsigned char size);




void main(void) { 
   unsigned char dat[2] = {0x0F, 0xF0}; 
   int i = 0;
   int dly_time = 500;

  // Setup transmitter 

//  PLL_Init();
  SCI0_Init();
  SCI1_Init();
  SCI0_OutString("Welcome to Transmitter");
  SCI0_OutChar(CR);
  SCI0_OutChar(LF);


 while(1){       //loop forever sending data
  
  sendData(dat, 2); 

  SCI0_OutString("Data Sent");
  SCI0_OutChar(CR);
  SCI0_OutChar(LF);
  
  for(i=0;i<dly_time;i++){}   //delay
  }

}

/* ---- Send Data ---- */ 


void sendData(const unsigned char *data, const unsigned char size) { 
   unsigned char i; 
    
   
    
   /* Send preamble */ 
   for( i = 0; i < 5; i++ ) { 
      SCI1_OutChar(0x55); 
      
   } 
   /* Send framing fix */ 
   SCI1_OutChar(0x44); 
  
   SCI1_OutChar(0x11); 
   
   SCI1_OutChar(0x45); 
    
   SCI1_OutChar(0x15); 
   
    
   /* Send identification code */ 
   SCI1_OutChar(0x59); 
   
   SCI1_OutChar(0x4A); 
    
   SCI1_OutChar(0xB2); 
   
    
   /* Send data */ 
   for( i = 0; i < size; i++ ) { 
      SCI1_OutChar((data[i] & 0xAA) | (~data[i] & 0xAA) >> 1); 
      
      SCI1_OutChar((data[i] & 0x55) | (~data[i] & 0x55) << 1); 
     
   } 
  

   //Write Delay...........

  
  
} 
 
 

The are header files for SCI support and PLL support. Thanks guys.

[quote][/quote]
By saipan59
#25715
I did not try to figure out if your code is OK or not (that takes a lot of time), but I would suggest that you start by removing the RF modules from the picture, and see if you can make the MCU's communicate over a wire. After that works, you should be real close to making the overall link work.

Note that some RF receiver modules won't output anything if the signal is too strong. Try moving the xmtr and rcvr several feet apart.

Pete
By hookups1534
#25778
Hey thanks pete, i am currently getting the link working with a wire across it. you were right it doesnt even work with a wire right now. i think its baud related. What baud did you use for your link. would you give up some code? Thanks for your response.
By reklipz
#25804
Hey guys!

Well, that code is basically the same as what I'm using for my RLP / TLP combo (I believe it is actually the same code I posted in another thread, just modified a bit, which is totally cool, thats why I posted it!).

From what I can see, the code looks like it should work fine.

The code that I am using, which is the same as what I've posted, works fine for me over the wireless link. The only weird thing is that I remember trying it over the USART with wires, and it didnt work! It would only work over the RF link.

What I suggest you do is add some LEDs so you can see how far the receiver gets, or add some echos over RS232 to the computer as at 24MHz the LEDs will be a tad hard to see flash (especially for the ones you will be interested in).

BTW, I'm running my modules at something like 3600baud (3670 something really, but the receiver and transmitter are both the same).

-Nate
By hookups1534
#25842
Hey thanks nate and pete, you guys have really helped me out. I am taking your advice and should have this thing up and running soon. About the code, i did copy and paste it from this forum because the code i wrote did not work and i decided i needed new ideas so i went into the forum. So you say your link did not work with a wire, thats weird. My link doesnt either. When i run the program, my transmitter outputs the data but the reciever does nothing. I checked the data register for my UART and there was nothing in it. Some thing is wrong. I even thought that i burned out my reciever and trans. so i bought new ones and hooked them up and still nothing. Well i will keep you guys posted, thanks so much for your help i really appreciate it. I will let you know when i get it to work.