Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

how to do code for nrf24L01+ as transceiver?

Status
Not open for further replies.

ketanrathod

Junior Member level 3
Joined
Nov 28, 2014
Messages
26
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
179
I am using nrf24L01+ with ATmegaga32. It acts as Tx. or Rx. at a time. But I want to act it as transceiver at a time. How can i use nrf24L01+ as transceiver in following code ?


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
void nrf24L01_init(void)
{
_delay_ms(100); // allow the radio to reach power-down if the shutdown
uint8_t val[5]; // an array of integers that sends values ??to WriteToNrf function
 
//EN_AA - (enable auto-acknowledgments) - Transmitter gets automatic response from receiver when successful transmission! (lovely function!)
//Only works if Transmitter has identical RF_Adress on its channel ex: RX_ADDR_Po = TX_ADDR
val[0]=0x01; //set value
WriteToNrf(W, EN_AA, val, 1); //N=write mode, EN_AA=register to write to, val=data to write, 1=number of data bytes.
 
//Choose number of enabled data pipes (1-5)
val[0]=0x01;
WriteToNrf(W, EN_RXADDR, val, 1); //enable data pipe 0
 
//RF_Adress width setup (how many bytes is the receiver address, the more the merrier 1-5)
val[0]=0x03; //0b0000 00011 = 5 bytes RF_Adress
WriteToNrf(W, SETUP_AW, val, 1);
 
// RF channel setup - select the frequency from 2.400 to 2.527 GHz 1MHz/steg
val[0]=0x01;
WriteToNrf(W,RF_CH,val,1); // RF channel registry 0b0000 0001 = 2.401 GHz (same on the TX RX)
 
//RF setup - choose power mode and data speed. Here is the diference with the (+) version!!!
val[0]=0x27; //00000111 bit 3="0" 1Mbps=longer range, bit 2-1 power mode ("11" = -odB ; "00"=-18dB)
WriteToNrf(W, RF_SETUP, val, 1);
 
//RF_Adress setup 5 byte - Set Receiver address (set RX_ADDR_Po = TX_ADDR if EN_AA is enabled!!!)
int i=0;
for(i=0; i<5; i++){
val[i]=0x11; //ox12 x 5 to get a long and secure address.
}
WriteToNrf(W, RX_ADDR_P0, val, 5); //since we chose pipe 0 on EN_RXADDR we give this address to that channel.
//Here you can give different addresses to different channels (if they are enabled in EN_RXADDR) to listen on several different transmitters)
 
//TX RF_Adress setup 5 byte - Set Transmitter address (not used in a receiver but can be set anyway)
for(i=0; i<5; i++){
val[i]=0x11; //ox12 x 5 - same on the Receiver chip and the RX-RF_Address above if EN_AA is enabled!!!
}
WriteToNrf(W, TX_ADDR, val, 5);
 
//Payload width Setup - 1-32byte (how many bytes to send per transmission)
val[0]=0x05; //Send 5 bytes per package this time (same on receiver and transmitter)
WriteToNrf(W,RX_PW_P0,val,1);
 
val[0]=0x2F; //0b00l0 00011 "2" sets it up to 7SouS delay between every retry (at least Seeus at 25okbps and if payload >5bytes in 1Hbps,
//and if payload >1Sbyte in 2Hbps) "F" is number of retries (1-15, now 15)
WriteToNrf(W, SETUP_RETR, val, 1);
 
//CONFIG reg setup - Now it's time to boot up the Qgf and choose if it's suppose to be a transmitter or receiver
[B]val[0]=0x1F; //0b0001 1110 - bit 0="0":transmitter bit 0="1":Receiver, bit 1="1"=power up,
//bit 4="1"= mask_Max_RT i.e. IRQ-interrupt is not triggered if transmission failed.
WriteToNrf(W, CONFIG, val, 1);[/B]
 
//device need 1.5ms to reach standby mode (CE=low)
_delay_ms(100);
 
// Sei ();
}

 
Last edited:

milan.rajik

Banned
Joined
Apr 1, 2013
Messages
2,528
Helped
540
Reputation
1,078
Reaction score
524
Trophy points
1,393
Activity points
0
There is Mirf library for Arduino. As you are using AVR, you can easily port the Arduino C++ Mirf code to C code.
 

ketanrathod

Junior Member level 3
Joined
Nov 28, 2014
Messages
26
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
179
I am using ATmega32 & C language. Please suggest me better option. If anybody have solution please tell me
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top