{"version":"1.0","provider_name":"Projects","provider_url":"https:\/\/projects.schneidr.de","author_name":"Gerald","author_url":"https:\/\/projects.schneidr.de\/author\/admin\/","title":"MRF24J40 and Arduino","html":"So, after some trial and error I managed to interface the\u00a0MRF24J40 modules with two Arduinos and have them exchange data.\r\n\r\n<a href=\"http:\/\/projects.schneidr.de\/files\/2012\/10\/P1150225.jpg\"><img class=\"aligncenter size-large wp-image-532\" title=\"P1150225\" src=\"http:\/\/projects.schneidr.de\/files\/2012\/10\/P1150225-600x450.jpg\" alt=\"\" width=\"584\" height=\"438\" \/><\/a>\r\n\r\nThis looks more complicated than it is.<!--more--> On the breadboard are two wireless transceiver modules, each one connected to an Arduino and an LED as a rudimentary status display. The Arduino communicates with the module over three\u00a0<a title=\"Serial Peripheral Interface Bus on Wikipedia\" href=\"http:\/\/en.wikipedia.org\/wiki\/Serial_Peripheral_Interface_Bus\">SPI<\/a>\u00a0pins and three\u00a0pins for reset, chip select and interrupt.\r\n<h2>Pin mapping:<\/h2>\r\n<table>\r\n<tbody>\r\n<tr>\r\n<th colspan=\"2\">MRF<\/th>\r\n<th colspan=\"2\">Arduino<\/th>\r\n<\/tr>\r\n<tr>\r\n<td>GND<\/td>\r\n<td>1<\/td>\r\n<td><\/td>\r\n<td>GND<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>RESET<\/td>\r\n<td>2<\/td>\r\n<td>6<\/td>\r\n<td><\/td>\r\n<\/tr>\r\n<tr>\r\n<td>INTR<\/td>\r\n<td>4<\/td>\r\n<td>2<\/td>\r\n<td>Interrupt 0<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>SDI<\/td>\r\n<td>5<\/td>\r\n<td>11<\/td>\r\n<td>MOSI<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>SCK<\/td>\r\n<td>6<\/td>\r\n<td>13<\/td>\r\n<td>SCK<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>SDO<\/td>\r\n<td>7<\/td>\r\n<td>12<\/td>\r\n<td>MISO<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>CS<\/td>\r\n<td>8<\/td>\r\n<td>7<\/td>\r\n<td><\/td>\r\n<\/tr>\r\n<tr>\r\n<td>VIN<\/td>\r\n<td>10<\/td>\r\n<td><\/td>\r\n<td>3V3<\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\nThis represents the pin layout from the Arduino Nano, on the Mega the SPI pins are a little different. MOSI, MISO and SCK are on pins 51, 50 and 52 instead of 11, 12 and 13.\r\n\r\nAs a bonus I connected pin 9 (NC) to a LED, figuring that \"not connected\" in the data sheet means that this can be used as an indicator if the module has a connection. It seems that I was right, the LED lights up when I connect the Arduino to power and turns off shortly after initializing, when the other module is available. Shortly after turning one device off the LED on the other device turns on again, so I guess it detected the connection loss.\r\n<h2>Software<\/h2>\r\nI used the Basic_TwoWay example from the library and changed just a few things:\r\n<pre>const int pin_reset = 6;\r\nconst int pin_cs = 7;\r\nconst int pin_interrupt = 2;<\/pre>\r\nI kept the default values for pin_reset and pin_cs but changed the pin_interrupt to 2 (which is the default interrupt 0 on both of my Arduinos.\r\n<pre>mrf.set_pan(0xcafe);\r\n\/\/ This is _our_ address\r\nmrf.address16_write(0x4201);<\/pre>\r\nI kept the PAN name 0xCAFE and just gave the devices different addresses. One stayed with the address 0x4201, the other got 0x4202. I don't have much experience with these devices yet, but I guess you can define those address pretty freely, you only have to make sure every one is unique and they all use the same PAN id.\r\n<pre>mrf.send16(0x4202, \"abcd\");<\/pre>\r\nThis is the last line I changed, making sure that 0x4201 sends to 0x4202 and vice versa.\r\n\r\nHere is my working code, but I'd check the github repository for updated versions:\u00a0<a href=\"http:\/\/projects.schneidr.de\/files\/2012\/10\/MRF24J40MA_test001.ino_.txt\">MRF24J40MA_test001.ino<\/a>\r\n\r\nHere is the output from the serial console:\r\n<pre>txxxing...\r\nTX went ok, got ack\r\nreceived a packet 15 bytes long\r\n\r\nASCII data (relevant data):\r\nabcd\r\nLQI\/RSSI=115\/255<\/pre>\r\n\"abcd\" is the transmitted data, LQI is a link quality indicator, RSSI is a signal strength indicator. I found a <a href=\"http:\/\/e2e.ti.com\/support\/low_power_rf\/w\/design_notes\/calculation-and-usage-of-lqi-and-rssi.aspx\">pretty good explanation about LQI and RSSI<\/a> on the Texas Instruments support site.\r\n<h2>Helpful resources<\/h2>\r\n<ul>\r\n\t<li><a href=\"http:\/\/www.microchip.com\/wwwproducts\/Devices.aspx?dDocName=en535967\">MRF24J40 Datasheet<\/a><\/li>\r\n\t<li><a href=\"https:\/\/github.com\/karlp\/Mrf24j40-arduino-library\">mrf24j40ma Arduino library on github<\/a><\/li>\r\n\t<li><a href=\"http:\/\/false.ekta.is\/2011\/03\/mrf24j40-with-arduino-teensyduino\/#comments\">Comments in this post<\/a> from the author of the library<\/li>\r\n\t<li>Hardware descriptions of <a href=\"http:\/\/arduino.cc\/en\/Main\/ArduinoBoardNano\">Arduino Nano<\/a> and <a href=\"http:\/\/arduino.cc\/en\/Main\/ArduinoBoardMega2560\">Arduino Mega<\/a><\/li>\r\n<\/ul>","type":"rich"}