I'm currently trying to make a NRF24L01 module work by using Java. I found this library that makes use of the JNI, but I can't get it to work.
When I try to run the provided example code the Raspberry Pi just hangs and the CPU rises to 100% after (or rather while) running rf24.begin()
.
I digged a little bit into the code and found out that the reason it hangs is due to an endless while loop inside the bcm2835_spi_transfernb()
function of this file.
The function is the following:
void bcm2835_spi_transfernb(char* tbuf, char* rbuf, uint32_t len)
{
volatile uint32_t* paddr = bcm2835_spi0 + BCM2835_SPI0_CS/4;
volatile uint32_t* fifo = bcm2835_spi0 + BCM2835_SPI0_FIFO/4;
uint32_t TXCnt=0;
uint32_t RXCnt=0;
// This is Polled transfer as per section 10.6.1
// BUG ALERT: what happens if we get interupted in this section, and someone else
// accesses a different peripheral?
// Clear TX and RX fifos
bcm2835_peri_set_bits(paddr, BCM2835_SPI0_CS_CLEAR, BCM2835_SPI0_CS_CLEAR);
// Set TA = 1
bcm2835_peri_set_bits(paddr, BCM2835_SPI0_CS_TA, BCM2835_SPI0_CS_TA);
// Use the FIFO's to reduce the interbyte times
while((TXCnt < len)||(RXCnt < len))
{
// TX fifo not full, so add some more bytes
while( (bcm2835_peri_read(paddr) & BCM2835_SPI0_CS_TXD ) && (TXCnt < len ) && !(bcm2835_peri_read(paddr) & BCM2835_SPI0_CS_RXR) )
{
bcm2835_peri_write_nb(fifo, tbuf[TXCnt]);
TXCnt++;
}
//Rx fifo not empty, so get the next received bytes
while(((bcm2835_peri_read(paddr) & BCM2835_SPI0_CS_RXD))&&( RXCnt < len )){
rbuf[RXCnt] = bcm2835_peri_read_nb(fifo);
RXCnt++;
}
}
while(! (bcm2835_peri_read(paddr) & BCM2835_SPI0_CS_DONE) ){}
if(TXCnt == len){ bcm2835_peri_set_bits(paddr, 0, BCM2835_SPI0_CS_TA);}
}
The problem is that the two while loops inside the outer while loop are never entered and therefore the exit-condition cannot occur turning this into an endless while loop.
Unfortunately I have no idea why that happens. Is it possible that this is due to a SPI related problem, like me forgetting to setup something? I did enable the SPI interface and validated it multiple times and also tested it. It seems to be working correctly. I also checked my wiring multiple times and I'm confident that its correct.
I would appreciate a little input, since I am really lost regarding this right now.
(2) TMRh20 RF24/RPi/RF24/bcm2835.c - Mike McCauley 2013 https://github.com/stanleyseow/RF24/blob/92f598cf70bb85fc1470a359d8eed38a7b28e393/RPi/RF24/bcm2835.c#L589
(3) Arduino and Raspberry Pi driver/libraries for nRF24L01 http://github.com/stanleyseow/RF24 - 2014 https://github.com/stanleyseow/RF24
(4) Optimized high speed nRF24L01+ driver class documentaion V1.3.4 - TMRh20 2020 http://tmrh20.github.io/RF24/.
– tlfong01 Apr 24 '20 at 02:42(a) CHAT Record of Rpi SPI nRF24L01+ 2.4GHz Transceiver Module Send Message to Arduino Problem https://chat.stackexchange.com/transcript/103645/2020/1/24 / to continue, ...
– tlfong01 Apr 24 '20 at 12:50(c) CHAT record on on How can Rpi python read a MFRC522/PN532 NFC/RFID MIFARE smart card/tag? https://chat.stackexchange.com/transcript/106073/2020/3/29
(d) How can Rpi python read a MFRC522/PN532 NFC/RFID MIFARE smart card/tag? https://raspberrypi.stackexchange.com/questions/109773/how-can-rpi-python-read-a-mfrc522-pn532-nfc-rfid-mifare-smart-card-tag/110791#110791
– tlfong01 Apr 24 '20 at 12:50:
– tlfong01 Apr 25 '20 at 01:50(3) "How to Install Java on Raspberry Pi - 2020feb24": https://linuxize.com/post/install-java-on-raspberry-pi/.
– tlfong01 Apr 25 '20 at 01:50The author Savage says the following: "The good news is that if you use the *Pi4J libraries all the nitty-gritty hard work (SPI communication protocol for the chipset and state change monitoring threads) is already done for you.*". Ah bed time!. I call it a day and see you tomorrow.
– tlfong01 Apr 25 '20 at 13:50