历史上的今天
今天是:2024年10月14日(星期一)
2019年10月14日 | nrf24l01无线芯片的开发板范例-AVR(已验证通过)
2019-10-14 来源:eefocus
#include "main.h"
#include "nRF24L01.h"
/*Bit field operations*/
#define SetBit( Byte, Bit ) ( Byte ) |= ( 1<<( Bit ) )
#define ClrBit( Byte, Bit ) ( Byte ) &= ~( 1<<( Bit ) )
#define GetBit( Byte, Bit ) ( ( Byte ) & ( 1<<( Bit ) ) )
#define ComBit( Byte, Bit ) ( Bytes ) ^= ( 1<<( Bit ) )
#define SetBits( Byte, Bits ) ( Byte ) |= ( Bits )
#define ClrBits( Byte, Bits ) ( Byte ) &= ~( Bits )
#define GetBits( Byte, Bits ) ( ( Byte ) & ( Bits ) )
#define ComBits( Byte, Bits ) ( Byte ) ^= ( Bits )
#define M32_MOSI PB5
#define M32_MISO PB6
#define M32_SCK PB7
/*
================================================================================
Function : USART_SendChar( )
Description: Send a single byte via the USART
InPut : -dt, The value you want to send
Output : None
================================================================================
*/
void USART_SendChar( unsigned char dt )
{
UCSRA |= ( 1< while( !( UCSRA & ( 1< /* ================================================================================ Function : USART_SendArray( ) Description: Send a array of data via the USART port InPut : -pBuff, The buffer to store the data -nBytes, How many bytes do you want to send ? Output : None ================================================================================ */ void USART_SendArray( unsigned char* pBuff, unsigned char nBytes ) { unsigned char btmp; for( btmp = 0; btmp < nBytes; btmp ++ ) { USART_SendChar( *( pBuff + btmp ) ); } } /* ================================================================================ Function : USART_SendStr( ) Description: Send a string of data via the USART port InPut : pstr->the string to be sent Output : None ================================================================================ */ void USART_SendStr( char *pstr ) { while( *pstr ) { USART_SendChar( *pstr++ ); } } /* ================================================================================ Function : USART_Init( ), Description: Initialize the USART port InPut : None Output : None ================================================================================ */ #define Bandrate 9600 #define F_CPU 12000000 void USART_Init( void ) { UCSRB = 0x00; //disable while setting baud rate UCSRA = 0x00; UCSRC = 0x86; UBRRL = ( F_CPU / 16 / Bandrate - 1 ) % 256; UBRRH = ( F_CPU / 16 / Bandrate - 1 ) >> 8; UCSRB = 0x98; } /* ================================================================================ Function : SPI_Init( ) Description : Initialize the SPI bus Input : None Output: None ================================================================================ */ /*void SPI_Init( void ) { //IO config PORTB |= ( 1<<0 ) | ( 1<<5 ) | ( 1<<3 ) | ( 1<<2 ) | ( 1<<4 ); DDRB |= ( 1<<0 ) | ( 1<<2 ) | ( 1<<3 ) | ( 1<<5 ); DDRB &= ~( 1<<4 ); SPCR = (1< void SPI_Init( void ) { /*IO config*/ PORTB |= ( 1<<0 ) | ( 1<<5 ) | ( 1<<6 ) | ( 1<<7 ) | ( 1<<4 ); DDRB |= ( 1<<7 ) | ( 1<<5 ) | ( 1<<0 ) | ( 1<<4 ); DDRB &= ~( 1<<6 ); SPCR = (1< /* ================================================================================ Function : SPI_ExchangeByte( ) Description : Exchange a byte via the SPI bus Input : -value, The byte sent Output: The byte read. ================================================================================ */ INT8U SPI_ExchangeByte( INT8U value ) { SPDR = value; while ( !(SPSR & (1< } INT8U testbuffer[32]; int main( void ) { INT8U tmp; unsigned char ReplayData[] = {"我很好!rn"}; SPI_Init( ); USART_Init( ); L01_Init( ); L01_SetRXMode( ); L01_WriteHoppingPoint( 0 ); USART_SendStr( "nRF24L01P接收测试开始!rn" ); while( 1 ) { for( tmp = 0; tmp < 32; tmp ++ ) { testbuffer[tmp] = tmp+0x20; } L01_FlushRX( ); L01_FlushTX( ); L01_WriteRXPayload_InAck( ReplayData, sizeof( ReplayData ) ); while( 1 ) { tmp = L01_ReadStatusReg( ); // USART_SendChar(tmp); //for test tmp &= ( 1< { break; } } if( tmp & ( 1< // USART_SendStr( "发送成功rn" ); } else if( tmp & ( 1< // USART_SendStr( "发送失败rn" ); } else if( tmp & ( 1< L01_WriteRXPayload_InAck( testbuffer, 32 ); USART_SendStr( "收到数据:" ); tmp = L01_ReadRXPayload( testbuffer ); USART_SendArray( testbuffer, tmp ); USART_SendStr( "回复数据:" ); USART_SendStr( ( char*) ReplayData ); } L01_ClearIRQ( IRQ_ALL ); } return 0; }
史海拾趣
|
在这我只想发发牢骚……因为我现在就是在闲着,时时刻刻都开着EEWORLD 快毕业了,本来找工作都几乎没什么搭理的,发过好多简历都石沉大海。毕竟我只是专科学历,虽然参加过几次比赛,但感觉这些经历并没给我找工作带来什么的。 ...… 查看全部问答> |
|
C:\\icc\\bin\\imakew -f xiaoche.mak iccavr -c -IC:\\icc\\include\\ -e -l -g -Wa-W C:\\DOCUME~1\\Administrator\\MYDOCU~1\\小车\\xiaoche.c !W C:\\DOCUME~1\\Administrator\\MYDOCU~1\\小车/drv.h(14 ...… 查看全部问答> |
|
在TI-2812开发板上调试485通讯,用串口调试器向下发数据时,RX状态寄存器显示有帧错误,从下望上发数据时,串口调试器接受的数据是错误的,但发送0是接受到的也是0.请高手帮帮忙! … 查看全部问答> |
|
最近在思考一个问题,就是有关SD卡升级的。 我看到过三星发布2442下的SD卡升级,但有个缺陷是只支持FAT格式的小容量卡,而且,在EBOOT里面去读写卡的block、sector,简直有点复杂。 我在想,如果是FAT32格式的(现在基本上都是FAT32格式了)SD卡能 ...… 查看全部问答> |
|
Wince 下用C#实现媒体播放,最好是Media Player的调用。希望有经验的各位前辈随便露两手绝艺,让俺开开眼届。最好有源码!! Wince 下用C#实现媒体播放,最好是Media Player的调用。希望有经验的各位前辈随便露两手绝艺,让俺开开眼届。最好有源码!! … 查看全部问答> |
|
初学者问个简单问题:关于WINXP SP2下的环境配置问题! 小弟的机器是WinXP SP2 HOME EDITION,想问一下,在这个系统下如何配置编译环境? 相关软件:DriverStudio3.2 XP SP1 DDK ...… 查看全部问答> |
|
我在VS2005中建了一个c++的移动设备的MFC,是一个264 的解码器,现在要加一个显示的程序,最好能解一点播一点,本来VC上有源程序,移植后无法使用,现在毕设中,急啊,哪位仁兄能帮我看看用什么方法显示,谢谢,本人菜鸟,不好意思!! ...… 查看全部问答> |
|
我用STM32 控制一个320x240的 TFT屏,需要显示jpg的文件,感觉刷整屏的时候速度很慢;显示bmp文件时刷整屏的时候就很快。STM32是不是不适合解码jpg文件呢?… 查看全部问答> |
|
广大DIY爱好者们,随着你们DIY程度的不断深入,你们的DIY工具是不是也在一点点的增加,随着工具的增加,DIY的水平是不是也在不断地提高,随着水平的不断提高,DIY的作品是不是也是愈加的丰富,显摆的时刻到了! 活动要求: 1、显摆自己所有用于D ...… 查看全部问答> |




