2 This project is free software: you can redistribute it and/or modify
3 it under the terms of the GNU General Public License as published by
4 the Free Software Foundation, either version 3 of the License, or
5 (at your option) any later version.
7 Multiprotocol is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
12 You should have received a copy of the GNU General Public License
13 along with Multiprotocol. If not, see <http://www.gnu.org/licenses/>.
16 #if defined(ASSAN_NRF24L01_INO)
18 #include "iface_nrf24l01.h"
20 #define ASSAN_PACKET_SIZE 20
21 #define ASSAN_RF_BIND_CHANNEL 0x03
22 #define ASSAN_ADDRESS_LENGTH 4
38 NRF24L01_Initialize();
40 NRF24L01_WriteReg(NRF24L01_03_SETUP_AW, 0x02); // 4 bytes rx/tx address
41 NRF24L01_WriteRegisterMulti(NRF24L01_10_TX_ADDR, (uint8_t *)"\x80\x80\x80\xB8", ASSAN_ADDRESS_LENGTH); // Bind address
42 NRF24L01_WriteRegisterMulti(NRF24L01_0A_RX_ADDR_P0, (uint8_t *)"\x80\x80\x80\xB8", ASSAN_ADDRESS_LENGTH); // Bind address
43 NRF24L01_WriteReg(NRF24L01_11_RX_PW_P0, ASSAN_PACKET_SIZE);
46 void ASSAN_send_packet()
48 for(uint8_t i=0;i<8;i++)
50 uint16_t val=Channel_data[i];
51 val=((val<<2)+val)+(860<<3); // PPM value <<3
56 for(uint8_t i=0;i<ASSAN_ADDRESS_LENGTH;i++)
57 packet[16+i]=packet[23-i];
58 NRF24L01_WriteReg(NRF24L01_07_STATUS, 0x70); // Clear data ready, data sent, and retransmit
60 NRF24L01_WritePayload(packet, ASSAN_PACKET_SIZE);
63 uint16_t ASSAN_callback()
70 NRF24L01_WriteReg(NRF24L01_05_RF_CH, ASSAN_RF_BIND_CHANNEL);
71 NRF24L01_SetBitrate(NRF24L01_BR_1M); // 1Mbps
72 NRF24L01_SetTxRxMode(RX_EN);
75 //Wait for receiver to send the frames
76 if( NRF24L01_ReadReg(NRF24L01_07_STATUS) & _BV(NRF24L01_07_RX_DR))
77 { //Something has been received
78 NRF24L01_ReadPayload(packet, ASSAN_PACKET_SIZE);
80 { //Last frame received
83 NRF24L01_SetTxRxMode(TXRX_OFF);
84 NRF24L01_SetTxRxMode(TX_EN);
86 memset(packet,0x05,ASSAN_PACKET_SIZE-5);
88 for(uint8_t i=0;i<ASSAN_ADDRESS_LENGTH;i++)
89 packet[16+i]=packet[23-i];
91 delayMilliseconds(260);
92 return 10000; // Wait 270ms in total...
100 packet[15]=0x13; // different value for last packet
101 NRF24L01_WritePayload(packet, ASSAN_PACKET_SIZE);
105 delayMilliseconds(2165);
112 NRF24L01_SetBitrate(NRF24L01_BR_250K); // 250Kbps
113 NRF24L01_SetTxRxMode(TXRX_OFF);
114 NRF24L01_SetTxRxMode(TX_EN);
117 // Change ID and RF channel
118 NRF24L01_WriteRegisterMulti(NRF24L01_10_TX_ADDR,packet+20+4*hopping_frequency_no, ASSAN_ADDRESS_LENGTH);
119 NRF24L01_WriteReg(NRF24L01_05_RF_CH, hopping_frequency[hopping_frequency_no]);
120 hopping_frequency_no^=0x01;
126 telemetry_set_input_sync(12000);
130 phase++; // DATA 3 or 4
136 static void __attribute__((unused)) ASSAN_initialize_txid()
138 /* //Renaud TXID with Freq=36 and alternate Freq 67 or 68 or 69 or 70 or 71 or 73 or 74 or 75 or 78 and may be more...
143 // Using packet[20..23] to store the ID1 and packet[24..27] to store the ID2
144 uint8_t freq=0,freq2;
145 for(uint8_t i=0;i<ASSAN_ADDRESS_LENGTH;i++)
147 uint8_t temp=rx_tx_addr[i];
154 freq=((freq%25)+2)<<1;
155 if(freq&0x02) freq|=0x01;
156 hopping_frequency[0]=freq;
157 // Alternate frequency has some random
160 freq2=random(0xfefefefe)%9;
163 while( (freq2>118) || (freq2<freq+1) || (freq2==2*freq) );
164 hopping_frequency[1]=freq2;
169 ASSAN_initialize_txid();
171 hopping_frequency_no = 0;
173 if(IS_BIND_IN_PROGRESS)