|
|
View previous topic :: View next topic |
Author |
Message |
amjad_alahdal
Joined: 19 Feb 2013 Posts: 50
|
|
Posted: Tue Mar 05, 2013 9:23 am |
|
|
A problem showed up. It says
"A #DEVICE required before this line"
it meant for this lines :
Code: |
enum {
R_REGISTER =0b00000000, //*bits from 0 to 4 are the addresses to be read(0 a 31)//Read command and status registers.
W_REGISTER =0b00100000, //*bits from 0 to 4 are the addresses to be write(0 a 31)//Write command and status registers. Executable in power down or standby modes only
R_RX_PAYLOAD=0b01100001, //*Read RX-payload: 1 – 32 bytes. A read operation always starts at byte 0. Payload is deleted from FIFO after it is read. Used in RX mode.
W_TX_PAYLOAD=0b10100000, //*Write TX-payload: 1 – 32 bytes. A write operation always starts at byte 0 used in TX payload.
FLUSH_TX =0b11100001, //*Flush TX FIFO, used in TX mode
FLUSH_RX =0b11100010, //*Flush RX FIFO, used in RX mode. Should not be executed during transmission of acknowledge, that is, acknowledge package will not be completed.
REUSE_TX_PL =0b11100011, //*Reuse last transmitted payload. TX payload reuse is active until W_TX_PAYLOAD or FLUSH TX is executed. TX payload reuse must not be activated or deactivated during package transmission.
R_RX_PL_WID =0b01100000, //*Read RX payload width for the top R_RX_PAYLOAD in the RX FIFO. Note: Flush RX FIFO if the read value is larger than 32 bytes.
W_ACK_PAYLOAD=0b10101000, //bits 0 to 2(value 0 a 5) Used in RX mode. Write Payload to be transmitted together with ACK packet on choosen Pipenumber(0 to 5). (Pipenumber valid in the range from 000 to 101[0d0 a 0d5]). Maximum three ACK packet payloads can be pending. Payloads with same pipenumber are handled using first in - first out principle. Write payload: 1– 32 bytes. A write operation always starts at byte 0.
W_TX_PAYLOAD_NOACK=0b10110000,//*Used in TX mode. Disables AUTOACK on this specific packet.
NOP =0b11111111}; //No Operation
|
has anyone faced such a problem ?
Here are some heads-up maybe you can figure out the problem
I'm using
PIC 18F2550 and PIC 18F2455
Crystal of 8 M
I need the pins to be as the following :
Code: |
#define TX_CE PIN_B0
#define TX_CSN PIN_B1
#define TX_SCK PIN_B3
#define TX_MOSI PIN_B4
#define TX_MISO PIN_B6
#define TX_IRQ PIN_A0
|
Last edited by amjad_alahdal on Tue Mar 05, 2013 4:45 pm; edited 1 time in total |
|
|
amjad_alahdal
Joined: 19 Feb 2013 Posts: 50
|
|
Posted: Tue Mar 05, 2013 4:43 pm |
|
|
I believe I have a problem with Compiler, code or anything else.
Or I have to set the PIC.
I have been working on this code for almost 48 hours, NOTHING worked.
Can anyone help please ?
If any could every used the Eduardo's library. Upload it on a website and send me the link. The copy and paste of the code doesn't seem to work.
or do I have to throw away the chip ? |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1345
|
|
Posted: Tue Mar 05, 2013 5:47 pm |
|
|
It probably means that the first thing in your code isn't the #include for your chip or that you are trying to do multiple file compilation and not providing the #include for your chip for each module. |
|
|
dezso
Joined: 04 Mar 2010 Posts: 102
|
|
Posted: Tue Mar 05, 2013 11:03 pm |
|
|
First of all I like to thank everyone specially Eduardo.....
I cannot make your code work !
I have read the datasheet and from frustration I come up with this working solution, this code will transmit and receive, my hardware are ok, the PINout fine.....It just to prove that works, I don't even need the darn thing's...it just happen to be so cheap I bought 10 of them...
Code: | #include <16F876A.H>
#device ICD=TRUE
#device *=16
//#device = PASS_STRINGS=IN_RAM
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#use delay(clock=10000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=PORT1)
//#USE SPI (MASTER, SPI1, BAUD=10000, MODE=0, BITS=8, STREAM=STREAM_SPI, MSB_FIRST) //this will set SPI in 4MHz(maximum for 16MHz Xtal. #Use SPI is a little buggy)
//#USE SPI (MASTER, CLK=PIN_C3, DI=PIN_C4, DO=PIN_C5, BAUD=50000, MODE=0, BITS=8, STREAM=STREAM_SPI, MSB_FIRST)
#define RF24_SPI_DISABLE_WARNING //for disabling nRF24 SPI warning message.
//********** DEFINE PORT NAMES
#define SPI_MISO PIN_C4 //RC4; SPI(Usar por hardware sempre que possivel)
#define SPI_MOSI PIN_C5 //RC5; SPI(Usar por hardware sempre que possivel)
#define SPI_CLK PIN_C3 //RC3; SPI(Usar por hardware sempre que possivel)
//Driver nRF24L01P.C
#define RF24_IRQ PIN_A5 //RA5; interrupcao nRF24L01+
#define RF24_CS PIN_C1 //RC1; chipselect nRF24L01+
#define RF24_CE PIN_C2 //RC2; chipEnable nRF24L01+
//#define RF24_PERFORMANCE_MODE //performance mode ON
//#define RF24_SPI STREAM_SPI//Redirects SPI2 port to RS24_SPI stream
//#define RF24_USE_DMA //nRF24 uses SPI DMA for multiple byte transfers
//INCLUDES_2 - Drivers
//#include <nRF24L01P.C> //Driver nRF24L01+ Single Chip 2.4GHz Transceiver Driver
//INCLUDES_3
#define RF24_xfer(xdata) bb_xfer(xdata) //Send/receive data through SPI(controls RF24_CS manualy)___DON´T USE RF24_xfer() ALIAS FOR MORE THAN 1 xdata PARAMETER
#define RX_CSN_Low() output_low(RF24_CS) //Controls bit Chipselect
#define RX_CSN_High() output_high(RF24_CS) //Controls bit Chipselect
#define RX_CE_Low() output_low(RF24_CE) //Controls bit Chipenable
#define RX_CE_High() output_high(RF24_CE) //Controls bit Chipenable
#define RF24_IRQ_state() !input(RF24_IRQ)
static int8 RF_DATA[8];
#include <nRF24L01R.h>
#include <STDLIB.H>
/*******************************************************************************/
int bb_xfer(spi_data)
{
// SPI_MISO
// SPI_MOSI
// SPI_CLK
delay_us(50);
int rt;
int result = 0;
int1 d = 0;
for(rt=0;rt<8;rt++)
{
d = bit_test(spi_data,7-rt);
if(d)
{
output_high(SPI_MOSI);
}
else
{
output_low(SPI_MOSI);
}
delay_us(10);
output_high(SPI_CLK);
delay_us(60);
output_low(SPI_CLK);
delay_us(10);
if(input(SPI_MISO))
{
bit_set(result,7-rt);
}
else
{
bit_clear(result,7-rt);
}
}
output_low(SPI_MOSI);
return(result);
}
void pulse_CSN()
{
RX_CSN_High();;
delay_us(20);
RX_CSN_Low();
}
void configure_RX()
{
int i;
RX_CSN_Low();
RX_CE_Low();;
bb_xfer(W_REGISTER); //PRX, CRC enabled
bb_xfer(0x39);
pulse_CSN();
delay_ms(2);
//-----------
bb_xfer(0x21); //dissable auto-ack for all channels
bb_xfer(0x00);
pulse_CSN();
//-----------
bb_xfer(0x23); //address width = 5 bytes
bb_xfer(0x03);
pulse_CSN();
//-----------
bb_xfer(0x26); //data rate = 1MB
bb_xfer(0x07);
pulse_CSN();
//-----------
bb_xfer(0x31); //4 byte payload
bb_xfer(0x04);
pulse_CSN();
//-----------
bb_xfer(0x25); //set channel 2
bb_xfer(0x02);
pulse_CSN();
//-----------
bb_xfer(0x30); //set address E7E7E7E7E7
for(i=0;i<=5;i++)
{
bb_xfer(0xe7);
}
pulse_CSN();
//----------------
bb_xfer(0x20); //PWR_UP = 1
bb_xfer(0x3b);
RX_CSN_High();;
RX_CE_High();
}
void reset_RX()
{
int i;
RX_CSN_Low();
bb_xfer(R_RX_PAYLOAD); //Read RX payload
for(i=0;i<4;i++)
{
RF_DATA[i] = bb_xfer(0x00);
printf("\n%u",RF_DATA[i]);
}
pulse_CSN();
//-----------
bb_xfer(0xe2); //Flush RX FIFO
pulse_CSN();
//-----------
bb_xfer(0x27); //reset int
bb_xfer(0x40);
RX_CSN_High();
}
void transmit_data()
{
RX_CSN_Low();
printf("\n%u",bb_xfer(0x27));
bb_xfer(0x7e);
pulse_CSN();
bb_xfer(W_REGISTER);
bb_xfer(0x3a);
pulse_CSN();
bb_xfer(0xe1);
pulse_CSN();
printf("\n%u",bb_xfer(0xa0));
bb_xfer(0x34);
bb_xfer(0x33);
bb_xfer(0x32);
bb_xfer(0x31);
RX_CSN_High();;
RX_CE_Low();
delay_ms(1);
RX_CE_High();;
}
void read_registers()
{
int i;
for(i=0;i<0x18;i++)
{
RX_CSN_Low();
bb_xfer(i);
printf("\nRegister 0x%X = 0x%X",i,bb_xfer(0x00));
RX_CSN_High();
delay_ms(50);
}
printf("\n\n");
}
void main()
{
output_toggle(PIN_A0);
RX_CE_Low();
RX_CSN_High();
printf("\nHello\n");
delay_ms(500);
output_toggle(PIN_A0);
configure_RX();
delay_ms(10);
while(true)
{
// read_registers();
if(!input(PIN_A5))
{
reset_RX();
}
output_toggle(PIN_A0);
delay_ms(50);
}
} |
_________________ I'm could be wrong many time's, at least I know what I'm doing |
|
|
amjad_alahdal
Joined: 19 Feb 2013 Posts: 50
|
|
Posted: Wed Mar 06, 2013 7:03 am |
|
|
Thank you all,
The library has been compiled correctly.
^_^ I'll be working on sending texts. Tonight |
|
|
amjad_alahdal
Joined: 19 Feb 2013 Posts: 50
|
|
Posted: Thu Mar 07, 2013 10:41 am |
|
|
I need a small example to send "123" from the sender
and receive it out on an LCD. |
|
|
amjad_alahdal
Joined: 19 Feb 2013 Posts: 50
|
|
Posted: Fri Mar 08, 2013 10:27 am |
|
|
dezso,,,,
Your code seems to be for the Receiver..
The function Transmit_data was never used |
|
|
dezso
Joined: 04 Mar 2010 Posts: 102
|
|
Posted: Fri Mar 08, 2013 11:07 am |
|
|
Yes you are correct, the posted code is to receive.
I can post my transmit code later today, basically the config different and txdata send 4 byte
bb_xfer(0x34);
bb_xfer(0x33);
bb_xfer(0x32);
bb_xfer(0x31);
You can create a for-loop with array to send whatever wanted. _________________ I'm could be wrong many time's, at least I know what I'm doing |
|
|
amjad_alahdal
Joined: 19 Feb 2013 Posts: 50
|
|
Posted: Fri Mar 08, 2013 11:55 am |
|
|
I would be very greatful to have the Transmitter code, I bit, it's not very different from this one.
If you don't mind, giving a small example, of sending 123 only. |
|
|
dezso
Joined: 04 Mar 2010 Posts: 102
|
|
Posted: Fri Mar 08, 2013 10:50 pm |
|
|
Don't want to hijack this thread..sorry
Code: | /*
* File: main.c
* Author: DevXP
*
* Created on March 8, 2013, 9:40 PM
*/
#include <16F876A.H>
#device ICD=TRUE
#device *=16
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#use delay(clock=10000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=PORT1))
//---------------- change this for Rx/Tx-----------------------
//#define TX_Mode // setup as Rx
#define TX_Mode // setup as Tx
//-------------------------------------------------------------
#define W_REGISTER 0x20
#define R_RX_PAYLOAD 0x61
#define W_TX_PAYLOAD 0xa0
//********** DEFINE PORT NAMES
#define SPI_MISO PIN_C4 //RC4; SPI
#define SPI_MOSI PIN_C5 //RC5; SPI
#define SPI_CLK PIN_C3 //RC3; SPI)
#define RF24_IRQ PIN_A5 //RA5; interrupcao nRF24L01+
#define RF24_CS PIN_C1 //RC1; chipselect nRF24L01+
#define RF24_CE PIN_C2 //RC2; chipEnable nRF24L01+
#define RF24_xfer(xdata) bb_xfer(xdata) //Send/receive data through SPI
#define RTX_CSN_Low() output_low(RF24_CS) //Controls bit Chipselect
#define RTX_CSN_High() output_high(RF24_CS) //Controls bit Chipselect
#define RTX_CE_Low() output_low(RF24_CE) //Controls bit Chipenable
#define RTX_CE_High() output_high(RF24_CE) //Controls bit Chipenable
#define RF24_IRQ_state() !input(RF24_IRQ)
static int8 RF_DATA[4];
#include <STDLIB.H>
/*******************************************************************************/
void pulse_CSN()
{
RTX_CSN_High();;
delay_us(20);
RTX_CSN_Low();
}
int bb_xfer(spi_data)
{
// SPI_MISO
// SPI_MOSI
// SPI_CLK
delay_us(50);
int rt;
int result = 0;
int1 d = 0;
for(rt=0;rt<8;rt++)
{
d = bit_test(spi_data,7-rt);
if(d)
{
output_high(SPI_MOSI);
}
else
{
output_low(SPI_MOSI);
}
delay_us(10);
output_high(SPI_CLK);
delay_us(60);
output_low(SPI_CLK);
delay_us(10);
if(input(SPI_MISO))
{
bit_set(result,6-rt);
}
else
{
bit_clear(result,6-rt);
}
}
output_low(SPI_MOSI);
return(result);
}
void configure_TX()
{
int i;
RTX_CSN_Low();
RTX_CE_Low();;
bb_xfer(W_REGISTER); // PTX, CRC enabled, mask a couple of ints
bb_xfer(0x38);
pulse_CSN();
delay_ms(2);
//-----------
bb_xfer(0x24); //auto retransmit off
bb_xfer(0x00);
pulse_CSN();;
//-----------
bb_xfer(0x23); //address width = 5
bb_xfer(0x03);
pulse_CSN();
//-----------
bb_xfer(0x26); //data rate = 1MB
bb_xfer(0x07);
pulse_CSN();
//-----------
bb_xfer(0x25); //set channel 2, this is default
bb_xfer(0x02);
pulse_CSN();
//-----------
bb_xfer(0x30); //set address E7E7E7E7E7
for(i=0;i<5;i++)
{
bb_xfer(0xe7);
}
pulse_CSN();
//----------------
bb_xfer(0x21); //disable auto-ack, RX mode
bb_xfer(0x00);
RTX_CSN_High();;
}
void configure_RX()
{
int i;
RTX_CSN_Low();
RTX_CE_Low();;
bb_xfer(W_REGISTER); //PRX, CRC enabled
bb_xfer(0x39);
pulse_CSN();
delay_ms(2);
//-----------
bb_xfer(0x21); //dissable auto-ack for all channels
bb_xfer(0x00);
pulse_CSN();
//-----------
bb_xfer(0x23); //address width = 5 bytes
bb_xfer(0x03);
pulse_CSN();
//-----------
bb_xfer(0x26); //data rate = 1MB
bb_xfer(0x07);
pulse_CSN();
//-----------
bb_xfer(0x31); //4 byte payload
bb_xfer(0x04);
pulse_CSN();
//-----------
bb_xfer(0x25); //set channel 2
bb_xfer(0x02);
pulse_CSN();
//-----------
bb_xfer(0x30); //set address E7E7E7E7E7
for(i=0;i<=5;i++)
{
bb_xfer(0xe7);
}
pulse_CSN();
//----------------
bb_xfer(W_REGISTER); //PWR_UP = 1
bb_xfer(0x3b);
RTX_CSN_High();;
RTX_CE_High();
}
void read_Data()
{
int i;
RTX_CSN_Low();
bb_xfer(R_RX_PAYLOAD); //Read RX payload
for(i=0;i<4;i++)
{
RF_DATA[i] = bb_xfer(0x00);
printf("%c",RF_DATA[i]);
}
printf("\n");
pulse_CSN();
//-----------
bb_xfer(0xe2); //Flush RX FIFO
pulse_CSN();
//-----------
bb_xfer(0x27); //reset int
bb_xfer(0x40);
RTX_CSN_High();
}
void transmit_Data()
{
int i;
RTX_CSN_High();
RTX_CSN_Low();
// printf("\n%u",bb_xfer(0x27)); //clear previous ints
bb_xfer(0x27);
bb_xfer(0x7e);
RTX_CSN_High();;
delay_us(20);
RTX_CSN_Low();
//-----------
bb_xfer(W_REGISTER); //PWR_UP = 1
bb_xfer(0x3a);
RTX_CSN_High();;
delay_us(20);
RTX_CSN_Low();
//-----------
bb_xfer(0xe1); //clear TX fifo
RTX_CSN_High();;
delay_us(20);
RTX_CSN_Low();
//-----------
// printf("\n%u",bb_xfer(0xa0)); //4 byte payload
bb_xfer(W_TX_PAYLOAD);
for(i=0;i<4;i++)
{
bb_xfer(RF_DATA[i]); //clock in payload
}
RTX_CSN_High();;
RTX_CE_High();
delay_us(50);
RTX_CE_Low();;
}
void main()
{
output_toggle(PIN_A0);
RTX_CE_Low();
RTX_CSN_High();
printf("\nHello\n");
delay_ms(500);
output_toggle(PIN_A0);
#if defined(TX_Mode)
configure_TX();
delay_ms(100);
while(true)
{
RF_Data[0]="1";
RF_Data[1]="2";
RF_Data[2]="3";
RF_Data[3]="4";
transmit_Data();
output_toggle(PIN_A0);
delay_ms(500);
}
#else //must be rx :)
configure_RX();
delay_ms(100);
while(true)
{
if(!input(PIN_A5))
{
read_Data();
}
output_toggle(PIN_A0);
delay_ms(250);
}
#endif
} |
_________________ I'm could be wrong many time's, at least I know what I'm doing |
|
|
amjad_alahdal
Joined: 19 Feb 2013 Posts: 50
|
|
Posted: Sun Mar 10, 2013 3:28 am |
|
|
Thank you, it worked. |
|
|
hararion
Joined: 04 Apr 2013 Posts: 1 Location: Colombia
|
help to use the RF module |
Posted: Thu Apr 04, 2013 2:16 pm |
|
|
hello for all, i wrote here, because i have a pair of these RF modules, and i need them to make some kind of robotic super controller, reading 6 analogs sticks and 14 buttons... also i need some feedback from the robot (example: there's several impact sensors mounted on the robot, when the robot is hit in one or more of those sensors, i need to make the controller to vibrate) just the same way like the play station or the xbox controller does.
I'll use a pic 16f877A in the robot, and the pic 16f876A in the controller.
the robot will have two rc standard servos modified to move a pair of wheels for locomotion, and it will have 2 more servos to move an on board camera and the other 2 servos to move a small air-soft gun. the rest of the 14 digital outputs can be used to lighting, turning on and off the air-soft gun, and other functions. the other pins are used to connect the impact sensors.
I've found something, but the problem are that all those projects are based on arduino, and other projects use those expensive xbee rf modules.
I've read all this topic, but i can't find something far nearly to the project I'm trying to do
I'll start to test the modules then start to modeling the project based on this awesome driver created by Eduardo__.
ill be post here as any troubles or request pops out.
thanks in advance for the future help... |
|
|
Eduardo__
Joined: 23 Nov 2011 Posts: 197 Location: Brazil
|
|
Posted: Thu Apr 04, 2013 2:27 pm |
|
|
ok hararion.
Please, look at this topip from beguining. I´ve used with success this driver in PIC18F876A(it´s very near to PIC16F877). I used Hardware SPI _________________ Eduardo Guilherme Brandt |
|
|
jgschmidt
Joined: 03 Dec 2008 Posts: 184 Location: Gresham, OR USA
|
|
Posted: Sun May 12, 2013 11:13 am |
|
|
The short code from deszo posted March 8, 2013 works great !!!
There's a small error that may cause some confusion when you try to port the code to another processor or different pins...
Toward the end in the receive section is a line: which should be Code: | if(!input(RF24_IRQ)) | instead.
It also helps to set up a #define for PIN_A0, for example: Code: | #define LED0 PIN_A0 | and replace all occurrences of PIN_A0 with LED0.
You can get these modules with the PCB trace antenna for as little as $2 from eBay and my test from one upstairs corner of my house to an opposite corner downstairs works great. _________________ Jürgen
www.jgscraft.com |
|
|
Eduardo__
Joined: 23 Nov 2011 Posts: 197 Location: Brazil
|
|
Posted: Sun May 12, 2013 4:24 pm |
|
|
Thanks a lot showing us your results Mr. jgschmidt.
What are the uCs that you used in your experiments with this driver?
Regards. _________________ Eduardo Guilherme Brandt |
|
|
|
|
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
|