00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00047 #ifndef __pic_rf_24l01_h
00048 #define __pic_rf_24l01_h
00049
00050 #include "config.h"
00051 #include "pic_utils.h"
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00086 typedef struct _rf_config {
00087 uns8 payload_width_ch2;
00088 uns8 payload_width_ch1;
00089 uns8 address_ch2[5];
00090 uns8 address_ch1[5];
00091 uns8 address_width;
00092 uns8 crystal;
00093 uns8 output_power;
00094 uns8 channel;
00095 uns8 options;
00096 } rf_config;
00097
00098
00099
00101 #define OP_ENABLE_RECEIVE 0
00102
00103 #define OP_LONG_CRC 1
00104
00105 #define OP_ENABLE_CRC 2
00106
00107 #define OP_ENABLE_1_MBPS 5
00108
00109 #define OP_ENABLE_SHOCKBURST 6
00110
00111 #define OP_ENABLE_CH2 7
00112
00113
00115 #define RECEIVE_MODE 1
00116
00117 #define TRANSMIT_MODE 0
00118
00120 static bit rf_current_mode_receive = 0;
00122 static uns8 rf_current_channel = 2;
00123
00124
00125
00126
00127
00128 #define RF_WR_REG_CONFIG_REG 0b00100000
00129 #define RF_RD_REG_CONFIG_REG 0b00000000
00130 #define RF_WR_REG_SETUP_RETR 0b00100100
00131 #define RF_WR_REG_SETUP_AW 0b00100011
00132 #define RF_WR_REG_RF_SETUP 0b00100110
00133 #define RF_WR_REG_TX_ADDR 0b00110000
00134 #define RF_WR_REG_RX_ADDR_P0 0b00101010
00135 #define RF_WR_REG_EN_AA 0b00100001
00136 #define RF_WR_REG_RX_PW_P0 0b00110001
00137 #define RF_WR_REG_RF_CH 0b00100101
00138 #define RF_WR_REG_STATUS 0b00100111
00139
00140 #define RF_RD_REG_RX_PW_P0 0b00010001
00141 #define RF_RD_REG_STATUS 0b00000111
00142 #define RF_RD_REG_FIFO_STATUS 0b00010111
00143 #define RF_RD_REG_CD 0b00001001
00144 #define RF_FLUSH_TX 0b11100001
00145 #define RF_FLUSH_RX 0b11100010
00146
00147
00148 #define RF_W_TX_PAYLOAD 0b10100000
00149 #define RF_R_RX_PAYLOAD 0b01100001
00150
00151
00152 #define RF_NOP 0b11111111
00153
00154
00155 #define CONFIG_MASK_RX_DR 6
00156 #define CONFIG_MASK_TX_DS 5
00157 #define CONFIG_MASK_MAX_RT 4
00158 #define CONFIG_EN_CRC 3
00159 #define CONFIG_CRCO 2
00160 #define CONFIG_PWR_UP 1
00161 #define CONFIG_PRIM_RX 0
00162
00163
00164 #define STATUS_RX_DR 6
00165 #define STATUS_TX_DS 5
00166 #define STATUS_MAX_RT 4
00167
00168 #define STATUS_TX_FULL 0
00169
00170
00171 #define FIFO_STATUS_TX_REUSE 6
00172 #define FIFO_STATUS_TX_FULL 5
00173 #define FIFO_STATUS_TX_EMPTY 4
00174 #define FIFO_STATUS_RX_FULL 1
00175 #define FIFO_STATUS_RX_EMPTY 0
00176
00177
00184 void pic_rf_setup();
00185
00193 void pic_rf_init(rf_config *my_config);
00194
00195
00208 void pic_rf_quick_init(char *my_config, uns8 my_channel, bit my_receive_on);
00216 void pic_rf_transmit(uns8 *data, uns8 bytes_to_transmit);
00217
00218
00225 void pic_rf_receive_inline(uns8 *data, uns8 bytes_to_receive);
00226
00227
00240 void pic_rf_set_channel(uns8 channel);
00241
00248 uns8 pic_rf_receive(uns8 *data, uns8 bytes_to_receive);
00249
00260 uns8 pic_rf_read_register(uns8 cmd, uns8 *data, uns8 data_len);
00261
00270 uns8 pic_rf_send_byte(uns8 b);
00279 uns8 pic_rf_send_byte_int(uns8 b);
00280
00290 void pic_rf_set_mode(uns8 mode);
00291
00302 uns8 pic_rf_send_command(uns8 cmd, uns8 *data, uns8 data_len);
00312 uns8 pic_rf_send_command_single(uns8 cmd, uns8 data);
00313
00314
00326 inline uns8 pic_rf_read_register_inline(uns8 cmd, uns8 *data, uns8 data_len) {
00327
00328 uns8 byte_counter, status;
00329
00330 clear_pin(rf_csn_port, rf_csn_pin);
00331
00332 status = pic_rf_send_byte_int(cmd);
00333
00334 for(byte_counter = 0 ; byte_counter < data_len ; byte_counter++) {
00335 data[byte_counter] = pic_rf_send_byte_int(0);
00336 }
00337
00338 set_pin(rf_csn_port, rf_csn_pin);
00339
00340 return status;
00341 }
00342
00354 inline uns8 pic_rf_send_command_inline(uns8 cmd, uns8 *data, uns8 data_len) {
00355
00356 uns8 byte_counter, status;
00357
00358 clear_pin(rf_csn_port, rf_csn_pin);
00359 status = pic_rf_send_byte_int(cmd);
00360 for(byte_counter = 0 ; byte_counter < data_len ; byte_counter++) {
00361 pic_rf_send_byte_int(data[byte_counter]);
00362 }
00363
00364 set_pin(rf_csn_port, rf_csn_pin);
00365 return status;
00366 }
00367
00368
00369 #define pic_rf_get_status() \
00370 pic_rf_read_register(RF_NOP, 0, 0)
00371
00372 #define pic_rf_set_status(status) \
00373 pic_rf_send_command(RF_WR_REG_STATUS, status, 1)
00374
00375 #define pic_rf_receive_mode() pic_rf_set_mode(RECEIVE_MODE)
00376 #define pic_rf_transmit_mode() pic_rf_set_mode(TRANSMIT_MODE)
00377
00378
00379
00380
00381
00382 #ifndef rf_ce_port
00383 #error "pic_rf: You haven't defined rf_ce_port in your config.h!"
00384 #endif
00385 #ifndef rf_ce_pin
00386 #error "pic_rf: You haven't defined rf_ce_pin in your config.h!"
00387 #endif
00388
00389 #ifndef rf_csn_port
00390 #error "pic_rf: You haven't defined rf_csn_port in your config.h!"
00391 #endif
00392 #ifndef rf_csn_pin
00393 #error "pic_rf: You haven't defined rf_csn_pin in your config.h!"
00394 #endif
00395
00396 #ifndef rf_irq_port
00397 #error "pic_rf: You haven't defined rf_irq_port in your config.h!"
00398 #endif
00399 #ifndef rf_irq_pin
00400 #error "pic_rf: You haven't defined rf_irq_pin in your config.h!"
00401 #endif
00402
00403 #ifndef rf_mosi_port
00404 #error "pic_rf: You haven't defined rf_mosi_port in your config.h!"
00405 #endif
00406 #ifndef rf_mosi_pin
00407 #error "pic_rf: You haven't defined rf_mosi_pin in your config.h!"
00408 #endif
00409
00410 #ifndef rf_miso_port
00411 #error "pic_rf: You haven't defined rf_miso_port in your config.h!"
00412 #endif
00413 #ifndef rf_miso_pin
00414 #error "pic_rf: You haven't defined rf_miso_pin in your config.h!"
00415 #endif
00416
00417 #ifndef rf_sck_port
00418 #error "pic_rf: You haven't defined rf_sck_port in your config.h!"
00419 #endif
00420 #ifndef rf_sck_pin
00421 #error "pic_rf: You haven't defined rf_sck_pin in your config.h!"
00422 #endif
00423
00424 #endif