We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hey out there, finally I'm at my PC again and can post my code if needed. Here's the situation: I've bought me a nRF24E1-EVKIT from nordic because I want to transmit an extern generated serial realtime protocol wireless. The protocol has 8 data bits and 1 start and stop bit, just like the serial interface. the baudrate is 31.25 kBaud. the problem is that i'm not that into programing 8051 and need a little help from my friend ;) Here's what I got so far:
/* init the serial I/O */ SM0 = 0; SM1 = 1; /* serial port MODE 1 */ SM2 = 0; REN = 1; /* enable serial receiver */ TI = 0; /* clear transmit interrupt */ RI = 0; /* clear receiver interrupt */ ES = 1; /* enable serial interrupts */ PS = 0; /* set ints to low priority */ /* init timer1 as baudrate generator */ TR1 = 0; /* stop timer 1 */ ET1 = 0; /* disable timer 1 interrupt */ PCON |= 0x80; /* 0x80=SMOD: set serial baudrate doubler */ TMOD &= ~0xF0; /* clear timer 1 mode bits */ TMOD |= 0x20; /* put timer 1 into MODE 2 */ TH1 = 248; /* 31250@16MHz is that value correct?*/ TR1 = 1; /* start timer 1 */ /* ISR for Rx and Tx serial data*/ static void com_isr (void) interrupt 4 using 1 { if (RI != 0) /* Received data interrupt */ { RI = 0; // problem: put the recieved data to the wireless SFR to be transmitted } }
ok then. I understand. first of all thank you for the help. after I've read the manuals, data sheets, whitepapers and code examples this night, I coded the following for the transmitting side:
#include <reg24e1.H> /* this stuff is needed to send data over the RF */ #define ADDR_INDEX 8 #define ADDR_COUNT 4 struct RFConfig { unsigned char n; unsigned char buf[15]; }; typedef struct RFConfig RFConfig; const RFConfig tconf = { 15, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xaa, 0xbb, 0x12, 0x34, 0x83, 0x6c, 0x04 }; const RFConfig rconf = { 15, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xaa, 0xbb, 0x12, 0x34, 0x83, 0x6c, 0x05 }; /* now init all we need to put the data over the air */ void init(void) { /* power up tranciever */ PWR_UP = 1; /* init serial interface */ SM0 = 0; SM1 = 1; /* serial port MODE 1 */ SM2 = 0; REN = 1; /* enable serial receiver */ TI = 0; /* clear transmit interrupt */ RI = 0; /* clear receiver interrupt */ ES = 1; /* enable serial interrupts */ PS = 0; /* set ints to low priority */ /* init timer 1 as baudrate generator */ TR1 = 0; /* stop timer 1 */ ET1 = 0; /* disable timer 1 interrupt */ PCON |= 0x80; /* 0x80=SMOD: set serial baudrate doubler */ TMOD &= ~0xF0; /* clear timer 1 mode bits */ TMOD |= 0x20; /* put timer 1 into MODE 2 */ TH1 = 0xF8; /* 31250@16MHz is that value correct?*/ TR1 = 1; /* start timer 1 */ } /* function that reads and writes a data byte to and from the SPI that is needed to force the data fly */ unsigned char spiReadWrite(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 has finished transmitting */ ; return SPI_DATA; /* for read reason */ } /* function that transmits the data byte over the air with the help from spiReadWrite() */ void transmitPacket(unsigned char b) { unsigned char i; CE = 1; /* activate RX or TX mode */ for(i = 0; i < ADDR_COUNT; i++) spiReadWrite(tconf.buf[ADDR_INDEX+1]); spiReadWrite(b); CE = 0; } /* ISR for the serial interface */ static void com_isr (void) interrupt 4 using 1 { unsigned char b; if (RI != 0) /* recieved data interrupt */ { RI = 0; b = SBUF; transmitPacket(b); } } void main(void) { init(); }