Go Down

Topic: Microchip MRF24J40MB Problems (Read 2067 times) previous topic - next topic

evanbarnes

I am trying to setup a telemetry system using two Microchip MRf24J40MB data radios data radios. See picture for the layout. I wired everything up according to the instructions at http://projects.schneidr.de/2012/10/mrf24j40-and-arduino/. One of the microcontrollers is a bare ATMEGA328P-PU with 16MHz crystal and Arduino bootloader. The other is an Arduino Nano also with the 328 chip. I ran the Nano through a 74LVC245 Logic Level Convertor (http://www.adafruit.com/products/735).

I am using the MRF24J40 Arduino Library (https://github.com/karlp/Mrf24j40-arduino-library) with both boards configured with the Basic_TwoWay program. I am able to receive packets from the Nano on the bare chip but only when they are less than a foot away from each other. Additionally the connection only lasts for about 5 to 30 seconds, after which the bare chip will not decode any packets. Pressing the reset button on the Nano will start another 5 to 30 seconds of valid packets.

I am not able to decode any packets on the Nano, in fact it doesn't even show that it cannot receive an ack.

I think the problem may be the logic level converter and I bought some more bare chips to run at 3.3v and am waiting for them to arrive. I have tried switching radios between both microcontrollers but there is no difference. I also tried swapping an Arduino Pro Mini 5v for the Nano but again no difference. See below for a serial log, note they are not from the same time. If anyone has any insight that would be very much appreciated.


Serial Log From the Nano, nothing else will happen until it is reset

NANO
txxxing...
txxxing...
txxxing...
txxxing...
txxxing...
txxxing...
txxxing...



Serial log from bare chip, it will keep txxxing, failing to get an ack and not getting any additional packets until the nano is reset. Notice that some received packets don't include the entire string "I Am NANO" that the nano is sending, and that one the the transmissions even got an ack.

ATMEGA
ASCII data (relevant data):
      NANO
LQI/RSSI=115/1
************************* 1
txxxing...
TX failed after 3 retries

received a packet 20 bytes long

ASCII data (relevant data):
I Am NANO
LQI/RSSI=103/1
************************* 2
received a packet 20 bytes long

ASCII data (relevant data):

LQI/RSSI=103/1
************************* 3
TX went ok, got ack

received a packet 20 bytes long

ASCII data (relevant data):
      NANO
LQI/RSSI=114/3
************************* 4
received a packet 20 bytes long
ASCII data (relevant data):
I Am NANO
LQI/RSSI=114/3
************************* 5
txxxing...
TX failed after 3 retries

received a packet 20 bytes long

ASCII data (relevant data):
I Am NANO
LQI/RSSI=111/0
************************* 6
received a packet 20 bytes long

ASCII data (relevant data):
I Am NANO
LQI/RSSI=111/0
************************* 7
txxxing...
TX failed after 3 retries

received a packet 20 bytes long

ASCII data (relevant data):
I Am NANO
LQI/RSSI=112/0
************************* 8
received a packet 20 bytes long

ASCII data (relevant data):
I Am NANO
LQI/RSSI=112/0
************************* 9
txxxing...
TX failed after 3 retries

received a packet 20 bytes long

ASCII data (relevant data):
I Am NANO
LQI/RSSI=117/5
************************* 10
received a packet 20 bytes long

ASCII data (relevant data):
I Am NANO
LQI/RSSI=117/5
************************* 11
txxxing...
TX failed after 3 retries

received a packet 20 bytes long

ASCII data (relevant data):
I Am NANO
LQI/RSSI=111/2
************************* 12
received a packet 20 bytes long

ASCII data (relevant data):
I Am NANO
LQI/RSSI=111/2
************************* 13
txxxing...
TX failed after 3 retries

received a packet 20 bytes long

ASCII data (relevant data):
I Am NANO
LQI/RSSI=108/0
************************* 14
received a packet 20 bytes long

ASCII data (relevant data):
I Am NANO
LQI/RSSI=108/0
************************* 15
txxxing...
TX failed after 3 retries

received a packet 20 bytes long

ASCII data (relevant data):
I Am NANO
LQI/RSSI=108/1
************************* 16
received a packet 20 bytes long

ASCII data (relevant data):
I Am NANO
LQI/RSSI=108/1
************************* 17
txxxing...
TX failed after 3 retries

received a packet 20 bytes long

ASCII data (relevant data):
I Am NANO
LQI/RSSI=102/2
************************* 18
received a packet 20 bytes long

ASCII data (relevant data):
I Am NANO
LQI/RSSI=102/2
************************* 19
txxxing...
TX failed after 3 retries

received a packet 20 bytes long

ASCII data (relevant data):
I Am NANO
LQI/RSSI=111/1
************************* 20
received a packet 20 bytes long

ASCII data (relevant data):
I Am NANO
LQI/RSSI=111/1
************************* 21
txxxing...
TX failed after 3 retries

received a packet 20 bytes long

ASCII data (relevant data):
I Am NANO
LQI/RSSI=108/0
************************* 22
received a packet 20 bytes long

ASCII data (relevant data):
I Am NANO
LQI/RSSI=108/0
************************* 23
txxxing...
TX failed after 3 retries

received a packet 20 bytes long

ASCII data (relevant data):
I Am NANO
LQI/RSSI=110/1
************************* 24
received a packet 20 bytes long

ASCII data (relevant data):
I Am NANO
LQI/RSSI=110/1
************************* 25
txxxing...
TX failed after 3 retries

received a packet 20 bytes long

ASCII data (relevant data):
I Am NANO
LQI/RSSI=107/0
************************* 26
received a packet 20 bytes long

ASCII data (relevant data):
I Am NANO
LQI/RSSI=107/0
************************* 27
txxxing...
TX failed after 3 retries

txxxing...
TX failed after 3 retries

evanbarnes

My code used.


Code for the Nano

/**
* Example code for using a microchip mrf24j40 module to send and receive
* packets using plain 802.15.4
* Requirements: 3 pins for spi, 3 pins for reset, chip select and interrupt
* notifications
* This example file is considered to be in the public domain
* Originally written by Karl Palsson, karlp@tweak.net.au, March 2011
*/
#include <SPI.h>
#include <mrf24j.h>

const int pin_reset = 6;
const int pin_cs = 10; // default CS pin on ATmega8/168/328
const int pin_interrupt = 2; // default interrupt pin on ATmega8/168/328

Mrf24j mrf(pin_reset, pin_cs, pin_interrupt);

long last_time;
long tx_interval = 1000;

void setup() {
  Serial.begin(9600);
  Serial.println("NANO");
 
  mrf.reset();
  mrf.init();
 
  mrf.set_pan(0xcafe);
  // This is _our_ address
  mrf.address16_write(0x4201);

  // uncomment if you want to receive any packet on this channel
  mrf.set_promiscuous(true);
 
  // uncomment if you want to enable PA/LNA external control
  //mrf.set_palna(true);
 
  // uncomment if you want to buffer all PHY Payload
  //mrf.set_bufferPHY(true);

  attachInterrupt(0, interrupt_routine, CHANGE); // interrupt 0 equivalent to pin 2(INT0) on ATmega8/168/328
  last_time = millis();
  interrupts();
}

void interrupt_routine() {
    mrf.interrupt_handler(); // mrf24 object interrupt routine
}

void loop() {
    mrf.check_flags(&handle_rx, &handle_tx);
    unsigned long current_time = millis();
    if (current_time - last_time > tx_interval) {
        last_time = current_time;
        Serial.println("txxxing...");
        mrf.send16(0x4202, "I Am NANO");
    }
}

void handle_rx() {
    Serial.print("received a packet ");Serial.print(mrf.get_rxinfo()->frame_length, DEC);Serial.println(" bytes long");
   
    if(mrf.get_bufferPHY()){
      Serial.println("Packet data (PHY Payload):");
      for (int i = 0; i < mrf.get_rxinfo()->frame_length; i++) {
          Serial.print(mrf.get_rxbuf());
      }
    }
   
    Serial.println("\r\nASCII data (relevant data):");
    for (int i = 0; i < mrf.rx_datalength(); i++) {
        Serial.write(mrf.get_rxinfo()->rx_data);
    }
   
    Serial.print("\r\nLQI/RSSI=");
    Serial.print(mrf.get_rxinfo()->lqi, DEC);
    Serial.print("/");
    Serial.println(mrf.get_rxinfo()->rssi, DEC);
}

void handle_tx() {
    if (mrf.get_txinfo()->tx_ok) {
        Serial.println("TX went ok, got ack");
    } else {
        Serial.print("TX failed after ");Serial.print(mrf.get_txinfo()->retries);Serial.println(" retries\n");
    }
}


Code for the bare chip

/**
* Example code for using a microchip mrf24j40 module to send and receive
* packets using plain 802.15.4
* Requirements: 3 pins for spi, 3 pins for reset, chip select and interrupt
* notifications
* This example file is considered to be in the public domain
* Originally written by Karl Palsson, karlp@tweak.net.au, March 2011
*/
#include <SPI.h>
#include <mrf24j.h>

const int pin_reset = 6;
const int pin_cs = 10; // default CS pin on ATmega8/168/328
const int pin_interrupt = 2; // default interrupt pin on ATmega8/168/328

Mrf24j mrf(pin_reset, pin_cs, pin_interrupt);

long last_time;
long tx_interval = 1000;
int rx_count = 0;

void setup() {
  Serial.begin(9600);
  Serial.println("ATMEGA");
 
  mrf.reset();
  mrf.init();
 
  mrf.set_pan(0xcafe);
  // This is _our_ address
  mrf.address16_write(0x4202);

  // uncomment if you want to receive any packet on this channel
  mrf.set_promiscuous(true);
 
  // uncomment if you want to enable PA/LNA external control
  //mrf.set_palna(true);
 
  // uncomment if you want to buffer all PHY Payload
  //mrf.set_bufferPHY(true);

  attachInterrupt(0, interrupt_routine, CHANGE); // interrupt 0 equivalent to pin 2(INT0) on ATmega8/168/328
  last_time = millis();
  interrupts();
}

void interrupt_routine() {
    mrf.interrupt_handler(); // mrf24 object interrupt routine
}

void loop() {
    mrf.check_flags(&handle_rx, &handle_tx);
    unsigned long current_time = millis();
    if (current_time - last_time > tx_interval) {
        last_time = current_time;
        Serial.println("txxxing...");
        mrf.send16(0x4201, "I am ATMEGA");
    }
}

void handle_rx() {
    Serial.print("received a packet ");Serial.print(mrf.get_rxinfo()->frame_length, DEC);Serial.println(" bytes long");
   
    if(mrf.get_bufferPHY()){
      Serial.println("Packet data (PHY Payload):");
      for (int i = 0; i < mrf.get_rxinfo()->frame_length; i++) {
          Serial.print(mrf.get_rxbuf());
      }
    }
   
    Serial.println("\r\nASCII data (relevant data):");
    for (int i = 0; i < mrf.rx_datalength(); i++) {
        Serial.write(mrf.get_rxinfo()->rx_data);
    }
   
    Serial.print("\r\nLQI/RSSI=");
    Serial.print(mrf.get_rxinfo()->lqi, DEC);
    Serial.print("/");
    Serial.println(mrf.get_rxinfo()->rssi, DEC);
   
    rx_count++;
    Serial.print("************************* ");
    Serial.println(rx_count);
}

void handle_tx() {
    if (mrf.get_txinfo()->tx_ok) {
        Serial.println("TX went ok, got ack");
    } else {
        Serial.print("TX failed after ");Serial.print(mrf.get_txinfo()->retries);Serial.println(" retries\n");
    }
}




Go Up