|
|
View previous topic :: View next topic |
Author |
Message |
Hexadec
Joined: 09 Jan 2013 Posts: 7
|
|
Posted: Wed Jan 09, 2013 6:39 am |
|
|
Hi Eduardo,
I've been lurking around this Forum for years but you have saved me so much work with your driver that I decided to join at last just to thank you.
So....
Thank-you Eduardo for a comprehensive driver that works very well.
Will be testing 'Multiceiver' mode this week so I'll let you know how it works. |
|
|
Eduardo__
Joined: 23 Nov 2011 Posts: 197 Location: Brazil
|
|
Posted: Wed Jan 09, 2013 8:11 am |
|
|
Dear Mr Hexadec,
Thank you very much for your kind reply.
I´m very happy with this, because this was my target when I post this driver: I just wanted to save work!
Thanks and good luck! _________________ Eduardo Guilherme Brandt |
|
|
amboleos
Joined: 13 Oct 2010 Posts: 8
|
|
Posted: Thu Jan 17, 2013 3:34 am |
|
|
Dear eduardo
I'm trying to use your great driver on pic24fj64gb002. In your RF24_driver_use_example_TXdata_simple() fuction, my transmitter is stuck at
Code: | while(RF24_IRQ_state()==false);//Waits for any interrupt. Same as "while(!RF24_IRQ_state());"
RF24_STATUS_clr_IRQs(IRQ_ALL);
|
I'm using internal osc, so maybe spi connection problem occurs :/ I reduced BAUD=250000 but it didnt work again. I couldnt find the problem for 2 days
This is my code,
Code: | #include <24FJ64GB002.h>
#DEVICE *=16 ICD=TRUE PASS_STRINGS=IN_RAM //I need PASS_STRINGS=IN_RAM
#FUSES NOWDT //No Watch Dog Timer
#FUSES ICSP2 //ICD uses PGC3/PGD3 pins
#FUSES CKSFSM //Clock Switching is enabled, fail Safe clock monitor is enabled
#FUSES FRC //Internal Fast RC Oscillator
#use delay (clock=8M, internal)
#include <math.h>
#include <string.h>
#INCLUDE <STDLIB.H>
#pin_select U1TX = PIN_B14
#pin_select U1RX = PIN_B15
#use rs232(UART1,baud=9600,parity=N,bits=8,stream=USART1A)
#define RF24_SPI_DISABLE_WARNING
//SPI2 PINS(It´s for my uC, because I´m using hardware I2C)
#pin_select SDI2=PIN_B7//#pin_select SDI2=PIN_B8 // ?????????????????
#pin_select SDO2=PIN_B3//#pin_select SDO2=PIN_B7 //
#pin_select SCK2OUT=PIN_B1//#pin_select SCK2OUT=PIN_B9 //
#USE SPI(SPI2, MASTER, BAUD=1000000, MODE=0, BITS=8, MSB_FIRST, STREAM=STREAM_SPI2) //this will set SPI in 4MHz(maximum for 16MHz Xtal. #Use SPI is a little buggy)
#include <input.c>
#include <tea.c>
//********** DEFINE PORT NAMES
#define SPI_MISO PIN_B3 //???????????????
#define SPI_MOSI PIN_B7 //SPI(Usar por hardware quando possivel)
#define SPI_CLK PIN_B1 //SPI(Usar por hardware quando possivel)
//Driver nRF24L01P.C
#define RF24_IRQ PIN_B8 //interrupcao nRF24L01+
#define RF24_CS PIN_B9 //chipselect nRF24L01+
#define RF24_CE PIN_B2 //chipEnable nRF24L01+
#define RF24_PERFORMANCE_MODE //performance mode ON
#define RF24_SPI STREAM_SPI2//Redirects SPI2 port to RS24_SPI stream
#include <nRF24L01P.C>
#include <STDLIB.H>
void main()
{
//setup_spi( FALSE );
//setup_spi2( FALSE );
//setup_timer1(TMR_DISABLED);
//enable_interrupts(INT_TIMER1);
//enable_interrupts(INTR_GLOBAL);
delay_ms(1000);
// TODO: USER CODE!!
while(1)
{
RF24_select();
RF24_enable();
delay_ms(1000);
printf("(%u)",RF24_comm_in(R_REGISTER|CONFIGURATION));
//***RF24_driver_use_example_TXdata_simple();***
RF24_initPorts();
RF24_default_config();
RF24_TX_SET(); //Transmitter on
while(true) { //Enter transmit mode infinitely
//now, you can write FIFO stack1
RF24_TX_putbuffer(false,32, "La cucaracha!!, Fill FIFO Stack3"); //Transmit 32bytes data(text string) to actual address(default_config address)
printf("La cucaracha!!, Fill FIFO Stack3");
//Do this to check each data transfer
delay_ms(1000);
while(RF24_IRQ_state()==false);//Waits for any interrupt. Same as "while(!RF24_IRQ_state());"
RF24_STATUS_clr_IRQs(IRQ_ALL); //Allows clearing all IRQs at the same time
}
}
} |
|
|
|
Eduardo__
Joined: 23 Nov 2011 Posts: 197 Location: Brazil
|
|
Posted: Thu Jan 17, 2013 4:47 am |
|
|
Try to use RF24_driver_use_example_TXdata_simple(); for transmitter and and RF24_driver_use_example_RXdata(); in receiver code.
If the problem remains, use the function RF24_check_config() to check if your nRF24 is exchanging data. You will need to put a debugger_break or send by RS232 serial port *bbuf data(first byte for most commands and the first 5 bytes for RX and TX addr commands) each delay_ms(10); command.
The checked data must be the same that in the function "RF24_default_config();"
Looking that functions inside driver and you will understand better.
Good luck _________________ Eduardo Guilherme Brandt |
|
|
amboleos
Joined: 13 Oct 2010 Posts: 8
|
|
Posted: Thu Jan 17, 2013 12:02 pm |
|
|
Hi eduardo
As you said, I use printf for check_congif
I have a problem at
Code: | RF24_comm_in(R_REGISTER|RX_ADDR_P0, bbuf, 5);//PROBLEMA( bbuf=0x00A1A2 ) //, //Receive address data pipe 0. 5 Bytes maximumlength. (LSByte first)
//0xA1A2A3, 24); //Address 0xA1A2A3 24bits(3 bytes)
delay_ms(10);
printf("%X-%X-%X-%X-%X-%X-\n\r",*(bbuf),*(bbuf+1),*(bbuf+2),*(bbuf+3),*(bbuf+4),bbuf[5]);
|
this printf returns this
As you see this mean 0-dd-a-0-0-0, correct result must be 0-r-d-d-a-0
I cant figure out the problem, I erased the "rv=spi_read2(); " lines.
And also tried to use FORCE_SW, but problem still continues. Do you have any idea? |
|
|
Eduardo__
Joined: 23 Nov 2011 Posts: 197 Location: Brazil
|
|
Posted: Thu Jan 17, 2013 2:54 pm |
|
|
You´re printing in Hex format.
It´s better to print in Ascii format(String).
For that, I use this command:
Code: | RF24_comm_in(R_REGISTER|RX_ADDR_P1, bbuf, 5);
fprintf(DBG, "\r\n");
for(i=0; i<sizeof(bbuf); i++) fputc(bbuf[i], DBG);
|
The correct code for RX_Addr_P0 should be(as default by driver):
"0rdda"
For pipe1 it shoud be "1rdda", for pipe2 it should be "2" , for pipe 3 "3" and so on.
It is because only pipe0 and pipe1 can have any of the 5 address bytes modified. Pipes 2 to 5 can modify only the first byte of pipe1 address.
I use the program below to check configuration:
ps: I´m not checking pipe 2 to 5 addresses at this program)
Code: | void RF24_byte_to_bin(int dt) {
int i;
for(i=8;i>0;i--) { //Funcao que Imprime valor em binário
if (bit_test(dt, i-1)==true) fputc('1', DBG);
else fputc('0', DBG);
}
fputc('\r', DBG); fputc('\n', DBG);
}
void RF24_check_conf() { //Check actual configuration(only for debugging purposes, stop in each delay)
char bbuf[7];
int i;
fprintf(DBG, "\r\n\n\n\nInicio configuracao_:\r\n\r\n ");
RF24_comm_in(R_REGISTER|CONFIGURATION, bbuf, 1); //EN_CRC|CRC16|PWR_UP); //RF_packet CRC and nRF24L01+ configuration and initialization
//fprintf(DBG, "\r\n");
RF24_byte_to_bin(bbuf[0]);
RF24_comm_in(R_REGISTER|EN_AUTOACK, bbuf, 1); //0b00011111); //autoack in pipe 0,1,2,3,4 and 5
RF24_byte_to_bin(bbuf[0]);
RF24_comm_in(R_REGISTER|EN_RXPIPES, bbuf, 1); //0b00000011); //****enable only pipes 0 and 1(pipes 2 to 5 are not used)
RF24_byte_to_bin(bbuf[0]);
RF24_comm_in(R_REGISTER|SETUP_ADDRESSWIDTH, bbuf, 1); //, 1); //addresswidth setting[1 to 3(3 to 5 bytes)]//ADDRESSWIDTH = 1 -> it means 3 bytes
RF24_byte_to_bin(bbuf[0]);
RF24_comm_in(R_REGISTER|SETUP_AUTORETRANSMISSION, bbuf, 1); //[7:4(250 to 4000us) autoretry delay, 3:0(0 to 15)Auto retry times]
//0b00011111); //waitretry 500us , retry 15times //ARD=500µs is long enough for any ACK payload length in 1 or 2Mbps mode
RF24_byte_to_bin(bbuf[0]);
RF24_comm_in(R_REGISTER|RF_CHANNEL, bbuf, 1); //, 0); //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_byte_to_bin(bbuf[0]);
RF24_comm_in(R_REGISTER|RF_SETUP, bbuf, 1); //, RF_DR_2Mbps|RF_PWR_0dBm); //Datarate 2Mbps. PowerAmplifier in 0dBm.
RF24_byte_to_bin(bbuf[0]);
RF24_comm_in(R_REGISTER|STATUS, bbuf, 1); //, //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_byte_to_bin(bbuf[0]);
RF24_comm_in(R_REGISTER|RX_ADDR_P0, bbuf, 5);//PROBLEMA( bbuf=0x00A1A2 ) //, //Receive address data pipe 0. 5 Bytes maximumlength. (LSByte first)
//0xA1A2A3, 24); //Address 0xA1A2A3 24bits(3 bytes)
//fprintf(DBG, "\r\n");
for(i=0; i<sizeof(bbuf); i++) fputc(bbuf[i], DBG);
RF24_comm_in(R_REGISTER|RX_ADDR_P1, bbuf, 5);//PROBLEMA( bbuf=0x00A1A2 ) //, //Receive address data pipe 1. 5 Bytes maximumlength. (LSByte first)
//0xA1A2A4, 24); //Address 0xA1A2A4 24bits(3 bytes)
fprintf(DBG, "\r\n");
for(i=0; i<sizeof(bbuf); i++) fputc(bbuf[i], DBG);
RF24_comm_in(R_REGISTER|TX_ADDR, bbuf, 5); //, //(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
//0xA1A2A3, 24); //Address 0xA1A2A3 24bits(3 bytes)
fprintf(DBG, "\r\n");
for(i=0; i<sizeof(bbuf); i++) fputc(bbuf[i], DBG); fprintf(DBG, "\r\n");
RF24_comm_in(R_REGISTER|RX_PW_P0, bbuf, 1); //, 32); //(set 1 to 32)RX payload size pipe0 set to 32 bytes
RF24_byte_to_bin(bbuf[0]);
RF24_comm_in(R_REGISTER|RX_PW_P1, bbuf, 1); //, 32); //(set 1 to 32)RX payload size pipe1 set to 32 bytes
RF24_byte_to_bin(bbuf[0]);
RF24_comm_in(R_REGISTER|EN_DYNAMIC_PAYLOAD, bbuf, 1); //,//bits 0 to 5 enables in pipe0 to pipe5
//0b00111111); //Dynamic payload Enabled in all pipes(pipe 0 to 5)
RF24_byte_to_bin(bbuf[0]);
fprintf(DBG, "\r\n fim \r\n\n ");
}//
|
Good luck _________________ Eduardo Guilherme Brandt |
|
|
amboleos
Joined: 13 Oct 2010 Posts: 8
|
|
Posted: Fri Jan 18, 2013 9:37 am |
|
|
There is something interesting :/
Inside RF24_comm_in, I added a print command
Code: | void RF24_comm_in(int comm, char *datain, int dataSZ) { //Send command and receive input(dataSZ=number of input bytes)(datain=pointer to data for receiving)
#ifndef RF24_USE_DMA int i; #endif
RF24_select();
RF24_xfer(comm); //RF24 Write address/command(see RF24_addr addresses list tabble in .h file)
#ifdef RF24_USE_DMA
DMA_read(dataSZ, datain); //Simple DMA Read and start transfer
DMA_start(); //Start DMA transfer
while(DMA_is_busy()); //DMA is working
#else //Programed IO mode(Normal mode)
for(i=0;i<dataSZ;i++) {
//*(datain+i)=spi_xfer(RF24_SPI, 0,8);
*(datain+i)=RF24_xfer(0);
printf("\n*(datain+%u)=%c="i,*(datain+i));
//*(datain+i)=spi_read2(); //It´s necessary due to spi_xfer read bug
}
#endif
RF24_unselect();
} |
So I can check the data, just after I get from SPI. And inside check config function, I added same print command that you sent;
Code: | RF24_comm_in(R_REGISTER|RX_ADDR_P0, bbuf, 5);//PROBLEMA( bbuf=0x00A1A2 ) //, //Receive address data pipe 0. 5 Bytes maximumlength. (LSByte first)
//0xA1A2A3, 24); //Address 0xA1A2A3 24bits(3 bytes)
delay_ms(10);
printf("\n>>");
for(int i=0; i<4; i++) putc(bbuf[i]);
printf("\n\r"); |
I get results as below;
Code: | *(datain+0)=0=
*(datain+1)=r=
*(datain+2)=d=
*(datain+3)=d=
*(datain+4)=a=
>>0da[00] |
Data is changing after RF24_comm_in function. But it is obivous that nrf24 is set correctly.
And Im using your example program to communicate but I can't understand how to be sure that data is recieved. So I modified RF24_driver_use_example_RXdata() as;
Code: |
...
RF24_RX_SET(); //Receiver on
while(true) {
while ( RF24_RX_getbuffer(&RXpipe, &RXdatasize, RXbuffer1)!=true ); //Wait till receive data(1 to 32 bytes) into buffer(from default_config address of pipe0)
{
}
printf("%s\n",*RXbuffer1);
... |
But already program returns zero inside the RF24_RX_getbuffer at
Code: |
...
if (!RF24_IRQ_state()){
return 0; }
... |
I ready confused |
|
|
amboleos
Joined: 13 Oct 2010 Posts: 8
|
|
Posted: Fri Jan 18, 2013 12:28 pm |
|
|
I can transmit message but still some problems occurs:)
reciever code;
Code: | rv=RF24_RX_getbuffer(&RXpipe, &RXdatasize, RXbuffer1); //Wait till receive data(1 to 32 bytes) into buffer(from default_config address of pipe0)
printf("\nhata=%u,status=%u",rv,RF24_get_status());
if(rv==1)
{
printf("\nRXpipe=%u\nRXdatasize=%u\nmessage=",RXpipe,RXdatasize);
for(int i=0;i<RXdatasize;i++)
{
printf("%c",RXbuffer1[i]);
}
} |
Inside RF24_comm_in(), there is a print command like I mention previous post. Moreover There is a RF24_comm_in function inside RF24_RX_getbuffer.
So I got this print out
Code: | *(datain+0)=a=
*(datain+1)=s=
*(datain+2)=d=
*(datain+3)=s=
hata=1,status=0
RXpipe=0
RXdatasize=4
message=adÒ5 |
As you see, data is correctly recieved in RF24_RX_getbuffer function. But when program come to print command, data is transformed to "adÒ5"
I suppose that strings like "asda" causes a problem. I cannot also send an array instead of a constant string :/ |
|
|
amboleos
Joined: 13 Oct 2010 Posts: 8
|
|
Posted: Fri Jan 18, 2013 12:46 pm |
|
|
And my problem almost solved,
I added this
Code: | printf("\n*(datain+%u)=%c,adres=%u"i,*(datain+i),(datain+i));
|
to see which adress are there.
also I change this
Code: | printf("\nRXpipe=%u\nRXdatasize=%u\nmessage=",RXpipe,RXdatasize);
for(int i=0;i<RXdatasize;i++)
{
printf("%u-",(RXbuffer1+i));
} |
to see which adress are used. And result is not suprised me;
Code: | *(datain+0)=a,adres=2366
*(datain+1)=s,adres=2367
*(datain+2)=d,adres=2368
*(datain+3)=s,adres=2369
hata=1,status=0
RXpipe=0
RXdatasize=4
message=2366-2368-2370-2372- |
why does it happen? pointers are 8 bits or 16 bits in same program |
|
|
Eduardo__
Joined: 23 Nov 2011 Posts: 197 Location: Brazil
|
|
Posted: Sat Jan 19, 2013 1:47 pm |
|
|
See thibow post on the first page of this driver topic.
This was because you didn't add " PASS_STRINGS=IN_RAM" directive.
Get a look in my post "How to do"(see first page of this topic) _________________ Eduardo Guilherme Brandt |
|
|
Eduardo__
Joined: 23 Nov 2011 Posts: 197 Location: Brazil
|
|
Posted: Sat Jan 19, 2013 1:53 pm |
|
|
Pointers are 16 bits, so you must printf them using %Lu instead of %u formating option. _________________ Eduardo Guilherme Brandt |
|
|
amboleos
Joined: 13 Oct 2010 Posts: 8
|
|
Posted: Mon Jan 21, 2013 1:56 am |
|
|
Eduardo__ wrote: | See thibow post on the first page of this driver topic.
This was because you didn't add " PASS_STRINGS=IN_RAM" directive.
Get a look in my post "How to do"(see first page of this topic) |
I already added it
Problem is that pointers are 8 bit inside RF24_comm_out(). You can see the ram address in RF24_comm_out() ;
Code: | *(datain+0)=a,adres=2366
*(datain+1)=s,adres=2367
*(datain+2)=d,adres=2368
*(datain+3)=s,adres=2369 |
I think its because of defining dataout pointer as char. Char is 8 bit.
In main function, increasing the pointer is increasing ram address twice.
Code: | printf("\nRXpipe=%u\nRXdatasize=%u\nmessage=",RXpipe,RXdatasize);
for(int i=0;i<RXdatasize;i++)
{
printf("%u-",(RXbuffer1+i));
} |
Code: | RXpipe=0
RXdatasize=4
message=2366-2368-2370-2372- |
|
|
|
Eduardo__
Joined: 23 Nov 2011 Posts: 197 Location: Brazil
|
|
Posted: Mon Jan 21, 2013 6:14 pm |
|
|
But pointer independs on variable type.
e.g.: If you´re using a *char or a *Long int, the pointer would be the same(16bits in case of Microchip uC).
There must be something wrong in your code. Please check it again. I´ve no time enough this week to check it, sorry.
Good luck friend! _________________ Eduardo Guilherme Brandt |
|
|
Eduardo__
Joined: 23 Nov 2011 Posts: 197 Location: Brazil
|
|
Posted: Mon Jan 21, 2013 6:21 pm |
|
|
I´m sorry amboleos, not I´m understood what you said.
Yes, but if you´ve any pointer and you add it by 1, it adds only 1 in any variable type. So if you expect store an array of long ints, you should add 2 to the pointer before writing data to it.
But if you´re using arrays, it will consider the array data type. But an array is a different way(and simpliest) of working with pointers. _________________ Eduardo Guilherme Brandt |
|
|
dezso
Joined: 04 Mar 2010 Posts: 102
|
|
Posted: Thu Jan 24, 2013 12:20 pm |
|
|
I cant make this driver to work, checked pinout, config, chip running, SPI send data/receive...will not transmit or receive anything, debug is stuck at while(RF24_IRQ_state()==false);
Loaded this for test and works, however its stops randomly after 10-50 transmission ? PSup 3.6v
Will try to find time to read datasheet, need to blow some steam!!
PIC16F877A and 876A CCS4.140 in MPLABX _________________ I'm could be wrong many time's, at least I know what I'm doing |
|
|
|
|
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
|