亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? nrf24l01.c

?? MSP430的SPI接口的例子程序。連接NRF24L01實現定長的數據包通信
?? C
?? 第 1 頁 / 共 3 頁
字號:
/******************************************************************************
*
* File: nrf24l01.c
* 
* Copyright S. Brennen Ball, 2006-2007
* 
* The author provides no guarantees, warantees, or promises, implied or
*	otherwise.  By using this software you agree to indemnify the author
* 	of any damages incurred by using it.
*
*****************************************************************************/

#include "nrf24l01.h"

//Arguments except opt_rx_standby_mode fill the actual register they are named 
//  after. Registers that do not need to be initialized are not included here.
//The argument opt_rx_active_mode is only used if the user is initializing the
//  24L01 as a receiver.  If the argument is false, the receiver will remain in
//  standby mode and not monitor for packets.  If the argument is true, the CE
//  pin will be set and the 24L01 will monitor for packets.  In TX mode, the value
//  of this argument is insignificant.
//If the user wants to leave any 1-byte register in its default state, simply put
//  as that register's argument nrf24l01_<reg>_DEFAULT_VAL, where <reg> is the register
//  name.
//If the user wants to leave any of the 5-byte registers RX_ADDR_P0, RX_ADDR_P1, or 
//  TX_ADDR in its default state, simply put NULL in the argument for that address value.
void nrf24l01_initialize(unsigned char config,
						 unsigned char opt_rx_active_mode,  
						 unsigned char en_aa, 
						 unsigned char en_rxaddr, 
						 unsigned char setup_aw, 
						 unsigned char setup_retr, 
						 unsigned char rf_ch, 
						 unsigned char rf_setup, 
						 unsigned char * rx_addr_p0, 
						 unsigned char * rx_addr_p1, 
						 unsigned char rx_addr_p2, 
						 unsigned char rx_addr_p3, 
						 unsigned char rx_addr_p4, 
						 unsigned char rx_addr_p5, 
						 unsigned char * tx_addr, 
						 unsigned char rx_pw_p0, 
						 unsigned char rx_pw_p1, 
						 unsigned char rx_pw_p2, 
						 unsigned char rx_pw_p3, 
						 unsigned char rx_pw_p4, 
						 unsigned char rx_pw_p5)
{
	unsigned char data[5];

	data[0] = en_aa;
	nrf24l01_write_register(nrf24l01_EN_AA, data, 1);

	data[0] = en_rxaddr;
	nrf24l01_write_register(nrf24l01_EN_RXADDR, data, 1);

	data[0] = setup_aw;
	nrf24l01_write_register(nrf24l01_SETUP_AW, data, 1);

	data[0] = setup_retr;
	nrf24l01_write_register(nrf24l01_SETUP_RETR, data, 1);

	data[0] = rf_ch;
	nrf24l01_write_register(nrf24l01_RF_CH, data, 1);

	data[0] = rf_setup;
	nrf24l01_write_register(nrf24l01_RF_SETUP, data, 1);

	if(rx_addr_p0 != NULL)
		nrf24l01_set_rx_addr(rx_addr_p0, 5, 0);
	else
	{
		data[0] = nrf24l01_RX_ADDR_P0_B0_DEFAULT_VAL;
		data[1] = nrf24l01_RX_ADDR_P0_B1_DEFAULT_VAL;
		data[2] = nrf24l01_RX_ADDR_P0_B2_DEFAULT_VAL;
		data[3] = nrf24l01_RX_ADDR_P0_B3_DEFAULT_VAL;
		data[4] = nrf24l01_RX_ADDR_P0_B4_DEFAULT_VAL;
		
		nrf24l01_set_rx_addr(data, 5, 0);
	}

	if(rx_addr_p1 != NULL)
		nrf24l01_set_rx_addr(rx_addr_p1, 5, 1);
	else
	{
		data[0] = nrf24l01_RX_ADDR_P1_B0_DEFAULT_VAL;
		data[1] = nrf24l01_RX_ADDR_P1_B1_DEFAULT_VAL;
		data[2] = nrf24l01_RX_ADDR_P1_B2_DEFAULT_VAL;
		data[3] = nrf24l01_RX_ADDR_P1_B3_DEFAULT_VAL;
		data[4] = nrf24l01_RX_ADDR_P1_B4_DEFAULT_VAL;
		
		nrf24l01_set_rx_addr(data, 5, 1);
	}

	data[0] = rx_addr_p2;
	nrf24l01_set_rx_addr(data, 1, 2);

	data[0] = rx_addr_p3;
	nrf24l01_set_rx_addr(data, 1, 3);

	data[0] = rx_addr_p4;
	nrf24l01_set_rx_addr(data, 1, 4);

	data[0] = rx_addr_p5;
	nrf24l01_set_rx_addr(data, 1, 5);

	if(tx_addr != NULL)
		nrf24l01_set_tx_addr(tx_addr, 5);
	else
	{
		data[0] = nrf24l01_TX_ADDR_B0_DEFAULT_VAL;
		data[1] = nrf24l01_TX_ADDR_B1_DEFAULT_VAL;
		data[2] = nrf24l01_TX_ADDR_B2_DEFAULT_VAL;
		data[3] = nrf24l01_TX_ADDR_B3_DEFAULT_VAL;
		data[4] = nrf24l01_TX_ADDR_B4_DEFAULT_VAL;
		
		nrf24l01_set_tx_addr(data, 5);
	}

	data[0] = rx_pw_p0;
	nrf24l01_write_register(nrf24l01_RX_PW_P0, data, 1);

	data[0] = rx_pw_p1;
	nrf24l01_write_register(nrf24l01_RX_PW_P1, data, 1);

	data[0] = rx_pw_p2;
	nrf24l01_write_register(nrf24l01_RX_PW_P2, data, 1);

	data[0] = rx_pw_p3;
	nrf24l01_write_register(nrf24l01_RX_PW_P3, data, 1);

	data[0] = rx_pw_p4;
	nrf24l01_write_register(nrf24l01_RX_PW_P4, data, 1);

	data[0] = rx_pw_p5;
	nrf24l01_write_register(nrf24l01_RX_PW_P5, data, 1);

	if((config & nrf24l01_CONFIG_PWR_UP) != 0)
		nrf24l01_power_up_param(opt_rx_active_mode, config);
	else
		nrf24l01_power_down_param(config);
}

//initializes the 24L01 to all default values except the PWR_UP and PRIM_RX bits
//this function also disables the auto-ack feature on the chip (EN_AA register is 0)
//bool rx is true if the device should be a receiver and false if it should be
//  a transmitter.
//unsigned char payload_width is the payload width for pipe 0.  All other pipes
//  are left in their default (disabled) state.
//bool enable_auto_ack controls the auto ack feature on pipe 0.  If true, auto-ack will
//  be enabled.  If false, auto-ack is disabled.
void nrf24l01_initialize_debug(bool rx, unsigned char p0_payload_width, bool enable_auto_ack)
{
	unsigned char config;
	unsigned char en_aa;
	
	config = nrf24l01_CONFIG_DEFAULT_VAL | nrf24l01_CONFIG_PWR_UP;
	
	if(enable_auto_ack != false)
		en_aa = nrf24l01_EN_AA_ENAA_P0;
	else
		en_aa = nrf24l01_EN_AA_ENAA_NONE;
	
	if(rx == true)
		config = config | nrf24l01_CONFIG_PRIM_RX;
		
	nrf24l01_initialize(config, 
						true,
						en_aa, 
						nrf24l01_EN_RXADDR_DEFAULT_VAL, 
						nrf24l01_SETUP_AW_DEFAULT_VAL, 
						nrf24l01_SETUP_RETR_DEFAULT_VAL, 
						nrf24l01_RF_CH_DEFAULT_VAL, 
						nrf24l01_RF_SETUP_DEFAULT_VAL,  
						NULL, 
						NULL, 
						nrf24l01_RX_ADDR_P2_DEFAULT_VAL, 
						nrf24l01_RX_ADDR_P3_DEFAULT_VAL, 
						nrf24l01_RX_ADDR_P4_DEFAULT_VAL, 
						nrf24l01_RX_ADDR_P5_DEFAULT_VAL, 
						NULL, 
						p0_payload_width, 
						nrf24l01_RX_PW_P1_DEFAULT_VAL, 
						nrf24l01_RX_PW_P2_DEFAULT_VAL, 
						nrf24l01_RX_PW_P3_DEFAULT_VAL, 
						nrf24l01_RX_PW_P4_DEFAULT_VAL, 
						nrf24l01_RX_PW_P5_DEFAULT_VAL);
}

//initializes only the CONFIG register and pipe 0's payload width
//the primary purpose of this function is to allow users with microcontrollers with
//  extremely small program memories to still be able to init their 24L01.  This code
//  should have a smaller footprint than the above init functions.
//when using this method, the 24L01 MUST have its default configuration loaded
//  in all registers to work.  It is recommended that the device be reset or
//  have its power cycled immediately before this code is run.
//in normal circumstances, the user should use nrf24l01_initialize() rather than this
//  function, since this function does not set all of the register values.
void nrf24l01_initialize_debug_lite(bool rx, unsigned char p0_payload_width)
{
	unsigned char config;
	
	config = nrf24l01_CONFIG_DEFAULT_VAL;
	
	if(rx != false)
		config |= nrf24l01_CONFIG_PRIM_RX;
		
	nrf24l01_write_register(nrf24l01_RX_PW_P0, &p0_payload_width, 1);
	nrf24l01_power_up_param(true, config);
}

//powers up the 24L01 with all necessary delays
//this function takes the existing contents of the CONFIG register and sets the PWR_UP 
//the argument rx_active_mode is only used if the user is setting up the
//  24L01 as a receiver.  If the argument is false, the receiver will remain in
//  standby mode and not monitor for packets.  If the argument is true, the CE
//  pin will be set and the 24L01 will monitor for packets.  In TX mode, the value
//  of this argument is insignificant.
//note: if the read value of the CONFIG register already has the PWR_UP bit set, this function
//  exits in order to not make an unecessary register write.
void nrf24l01_power_up(bool rx_active_mode)
{
	unsigned char config;
	
	nrf24l01_read_register(nrf24l01_CONFIG, &config, 1);
	
	if((config & nrf24l01_CONFIG_PWR_UP) != 0)
		return;
		
	config |= nrf24l01_CONFIG_PWR_UP;
	
	nrf24l01_write_register(nrf24l01_CONFIG, &config, 1);
	
	delay_us(1500);
	
	if((config & nrf24l01_CONFIG_PRIM_RX) == 0)
		nrf24l01_clear_ce();
	else
	{
		if(rx_active_mode != false)
			nrf24l01_set_ce();
		else
			nrf24l01_clear_ce();
	}
}

//powers up the 24L01 with all necessary delays
//this function allows the user to set the contents of the CONFIG register, but the function
//  sets the PWR_UP bit in the CONFIG register, so the user does not need to.
//the argument rx_active_mode is only used if the user is setting up the
//  24L01 as a receiver.  If the argument is false, the receiver will remain in
//  standby mode and not monitor for packets.  If the argument is true, the CE
//  pin will be set and the 24L01 will monitor for packets.  In TX mode, the value
//  of this argument is insignificant.
void nrf24l01_power_up_param(bool rx_active_mode, unsigned char config)
{
	unsigned char test, test2;
	
	config |= nrf24l01_CONFIG_PWR_UP;
	
	nrf24l01_write_register(nrf24l01_CONFIG, &config, 1);

	delay_us(1500);

	if((config & nrf24l01_CONFIG_PRIM_RX) == 0)
		nrf24l01_clear_ce();
	else
	{
		if(rx_active_mode != false)
			nrf24l01_set_ce();
		else
			nrf24l01_clear_ce();
	}
}

//powers down the 24L01
//this function takes the existing contents of the CONFIG register and simply
//  clears the PWR_UP bit in the CONFIG register.
//note: if the read value of the CONFIG register already has the PWR_UP bit cleared, this 
//  function exits in order to not make an unecessary register write.
void nrf24l01_power_down()
{
	unsigned char config;
	
	nrf24l01_read_register(nrf24l01_CONFIG, &config, 1);
	
	if((config & nrf24l01_CONFIG_PWR_UP) == 0)
		return;
	
	config &= (~nrf24l01_CONFIG_PWR_UP);
	
	nrf24l01_write_register(nrf24l01_CONFIG, &config, 1);

	nrf24l01_clear_ce();
}

//powers down the 24L01
//this function allows the user to set the contents of the CONFIG register, but the function
//  clears the PWR_UP bit in the CONFIG register, so the user does not need to.
void nrf24l01_power_down_param(unsigned char config)
{
	config &= (~nrf24l01_CONFIG_PWR_UP);
	
	nrf24l01_write_register(nrf24l01_CONFIG, &config, 1);

	nrf24l01_clear_ce();
}


//sets up the 24L01 as a receiver with all necessary delays
//this function takes the existing contents of the CONFIG register and sets the PRIM_RX 
//  bit in the CONFIG register.
//if the argument rx_active_mode is false, the receiver will remain in standby mode
//  and not monitor for packets.  If the argument is true, the CE pin will be set 
//  and the 24L01 will monitor for packets.
//note: if the read value of the CONFIG register already has the PRIM_RX bit set, this function
//  exits in order to not make an unecessary register write.
void nrf24l01_set_as_rx(bool rx_active_mode)
{
	unsigned char config;
	unsigned char status;
	
	status = nrf24l01_read_register(0, &config, 1);

	if((config & nrf24l01_CONFIG_PRIM_RX) != 0)
		return;

	config |= nrf24l01_CONFIG_PRIM_RX;
	
	nrf24l01_write_register(nrf24l01_CONFIG, &config, 1);

	if(rx_active_mode != false)
		nrf24l01_set_ce();
	else
		nrf24l01_clear_ce();
}

//sets up the 24L01 as a receiver with all necessary delays
//this function allows the user to set the contents of the CONFIG register, but the function
//  sets the PRIM_RX bit in the CONFIG register, so the user does not need to.

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日本精品一区二区三区高清| 亚洲欧洲日韩综合一区二区| 国产精品情趣视频| 美女尤物国产一区| 在线视频观看一区| 中文字幕不卡在线观看| 精彩视频一区二区| 91精品国产色综合久久不卡蜜臀 | 国产69精品久久99不卡| 欧美日韩极品在线观看一区| 日韩伦理电影网| 国产成人在线观看| 精品国产一区二区在线观看| 亚洲成人精品一区二区| 91在线观看下载| 国产欧美一区二区精品性色| 国产在线播放一区二区三区| 日韩精品一区二区三区四区 | 国产成人亚洲精品青草天美| 欧美精品国产精品| 亚洲二区在线视频| 欧美三级乱人伦电影| 亚洲午夜成aⅴ人片| 91理论电影在线观看| 中文字幕一区二区三区四区| 国产精品69毛片高清亚洲| 久久久久久久精| 国产乱码精品一区二区三区忘忧草 | 国产精品美女久久久久aⅴ | 日韩一区二区三区高清免费看看| 亚洲自拍偷拍图区| 欧美群妇大交群中文字幕| 亚洲动漫第一页| 欧美一区二区三区成人| 蜜桃一区二区三区在线| 精品剧情在线观看| 黑人巨大精品欧美黑白配亚洲| 精品久久久网站| 成人午夜私人影院| 亚洲色图在线播放| 欧美综合天天夜夜久久| 日韩制服丝袜先锋影音| 日韩欧美一级精品久久| 国产精品18久久久久久久网站| 国产日韩精品一区二区浪潮av | 一区二区高清在线| 欧美日韩在线播| 久久精品国产第一区二区三区| 精品人在线二区三区| 国产成人自拍网| 一区二区三区四区精品在线视频| 欧美日韩日本视频| 久久精品国产精品青草| 国产日韩精品一区二区三区 | 午夜影视日本亚洲欧洲精品| 欧美一级片在线看| 国产精品一区二区视频| 亚洲精品视频自拍| 欧美岛国在线观看| 不卡电影免费在线播放一区| 亚洲一线二线三线视频| 精品国产乱码久久| 91麻豆国产在线观看| 免费观看久久久4p| 国产精品久久久久9999吃药| 欧美二区在线观看| caoporen国产精品视频| 亚洲国产aⅴ天堂久久| 欧美精品一区二区三区视频| av一二三不卡影片| 久久精品国产99国产| 亚洲区小说区图片区qvod| 91精品国产乱码久久蜜臀| 成人午夜av影视| 免费成人性网站| 夜夜夜精品看看| 国产亚洲精品aa| 日韩一区二区影院| 在线观看视频91| 成人免费毛片app| 麻豆极品一区二区三区| 亚洲综合av网| 最新不卡av在线| 亚洲国产精品t66y| 欧美va亚洲va国产综合| 欧美三级电影网站| 99久久免费国产| 国产精品自产自拍| 蜜臀久久99精品久久久画质超高清| 亚洲少妇最新在线视频| 99久久久国产精品| 成人h精品动漫一区二区三区| 亚洲午夜电影在线| 国产精品久久影院| 国产偷国产偷亚洲高清人白洁| 欧美美女直播网站| 日本高清不卡视频| www.在线欧美| 国产99一区视频免费| 国产精品影音先锋| 国内精品写真在线观看| 久国产精品韩国三级视频| 亚洲成av人片在www色猫咪| 亚洲精品国产视频| 亚洲精品一二三区| 一区二区三区久久| 亚洲精品乱码久久久久| 亚洲摸摸操操av| 综合婷婷亚洲小说| 一区二区三区四区视频精品免费 | 欧美美女直播网站| 欧美巨大另类极品videosbest | 春色校园综合激情亚洲| 国产精品99久| 国产成人精品免费视频网站| 国产高清不卡一区二区| 一色屋精品亚洲香蕉网站| 日本韩国一区二区| 色综合久久88色综合天天6 | 91精品在线一区二区| 欧美精品欧美精品系列| 7777精品久久久大香线蕉| 制服视频三区第一页精品| 日韩精品在线看片z| 久久这里都是精品| 国产欧美日韩中文久久| 中文字幕亚洲在| 亚洲成a人片在线不卡一二三区| 午夜视频在线观看一区二区三区| 性做久久久久久| 美国三级日本三级久久99| 国产在线看一区| 97se亚洲国产综合自在线不卡| 成人精品高清在线| 在线中文字幕不卡| 欧美三级一区二区| 欧美不卡在线视频| 欧美激情一区二区三区全黄| 亚洲欧美另类在线| 日韩精品视频网| 国产suv精品一区二区883| 色婷婷精品久久二区二区蜜臀av | 91成人网在线| 日韩午夜激情av| 国产欧美日韩三区| 亚洲一区二区黄色| 国内偷窥港台综合视频在线播放| 99re视频精品| 3atv一区二区三区| 国产精品久久久久一区| 日韩电影免费在线观看网站| 国产麻豆精品在线| 欧美日韩亚洲综合一区| 久久久久久久综合色一本| 亚洲一区二区在线免费看| 国产麻豆一精品一av一免费| 在线免费观看视频一区| 久久综合色8888| 亚洲综合久久久| 成人综合在线观看| 欧美一级黄色大片| 一区二区三区精密机械公司| 国产精品99久| 欧美一区二区三区思思人| 国产精品私房写真福利视频| 三级精品在线观看| 99精品黄色片免费大全| 日韩欧美激情一区| 亚洲成人黄色小说| 91日韩一区二区三区| 久久久不卡影院| 男男视频亚洲欧美| 日本高清不卡视频| 一区精品在线播放| 精品在线观看视频| 欧美日韩一级视频| 亚洲黄色av一区| 北条麻妃国产九九精品视频| 久久综合99re88久久爱| 婷婷激情综合网| 色婷婷国产精品综合在线观看| 国产三级欧美三级| 极品少妇xxxx偷拍精品少妇| 日韩一区二区高清| 奇米888四色在线精品| 欧美日韩在线一区二区| 有码一区二区三区| 91亚洲永久精品| 亚洲精品自拍动漫在线| av不卡一区二区三区| 中日韩av电影| 成人精品视频一区二区三区| 国产校园另类小说区| 极品美女销魂一区二区三区免费| 欧美tickling挠脚心丨vk| 美脚の诱脚舐め脚责91| 欧美成人一区二区三区片免费| 秋霞影院一区二区| 欧美一级免费大片| 六月丁香综合在线视频|