Hi All,
I have two Transceiver nRF24L01+ Module with Chip Antenna WRL-00691 each connected to a MSP430FG439. I am trying to send an 8bit character 10100110 from one two the other. However the receiver unit is not getting any data and the status register is always zero. Any help would be appreciated
Thanks in advance
Transmitter Code
#include <msp430xG43x.h>
void initialise(void);
void nRF_setup(void);
void rx_complete(void);
void tx_complete(void);
void setup_SPI(void);
void delay_us (unsigned long time); //Produces delay of length time in us
void w_register(int address, int data);
int r_register(int address, int length);
void flush_TX(void);
void w_TX_payload(int data);
int status=0;
int receive[20];
#define CSN 0x20;
#define CE 0x08;
//temp variables
int i=0;
int a=253;
int trash=0;
int temp=0;
//Define Ports
/*
P3.1 SIMO0
P3.2 SOMI0
P3.3 UCLK
*/
int main(void)
{
int data=0;
WDTCTL = WDTPW + WDTHOLD; //stop watchdog timer
initialise(); //initialise input output ports
setup_SPI(); //setup SPI
nRF_setup(); //setup nRF24L01+
flush_TX(); //clear nRF TX buffer
while(1)
{
status = r_register(0x07, 1); //read status register
if (status & (0x10 | 0x08)) //status & (TX_DS | MAX_RT)
{
flush_TX();
}
w_TX_payload(0xA6); //transmit A6
delay_us(150); //delay
}
}//end main
void nRF_setup(void)
{
w_register(0x01, 0x00); //EN_AA Disable auto ack
w_register(0x11, 1); //Port 0 1 bytes
w_register(0x00, 0x7A); //Config Interrupt not reflected, enable CRC, Power up, PTX
P5OUT &= ~CE; //Transmitter mode
}
//********************
// Checks for SPI transfer completion
//********************
void tx_complete(void)
{
while (!(IFG1 & UTXIFG0)); // USART0 TX buffer ready?
}
//********************
// Checks for SPI receive completion
//********************
void rx_complete(void)
{
while (!(IFG1 & URXIFG0)); // USART0 RX buffer ready?
}
//*************************
//Initialise MSP I/O ports
//************************
void initialise(void)
{
P3SEL = 0x0E; //Set port 3.1 MOSI 3.2 MISO 3.3 UCLK
P5OUT = 0xFF; //Port 5 Outputs
P5OUT = 0x00; //Set as 0
P5OUT |= 0x20; //Set CSN P5.5 high
}
//*************************
//Setup SPI to interface with ext ADC and display driver
//*************************
void setup_SPI(void)
{
UCTL0 |= SWRST; // Set SWRST
UCTL0 |= CHAR + SYNC + MM; // 8-bit SPI Master **SWRST**
UTCTL0 |= CKPH + SSEL1 + STC; // SMCLK, 3-pin mode
UBR00 = 0x04; // Baud rate set by U0BR10 + U0BR10
UBR10 = 0x00; // 0
UMCTL0 = 0x00; // no modulation
ME1 |= USPIE0; // Enable USART0 SPI mode
UCTL0 &= ~SWRST; // Initalize USART state machine
}
//*****************************
//Reads nRF register
//Returns status register
//****************************
int r_register(address, length)
{
int a=0; //Temp variable to hold status
P5OUT &= ~CSN;
U0TXBUF = address; //Send address of register to read
//tx_complete();
a = U0RXBUF; //Read status register
P5OUT |= CSN;
return a;
}
//***************************
//Writes data to nRF register
//***************************
void w_register(address, data)
{
address = address + 0x20; //Set bit 5 high to set write instruction
P5OUT &= ~CSN;
U0TXBUF = address; //Address to be sent
temp = U0RXBUF; //status register
tx_complete(); //Wait until sent
U0TXBUF = data; //Data to be sent
tx_complete(); //Wait until sent
P5OUT |= CSN;
}
//*******************
//Writes byte to be send
//*******************
void w_TX_payload(data)
{
P5OUT &= ~CSN;
U0TXBUF = 0xA0; //Write TX command
temp = U0RXBUF; //status register
tx_complete(); //Wait until sent
U0TXBUF = data; //Data to be sent
tx_complete(); //Wait until sent
P5OUT |= CSN;
}
// *****************************************
//Produces delay in us
// ****************************************
void delay_us (unsigned long time)
{
TBCCR0 = (unsigned int)(32768 * time / 1000000); //Set up Timer B interval
TBCCR1 = TBCCR0 - 1; //Set TBCL1 to 1 less than TBCL0
TBCCTL1 = OUTMOD_3; //OUT1 is set when the timer reaches TBCL1 and reset when it reaches TBCL0
TBCTL |= TBCLR;
TBCTL &= ~TBIFG;
TBCTL = TBSSEL_1 | MC_1; // ALCK up mode
while ((TBCTL & TBIFG) == 0) {} // Wait till time elapses
TBCTL = MC_0; //Stop Timer B
}
//************************
//Flushes nRF Transmit buffer
//*********
void flush_TX()
{
P5OUT &= ~CSN;
U0TXBUF = 0xE1; //Flush TX
P5OUT |= CSN;
}
Receiver Code
#include <msp430xG43x.h>
void initialise(void);
void nRF_setup(void);
void rx_complete(void);
void tx_complete(void);
void setup_SPI(void);
void delay_us (unsigned long time); //Produces delay of length time in us
void w_register(int address, int data);
int r_register(int address, int length);
void flush_TX(void);
void flush_RX(void);
void w_TX_payload(int data);
int r_RX_payload(void);
int status=0;
int receive=0;
#define CSN 0x20;
#define CE 0x08;
//temp variables
int i=0;
int a=253;
int trash=0;
int temp=0;
//Define Ports
/*
P3.1 SIMO0
P3.2 SOMI0
P3.3 UCLK
*/
int main(void)
{
int data=0;
WDTCTL = WDTPW + WDTHOLD; //stop watchdog timer
initialise(); //initialise input output ports
setup_SPI(); //setup SPI
nRF_setup(); //setup nRF24L01+
flush_RX(); //removes stray data from Receiver
while(1)
{
status = r_register(0x07, 1); //read status register
if (status & 0x40 ) //status & RX_DR)
{
P5OUT &= ~CE; //Set CE Low
receive = r_RX_payload(); //received data
flush_RX(); //clear receiver
P5OUT |= CE; //Set CE High
}
}
}//end main
//********************************
//Commands to set up nRF24L01+
//********************************
void nRF_setup(void)
{
w_register(0x01, 0x00); //EN_AA Disable auto ack
w_register(0x11, 1); //Port 0 1 bytes
w_register(0x00, 0x7B); //Config Interrupt not reflected, enable CRC, Power up, PTX
P5OUT |= CE; //Receiver mode
}
//********************
// Checks for SPI transfer completion
//********************
void tx_complete(void)
{
while (!(IFG1 & UTXIFG0)); // USART0 TX buffer ready?
}
//********************
// Checks for SPI receive completion
//********************
void rx_complete(void)
{
while (!(IFG1 & URXIFG0)); // USART0 RX buffer ready?
}
//*************************
//Initialise MSP I/O ports
//************************
void initialise(void)
{
P3SEL = 0x0E; //Set port 3.1 MOSI 3.2 MISO 3.3 UCLK
P5OUT = 0xFF; //Port 5 Outputs
P5OUT = 0x00; //Set as 0
P5OUT |= 0x20; //Set CSN P5.5 high
}
//*************************
//Setup SPI to interface with ext ADC and display driver
//*************************
void setup_SPI(void)
{
UCTL0 |= SWRST; // Set SWRST
UCTL0 |= CHAR + SYNC + MM; // 8-bit SPI Master **SWRST**
UTCTL0 |= CKPH + SSEL1 + STC; // SMCLK, 3-pin mode
UBR00 = 0x04; // UCLK/8 = 1.048MHz/8 = 131kHz
UBR10 = 0x00; // 0
UMCTL0 = 0x00; // no modulation
ME1 |= USPIE0; // Enable USART0 SPI mode
UCTL0 &= ~SWRST; // Initalize USART state machine
}
//*****************************
//Reads nRF register
//Returns status register
//****************************
int r_register(address, length)
{
int a=0; //Temp variable to hold status
P5OUT &= ~CSN;
U0TXBUF = address; //Config
a = U0RXBUF;
P5OUT |= CSN;
return a;
}
//***************************
//Writes data to nRF register
//***************************
void w_register(address, data)
{
address = address + 0x20; //Set bit 5 high to set write instruction
P5OUT &= ~CSN;
U0TXBUF = address; //Address to be sent
temp = U0RXBUF; //status register
tx_complete(); //Wait until sent
U0TXBUF = data; //Data to be sent
tx_complete(); //Wait until sent
P5OUT |= CSN;
}
//*******************
//Writes byte to be send
//*******************
void w_TX_payload(data)
{
P5OUT &= ~CSN;
U0TXBUF = 0xA0; //Write TX command
temp = U0RXBUF; //status register
tx_complete(); //Wait until sent
U0TXBUF = data; //Data to be sent
tx_complete(); //Wait until sent
P5OUT |= CSN;
}
//*******************
//Reads bytes sent
//*******************
int r_RX_payload()
{
int RX_data=0; //Received data
P5OUT &= ~CSN;
U0TXBUF = 0xA0; //Write TX command
temp = U0RXBUF; //status register
tx_complete(); //Wait until sent
U0TXBUF = 0xFF; //send nop to get received data
temp = U0RXBUF; //RX data
tx_complete(); //Wait until sent
P5OUT |= CSN;
return RX_data;
}
// *****************************************
//Produces delay in us
// ****************************************
void delay_us (unsigned long time)
{
TBCCR0 = (unsigned int)(32768 * time / 1000000); //Set up Timer B interval
TBCCR1 = TBCCR0 - 1; //Set TBCL1 to 1 less than TBCL0
TBCCTL1 = OUTMOD_3; //OUT1 is set when the timer reaches TBCL1 and reset when it reaches TBCL0
TBCTL |= TBCLR;
TBCTL &= ~TBIFG;
TBCTL = TBSSEL_1 | MC_1; // ALCK up mode
while ((TBCTL & TBIFG) == 0) {} // Wait till time elapses
TBCTL = MC_0; //Stop Timer B
}
void flush_TX()
{
P5OUT &= ~CSN;
U0TXBUF = 0xE1; //Flush TX
P5OUT |= CSN;
}
void flush_RX()
{
P5OUT &= ~CSN;
U0TXBUF = 0xE2; //Flush RX
P5OUT |= CSN;
}