The answer to that question is NO; I don’t have a 20Mhz Xtal inside the TRF. I’ve modify that part: Now using 16Mhz. Thanks
As you can see is a transcription of a prev code posted by Steven Cholewiak. I thought that if I use that code, the dive will work correctly. This is the configuration header
byte Buffer_Config[15]; // Buffer for Configuration
byte BCp; // pointer for that buffer
#define numOfBytes
#define DATA2_W numOfBytes*8
#define DATA1_W numOfBytes*8
#define ADDR_CH2_4 0x10
#define ADDR_CH2_3 0x11
#define ADDR_CH2_2 0x42
#define ADDR_CH2_1 0x11
#define ADDR_CH2_0 0x42
#define ADDR_CH1_4 0x10
#define ADDR_CH1_3 0x11
#define ADDR_CH1_2 0x42
#define ADDR_CH1_1 0x11
#define ADDR_CH1_0 0x42
#define ADDR_W_5bytes 0xA0 //0b1010 0000
#define ADDR_W_4bytes 0x80 //0b1000 0000
#define ADDR_W_3bytes 0x60 //0b0110 0000
#define ADDR_W_2bytes 0x40 //0b01000000
#define ADDR_W_1bytes 0x20 //0b00100000
#define CRC_L16 0x20 //0b00000010
#define CRC_ENABLE 0x01 //0b00000001
#define RX2_DISABLE 0x00
#define CM_SB 0x40
#define RFDR_SB_250Kbps 0x00
#define XO_F_16MHz 0x0C
#define RF_PWR_0db 0x03 // 0db (Full Power)
#define RF_CH 0x80 // 2464MHz
#define RXEN_Tx 0x00
#define RXEN_Rx 0x01
void WEN_Config_Rx (void){
Buffer_Config[0]=DATA1_W;
Buffer_Config[1]=DATA2_W;
Buffer_Config[2]=ADDR_CH2_4;
Buffer_Config[3]=ADDR_CH2_3;
Buffer_Config[4]=ADDR_CH2_2;
Buffer_Config[5]=ADDR_CH2_1;
Buffer_Config[6]=ADDR_CH2_0;
Buffer_Config[7]=ADDR_CH1_4;
Buffer_Config[8]=ADDR_CH1_3;
Buffer_Config[9]=ADDR_CH1_2;
Buffer_Config[10]=ADDR_CH1_1;
Buffer_Config[11]=ADDR_CH1_0;
Buffer_Config[12]=ADDR_W_5bytes | CRC_L16 | CRC_ENABLE;
Buffer_Config[13]=RX2_DISABLE | CM_SB | RFDR_SB_250Kbps | XO_F_16MHz | RF_PWR_0db;
Buffer_Config[14]=RF_CH | RXEN_Rx;
}
void WEN_Config_Tx (void){
Buffer_Config[0]=DATA1_W;
Buffer_Config[1]=DATA2_W;
Buffer_Config[2]=ADDR_CH2_4;
Buffer_Config[3]=ADDR_CH2_3;
Buffer_Config[4]=ADDR_CH2_2;
Buffer_Config[5]=ADDR_CH2_1;
Buffer_Config[6]=ADDR_CH2_0;
Buffer_Config[7]=ADDR_CH1_4;
Buffer_Config[8]=ADDR_CH1_3;
Buffer_Config[9]=ADDR_CH1_2;
Buffer_Config[10]=ADDR_CH1_1;
Buffer_Config[11]=ADDR_CH1_0;
Buffer_Config[12]=ADDR_W_5bytes | CRC_L16 | CRC_ENABLE;
Buffer_Config[13]=RX2_DISABLE | CM_SB | RFDR_SB_250Kbps | XO_F_16MHz | RF_PWR_0db;
Buffer_Config[14]=RF_CH | RXEN_Tx;
CONNECTIONS:
DATA----------MOSI (SPI)
CE-------------SS (Slave Select, not config as SPI, but as general I/O)
CS-------------PortA_3
CLK------------SCLK (SPI)
DR1-----------LED (and uC IRQ pin)
:arrow:And now the main program: You’ll find it very short.
Rx:
You’ll see that some uC config is missing; that’s because I remove it so it would be shorter. I ASSURE (is it right? the spelling?) you that the uC is working with a Bus Freq=20Mhz with and external Xtla=4Mhz. All ports are well (I mean DDR) and the SPI is:
The following code only config the Rx module and sets CE high, it does not receive the data from that module. I’ve got a LED connected to DR1 so when a valid address and CRC arrive, it turns on.
“hab” is a variable I use to transmit via SPI. I command it via the emulator (CodeWarrior). So the SPI transmit whenever I want. “transmitiendo” tells me that the SPI is transmitting.
// States
#define LOW 0
#define HIGH 1
// SPI y Wenshing
byte hab=0;
byte transmitiendo=0;
byte rx=0;
byte RxTx=0;
/*****************************************************************************************/
void main(void) {
WEN_Config_Rx(); // Configura al WENSHING como RECEPTOR
SPI_config();
WEN_CE=LOW;
WEN_CS=LOW;
// 1st time Config
hab=1;
RxTx=1;
EnableInterrupts;
for(;;) {
__RESET_WATCHDOG();
if (hab && !transmitiendo){
WEN_CS=HIGH;
WEN_CE=LOW;
SPI_Rx_Tx(RxTx); // Enable Tx interrupt (SPI)
}
if(rx){ // TRF mode: Rx
WEN_CS=LOW;
WEN_CE=HIGH;
}
}
}
/*****************************************************************************************/
/*******/
/* ISRs */
/*******/
// SPI ISR
#pragma TRAP_PROC
void SPI_ISR(void){
if (SPI1S_SPTEF){ //Tx
transmitiendo=1;
SPI1S;
SPI1D=Buffer_Config[BCp];
BCp++;
if (BCp>14){
WEN_CE=LOW;
WEN_CS=LOW;
SPI1C1=0x54; // Disable Tx interrupt (SPI)
rx=1; // TRF mode: Rx
transmitiendo=0; // Reset my flags
BCp=0;
hab=0;
}
}
if (SPI1S_SPRF){ //Rx
SPI1D;
}
}
:arrow: And for the Tx module:
“hab” is a variable I use to transmit via SPI. I command it via the emulator (CodeWarrior). So the SPI transmit whenever I want. “transmitiendo” tells me that the SPI is transmitting.
// States
#define LOW 0
#define HIGH 1
#pragma DATA_SEG SHORT MY_ZEROPAGE
// SPI y Wenshing
byte hab=0;
byte transmitiendo=0;
byte config=0;
byte RxTx=0;
byte Buffer_Tx[5];
byte txp=0;
#pragma DATA_SEG DEFAULT
/**********************/
/* RUTINAS AUXILIARES */
/**********************/
// Carga Buffer con los datos a transmitir por aire: ADDRESS+DATA
void load_data (void){
Buffer_Tx[0]=ADDR_CH1_1;
Buffer_Tx[1]=ADDR_CH1_0;
Buffer_Tx[2]=0x57;
Buffer_Tx[3]=0x58;
Buffer_Tx[4]=0x65;
}
/*****************************************************************************************/
void main(void) {
WEN_Config_Tx(); // Configura al WENSHING como TRANSMISOR
SPI_config();
load_data();
WEN_CE=LOW;
WEN_CS=LOW;
// 1st time config
hab=1; // enable Tx
config=1; // config mode
RxTx=1; // enable Tx interrupt (SPI)
EnableInterrupts;
for(;;) {
__RESET_WATCHDOG();
if (hab && !transmitiendo){
if (config){
WEN_CS=HIGH;
WEN_CE=LOW;
}else{
WEN_CS=LOW;
WEN_CE=HIGH;
}
SPI_Rx_Tx(RxTx); // Enable Tx interrupt
}
}
}
/*****************************************************************************************/
/*****************************************/
/* Rutinas de Servicio de Interrupciones */
/*****************************************/
// SPI ISR
#pragma TRAP_PROC
void SPI_ISR(void){
if (SPI1S_SPTEF){ //Tx
transmitiendo=1;
if(config){
SPI1S;
SPI1D=Buffer_Config[BCp];
BCp++;
}else{
SPI1S;
SPI1D=Buffer_Tx[txp];
txp++;
}
if (BCp>14 || txp>(numOfBytes+1)){
WEN_CE=LOW;
WEN_CS=LOW;
SPI1C1=0x54; // Disable SPI Tx interrupt
transmitiendo=0;
config=0;
BCp=0;
txp=0;
hab=0;
}
}
}
If you need the full code, for a better understanding email me or ask for it in a reply
Once and allways THANK YOU