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.
//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.