SPI Communication with MRF24J40MA Module

Hello everyone,

I am currently using a project for my college which requires a RF module and I have met some problem trying to configure the RF module.

This is the data sheet for the MRF24J40 ww1.microchip.com/downloads/en/DeviceDoc/39776C.pdf

I have attached the code in this discussion. I tried setting the interrupt of the chip so it will be active low but it does not seem to work after setting address 0x211 to 0x02(INTEDGE = High) and address 0x32 to 0xF6(Enable RXIE and TXNIE).

I also tried to send and receive with the code but it does not work as well.

Please give me a suggestion or tips if anyone have an experience using similar chip. Much appreciated. Thank you.


First thing is that you are driving reset the wrong way round. Reset is active low, an inactive high - when using the chip, the reset line should be high.

Your code has the device held in reset continuously, which may explain why it isn’t working :slight_smile:

There are some small bits like this function:
//Function to write short address function writeShort(address,value) { local data = blob(2); // Make sure the output is disabled before we start clocking out data cs.write(0); data.writen((address<<1 & 0x7F) | 0x01,'b'); data.writen(value,'b'); data.writen(0x00,'b'); // Now send the data spi.writeread(data); // Last, re-enable the output server.log("Short" + data.len()); server.log(data); cs.write(1); }

…could be done more neatly as:

`//Function to write short address
function writeShort(address,value) {
local data = blob(3);

// Make sure the output is disabled before we start clocking out data
data[0]=(address<<1 & 0x7F) | 0x01;

// Now send the data

server.log("Short" + data.len());


…as in, you can just address a blob directly like an array, and generally you only assert CS for the actual transaction, as this makes it easier to catch transactions on a scope (wouldn’t have prevented your code working before - even the too-short blob would have auto-extended).

When you’re reading you can also extract the actual data bytes from the transaction and return a number, vs the blob which will include junk during the outbound phase of the transactions.

Anyway, give it a try with the reset inverted?

Thank you very much for the help Hugo. I have tried inverting the reset and tidying the code but it doesn’t seem to work. I have changed over to bluetooth for now as I am running out of time in completing my project. Will come back to RF when I have the time to. Much appreciated.