最新免费av在线观看,亚洲综合一区成人在线,中文字幕精品无码一区二区三区,中文人妻av高清一区二区,中文字幕乱偷无码av先锋

STM32連接射頻si4438模塊

出處:eefocus 發(fā)布于:2017-07-14 14:58:45

SI4438射頻模塊參數(shù):

1、頻率范圍:425-525 MHz

2、數(shù)字接收信號強度指示(RSSI)

3、64字節(jié)收發(fā)數(shù)據(jù)寄存器(FIFO)

4、跳頻功能

等!


使用SI的WDS工具生成代碼

1、  選擇仿真模式

2、  芯片選擇si4438 B1模式

3、  Radio Configuration Application

4、  Select Application




1、  Select Project

選擇Bidirectional packet ,雙向通信模式

2、  Configure project 配置工程

Frequency and power: 頻率和功率的設(shè)置,

base freq基頻,中心頻率,

Channel spacing 通道空間,某個通道回憶 base freq+ channel spacin*num 為頻率通信,當(dāng)然會有小浮動,但是浮動不會超過 Channel spacing。

計算通道號數(shù)量:

(Base freq  +  channel spacin*num) >=425MHz

(Base freq  +  channel spacin*num) <=525MHz


所以Base freq的設(shè)置以及channel spacing的設(shè)置會影響到通道的數(shù)量。

Crystal:晶振默認(rèn)!

其他的不動

 

RF parameter



這里設(shè)置的射頻參數(shù),包括調(diào)制模式、數(shù)據(jù)速率等參數(shù),RSSI threshold設(shè)置信號閾值。數(shù)據(jù)速率射頻之間的距離有關(guān)系,速度越快,對應(yīng)的距離要求越短。所以這應(yīng)該按照自己的需求來選。




Pakect數(shù)據(jù)包的設(shè)置,包括TX和RX緩沖區(qū)的長度、前導(dǎo)碼的配置Preamble、同步字的配置SyncWord、Field對應(yīng)負(fù)載的字節(jié)數(shù)據(jù),注意總的負(fù)載字節(jié)數(shù)為TX和RX閾值,具體分幾個fields看個人需求。



NIRQ配置成RX data output,即NIRQ和單片機引腳相連單片機可以通過該引腳判斷是否有數(shù)據(jù)接收。低電平有效!然后即可生成代碼!

生成的代碼是基于C8051F910單片機的,我們所用的是,所以必須做好移植。

SPI移植:

不需要生成spi.c,建立STM32 SPI配置文件:


  1. #include   

  2. #include "stm32f10x_spi.h"  

  3. #include " STM32SPI2.h"  

  4. u8 STM32SPI2_ReadWriteByte(u8 TxData)  

  5. {         

  6.     u8 retry=0;                

  7.     while((SPI2->SR&1<<1) == 0)    {  

  8.         retry++;  

  9.         if(retry>250)  

  10.       return 0;  

  11.     }               

  12.     SPI2->DR=TxData;   

  13.     retry=0;  

  14.     while((SPI2->SR&1<<0) == 0)//    

  15.     {  

  16.         retry++;  

  17.         if(retry>250)  

  18.       return 0;  

  19.     }                                 

  20.     return SPI2->DR;  

  21. }  

  22. //APB2=72M/8=9M  

  23. void STM32SPI2_Config(void)  

  24. {             

  25.      SPI_InitTypeDef  SPI_InitStructure;  

  26.     GPIO_InitTypeDef GPIO_InitStructure;  

  27.     RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE );  

  28.     /* Configure SPI2 pins: SCK, MISO and MOSI */  

  29.     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;  

  30.     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;  

  31.     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;  

  32.     GPIO_Init(GPIOB, &GPIO_InitStructure);  

  33.     /* Configure NSEL pins */  

  34.     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;  

  35.     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;  

  36.     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;  

  37.     GPIO_Init(GPIOB, &GPIO_InitStructure);  

  38.     GPIO_SetBits(GPIOB, GPIO_Pin_12);  

  39.     /* SPI2 configuration */  

  40.     SPI_I2S_DeInit(SPI2);  

  41.     RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);  

  42.     SPI_Cmd(SPI2, DISABLE);  

  43.     SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;  

  44.     SPI_InitStructure.SPI_Mode = SPI_Mode_Master;  

  45.     SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;  

  46.     SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;  

  47.     SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;  

  48.     SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;  

  49.     SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_128;//SPI_BaudRatePrescaler_64;  

  50.     SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;  

  51.     SPI_InitStructure.SPI_CRCPolynomial = 7;  

  52.     SPI_Init(SPI2, &SPI_InitStructure);  

  53.     /* Enable SPI2  */  

  54.     SPI_Cmd(SPI2, ENABLE);  

  55.     STM32SPI2_ReadWriteByte(0xff);//啟動傳輸      

  56. }    

  57. //í?ò?ê±?????üê1?üò???SPIéè±?,2?êyTYPE_SPI_ALL?TD§  

  58. void STM32SPI2_Enable(TYPE_SPI type)  

  59. {  

  60. /* 

  61.   if(type == TYPE_SPI_FLASH) //這其實沒啥用 

  62.   { 

  63.     GPIO_SetBits(GPIOA,GPIO_Pin_4);//ê§?üRF 

  64.     GPIO_ResetBits(GPIOC,GPIO_Pin_4);//ê1?üFLASH 

  65.   }   

  66.   else 

  67.   { 

  68. */  

  69. //    GPIO_SetBits(GPIOC,GPIO_Pin_4);//ê§?üFLASH  

  70.    GPIO_ResetBits(GPIOB,GPIO_Pin_12);//   

  71. /* 

  72.   } 

  73. */  

  74. }  


  1. void STM32SPI2_Disable(TYPE_SPI type)  

  2. {  

  3.   if(type == TYPE_SPI_FLASH)  

  4.   {  

  5.     GPIO_SetBits(GPIOC,GPIO_Pin_4);//ê§?üFLASH     

  6.   }    

  7.   else if(type == TYPE_SPI_RF)  

  8.   {  

  9.     GPIO_SetBits(GPIOB,GPIO_Pin_12);//ê§?üRF  

  10.   }  

  11.   else  

  12.   {  

  13.     GPIO_SetBits(GPIOC,GPIO_Pin_4);//ê§?üFLASH  

  14.     GPIO_SetBits(GPIOA,GPIO_Pin_4);//ê§?üRF  

  15.   }  

  16. }  

  17. radio.c  radio hal層 spi接口修改處  

  18. void radio_hal_SpiWriteByte(u8 byteToWrite)  

  19. {  

  20.   STM32SPI2_ReadWriteByte(byteToWrite);  

  21. }  

  22. u8 radio_hal_SpiReadByte(void)  

  23. {  

  24.   return STM32SPI2_ReadWriteByte(0xFF);  

  25. }  

  26. void radio_hal_SpiWriteData(u8 byteCount, u8* pData)  

  27. {  

  28.   while(byteCount--)  

  29.   {  

  30.     STM32SPI2_ReadWriteByte(*pData++);  

  31.   }  

  32. }  

  33. void radio_hal_SpiReadData(u8 byteCount, u8* pData)  

  34. {  

  35.   while(byteCount--)  

  36.   {  

  37.     *pData++ = STM32SPI2_ReadWriteByte(0xFF);  

  38.   }  

  39. }  

  40. Radio_Config:配置SDN power IRQ引腳  

  41. void Radio_Config(void)  

  42. {  

  43.   GPIO_InitTypeDef GPIO_InitStructure;  

  44.   //oíFLASH12ó?ò???SPI,SPIò??-?úFLASHμ?3?ê??ˉ?Dμ÷ó?    

  45.   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC, ENABLE);  

  46.   //RF_POWER  

  47.   GPIO_InitStructure.GPIO_Pin = RF_POWER_PIN;  

  48.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;  

  49.   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;  

  50.   GPIO_Init(RF_POWER_PORT, &GPIO_InitStructure);  

  51.   GPIO_SetBits(RF_POWER_PORT, RF_POWER_PIN);  

  52.     //RF_ON  

  53. GPIO_InitStructure.GPIO_Pin = RF_

  1.   GPIO_InitStructure.GPIO_Pin = RF_ON_PIN;  

  2.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;  

  3.   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;  

  4.   GPIO_Init(RF_ON_PORT, &GPIO_InitStructure);  

  5.   GPIO_SetBits(RF_ON_PORT, RF_ON_PIN);  

  6.   //RF_SDN  

  7.   GPIO_InitStructure.GPIO_Pin = RF_SDN_PIN;  

  8.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;  

  9.   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;  

  10.   GPIO_Init(RF_SDN_PORT, &GPIO_InitStructure);  

  11.   GPIO_SetBits(RF_SDN_PORT, RF_SDN_PIN);  

  12.   //RF_IRQ  

  13.   GPIO_InitStructure.GPIO_Pin = RF_IRQ_PIN;  

  14.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;//????ê?è?  

  15.   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;  

  16.   GPIO_Init(RF_IRQ_PORT, &GPIO_InitStructure);  

  17. }     

  18. 接收信號:  

  19. u8 radio_hal_NirqLevel(void)  

  20. {  

  21.   return GPIO_ReadInputDataBit(RF_IRQ_PORT, RF_IRQ_PIN);  

  22. }  

  23. void radio_hal_AssertShutdown(void)  

  24. {  

  25.   GPIO_SetBits(RF_SDN_PORT, RF_SDN_PIN);  

  26. }  

  27. void radio_hal_DeassertShutdown(void)  

  28. {  

  29.   GPIO_ResetBits(RF_SDN_PORT, RF_SDN_PIN);  

  30. }  




底層配置完畢,配置bsh頭文件:


  1. #include "stdio.h"  

  2. #include "compiler_defs.h"  

  3. //#include "platform_defs.h"  

  4. //#include "hardware_defs.h"  

  5. //#include "application_defs.h"  

  6. //#include "cdd_common.h"  

  7. #include "radio_config.h"  

  8. #include "radio.h"  

  9. //#include "sample_code_func.h"  

  10. #include "radio_hal.h"  

  11. #define SILABS_RADIO_SI446X  

  12. #include "radio_comm.h"  

  13. #include "si446x_api_lib.h"  

  14. #include "si446x_defs.h"  

  15. //#include "si446x_nirq.h"  

  16. #include   

  17. //#include "drivers\radio\Si446x\si446x_patch.h"  


把不是自己的平臺的屏蔽了!

 

Main接收端

接收函數(shù):


  1. int SI4338RecvData(void* buf,u32 len){  

  2.     u16 i,crc16;  

  3.     u8* ptr;  

  4.     SEGMENT_VARIABLE(bMain_IT_Status, U8, SEG_XDATA);  

  5.     ptr = (u8*)buf;  

  6.     if(ptr == NULL) return -1;  

  7.     bMain_IT_Status = bRadio_Check_Tx_RX();  

  8.     switch (bMain_IT_Status)  

  9.     {  

  10.         case SI446X_CMD_GET_INT_STATUS_REP_PH_PEND_PACKET_SENT_PEND_BIT:{  

  11.             vRadio_StartRX(pRadioConfiguration->Radio_ChannelNumber, 64);  

  12.             ///* Clear Packet Sending flag */  

  13.         }  

  14.         break;  

  15.         case SI446X_CMD_GET_INT_STATUS_REP_PH_PEND_PACKET_RX_PEND_BIT:{  

  16.             memset(ptr,0,len);  

  17.             memcpy(ptr,SI4338RecvData,SI4338RecvLen);  

  18.             //recv OK ,you must start RX!  

  19.             vRadio_StartRX(pRadioConfiguration->Radio_ChannelNumber,pRadioConfiguration->Radio_PacketLength);  

  20.             return SI4338RecvLen;  

  21.         }  

  22.         break;  

  23.         default:  

  24.         break;  

  25.     } /* switch */  

  26.     return -1;  

  27. }  

  28. //注意:需要在U8 bRadio_Check_Tx_RX(void)函數(shù)把接收的數(shù)據(jù)拷貝出來,然后再RECV函數(shù)memcpy過來就可以了。  

  29. U8 bRadio_Check_Tx_RX(void){  

  30. ……………………………………….  

  31.       if(Si446xCmd.GET_INT_STATUS.PH_PEND & SI446X_CMD_GET_INT_STATUS_REP_PH_PEND_PACKET_RX_PEND_BIT)  

  32.       {  

  33.         /* Packet RX */  

  34.         /* Get payload length */  

  35.         si446x_fifo_info(0x00);  

  36.         si446x_read_rx_fifo(Si446xCmd.FIFO_INFO.RX_FIFO_COUNT, &rxInformation[0]);  

  37.                 SI4338RecvLen =Si446xCmd.FIFO_INFO.RX_FIFO_COUNT;  

  38.                 memcpy(SI4338RecvData,rxInformation,Si446xCmd.FIFO_INFO.RX_FIFO_COUNT);  

  39.         return SI446X_CMD_GET_INT_STATUS_REP_PH_PEND_PACKET_RX_PEND_BIT;  

  40.       }  

  41.       ….  

  42. }  

  43. unsigned char buf[64];  

  44. int recvLen;  

  45. vRadio_StartRX(pRadioConfiguration->Radio_ChannelNumber,0u); 啟動接收  

  46. while(1){  

  47. if((recvLen  = SI4338RecvData(void*( buf),64)) >0){  

  48.     //處理接收的數(shù)據(jù)  

  49. }  

  50. }  


  1. 發(fā)送端:使用這個函數(shù)發(fā)送既可以!  

  2. int SI4338SendData(void* buf,u32 len){  

  3.     u8* ptr;  

  4.     int ret = -1;  

  5.     u16 i;  

  6.     SEGMENT_VARIABLE(bMain_IT_Status, U8, SEG_XDATA);  

  7.     ptr = (u8*)buf;  

  8.     if(buf == NULL) return -1;  

  9.     vRadio_StartTx_Variable_Packet(pRadioConfiguration->Radio_ChannelNumber,ptr, len);  

  10.     #if 1  

  11.     bMain_IT_Status = bRadio_Check_Tx_RX();  

  12.     switch (bMain_IT_Status)  

  13.     {  

  14.         case SI446X_CMD_GET_INT_STATUS_REP_PH_PEND_PACKET_SENT_PEND_BIT:  

  15.             //vRadio_StartTx_Variable_Packet(pRadioConfiguration->Radio_ChannelNumber,ptr, len);  

  16.             vRadio_StartRX(pRadioConfiguration->Radio_ChannelNumber, pRadioConfiguration->Radio_PacketLength);  

  17.             ret = 0;  

  18.         break;  

  19.         case SI446X_CMD_GET_INT_STATUS_REP_PH_PEND_PACKET_RX_PEND_BIT:{  

  20.             vRadio_StartRX(pRadioConfiguration->Radio_ChannelNumber, pRadioConfiguration->Radio_PacketLength);  

  21.             return SI4338RecvLen;  

  22.         }  

  23.         default: ;break;  

  24.     }  

  25. #endif  

  26.     return ret;  

  27. }  


關(guān)鍵詞:STM32,連接射頻,si4438模塊

版權(quán)與免責(zé)聲明

凡本網(wǎng)注明“出處:維庫電子市場網(wǎng)”的所有作品,版權(quán)均屬于維庫電子市場網(wǎng),轉(zhuǎn)載請必須注明維庫電子市場網(wǎng),http://www.udpf.com.cn,違反者本網(wǎng)將追究相關(guān)法律責(zé)任。

本網(wǎng)轉(zhuǎn)載并注明自其它出處的作品,目的在于傳遞更多信息,并不代表本網(wǎng)贊同其觀點或證實其內(nèi)容的真實性,不承擔(dān)此類作品侵權(quán)行為的直接責(zé)任及連帶責(zé)任。其他媒體、網(wǎng)站或個人從本網(wǎng)轉(zhuǎn)載時,必須保留本網(wǎng)注明的作品出處,并自負(fù)版權(quán)等法律責(zé)任。

如涉及作品內(nèi)容、版權(quán)等問題,請在作品發(fā)表之日起一周內(nèi)與本網(wǎng)聯(lián)系,否則視為放棄相關(guān)權(quán)利。

廣告
OEM清單文件: OEM清單文件
*公司名:
*聯(lián)系人:
*手機號碼:
QQ:
有效期:

掃碼下載APP,
一鍵連接廣大的電子世界。

在線人工客服

買家服務(wù):
賣家服務(wù):
技術(shù)客服:

0571-85317607

網(wǎng)站技術(shù)支持

13606545031

客服在線時間周一至周五
9:00-17:30

關(guān)注官方微信號,
第一時間獲取資訊。

建議反饋

聯(lián)系人:

聯(lián)系方式:

按住滑塊,拖拽到最右邊
>>
感謝您向阿庫提出的寶貴意見,您的參與是維庫提升服務(wù)的動力!意見一經(jīng)采納,將有感恩紅包奉上哦!