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.