CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Some slave nodes can't receive nRF24L01+ data from master

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
tienchuan



Joined: 25 Aug 2009
Posts: 175

View user's profile Send private message Yahoo Messenger

Some slave nodes can't receive nRF24L01+ data from master
PostPosted: Mon May 16, 2016 7:02 pm     Reply with quote

Hi.
I tried this driver to create a RF network using 1 master and 6 slave.
http://www.ccsinfo.com/forum/viewtopic.php?t=47351

In my project, the master request data from slave, send data config to slave so that I'm using a broadcast mode for this case.
I've configured all nodes to turn off auto ACK, maximum power 0dbm and data rate speed~250kbps.
But I have a problem that some slave nodes can't receive data from master.
Can you have an ideas about this problem?

I'm using CCS C 5.048, PIC16F1455 for master node( transfer data through USB port), PIC18F25K20 for slave node.

Here is my driver for NRF24l01:
Code:

void RF24_default_config() {  //Ititializes default configuration for chip nRF24L01+

   #ifdef RF24_USE_DMA
      DMA_default_config();   //Sets default DMA configuration
   #endif     

   RF24_disable();     

   RF24_comm(W_REGISTER|CONFIGURATION, EN_CRC|CRC16|PWR_UP);   //RF_packet CRC and nRF24L01+ configuration and initialization
   RF24_PWUPDELAY();

   RF24_comm(W_REGISTER|EN_AUTOACK, 0b0000000);   //autoack in pipe 0,1,2,3,4 and 5

   RF24_comm(W_REGISTER|EN_RXPIPES, 0b00000011);   //****enable only pipes 0 and 1(pipes 2 to 5 are not used)

   RF24_comm(W_REGISTER|SETUP_ADDRESSWIDTH, 1);    //addresswidth setting[1 to 3(3 to 5 bytes)]
                                                   //ADDRESSWIDTH = 1 -> it means 3 bytes

   RF24_comm(W_REGISTER|SETUP_AUTORETRANSMISSION,  //[7:4(250 to 4000us) autoretry delay, 3:0(0 to 15)Auto retry times]
         0b00111111);                                 //waitretry 500us   , retry 15times  //ARD=500µs is long enough for any ACK payload length in 1 or 2Mbps mode
   RF24_comm(W_REGISTER|RF_CHANNEL, sw_freq);               //Set RF channel. F0= 2400 + RF_CHANNEL [MHz]. Use 1 channel of space for 250kbps to 1Mbps radios and 2 channels of space between 2Mbps radios.
                                                      //RF channel=0(2400MHz)
   RF24_comm(W_REGISTER|RF_SETUP,
      RF_DR_250kbps|RF_PWR_0dBm);                     //Datarate 2Mbps. Power Amplifier in 0dBm.
   
   RF24_comm(W_REGISTER|STATUS,                                //Status Register (In parallel to the SPI command word applied on the MOSI pin, the STATUS register is shifted serially out on the MISO pin)
      IRQ_RX_dataready|IRQ_TX_datasent|IRQ_MAX_retransmit);    //Clear these tree interrupts

   RF24_comm_out(W_REGISTER|RX_ADDR_P0,               //Receive address data pipe 0. 5 Bytes maximum length. (LSByte first)
      "0rdda", 5 );                                   //Address ascii "addr0"(5 bytes), LSB first. Because of that, it is written on the contrary.
   RF24_comm_out(W_REGISTER|RX_ADDR_P1,               //Receive address data pipe 1. 5 Bytes maximum length. (LSByte first)
      "1rdda", 5 );                                   //Address ascii "addr1"(5 bytes), LSB first. Because of that, it is written on the contrary.
   RF24_comm_out(W_REGISTER|RX_ADDR_P2,               //Receive address data pipe 2. 5 Bytes maximum length. (LSByte first)
      '2', 1);                                        //Address ascii "addr2"  (I can change only the LsByte)
   RF24_comm_out(W_REGISTER|RX_ADDR_P3,               //Receive address data pipe 3. 5 Bytes maximum length. (LSByte first)
      '3', 1);                                        //Address ascii "addr3"  (I can change only the LsByte)
   RF24_comm_out(W_REGISTER|RX_ADDR_P4,               //Receive address data pipe 4. 5 Bytes maximum length. (LSByte first)
      '4', 1);                                        //Address ascii "addr4"  (I can change only the LsByte)
   RF24_comm_out(W_REGISTER|RX_ADDR_P5,               //Receive address data pipe 5. 5 Bytes maximum length. (LSByte first)
      '5', 1);                                        //Address ascii "addr5"  (I can change only the LsByte)

   RF24_comm_out(W_REGISTER|TX_ADDR,      //(3 to 5 bytes)Transmit address. Used for a PTX device only.(LSByte first). Set RX_ADDR_P0 equal to this address to handle automatic acknowledge if Enhanced ShockBurst enabled
      "0rdda", 5 );                       //Address ascii "addr0"(5 bytes), LSB first. Because of that, it is written on the contrary.

   RF24_comm(W_REGISTER|RX_PW_P0, 32);    //(set 1 to 32)RX payload size pipe0 set to 32 bytes
   RF24_comm(W_REGISTER|RX_PW_P1, 32);    //(set 1 to 32)RX payload size pipe1 set to 32 bytes
   RF24_comm(W_REGISTER|RX_PW_P2, 32);    //(set 1 to 32)RX payload size pipe2 set to 32 bytes
   RF24_comm(W_REGISTER|RX_PW_P3, 32);    //(set 1 to 32)RX payload size pipe3 set to 32 bytes
   RF24_comm(W_REGISTER|RX_PW_P4, 32);    //(set 1 to 32)RX payload size pipe4 set to 32 bytes
   RF24_comm(W_REGISTER|RX_PW_P5, 32);    //(set 1 to 32)RX payload size pipe5 set to 32 bytes
                                          //although other pipes(pipe 2 to 5) are not used(see EN_RXPIPES setting)
   RF24_comm(W_REGISTER|EN_DYNAMIC_PAYLOAD,//bits 0 to 5 enables in pipe0 to pipe5
      0b00111111);                        //Dynamic payload Enabled in all pipes(pipe 0 to 5)

   RF24_comm(W_REGISTER|DYN_PAYLOAD_CONFIG,//Enables (DPL)Dynamic payload length feature. Enable to be able to transmit variable data length packets(from 1 to 32 data bytes)
      EN_DPL|EN_ACK_PAY|EN_DYN_ACK);       //All DPL functions enabled
   
   RF24_comm(W_REGISTER|FLUSH_RX);        //Delete RX buffer(already transfered to buffer)
   RF24_comm(W_REGISTER|FLUSH_TX);        //Delete TX buffer(already transfered to buffer)
   RF24_STATUS_clr_IRQs(IRQ_ALL);         //clear IRQs

   RF24_disable();       
}//


* Slave node code trans and receiver:
Code:

if(RF24_RX_getbuffer(&RXpipe, &RXdatasize, RXbuffer1) ==true )     
      {
         output_toggle(led_trx);
         if( RXbuffer1[0]=='R' && RXbuffer1[1]=='L' && RXbuffer1[2]=='S' && RXbuffer1[3]==id_code[0] && RXbuffer1[4]== id_code[1] && RXbuffer1[5]== id_code[2]){
            str_ack[0]= 'A';
            str_ack[1]= 'C';
            str_ack[2]= 'K';
            str_ack[3]= id_code[0];
            str_ack[4]= id_code[1];
            str_ack[5]= id_code[2];

            output_low(relay);
            output_low(led_sa);
           
            RF24_TX_SET();   
            delay_ms(10);
            RF24_TX_putbuffer(false,6,str_ack);
            while(RF24_IRQ_state()==false);       
            RF24_STATUS_clr_IRQs(IRQ_ALL); 
            delay_ms(10);
            RF24_RX_SET();   
            RF24_comm(FLUSH_RX);                         //Delete RX buffer
            RF24_STATUS_clr_IRQs(IRQ_RX_dataready);             
         }

         if( RXbuffer1[0]=='R' && RXbuffer1[1]=='L' && RXbuffer1[2]=='O' && RXbuffer1[3]==id_code[0] && RXbuffer1[4]== id_code[1] && RXbuffer1[5]== id_code[2]){
            str_ack[0]= 'A';
            str_ack[1]= 'C';
            str_ack[2]= 'K';
            str_ack[3]= id_code[0];
            str_ack[4]= id_code[1];
            str_ack[5]= id_code[2];
           
            output_high(relay);
            output_high(led_sa);
           
            RF24_TX_SET();
            delay_ms(10);
            RF24_TX_putbuffer(false,6,str_ack);
            while(RF24_IRQ_state()==false);       
            RF24_STATUS_clr_IRQs(IRQ_ALL);
            delay_ms(10);
            RF24_RX_SET(); 
            RF24_comm(FLUSH_RX);                         //Delete RX buffer
            RF24_STATUS_clr_IRQs(IRQ_RX_dataready);
           
         }   
         
         RF24_comm(FLUSH_RX);       
         RF24_comm(FLUSH_TX);     
         RF24_STATUS_clr_IRQs(IRQ_RX_dataready);           
         RF24_STATUS_clr_IRQs(IRQ_ALL);           
      }



* master node code trans and receiver:
Code:

if (usb_enumerated())
      { 
         if(alert_pc==0)
         {
            delay_ms(3000);
            out_data="USBOK  ";
            usb_put_packet(USB_HID_ENDPOINT, out_data, USB_CONFIG_HID_TX_SIZE, USB_DTS_TOGGLE);
            alert_pc=1;           
         }
         //-----------------------------------------------------------------------------------
         //-------------------------- SEND ACK TO PC  ----------------------------------------
         //-----------------------------------------------------------------------------------
         if(RF24_RX_getbuffer(&RXpipe, &RXdatasize, RX_RF_buffer)==true )
         {
            rf_finish=1;
            if(RXdatasize==6 && RX_RF_buffer[0]=='A')
            {
               out_data[0] = '$';
               out_data[1] = RX_RF_buffer[0]; 
               out_data[2] = RX_RF_buffer[1];
               out_data[3] = RX_RF_buffer[2];
               out_data[4] = RX_RF_buffer[3];
               out_data[5] = RX_RF_buffer[4];
               out_data[6] = RX_RF_buffer[5];               
               out_data[7] = '#';
               
               usb_put_packet(USB_HID_ENDPOINT, out_data, USB_CONFIG_HID_TX_SIZE, USB_DTS_TOGGLE);//!               output_low(led_dbg);
               delay_ms(10);
               usb_put_packet(USB_HID_ENDPOINT, out_data, USB_CONFIG_HID_TX_SIZE, USB_DTS_TOGGLE); //!               output_high(led_dbg);
               
               timeout=0;
               count_t0=0;
               disable_interrupts(int_timer1);   
               clear_interrupt(int_timer1);
            }
            else
            {
               out_data="Erros";
               usb_put_packet(USB_HID_ENDPOINT, out_data, USB_CONFIG_HID_TX_SIZE, USB_DTS_TOGGLE);//!               output_low(led_dbg);
               delay_ms(10);  //!               output_high(led_dbg);
            }
           
            RF24_comm(FLUSH_RX);        //Delete RX buffer(already transfered to buffer)
            RF24_comm(FLUSH_TX);
            RF24_STATUS_clr_IRQs(IRQ_RX_dataready);      //clear RX IRQ     
            RF24_STATUS_clr_IRQs(IRQ_ALL);
           
            output_toggle(PIN_C3);
            rf_finish=0;
         }


         //-----------------------------------------------------------------------------------
         //-------------------------- SEND REQUEST TO NODE  ----------------------------------
         //-----------------------------------------------------------------------------------         
         if (usb_kbhit(USB_HID_ENDPOINT) && (rf_finish==0) )
         {
            usb_get_packet(USB_HID_ENDPOINT, in_data, USB_CONFIG_HID_RX_SIZE);
            if( (in_data[0]=='$') && (in_data[1]=='R') && (in_data[2]=='L') && ( in_data[7]=='#') )
            {
               TX_RF_buffer[0]= in_data[1];
               TX_RF_buffer[1]= in_data[2];
               TX_RF_buffer[2]= in_data[3];
               TX_RF_buffer[3]= in_data[4];     
               TX_RF_buffer[4]= in_data[5];   
               TX_RF_buffer[5]= in_data[6];   
               
               RF24_comm(FLUSH_RX);        //Delete RX buffer(already transfered to buffer)
               RF24_comm(FLUSH_TX);
               
               RF24_TX_SET();
               delay_ms(10);
               RF24_TX_putbuffer(false,6,tx_rf_buffer);
               while(RF24_IRQ_state()==false);       
               RF24_STATUS_clr_IRQs(IRQ_ALL); 
               delay_ms(10);
               RF24_RX_SET();
               RF24_STATUS_clr_IRQs(IRQ_RX_dataready);   
               
               count_t0=0;
               timeout=0;
               enable_interrupts(int_timer1);
               clear_interrupt(int_timer1);
               output_toggle(led_dbg);
            }
//!            if( in_data[0]=='$' && in_data[1]=='R' && in_data[2]=='F' && in_data[7]=='#')
//!            {
//!               RF_Freq[0] = in_data[3] - 0x30  ;
//!               RF_Freq[1] = in_data[4] - 0x30  ;
//!               RF_Freq[2] = in_data[5] - 0x30  ;
//!               RF_Freq[3] = in_data[6] - 0x30  ;
//!               
//!               rf_freq_set = make32(RF_Freq[0],RF_Freq[1],RF_Freq[2],RF_Freq[3]);
//!               rF_freq_set-= 2400;
//!               if( rf_freq_set<2400) rf_freq_set=0;
//!            }
         
         }

Thanks you.
_________________
Begin Begin Begin !!!
Ttelmah



Joined: 11 Mar 2010
Posts: 19339

View user's profile Send private message

PostPosted: Thu May 19, 2016 12:46 pm     Reply with quote

Seriously if some slaves are working and they are all using the same code, you need to be looking at hardware.
Tidy things down. Get one of the modules that doesn't work, and substitute this for one that does. Physical position and code.

Then also be aware that the range of these varies between modules:
<https://hallard.me/nrf24l01-real-life-range-test/>

They are also very fussy about power. Though the average consumption is low, there are big spikes, and if these aren't handled properly, reliability plummets.

Are your modules the high power, or low power versions?.
Look at this thread:
<http://forum.arduino.cc/index.php?topic=125512.0>

If you look at the end of this, you will see that problems are not uncommon.....
tienchuan



Joined: 25 Aug 2009
Posts: 175

View user's profile Send private message Yahoo Messenger

PostPosted: Wed May 25, 2016 7:10 pm     Reply with quote

Thanks for helping.
Really, the code same in all slave node, because i'm using 8 dip switch to choose an id for node, so that when communication between nodes, they have a different ID address.
Sorry about my careless with the problems solve when i connected external antena for master and slave, every msg send and received is OK.
And I want to expand a quantity of slave node, i read in datasheet but not find informatin about maximum node for broadcast mode.
Thanks for your support.
_________________
Begin Begin Begin !!!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group