Jump to content
43oh

TM4C129 nRF24L01 RX working example


Recommended Posts

Hi,

 

Here is a working example TM4C129 using Enrf24 library

/* Tiva launchpad connected TM4C129
   nRF24L01 RX
   SPI module 2
   25/06/2014
*/

#include <Enrf24.h>
#include <nRF24L01.h>
#include <string.h>
#include <SPI.h>

Enrf24 radio(PE_0,PE_2,PE_1);  // CE, CSN, IRQ + SCK/MOSI/MISO ==> PD_3/PD_0/PD_1

const uint8_t rxaddr[] = { 0xF0,0xF0,0xF0,0xF0,0xE1 };

unsigned long prev_time;

void setup()
{
  Serial.begin(9600);
  Serial.flush();
  SPI.setModule(2);
  SPI.begin();
  SPI.setDataMode(SPI_MODE0);
  SPI.setBitOrder(1);
  
  radio.begin();  // Defaults 1Mbps, channel 0, max TX power
  dump_radio_status_to_serialport(radio.radioState());  
  radio.setRXaddress((void*)rxaddr);  
  radio.enableRX();  // Start listening
  delay(100);
}

void loop() {
  char inbuf[33];  
  delta_set();
  
  while (!radio.available(true)&& delta_get()<1000);
   
  if (radio.read(inbuf)) {
      Serial.println(inbuf);    
  }
}

void delta_set() {
  prev_time = millis();
}

// TimeOut  
unsigned long delta_get() {
  unsigned long time;
  unsigned long delta;

  time = millis();
  if (time < prev_time) { // TimeOut
    delta = 0xffffffff - prev_time + time + 1;
  } 
  else {
    delta = time - prev_time;
  }
  return delta;
}

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");
  }
}

TX is MSP430 + DHT22 sending humidity and temperature

 

Salutations

 

Bernard

Link to post
Share on other sites

Hi again,

 

I forgot to post the TX side :

/*
MSP 430g2553 TX
DHT22
25/06/2014
*/

#include <Enrf24.h>
#include <nRF24L01.h>
#include <string.h>
#include <SPI.h>
#include <DHT22_430.h>

#define DHTPIN P1_4

DHT22 mySensor(DHTPIN);
Enrf24 radio(P2_0, P2_1, P2_2);  // P2.0=CE, P2.1=CSN, P2.2=IRQ
const uint8_t txaddr[] = { 0xF0,0xF0,0xF0,0xF0,0xE1 };
boolean flag = 0;


void dump_radio_status_to_serialport(uint8_t);

void setup() {
  Serial.begin(9600);

  SPI.begin();
  SPI.setDataMode(SPI_MODE0);
  SPI.setBitOrder(1); // MSB-first
  mySensor.begin();

  radio.begin();  // Defaults 1Mbps, channel 0, max TX power
  //radio.setCRC(1,1);
  

  radio.setTXaddress((void*)txaddr);
}

void loop()
{  
  char str[16];
  long h = mySensor.humidityX10();
  long t = mySensor.temperatureX10();
  flag = mySensor.get();

  if (!flag) {
    radio.print("DHT error");
  } 
  else{ 
  sprintf(str, "%ld",h/10);   
  radio.print(str);
  radio.print(".");
  sprintf(str, "%ld",h%10); 
  radio.print(str);
  radio.print("---");
  sprintf(str, "%ld",t/10); 
  radio.print(str);
  radio.print(".");
  sprintf(str, "%ld",t%10);
  radio.print(str);
  
  radio.flush();  // Force transmit (don't wait for any more data)
  }
  
 
  delay(1000); 
}


My project is to centrally manage several rf sensors on Tiva connected board and make a  web server.

I have spent many time to add  the Ethernet part in the loop and so far no success ... any help would be appreciate :)

Salutations

Bernard

Link to post
Share on other sites
  • 2 weeks later...
  • 1 year later...

Hi,

 

I was not able to make TM4C129 transmit but finally it works. Before you give up when only Rx is working but no Tx (even if your module is working with MSP430 and TM4C123 correctly try to INSTALL BYPASS CAPACITOR on the module (e.g. 10uf capacitor directly over VCC and GND).

 

P

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...