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.
Hi all. I am trying to set up two Nordic boards to send and receive data at the same time and at the same time send this data to the serial port. Each board is connected to a PC and will send any received data to the PC through the serial port and will also transmit any data obtained from the serial port.I have set the DR1 and the Serial as an interrupt. The DR1 interrupt occurs when the board has wirelessly received data and this data is ready. The serial interrupt occurs when the serial port on the board receives data(which is to be transmitted) from the PC. The problem is that I can only get the boards to transmit but not receive. I am pretty new to this and I am not sure if I have set the interrupts correctly or if the problem is some where else in the code. I have given the code below:
#include <Nordic\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 tconf = // TX config structure { 15, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x34, 0x56, 0x78, 0x83, 0x6F, 0x76 }; const RFConfig rconf = // RX config { 15, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9a, 0xbc, 0xde, 0xf0, 0x83, 0x6F, 0x05 }; volatile unsigned char rxbyte, rxcount,txcount, txbyte; void Delay100us(volatile unsigned char n) { unsigned char i; while(n--) for(i=0;i<35;i++) ; } 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 hs finished //transmitting ; return SPI_DATA; // Return data from SPI } void PutChar(char c) { while(!TI) ; TI = 0; SBUF = c; } void PutString(const char *s) { while(*s != 0) PutChar(*s++); } void drirq(void) interrupt 10 { EXIF &= ~0x40; // Clear DR1 interrupt rxbyte = SpiReadWrite(0); rxcount = 1; } void TransmitPacket(unsigned char b) { unsigned char i; CE = 1; Delay100us(0); for(i=0;i<ADDR_COUNT;i++) // we're using 32-bit address SpiReadWrite(rconf.buf[ADDR_INDEX+i]); SpiReadWrite(b); CE = 0; Delay100us(3); } void Receiver(void) { unsigned char b; CS = 1; Delay100us(0); for(b=0;b<rconf.n;b++) { SpiReadWrite(rconf.buf[b]); } CS = 0; CE = 1; for(;;) { if (rxcount > 0) { EX4 = 0; b = rxbyte; rxcount = 0; EX4 = 1; PutChar(b); } } } void TransmitString(const char *s) { while(*s != 0) { TransmitPacket(*s++); Delay100us(20); // Wait a few ms } } void Transmitter(void) { char b; CS = 1; Delay100us(0); for(b=0;b<tconf.n;b++) { SpiReadWrite(tconf.buf[b]); } CS = 0; for(;;) { if (txcount > 0) { ES = 0; b = txbyte; txcount = 0; TransmitPacket(b); ES = 1; } } } void spirq(void) interrupt 4 { txbyte = SBUF; txcount = 1; SCON &= ~0x03; } void Init(void) { TH1 = 230; // 19200@16MHz (when T1M=1 and SMOD=1) CKCON |= 0x10; // T1M=1 (/4 timer clock) PCON = 0x80; // SMOD=1 (double baud rate) SCON = 0x52; // Serial mode1, enable receiver TMOD = 0x20; // Timer1 8bit auto reload TCON = 0x40; // Start timer1 P0_ALT = 0x06; // Select alternate functions on pins P0.1 and //P0.2 P0_DIR = 0x42; // P0.1 and P0.6 is input, the rest output P0 = 0x10; // P0.4 = 1 for the RX/TX selection PWR_UP = 1; // Turn on Radio Delay100us(0); SPICLK = 0; // Max SPI clock (XTAL/8) SPI_CTRL = 0x02; // Connect internal SPI controller to Radio } void main(void) { Init(); EX4 = 1; ES = 1; EA = 1; while (1) { if (rxcount > 0) { Receiver(); } if (txcount > 0 ) { Transmitter(); } }
Any help is greatly appreciated. Thanks in advance for your time.
In Noric's website,there is a sample which is for your need.
I have had a look on their site and I cannot find it. Can you post the link? Thanks.