Hi guy’s I hope I’m not digging thread that’s too old but I spent bunch of hours with this and I’m starting to hit a brick wall with it ![]()
I have one arduino sitting 1m from my table running ping_server ( [mirf library example) that looks like this
void setup(){
Serial.begin(9600);
Mirf.cePin = 8;
Mirf.csnPin = 9;
Mirf.spi = &MirfHardwareSpi;
Mirf.init();
Mirf.setRADDR((byte *)"serv1");
Mirf.payload = sizeof(unsigned long);
Mirf.config();
Serial.println("Listening...");
}
void loop(){
byte data[Mirf.payload];
int i;
if(!Mirf.isSending() && Mirf.dataReady()){
Serial.print("Got packet: 0x");
Mirf.getData(data);
for(i=0;i<Mirf.payload;i++)
Serial.print(data[i], HEX);
Serial.println(".");
Mirf.setTADDR((byte *)"clie1");
Mirf.send(data);
Serial.println("Reply sent.");
}
}
And when I use the ping_client on another arduino everything works (client code looks like)
void setup(){
Serial.begin(9600);
Mirf.cePin = 7;
Mirf.csnPin = 53;
Mirf.spi = &MirfHardwareSpi;
Mirf.init();
Mirf.setRADDR((byte *)"clie1");
Mirf.payload = sizeof(unsigned long);
Mirf.config();
Serial.println("Beginning ... ");
}
void loop(){
unsigned long time = millis();
Mirf.setTADDR((byte *)"serv1");
Mirf.send((byte *)&time);
while(Mirf.isSending()){}
Serial.println("Finished sending");
delay(10);
while(!Mirf.dataReady()){
if ( ( millis() - time ) > 1000 ) {
Serial.println("Timeout on response from server!");
return;
}
}
Mirf.getData((byte *) &time);
delay(1000);
}
And, as I say - this works … now, I don’t use arduino in my project but I use pic32.
I rewrote first the arduino code and it don’t work, now I tried Brennen code and it again don’t work …
The only changes to Brennen code to run on pic32 (pic32mx460F512L, c32, mplabx) are in the nrf24l01.c:
#define NRFL_SPI_CHN SPI_CHANNEL1
#define NRFL_cePin PORTAbits.RA15
#define NRFL_ceTris TRISAbits.TRISA15
#define NRFL_csnPin PORTAbits.RA14
#define NRFL_csnTris TRISAbits.TRISA14
#define NRFL_irqPin PORTBbits.RB10
#define NRFL_irqTris TRISBbits.TRISB10
extern volatile unsigned int CoreDelay; //decreased every 10us
void delay10us(unsigned int i) {
CoreDelay = i;
while (CoreDelay);
}
unsigned char spi_send_read_byte(unsigned char b) {
unsigned short txData, rxData; // transmit, receive characters
txData = b; // take inputted byte and store into txData
SpiChnPutC(NRFL_SPI_CHN, txData); // send data
rxData = SpiChnGetC(NRFL_SPI_CHN); // retreive over channel chn the received data into rxData
return rxData;
}
void SpiInitDevice(int chn, int isMaster, int frmEn, int frmMaster) {
unsigned int config = SPI_CON_MODE8 | SPI_CON_SMP | SPI_CON_ON;
if (isMaster) {
config |= SPI_CON_MSTEN;
}
if (frmEn) {
config |= SPI_CON_FRMEN;
if (!frmMaster) {
config |= SPI_CON_FRMSYNC;
}
}
SpiChnOpen(chn, config, 15);
}
//....
// This is added to beginning of the nrf24l01_initialize
NRFL_ceTris = 0;
NRFL_csnTris = 0;
NRFL_irqTris = 1;
SpiInitDevice(NRFL_SPI_CHN, 1, 0, 0);
//...
void nrf24l01_clear_ce()
{
//nrf24l01_CE_IOREGISTER &= ~nrf24l01_CE_PINMASK;
NRFL_cePin = 0;
}
//sets the pin on the host microcontroller that is attached to the 24l01's CE pin
void nrf24l01_set_ce()
{
//nrf24l01_CE_IOREGISTER |= nrf24l01_CE_PINMASK;
NRFL_cePin = 1;
}
//returns true if CE is high, false if not
bool xnrf24l01_ce_pin_active()
{
/*
if((nrf24l01_CE_IOREGISTER & nrf24l01_CE_PINMASK) != 0)
return true;
else
return false;
*/
return (NRFL_cePin)?true:false; //not sure how is this useful as CE pin is output from mcu?!
}
//sets the pin on the host microcontroller that is attached to the 24l01's CSN pin
void nrf24l01_clear_csn()
{
//nrf24l01_CSN_IOREGISTER &= ~nrf24l01_CSN_PINMASK;
NRFL_csnPin = 0;
}
//clears the pin on the host microcontroller that is attached to the 24l01's CSN pin
void nrf24l01_set_csn()
{
//nrf24l01_CSN_IOREGISTER |= nrf24l01_CSN_PINMASK;
NRFL_csnPin = 1;
}
//returns true if CSN is high, false if not
bool xnrf24l01_csn_pin_active()
{
/*
if((nrf24l01_CSN_IOREGISTER & nrf24l01_CSN_PINMASK) != 0)
return true;
else
return false;
*/
return (NRFL_csnPin)?true:false;
}
[/quote]
and that's all changes I made.
The main goes like this:
[code]
// config bits
//...
volatile unsigned int CoreDelay;
int main(void) {
unsigned long ttt;
SYSTEMConfigPerformance(GetSystemClock());
while (!(OSCCON & 0x00000020));
OpenCoreTimer(CORE_TICK_RATE);
mConfigIntCoreTimer((CT_INT_ON | CT_INT_PRIOR_2 | CT_INT_SUB_PRIOR_0));
INTEnableSystemMultiVectoredInt();
CloseADC10();
CoreDelay = 0;
nrf24l01_initialize_debug(true, 4, false);
nrf24l01_set_rx_addr("clie1", 5, 0);
nrf24l01_set_rx_pw(4,0);
nrf24l01_set_tx_addr("serv1", 5);
ttt = 0;
while (1) {
ttt++;
nrf24l01_set_as_tx();
nrf24l01_write_tx_payload((unsigned char *)&ttt, 4, true);
mLED_1_On();
while (!(nrf24l01_irq_pin_active() && nrf24l01_irq_tx_ds_active()));
//////////////////////////////
//IT NEVER ARRIVES HERE!!!!!!!!!!!
//////////////////////////////
mLED_2_On();
nrf24l01_irq_clear_all(); //clear interrupts again
nrf24l01_set_as_rx(true); //operation as a RX
mLED_3_On();
CoreDelay = 10000;
while (CoreDelay);
}
//...
I use arduino ping_server as receiver but there I receive nothing and pic32 is stuck in
while (!(nrf24l01_irq_pin_active() && nrf24l01_irq_tx_ds_active()));
Logic analyzer show that everything is perfectly going trough wires (SPI is 6MHz so below 8MHz limit of the module, slowing it down didn’t change anything).](Arduino Playground - HomePage)