這是SI4438的射頻收發程序,使用STM系列MCU通過四線SPI實現對SI4438的讀寫操作。
源程序見附件。
0.png (50.21 KB, 下載次數: 149)
下載附件
2017-6-26 18:09 上傳
所有資料51hei提供下載:
SI4438 初始化 和收發函數.zip
(16.56 KB, 下載次數: 154)
2017-6-26 14:28 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
單片機源程序如下:
- #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黑下載附件…………
復制代碼
|