nRF24L01 with Arduinio’s SPI Library

Hi Guys, We have received some mails for asking if we will provide the nRF24L01‘s hardware SPI demo or library, which we just provided the software SPI before. So we modified the code used SPI library which you can get from Arduino’s standard library.

The frist change is the connection between pins and Arduino. The old mode is:

GND – GND, VCC – 3.3V, CS – D8, CSN – D9, SCK – D10, MOSI – D11, MISO – D12, IRQ – D13

If you want to use Arduino’s SPI library, you should connect them as below:

GND – GND, VCC – 3.3V, CS – D8, CSN – D9, SCK – D13,  MOSI – D11, MISO – D12, IRQ – D10

Define about CS, IRQ and CSN could be changed by yourself, the other pins you can not change because of the Arduino’s board provide.

The second, let us show you where the code was changed, it was very easy.

Main modefied is :


unsigned char SPI_RW(unsigned char Byte)
{
  unsigned char i;
  for(i=0;i<8;i++)                      // output 8-bit
  {
    if(Byte&0x80)
    {
      SPI_PORT |=MOSI;                  // output 'unsigned char', MSB to MOSI
    }
    else
    {
      SPI_PORT &=~MOSI;
    }
    SPI_PORT|=SCK;                      // Set SCK high..
    Byte <<= 1;                         // shift next bit into MSB..
    if(SPI_IN & MISO)
    {
      Byte |= 1;                        // capture current MISO bit
    }
    SPI_PORT&=~SCK;                     // ..then set SCK low again
  }
  return(Byte);                         // return read unsigned char
}

to


unsigned char SPI_RW(unsigned char Byte)
{
  return SPI.transfer(Byte);
}

Oh, So clear.

At last, maybe you like this code mode, however there are some defects also,  it’s just for Arduino but other microprocessors.

The softwore SPI is more in common use other development platform.

OK, this just is a sample code for your reference.

Download the Full Code..  (include SPI_rf24L01_TX and  SPI_rf24L01_RX)

Link to nRF24L01_Demo_For_Arduino..  (software SPI mode)

VN:F [1.9.13_1145]
Rating: 7.3/10 (6 votes cast)
VN:F [1.9.13_1145]
Rating: +1 (from 1 vote)
nRF24L01 with Arduinio's SPI Library, 7.3 out of 10 based on 6 ratings

Related Posts

  • Pingback: NRF24L01 ,NRF24L01 Module Demo For Arduino

  • Pingback: NRF24L01

    • dany

      Thank you for your attention and message. Welcome to contact us if you have any advice.

      VN:F [1.9.13_1145]
      Rating: 0.0/5 (0 votes cast)
      VN:F [1.9.13_1145]
      Rating: 0 (from 0 votes)
  • Pingback: AUTOMALABS &raquo Módulo de comunicação sem fio NRF24L01+

  • dandrade

    Here code result! SOLVE! ERROR COMPILING:

    sketch_mar29a.cpp: In function ‘void setup()’:
    sketch_mar29a.cpp:10:3: error: ‘SPI_DIR’ was not declared in this scope
    sketch_mar29a.cpp:10:15: error: ‘CE’ was not declared in this scope
    sketch_mar29a.cpp:10:26: error: ‘CSN’ was not declared in this scope
    sketch_mar29a.cpp:11:17: error: ‘IRQ’ was not declared in this scope
    sketch_mar29a.cpp:14:11: error: ‘init_io’ was not declared in this scope
    sketch_mar29a.cpp:15:39: error: ‘SPI_Read’ was not declared in this scope
    sketch_mar29a.cpp:19:11: error: ‘TX_Mode’ was not declared in this scope
    sketch_mar29a.cpp: In function ‘void loop()’:
    sketch_mar29a.cpp:27:9: error: ‘tx_buf’ was not declared in this scope
    sketch_mar29a.cpp:28:43: error: ‘SPI_Read’ was not declared in this scope
    sketch_mar29a.cpp:31:28: error: ‘SPI_RW_Reg’ was not declared in this scope
    sketch_mar29a.cpp:32:21: error: ‘WR_TX_PLOAD’ was not declared in this scope
    sketch_mar29a.cpp:32:33: error: ‘tx_buf’ was not declared in this scope
    sketch_mar29a.cpp:32:40: error: ‘TX_PLOAD_WIDTH’ was not declared in this scope
    sketch_mar29a.cpp:32:54: error: ‘SPI_Write_Buf’ was not declared in this scope
    sketch_mar29a.cpp:36:28: error: ‘SPI_RW_Reg’ was not declared in this scope
    sketch_mar29a.cpp:37:21: error: ‘WR_TX_PLOAD’ was not declared in this scope
    sketch_mar29a.cpp:37:33: error: ‘tx_buf’ was not declared in this scope
    sketch_mar29a.cpp:37:40: error: ‘TX_PLOAD_WIDTH’ was not declared in this scope
    sketch_mar29a.cpp:37:54: error: ‘SPI_Write_Buf’ was not declared in this scope
    sketch_mar29a.cpp:39:16: error: ‘WRITE_REG’ was not declared in this scope
    sketch_mar29a.cpp:39:39: error: ‘SPI_RW_Reg’ was not declared in this scope

    VA:F [1.9.13_1145]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.13_1145]
    Rating: 0 (from 0 votes)
  • Pina

    The code’s gone! Don’t bother clicking or using anything on this page unfortunately. Khunts!

    VA:F [1.9.13_1145]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.13_1145]
    Rating: -1 (from 1 vote)
  • http://www.bing.com/ Chubby

    BION I’m ipmressed! Cool post!

    VA:F [1.9.13_1145]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.13_1145]
    Rating: 0 (from 0 votes)
  • http://www.bing.com/ Alexavier

    That’s more than snelsibe! That’s a great post!

    VA:F [1.9.13_1145]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.13_1145]
    Rating: 0 (from 0 votes)
  • http://www.google.com/ Gump

    Hey, that’s the gretaset! So with ll this brain power AWHFY?

    VA:F [1.9.13_1145]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.13_1145]
    Rating: 0 (from 0 votes)
  • Pingback: nRF24L01 Module Demo for Arduino | ElecFreaks

Go To Top