Wireless 8051 problemsNext Thread | Thread List | Previous Thread Start a Thread | Settings | Details | Message |
|---|
Read-Only Author leigh griffiths Posted 12-Feb-2007 10:48 GMT Toolset C51 |  Wireless 8051 problems leigh griffiths 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 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++);
}
}
/*------------------------------------------------------------------*-
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, bo, err;
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
}
| | Read-Only Author leigh griffiths Posted 12-Feb-2007 10:49 GMT Toolset C51 |  RE: Wireless 8051 problems leigh griffiths 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);
unsigned char RECEIVE_Packet();
void RECEIVER(void);
void LED_Flash();
void INIT(void);
/*..................................................................*/
void main(void)
{
INIT();
while(1)
{
TRANSMITTER();
RECEIVER();
}
}
/*------------------------------------------------------------------*-
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()
{
do
{
LED_pin = 0;
DELAY_LOOP_Wait(1000);
LED_pin = 1;
DELAY_LOOP_Wait(1000);
} while(1);
}
/*------------------------------------------------------------------*-
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
}
/*------------------------------------------------------------------*-
RECEIVE_Packet()
-*------------------------------------------------------------------*/
unsigned char RECEIVE_Packet()
{
unsigned char b;
CE = 1;
while(DR1 == 0)
;
b = SPI_ReadWrite(0);
CE = 0;
return b;
}
/*------------------------------------------------------------------*-
RECEIVER()
-*------------------------------------------------------------------*/
void RECEIVER(void)
{
unsigned char b, bo, err;
CS = 1;
DELAY_100us(0);
for(b=0;b<rxconf.n;b++)
{
SPI_ReadWrite(rxconf.buf[b]);
}
CS = 0;
bo = err = 0;
for(;;)
{
b = RECEIVE_Packet();
LED_Flash();
}
}
/*------------------------------------------------------------------*-
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)
{
P1_DIR = 0;
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
}
| | Read-Only Author leigh griffiths Posted 12-Feb-2007 10:52 GMT Toolset C51 |  RE: Wireless 8051 problems leigh griffiths sorry mistake in above text, should be like this:
void main(void)
{
INIT();
while(1)
{
RECEIVER();
}
}
| | Read-Only Author Carlos Gustavo Machado Posted 13-Feb-2007 02:32 GMT Toolset C51 |  RE: Wireless 8051 problems Carlos Gustavo Machado Hello Leigh, I'm trying to blink a led in the nRF24e1 also but so far no success. Could you please check my code to see if I'm forgetting something?
sfr P0_DIR = 0x94;
sfr P0_ALT = 0x95;
org 00h
jmp INICIO
org 33h
INICIO: call delay
mov P0_ALT, #00h
mov P0_DIR, #01h
mov P0, #00h
volta: setb P0.7
call delay
clr P0.7
call delay
setb P0.6
call delay
clr P0.6
call delay
jmp volta
delay: mov R0, #0FFh
delay3: mov R1, #0FFh
delay2: mov R2, #0FFh
djnz R2, $
djnz R1, delay2
djnz R0, delay3
ret
end
feel free to contact me in my email: gustavo79@gmail.com I'd appreciate your help. | |
Next Thread | Thread List | Previous Thread Start a Thread | Settings |