I'm trying to send data from MSP430 to Arduino using Nrf24l01 but my code doesn't seem to work . Also which of MOSI or MISO should be used for one direction communication ?
//Transmitter Code(MSP430G2553)
#include <SPI.h>
#include <Enrf24.h>
#include <nRF24L01.h>
#include <string.h>
Enrf24 radio(P2_0, P2_1, P2_2); // P2.0=CE, P2.1=CSN, P2.2=IRQ
const uint8_t txaddr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0x01 };
const char *str_on = "ON";
const char *str_off = "OFF";
void dump_radio_status_to_serialport(uint8_t);
int val = 420;
void setup() {
Serial.begin(9600);
SPI.begin();
SPI.setDataMode(SPI_MODE0);
SPI.setBitOrder(MSBFIRST);
radio.begin(); // Defaults 1Mbps, channel 0, max TX power
dump_radio_status_to_serialport(radio.radioState());
radio.setTXaddress((void*)txaddr);
}
void loop() {
Serial.print("Sending packet: ");
Serial.println(str_on);
radio.print(val);
radio.flush(); // Force transmit (don't wait for any more data)
dump_radio_status_to_serialport(radio.radioState()); // Should report IDLE
delay(1000);
Serial.print("Sending packet: ");
Serial.println(str_off);
radio.print(val);
radio.flush(); //
dump_radio_status_to_serialport(radio.radioState()); // Should report IDLE
delay(1000);
}
void dump_radio_status_to_serialport(uint8_t status)
{
Serial.print("Enrf24 radio transceiver status: ");
switch (status) {
case ENRF24_STATE_NOTPRESENT:
Serial.println("NO TRANSCEIVER PRESENT");
break;
case ENRF24_STATE_DEEPSLEEP:
Serial.println("DEEP SLEEP <1uA power consumption");
break;
case ENRF24_STATE_IDLE:
Serial.println("IDLE module powered up w/ oscillators running");
break;
case ENRF24_STATE_PTX:
Serial.println("Actively Transmitting");
break;
case ENRF24_STATE_PRX:
Serial.println("Receive Mode");
break;
default:
Serial.println("UNKNOWN STATUS CODE");
}
}
Receiver Code(Arduino)
#include <SPI.h>
// RF24 - Version: Latest
#include <RF24.h>
#include <RF24_config.h>
#include <nRF24L01.h>
#include <printf.h>
RF24 radio(7, 8);
const uint8_t pipe[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0x01 };
void setup()
{
while (!Serial);
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(0,pipe);
radio.startListening();
}
void loop()
{
if (radio.available())
{
int text;
radio.read(&text, sizeof(text));
Serial.println(text);
Serial.println("Complete");
delay(100);
}
}