这是SI4438的射频收发程序,使用STM系列MCU通过四线SPI实现对SI4438的读写操作。
源程序见附件。
所有资料51hei提供下载:
SI4438 初始化 和收发函数.zip
(16.56 KB, 下载次数: 154)
单片机源程序如下:
- #include "SI4463_src.h"
- /*********************************************************************
- ** Constant Declaration
- *********************************************************************/
- const u8 config_table[] = RADIO_CONFIGURATION_DATA_ARRAY;
- const u8 config_10k[] = RADIO_CONFIGURATION_DATA_10K;
- /*********************************************************************
- ** Nrf24l01_InterFace
- *********************************************************************/
- void SI4463_InterFace(void)
- {
- //init io pin
- GPIO_Init(SI_SDN_GPIO,SI_SDN_PIN,GPIO_MODE_OUT_PP_HIGH_FAST);//SDN 引脚设置为输出
- Init_SPI();
- }
- /*
- =================================================================================
- SI446X_CMD( );
- Function : Send a command to the device
- INTPUT : cmd, the buffer stores the command array
- cmdsize, the size of the command array
- OUTPUT : NONE
- =================================================================================
- */
- void SI446X_CMD( u8 *cmd, u8 cmdsize )
- {
- SI446X_WAIT_CTS( );
- SS_LOW( );
- while( cmdsize -- )
- {
- SPI_ExchangeByte( *cmd++ );
- }
- SS_HIGH( );
- }
- /*
- =================================================================================
- SI446X_POWER_UP( );
- Function : Power up the device
- INTPUT : f_xtal, the frequency of the external high-speed crystal
- OUTPUT : NONE
- =================================================================================
- */
- void SI446X_POWER_UP( u32 f_xtal )
- {
- u8 cmd[7];
- cmd[0] = POWER_UP;
- cmd[1] = 0x01;
- cmd[2] = 0x00;
- cmd[3] = f_xtal>>24;
- cmd[4] = f_xtal>>16;
- cmd[5] = f_xtal>>8;
- cmd[6] = f_xtal;
- SI446X_CMD( cmd, 7 );
- }
- /*
- =================================================================================
- SI446X_READ_RESPONSE( );
- Function : read a array of command response
- INTPUT : buffer, a buffer, stores the data responsed
- size, How many bytes should be read
- OUTPUT : NONE
- =================================================================================
- */
- void SI446X_READ_RESPONSE( u8 *buffer, u8 size )
- {
- SI446X_WAIT_CTS( );
- SS_LOW( );
- SPI_ExchangeByte( READ_CMD_BUFF );
- while( size -- )
- {
- *buffer++ = SPI_ExchangeByte( 0xFF );
- }
- SS_HIGH( );
- }
- /*
- =================================================================================
- SI446X_WAIT_CTS( );
- Function : wait the device ready to response a command
- INTPUT : NONE
- OUTPUT : NONE
- =================================================================================
- */
- void SI446X_WAIT_CTS( void )
- {
- u8 cts;
- for(u16 i=0xffff;i>0;i--) //5000次查询等待
- {
- SS_LOW( );
- SPI_ExchangeByte( READ_CMD_BUFF );
- cts = SPI_ExchangeByte( 0xFF );
- SS_HIGH( );
-
- if(cts == 0xFF)
- break;
- }
- }
- /*
- =================================================================================
- SI446X_NOP( );
- Function : NO Operation command
- INTPUT : NONE
- OUTPUT : NONE
- =================================================================================
- */
- u8 SI446X_NOP( void )
- {
- u8 cts;
- SS_LOW( );
- cts = SPI_ExchangeByte( NOP );
- SS_HIGH( );
- return cts;
- }
- /*
- =================================================================================
- SI446X_PART_INFO( );
- Function : Read the PART_INFO of the device, 8 bytes needed
- INTPUT : buffer, the buffer stores the part information
- OUTPUT : NONE
- =================================================================================
- */
- void SI446X_PART_INFO( u8 *buffer )
- {
-
-
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
|