Wireless RF module

Discussion in 'Embedded Systems and Microcontrollers' started by Gelingo, May 30, 2011.

  1. Gelingo

    Thread Starter New Member

    May 30, 2011
    3
    0
    Hello Guys:

    I make a demo of nRF24L01 module, which show how to control it by using Arduino. This is the part of the code.

    Code ( (Unknown Language)):
    1. void setup()
    2. {
    3.   SPI_DIR = ( CE + SCK + CSN + MOSI);
    4.   SPI_DIR &=~ ( IRQ + MISO);
    5.   //  attachInterrupt(1, _ISR, LOW);// interrupt enable
    6.   Serial.begin(9600);
    7.   init_io();                        // Initialize IO port
    8.   unsigned char status=SPI_Read(STATUS);
    9.   Serial.print("status = ");
    10.   Serial.println(status,HEX);      // read the mode’s status register, the default value should be ‘E’
    11.   Serial.println("*******************TX_Mode Start****************************");
    12.   TX_Mode();                       // set TX mode
    13. }
    14. void loop()
    15. {
    16.   int k = 0;
    17.   for(;;)
    18.   {
    19.     for(int i=0; i<32; i++)
    20.         tx_buf[i] = k++;
    21.     unsigned char status = SPI_Read(STATUS);                // read register STATUS's value
    22.     if(status&TX_DS)                                        // if receive data ready (TX_DS) interrupt
    23.     {
    24.       SPI_RW_Reg(FLUSH_TX,0);
    25.       SPI_Write_Buf(WR_TX_PLOAD,tx_buf,TX_PLOAD_WIDTH);     // write playload to TX_FIFO
    26.     }
    27.     if(status&MAX_RT)                                       // this is retransmit than  SETUP_RETR
    28.     {
    29.       SPI_RW_Reg(FLUSH_TX,0);
    30.       SPI_Write_Buf(WR_TX_PLOAD,tx_buf,TX_PLOAD_WIDTH);     // disable standy-mode
    31.     }
    32.     SPI_RW_Reg(WRITE_REG+STATUS,status);                    // clear RX_DR or TX_DS or MAX_RT interrupt flag
    33.     delay(1000);
    34.   }
    35. }[/i]


    The whole code is here: http://www.elecfreaks.com/203.html

    This is just one way to use the module, any other ideas? Thank you for your help first.
     
Loading...