Hello, I need some help. I connected NRLF24L01 and Sensor Bme280(SPI) on the SPI, with different CS pins. In separate codes, both devices works fine. However when I want to make them work in the same code - reading sensor value and sending it with nrf - Sensor doesn't work. I think it can be SPI conflict? I found out that after I wrote nrf radio.begin() function, my sensor stoped working - mabye because bme.begin() function can't be initialized?
When I put radio.begin() and bme.begin() not in setup, but in a function - both devices works, but sensor show -147 temp. When radio.begin() is in the setup, bme.begin() doesn't even start. I tried to analyze libraries, but I can't find what is wrong, can you look at these functions?
bool RF24::begin(void)
572 {
573
574 uint8_t setup=0;
575
576 #if defined (RF24_LINUX)
577
578 #if defined (MRAA)
579 GPIO();
580 gpio.begin(ce_pin,csn_pin);
581 #endif
582
583 #ifdef RF24_RPi
584 switch(csn_pin){ //Ensure valid hardware CS pin
585 case 0: break;
586 case 1: break;
587 // Allow BCM2835 enums for RPi
588 case 8: csn_pin = 0; break;
589 case 7: csn_pin = 1; break;
590 default: csn_pin = 0; break;
591 }
592 #endif
593
594 _SPI.begin(csn_pin);
595
596 pinMode(ce_pin,OUTPUT);
597 ce(LOW);
598
599 delay(100);
600
601 #elif defined(LITTLEWIRE)
602 pinMode(csn_pin,OUTPUT);
603 _SPI.begin();
604 csn(HIGH);
605 #elif defined(XMEGA_D3)
606 if (ce_pin != csn_pin) pinMode(ce_pin,OUTPUT);
607 _SPI.begin(csn_pin);
608 ce(LOW);
609 csn(HIGH);
610 delay(200);
611 #else
612 // Initialize pins
613 if (ce_pin != csn_pin) pinMode(ce_pin,OUTPUT);
614
615 #if ! defined(LITTLEWIRE)
616 if (ce_pin != csn_pin)
617 #endif
618 pinMode(csn_pin,OUTPUT);
619
620 _SPI.begin();
621 ce(LOW);
622 csn(HIGH);
623 #if defined (__ARDUINO_X86__)
624 delay(100);
625 #endif
626 #endif //Linux
627
628 // Must allow the radio time to settle else configuration bits will not necessarily stick.
629 // This is actually only required following power up but some settling time also appears to
630 // be required after resets too. For full coverage, we'll always assume the worst.
631 // Enabling 16b CRC is by far the most obvious case if the wrong timing is used - or skipped.
632 // Technically we require 4.5ms + 14us as a worst case. We'll just call it 5ms for good measure.
633 // WARNING: Delay is based on P-variant whereby non-P *may* require different timing.
634 delay( 5 ) ;
635
636 // Reset NRF_CONFIG and enable 16-bit CRC.
637 write_register( NRF_CONFIG, 0b00001100 ) ;
638
639 // Set 1500uS (minimum for 32B payload in ESB@250KBPS) timeouts, to make testing a little easier
640 // WARNING: If this is ever lowered, either 250KBS mode with AA is broken or maximum packet
641 // sizes must never be used. See documentation for a more complete explanation.
642 setRetries(5,15);
643
644 // Reset value is MAX
645 //setPALevel( RF24_PA_MAX ) ;
646
647 // check for connected module and if this is a p nRF24l01 variant
648 //
649 if( setDataRate( RF24_250KBPS ) )
650 {
651 p_variant = true ;
652 }
653 setup = read_register(RF_SETUP);
654 /*if( setup == 0b00001110 ) // register default for nRF24L01P
655 {
656 p_variant = true ;
657 }*/
658
659 // Then set the data rate to the slowest (and most reliable) speed supported by all
660 // hardware.
661 setDataRate( RF24_1MBPS ) ;
662
663 // Initialize CRC and request 2-byte (16bit) CRC
664 //setCRCLength( RF24_CRC_16 ) ;
665
666 // Disable dynamic payloads, to match dynamic_payloads_enabled setting - Reset value is 0
667 toggle_features();
668 write_register(FEATURE,0 );
669 write_register(DYNPD,0);
670
671 // Reset current status
672 // Notice reset and flush is the last thing we do
673 write_register(NRF_STATUS,_BV(RX_DR) | _BV(TX_DS) | _BV(MAX_RT) );
674
675 // Set up default configuration. Callers can always change it later.
676 // This channel should be universally safe and not bleed over into adjacent
677 // spectrum.
678 setChannel(76);
679
680 // Flush buffers
681 flush_rx();
682 flush_tx();
683
684 powerUp(); //Power up by default when begin() is called
685
686 // Enable PTX, do not write CE high so radio will remain in standby I mode ( 130us max to transition to RX or TX instead of 1500us from powerUp )
687 // PTX should use only 22uA of power
688 write_register(NRF_CONFIG, ( read_register(NRF_CONFIG) ) & ~_BV(PRIM_RX) );
689
690 // if setup is 0 or ff then there was no response from module
691 return ( setup != 0 && setup != 0xff );
692 }
Are you expecting 25s where it is actually showing -147?
Can you ask the Adafruit people about it?
Another thought is to study the SPI library reference and maybe try putting some SPI settings commands between the RF24 call and the BME call.
I note you are using pin 10 with the RF24. Maybe re-wire things so the BME can use that - though I can't think why it would matter. I do know that the RF24 won't care what pins are used for CE and CSN.
...R
PS make sure to set the RF24 code back to what it should be.