历史上的今天
今天是:2024年10月16日(星期三)
2019年10月16日 | nRF24L01p+AVR单片机ATmage88射频收发程序
2019-10-16 来源:eefocus
单片机源程序如下:
#define _nRF24L01_C_
#include "nRF24L01.h"
INT8U CE_Status = 0;
/*
================================================================================
Function : L01_GetCEStatus( )
Description : Get the status of the CE PIN
Input : NONE
Output: 1:CE=1, 0:CE=0
================================================================================
*/
INT8U L01_GetCEStatus( void )
{
return CE_Status;
}
/*
================================================================================
Function : L01_SetCE( )
Description : Set the CE PIN as 1 or 0
Input : -status, 1: CE=1, 0: CE=0
Output: None
================================================================================
*/
void L01_SetCE( INT8U status )
{
CE_Status = status;
if( status == 0 ) { L01_CE_LOW( ); }
else { L01_CE_HIGH( ); }
}
/*
================================================================================
Function : L01_ReadSingleReg( )
Description : Read a single register of nRF24L01
Input : -Addr, The address of the register
Output: The value read from the register
================================================================================
*/
INT8U L01_ReadSingleReg( INT8U Addr )
{
INT8U btmp;
L01_CSN_LOW( );//PB2输出低电平
SPI_ExchangeByte( R_REGISTER | Addr );
btmp = SPI_ExchangeByte( 0xFF );
L01_CSN_HIGH( );//PB2输出高电平
return btmp;
}
/*
================================================================================
Function : L01_ReadMultiReg( )
Description : Read several registers of nRF24L01
Input : -StartAddr, The start address of the registers
-nBytes, How many registers do you want to read
-pBuff, The buffer to save the values
Output: None
================================================================================
*/
/*void L01_ReadMultiReg( INT8U StartAddr, INT8U nBytes, INT8U *pBuff )
{
INT8U btmp;
L01_CSN_LOW( );
SPI_ExchangeByte( R_REGISTER | StartAddr );
for( btmp = 0; btmp < nBytes; btmp ++ )
{
*( pBuff + btmp ) = SPI_ExchangeByte( 0xFF );
}
L01_CSN_HIGH( );
}
================================================================================
Function : L01_WriteSingleReg( )
Description : Write a single byte to a register
Input : -Addr, The address of the register
-Value, The value to be written
Output: None
================================================================================
*/
void L01_WriteSingleReg( INT8U Addr, INT8U Value )
{
INT8U tmp = L01_GetCEStatus( );
L01_SetCE( 0 );
L01_CSN_LOW( );
SPI_ExchangeByte( W_REGISTER | Addr );
SPI_ExchangeByte( Value );
L01_CSN_HIGH( );
L01_SetCE( tmp );
}
/*
================================================================================
Function : L01_WriteMultiReg( )
Description : Read several registers of nRF24L01
Input : -StartAddr, The start address of the registers
-pBuff, The buffer store the values
-Length, How many registers do you want to write
Output: None
================================================================================
*/
void L01_WriteMultiReg( INT8U StartAddr, INT8U *pBuff, INT8U Length )
{
INT8U i;
INT8U tmp = L01_GetCEStatus( );
L01_SetCE( 0 );
L01_CSN_LOW( );
SPI_ExchangeByte( W_REGISTER | StartAddr );
for( i = 0; i < Length; i ++ )
{
SPI_ExchangeByte( *( pBuff + i ) );
}
L01_CSN_HIGH( );
L01_SetCE( tmp );
}
/*
================================================================================
Function : L01_FlushTX( )
Description : Flush the TX buffer
Input : None
Output: None
================================================================================
*/
void L01_FlushTX( void )
{
L01_CSN_LOW( );
SPI_ExchangeByte( FLUSH_TX );
L01_CSN_HIGH( );
}
/*
================================================================================
Function : L01_FlushRX( )
Description : Flush the RX buffer
Input : None
Output: None
================================================================================
*/
void L01_FlushRX( void )
{
L01_CSN_LOW( );
SPI_ExchangeByte( FLUSH_RX );
L01_CSN_HIGH( );
}
/*
================================================================================
Function : L01_ReuseTXPayload( )
Description : Reuse the last transmitted payload
Input : None
Output: None
================================================================================
*/
void L01_ReuseTXPayload( void )
{
L01_CSN_LOW( );
SPI_ExchangeByte( REUSE_TX_PL );
L01_CSN_HIGH( );
}
/*
================================================================================
Function : L01_Nop( )
Description : nop operation of nRF24L01
Input : None
Output: None
================================================================================
*/
void L01_Nop( void )
{
L01_CSN_LOW( );
SPI_ExchangeByte( L01_NOP );
L01_CSN_HIGH( );
}
/*
================================================================================
Function : L01_ReadStatusReg( )
Description : Read statu register of nRF24L01
Input : None
Output: Statu register of nRF24L01
================================================================================
*/
INT8U L01_ReadStatusReg( void )
{
INT8U Status;
L01_CSN_LOW( );
Status = SPI_ExchangeByte( R_REGISTER + L01REG_STATUS );
L01_CSN_HIGH( );
return Status;
}
/*
================================================================================
Function : L01_ClearIRQ( )
Description : Clear IRQ cuased by nRF24L01
Input : None
Output: None
================================================================================
*/
void L01_ClearIRQ( INT8U IRQ_Source )
{
INT8U btmp = 0;
IRQ_Source &= ( 1< L01_CSN_LOW( ); L01_WriteSingleReg( L01REG_STATUS, IRQ_Source | btmp ); L01_CSN_HIGH( ); L01_ReadStatusReg( ); } /* ================================================================================ Function : L01_ReadIRQSource( ) Description : Read the IRQ source of nRF24L01+ Input : None Output: IRQ source mask code ================================================================================ */ INT8U L01_ReadIRQSource( void ) { return ( L01_ReadStatusReg( ) & ( ( 1< /* ================================================================================ Function : L01_ReadTopFIFOWidth( ) Description : Read the payload width of the top buffer of FIFO Input : None Output: The width of the pipe buffer ================================================================================ */ INT8U L01_ReadTopFIFOWidth( void ) { INT8U btmp; L01_CSN_LOW( ); SPI_ExchangeByte( R_RX_PL_WID ); btmp = SPI_ExchangeByte( 0xFF ); L01_CSN_HIGH( ); return btmp; } /* ================================================================================ Function : L01_ReadRXPayload( ) Description : Read the RX payload from internal buffer Input : -pBuff, buffer to store the data Output: The length of data read ================================================================================ */ INT8U L01_ReadRXPayload( INT8U *pBuff ) { INT8U width, PipeNum; PipeNum = ( L01_ReadSingleReg( L01REG_STATUS ) >> 1 ) & 0x07; width = L01_ReadTopFIFOWidth( ); L01_CSN_LOW( ); SPI_ExchangeByte( R_RX_PAYLOAD ); for( PipeNum = 0; PipeNum < width; PipeNum ++ ) { *( pBuff + PipeNum ) = SPI_ExchangeByte( 0xFF ); } L01_CSN_HIGH( ); L01_FlushRX( ); return width; } /* ================================================================================ Function : L01_WriteTXPayload( ) Description : Write TX payload to a pipe and prx will return ack back Input : -PipeNum, number of the pipe -pBuff, A buffer stores the data -nBytes, How many bytes to be wrote to Output: None ================================================================================ */ void L01_WriteTXPayload_Ack( INT8U *pBuff, INT8U nBytes ) { INT8U btmp; INT8U length = ( nBytes > 32 ) ? 32 : nBytes; L01_FlushTX( ); L01_CSN_LOW( ); SPI_ExchangeByte( W_TX_PAYLOAD ); for( btmp = 0; btmp < length; btmp ++ ) { SPI_ExchangeByte( *( pBuff + btmp ) ); } L01_CSN_HIGH( ); } /* ================================================================================ Function : L01_WritePayload_NoAck( ) Description : write data in tx mode, and prx won't return ack back Input : -Data, A buffer stores the address data -Data_Length, How many bytes of the data buff Output: None ================================================================================ */ void L01_WriteTXPayload_NoAck( INT8U *Data, INT8U Data_Length ) { if( Data_Length > 32 || Data_Length == 0 ) { return ; } L01_CSN_LOW( );
史海拾趣
|
在柏林推出的DVB T(地面数字广播)数字电视也已经影响到汽车娱乐系统中的电视接收。现在,汽车电视接收机不仅能够接收模拟电视信号(它仍将在城市以外的地区继续存在数年),而且也能够接收和处理DVB T信号。Hirschmann Electronic ...… 查看全部问答> |
|
原贴在http://topic.eeworld.net/u/20091029/10/4e29dc9d-fbfa-4ccc-920c-2c5f23bada64.html,100求解,分光了, 急~~~… 查看全部问答> |
|
读PHY芯片DM9161寄存器的LINK STATUS位始终显示为可用连接没有建立 最近用STM32F107+DM9161+LWIP实现一个tcpip的通讯,但是在写DM9161驱动的时候,当复位DM9161,使能自协商模式后,检测连接是够建立,也就是BMSR的link status位始终为0,我的PHY地址为0.网上有说地址设置为0的时候DM9161处于掉电模式,请问这种说法 ...… 查看全部问答> |
|
本帖最后由 tianshuihu 于 2014-2-24 21:23 编辑 有一块LaunchPad仿真器不知什么原因无法使用了,连接电脑显示无法连接的USB设备...但是板子还可以运行原来的程序 初步怀疑MSP430F1612 或 TUSB3410 损坏 换了一块 TUSB3410 ,无果。。。 如果 ...… 查看全部问答> |




