This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Wireless 8051 problems

HI :-) as promised, im having problems with the wireless connection on the nordic nrf24e1, I am trying to send a packet and then if received, flash an LED. Can anyone see any problems with the below code. first is the transmitter code then i will reply with the receiver code:

#include <reg24e1.h>

struct RFConfig
{ unsigned char n; unsigned char buf[15];
};

typedef struct RFConfig RFConfig;

#define ADDR_INDEX 8 // Index to address bytes in RFConfig.buf
#define ADDR_COUNT 4 // Number of address bytes

const RFConfig txconf =
{ 15, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x34, 0x56, 0x78, 0x83, 0x6c, 0x04
};

const RFConfig rxconf =
{ 15, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x87, 0x65, 0x43, 0x21, 0x83, 0x6c, 0x05
};

// LED is to be connected to this pin
sbit LED_pin = P1^0;

// Function prototypes
void DELAY_LOOP_Wait(const unsigned int);
void DELAY_100us(volatile unsigned char n);
unsigned char SPI_ReadWrite(unsigned char b);
void TRANSMIT_Packet(unsigned char b);
void TRANSMITTER(void);
void LED_Flash();
void INIT(void);

/*..................................................................*/

void main(void)
{ INIT();

while(1) {

TRANSMITTER();

}

}

/*------------------------------------------------------------------*-

DELAY_LOOP_Wait()

-*------------------------------------------------------------------*/

void DELAY_LOOP_Wait(const unsigned int DELAY) { unsigned int x, y;

for (x = 0; x <= DELAY; x++) { for (y = 0; y <= 800; y++); } }

/*------------------------------------------------------------------*-

LED_FLASH()

-*------------------------------------------------------------------*/

void LED_Flash()
{ LED_pin = 0; DELAY_LOOP_Wait(1000); LED_pin = 1; DELAY_LOOP_Wait(1000);
}

/*------------------------------------------------------------------*-

DELAY_100us()

-*------------------------------------------------------------------*/

void DELAY_100us(volatile unsigned char n)
{ unsigned char i; while(n--) for(i=0;i<35;i++) ;
}

/*------------------------------------------------------------------*-

SPI_ReadWrite()

-*------------------------------------------------------------------*/

unsigned char SPI_ReadWrite(unsigned char b)
{ EXIF &= ~0x20; // Clear SPI interrupt SPI_DATA = b; // Move byte to send to SPI data register while((EXIF & 0x20) == 0x00) // Wait until SPI hs finished transmitting ; return SPI_DATA;
}

/*------------------------------------------------------------------*-

TRANSMIT_Packet()

-*------------------------------------------------------------------*/

void TRANSMIT_Packet(unsigned char b)
{ unsigned char i; CE = 1; DELAY_100us(0); // Start with the address of the receiver: for(i=0;i<ADDR_COUNT;i++) SPI_ReadWrite(rxconf.buf[ADDR_INDEX+i]); SPI_ReadWrite(b); CE = 0; DELAY_100us(3); // Wait ~300us
}

/*------------------------------------------------------------------*-

TRANSMITTER()

-*------------------------------------------------------------------*/

void TRANSMITTER(void)
{ unsigned char b; CS = 1; DELAY_100us(0); for(b=0;b<txconf.n;b++) { SPI_ReadWrite(txconf.buf[b]); } CS = 0; for(;;) { //b = ReadADC(); // Read ADC TRANSMIT_Packet(b); // Transmit data }
}

void INIT(void)
{ PWR_UP = 1; // Turn on Radio DELAY_100us(30); // Wait > 3ms SPICLK = 0; // Max SPI clock (XTAL/8) SPI_CTRL = 0x02; // Connect internal SPI controller to Radio

}

0