久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费
標題:
親測cc1101驅動程序源碼,有問題隨時聯系我
[打印本頁]
作者:
瘋子教授
時間:
2018-5-11 10:05
標題:
親測cc1101驅動程序源碼,有問題隨時聯系我
親自使用的cc1101驅動程序,使用0x06方式接收中斷 ,目前公司產品大規模使用中,有需要的小伙伴可以試一下
0.jpg
(13.42 KB, 下載次數: 126)
下載附件
2018-5-12 04:06 上傳
單片機源程序如下:
/**
*@file CC1101.c
*@brief 這個文件定義了CC1101驅動的功能相關的源碼
*@author phang
*@date 2015/11/4 18:02:50
*@version ver 0.1
*@copyright seenboom
*/
#include "CC1101.H"
//10, 7, 5, 0, -5, -10, -15, -20, dbm output power, 0x12 == -30dbm
const u8 PaTabel[] = { 0xc0, 0xC8, 0x84, 0x60, 0x68, 0x34, 0x1D, 0x0E};
// Sync word qualifier mode = 30/32 sync word bits detected
// CRC autoflush = false
// Channel spacing = 199.951172
// Data format = Normal mode
// Data rate = 2.00224
// RX filter BW = 58.035714
// PA ramping = false
// Preamble count = 4
// Whitening = false
// Address config = No address check
// Carrier frequency = 400.199890
// Device address = 0
// TX power = 10
// Manchester enable = false
// CRC enable = true
// Deviation = 5.157471
// Packet length mode = Variable packet length mode. Packet length configured by the first byte after sync word
// Packet length = 255
// Modulation format = GFSK
// Base frequency = 399.999939
// Modulated = true
// Channel number = 1
// PA table
#define PA_TABLE {0xc2,0x00,0x00,0x00,0x00,0x00,0x00,0x00,}
/** 初始化用的寄存器表,寄存器名和寄存器值 **/
static const u8 CC1101InitData[22][2]=
{
{CC1101_IOCFG0, 0x06},
{CC1101_FIFOTHR, 0x47},
{CC1101_PKTCTRL0, 0x05},
{CC1101_CHANNR, 0x01},
{CC1101_FSCTRL1, 0x06},
{CC1101_FREQ2, 0x0F},
{CC1101_FREQ1, 0x62},
{CC1101_FREQ0, 0x76},
{CC1101_MDMCFG4, 0xF6},
{CC1101_MDMCFG3, 0x43},
{CC1101_MDMCFG2, 0x13},
{CC1101_DEVIATN, 0x15},
{CC1101_MCSM0, 0x18},
{CC1101_FOCCFG, 0x16},
{CC1101_WORCTRL, 0xFB},
{CC1101_FSCAL3, 0xE9},
{CC1101_FSCAL2, 0x2A},
{CC1101_FSCAL1, 0x00},
{CC1101_FSCAL0, 0x1F},
{CC1101_TEST2, 0x81},
{CC1101_TEST1, 0x35},
{CC1101_MCSM1, 0x3B},
};
/*read a byte from the specified register*/
u8 CC1101ReadReg( u8 addr );
/*Read some bytes from the rigisters continously*/
void CC1101ReadMultiReg( u8 addr, u8 *buff, u8 size );
/*Write a byte to the specified register*/
void CC1101WriteReg( u8 addr, u8 value );
/*Flush the TX buffer of CC1101*/
void CC1101ClrTXBuff( void );
/*Flush the RX buffer of CC1101*/
void CC1101ClrRXBuff( void );
/*Get received count of CC1101*/
u8 CC1101GetRXCnt( void );
/*Reset the CC1101 device*/
void CC1101Reset( void );
/*Write some bytes to the specified register*/
void CC1101WriteMultiReg( u8 addr, u8 *buff, u8 size );
u8 SPI_ExchangeByte( u8 input );
/** CC1101射頻需要用的關鍵函數 **/
u8 SPI_ExchangeByte( u8 input )
{
//wait for last transmitt finishing
/** 等待SPI狀態,BSY指SPI是否忙 **/
while (SPI_GetFlagStatus(SPI_FLAG_BSY))
{
};
SPI_SendData( input );
//wait for receiving a byte
while (SPI_GetFlagStatus(SPI_FLAG_BSY))
{
};
return SPI_ReceiveData();
}
/*
================================================================================
Function : CC1101WORInit( )
Initialize the WOR function of CC1101
INPUT : None
OUTPUT : None
================================================================================
*/
void CC1101WORInit( void )
{
CC1101WriteReg(CC1101_MCSM0,0x18);
CC1101WriteReg(CC1101_WORCTRL,0x78); //Wake On Radio Control
CC1101WriteReg(CC1101_MCSM2,0x00);
CC1101WriteReg(CC1101_WOREVT1,0x8C);
CC1101WriteReg(CC1101_WOREVT0,0xA0);
CC1101WriteCmd( CC1101_SWORRST );
}
/*
================================================================================
Function : CC1101ReadReg( )
read a byte from the specified register
INPUT : addr, The address of the register
OUTPUT : the byte read from the rigister
================================================================================
*/
u8 CC1101ReadReg( u8 addr )
{
u8 i;
CC_CSN_LOW( );
SPI_ExchangeByte( addr | READ_SINGLE);
i = SPI_ExchangeByte( 0xFF );
CC_CSN_HIGH( );
return i;
}
/*
================================================================================
Function : CC1101ReadMultiReg( )
Read some bytes from the rigisters continously
INPUT : addr, The address of the register
buff, The buffer stores the data
size, How many bytes should be read
OUTPUT : None
================================================================================
*/
void CC1101ReadMultiReg( u8 addr, u8 *buff, u8 size )
{
u8 i, j;
CC_CSN_LOW( );
SPI_ExchangeByte( addr | READ_BURST);
for( i = 0; i < size; i ++ )
{
for( j = 0; j < 20; j ++ );
*( buff + i ) = SPI_ExchangeByte( 0xFF );
}
CC_CSN_HIGH( );
}
/*
================================================================================
Function : CC1101ReadStatus( )
Read a status register
INPUT : addr, The address of the register
OUTPUT : the value read from the status register
================================================================================
*/
u8 CC1101ReadStatus( u8 addr )
{
u8 i;
CC_CSN_LOW( );
SPI_ExchangeByte( addr | READ_BURST);
i = SPI_ExchangeByte( 0xFF );
CC_CSN_HIGH( );
return i;
}
/*
================================================================================
Function : CC1101SetTRMode( )
Set the device as TX mode or RX mode
INPUT : mode selection
OUTPUT : None
================================================================================
*/
void CC1101SetTRMode( TRMODE mode )
{
if( mode == TX_MODE )
{
CC1101WriteReg(CC1101_IOCFG0,0x46);
CC1101WriteCmd( CC1101_STX );
}
else if( mode == RX_MODE )
{
CC1101WriteReg(CC1101_IOCFG0,0x46);
CC1101WriteCmd( CC1101_SRX );
}
}
/*
================================================================================
Function : CC1101WriteReg( )
Write a byte to the specified register
INPUT : addr, The address of the register
value, the byte you want to write
OUTPUT : None
================================================================================
*/
void CC1101WriteReg( u8 addr, u8 value )
{
CC_CSN_LOW( );
SPI_ExchangeByte( addr );
SPI_ExchangeByte( value );
CC_CSN_HIGH( );
}
/*
================================================================================
Function : CC1101WriteMultiReg( )
Write some bytes to the specified register
INPUT : addr, The address of the register
buff, a buffer stores the values
size, How many byte should be written
OUTPUT : None
================================================================================
*/
void CC1101WriteMultiReg( u8 addr, u8 *buff, u8 size )
{
u8 i;
CC_CSN_LOW( );
SPI_ExchangeByte( addr | WRITE_BURST );
for( i = 0; i < size; i ++ )
{
SPI_ExchangeByte( *( buff + i ) );
}
CC_CSN_HIGH( );
}
/*
================================================================================
Function : CC1101WriteCmd( )
Write a command byte to the device
INPUT : command, the byte you want to write
OUTPUT : None
================================================================================
*/
void CC1101WriteCmd( u8 command )
{
CC_CSN_LOW( );
SPI_ExchangeByte( command );
CC_CSN_HIGH( );
}
/*
================================================================================
Function : CC1101Reset( )
Reset the CC1101 device
INPUT : None
OUTPUT : None
================================================================================
*/
void CC1101Reset( void )
{
u8 x;
CC_CSN_HIGH( );
CC_CSN_LOW( );
CC_CSN_HIGH( );
for( x = 0; x < 100; x ++ );
CC1101WriteCmd( CC1101_SRES );
}
/*
================================================================================
Function : CC1101SetIdle( )
Set the CC1101 into IDLE mode
INPUT : None
OUTPUT : None
================================================================================
*/
void CC1101SetIdle( void )
{
CC1101WriteCmd(CC1101_SIDLE);
}
/*
================================================================================
Function : CC1101ClrTXBuff( )
Flush the TX buffer of CC1101
INPUT : None
OUTPUT : None
================================================================================
*/
void CC1101ClrTXBuff( void )
{
CC1101SetIdle();//MUST BE IDLE MODE
CC1101WriteCmd( CC1101_SFTX );
}
/*
================================================================================
Function : CC1101ClrRXBuff( )
Flush the RX buffer of CC1101
INPUT : None
OUTPUT : None
================================================================================
*/
void CC1101ClrRXBuff( void )
{
CC1101SetIdle();//MUST BE IDLE MODE
CC1101WriteCmd( CC1101_SFRX );
}
/*
================================================================================
Function : CC1101SendPacket( )
Send a packet
INPUT : txbuffer, The buffer stores data to be sent
size, How many bytes should be sent
mode, Broadcast or address check packet
OUTPUT : None
================================================================================
*/
void CC1101SendPacket( u8 *txbuffer, u8 size, TX_DATA_MODE mode )
{
u8 address;
if( mode == BROADCAST ) { address = 0; }
else if( mode == ADDRESS_CHECK ) { address = CC1101ReadReg( CC1101_ADDR ); }
CC1101ClrTXBuff( );
if( ( CC1101ReadReg( CC1101_PKTCTRL1 ) & ~0x03 ) != 0 )
{
CC1101WriteReg( CC1101_TXFIFO, size + 1 );
CC1101WriteReg( CC1101_TXFIFO, address );
}
else
{
CC1101WriteReg( CC1101_TXFIFO, size );
}
CC1101WriteMultiReg( CC1101_TXFIFO, txbuffer, size );
CC1101SetTRMode( TX_MODE );
/** Wait for GDO0 to be set -> sync transmitted **/
while(!GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_4 ));
/** Wait for GDO0 to be cleared -> end of packet **/
while(GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_4 ));
CC1101ClrTXBuff( );
}
/*
================================================================================
Function : CC1101GetRXCnt( )
Get received count of CC1101
INPUT : None
OUTPUT : How many bytes hae been received
================================================================================
*/
u8 CC1101GetRXCnt( void )
{
return ( CC1101ReadStatus( CC1101_RXBYTES ) & BYTES_IN_RXFIFO );
}
/*
================================================================================
Function : CC1101SetAddress( )
Set the address and address mode of the CC1101
INPUT : address, The address byte
AddressMode, the address check mode
OUTPUT : None
================================================================================
*/
void CC1101SetAddress( u8 address, ADDR_MODE AddressMode)
{
u8 btmp = CC1101ReadReg( CC1101_PKTCTRL1 ) & ~0x03;
CC1101WriteReg(CC1101_ADDR, address);
if ( AddressMode == BROAD_ALL ) {}
else if( AddressMode == BROAD_NO ) { btmp |= 0x01; }
else if( AddressMode == BROAD_0 ) { btmp |= 0x02; }
else if( AddressMode == BROAD_0AND255 ) { btmp |= 0x03; }
}
/*
================================================================================
Function : CC1101SetSYNC( )
Set the SYNC bytes of the CC1101
INPUT : sync, 16bit sync
OUTPUT : None
================================================================================
*/
void CC1101SetSYNC( u16 sync )
{
CC1101WriteReg(CC1101_SYNC1, 0xFF & ( sync>>8 ) );
CC1101WriteReg(CC1101_SYNC0, 0xFF & sync );
}
/*
================================================================================
Function : CC1101RecPacket( )
Receive a packet
INPUT : rxBuffer, A buffer store the received data
OUTPUT : 1:received count, 0:no data
================================================================================
*/
u8 CC1101RecPacket( u8 *rxBuffer )
{
u8 status[2];
u8 pktLen;
volatile u16 x , j = 0;
if ( CC1101GetRXCnt( ) != 0 )
{
pktLen = CC1101ReadReg(CC1101_RXFIFO); // Read length byte
if( ( CC1101ReadReg( CC1101_PKTCTRL1 ) & ~0x03 ) != 0 )
{
x = CC1101ReadReg(CC1101_RXFIFO);
}
if( pktLen == 0 ) { return 0; }
……………………
…………限于本文篇幅 余下代碼請從51黑下載附件…………
復制代碼
所有資料51hei提供下載:
cc1101驅動.rar
(4.34 KB, 下載次數: 85)
2018-5-11 10:04 上傳
點擊文件名下載附件
cc1101
下載積分: 黑幣 -5
作者:
ryanwong
時間:
2018-11-23 11:35
大哥,請問你這個程序調過低功耗嗎?功耗多少?
作者:
jin8882008
時間:
2018-12-5 16:52
有沒有完整的主程序可以調用
作者:
zhw2008
時間:
2018-12-9 14:51
大哥,請問你這個程序調過低功耗嗎?
作者:
zhw2008
時間:
2018-12-9 17:20
你好,有低功耗的配置嗎?我的低功耗模式未調通!
作者:
只是一個用戶名
時間:
2018-12-12 11:49
下了看看
作者:
pm1981
時間:
2019-3-6 10:57
聽說長時間接收會死機?
作者:
lfywl
時間:
2019-8-30 08:15
老哥,帶地址檢測的源碼有嗎?想做個參考
作者:
薄幸名的薄
時間:
2021-7-12 11:09
老哥這些作用是什么 PaTabel[] = { 0xc0, 0xC8, 0x84, 0x60, 0x68, 0x34, 0x1D, 0x0E};
歡迎光臨 (http://www.zg4o1577.cn/bbs/)
Powered by Discuz! X3.1
主站蜘蛛池模板:
亚洲精品乱码久久久久久久久久
|
精品久久久久久亚洲综合网
|
二区亚洲
|
国产精品久久久久久一区二区三区
|
在线国产视频观看
|
欧美不卡一区二区
|
欧美成视频
|
热久久性
|
成人精品久久
|
久久伊
|
日韩在线免费视频
|
精品久久一
|
日本一区二区在线视频
|
成人在线视频免费看
|
亚洲一区二区在线视频
|
国产一级视频免费播放
|
国产在线高清
|
国产情侣久久
|
在线观看国产wwwa级羞羞视频
|
国产亚洲精品美女久久久久久久久久
|
伦理片97
|
欧美成年黄网站色视频
|
国产欧美精品一区二区色综合朱莉
|
红色av社区
|
亚洲免费一区二区
|
伊人一二三
|
日韩精品在线观看一区二区
|
精品国产乱码久久久久久丨区2区
|
日日噜噜夜夜爽爽狠狠
|
www.日本在线
|
精品国产伦一区二区三区观看体验
|
国产片侵犯亲女视频播放
|
黄网免费看
|
国产www在线
|
91在线成人
|
另类 综合 日韩 欧美 亚洲
|
久久精品亚洲欧美日韩精品中文字幕
|
男人的天堂中文字幕
|
日本亚洲一区
|
精品国产乱码久久久久久a丨
|
久久久久91
|