⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main_sdbc_dk3.c.svn-base

📁 Si4432-T-B1版本资料.rar
💻 SVN-BASE
📖 第 1 页 / 共 2 页
字号:
/*** ============================================================================**** FILE**  main.c**** DESCRIPTION**  This is the main file of the project.	    **  HW platform SDB with C8051F93x Silabs MCU **** CREATED**  Silicon Laboratories Hungary Ltd**** COPYRIGHT**  Copyright 2009 Silicon Laboratories, Inc.  **	http://www.silabs.com**** ============================================================================*/								/* ======================================================== *								 *									INCLUDE					*							 	 * ======================================================== */#include "C8051F930_defs.h"#include "compiler_defs.h"#include "string.h"							/* ================================================================ *							 * C8051F930 Pin definitions for Software Development Board         *							 * 					(using compiler_def.h macros) 					*							 *	=============================================================== */	SBIT(NSS, SFR_P1, 3);SBIT(NIRQ, SFR_P0, 6);SBIT(PB1, SFR_P0, 0);SBIT(PB2, SFR_P0, 1);SBIT(PB3, SFR_P2, 0);SBIT(PB4, SFR_P2, 1);SBIT(LED1, SFR_P1, 4);SBIT(LED2, SFR_P1, 5);SBIT(LED3, SFR_P1, 6);SBIT(LED4, SFR_P1, 7);//One out of these definitions has to be uncommented which tells to the compiler what kind //of Testcard is plugged into the Software Development board#define SEPARATE_RX_TX//#define ANTENNA_DIVERSITY//#define ONE_SMA_WITH_RF_SWITCH								/* ======================================================== *								 *							Function PROTOTYPES				* 										 * ======================================================== *///MCU initializationvoid MCU_Init(void);//SPI functions						void SpiWriteRegister (U8, U8);U8 SpiReadRegister (U8);void main(void){	U8 ItStatus1,ItStatus2;	U16 delay;	U8 length,temp8;	U8 payload[10];	//Initialize the MCU: 	//	- set IO ports for the Software Development board	//	- set MCU clock source	//	- initialize the SPI port 	//	- turn off LEDs	MCU_Init();							/* ======================================================== *							 *						Initialize the Si4431 ISM chip		* 							 * ======================================================== */	//SW reset      SpiWriteRegister(0x07, 0x80);																//write 0x80 to the Operating & Function Control1 register 	//wait for chip ready interrupt from the radio (while the nIRQ pin is high)	while ( NIRQ == 1); 	//read interrupt status registers to clear the interrupt flags and release NIRQ pin	ItStatus1 = SpiReadRegister(0x03);															//read the Interrupt Status1 register	ItStatus2 = SpiReadRegister(0x04);															//read the Interrupt Status2 register 													/*set the physical signal parameters*/	//set the center frequency to 915 MHz	SpiWriteRegister(0x75, 0x75);																//write 0x75 to the Frequency Band Select register                SpiWriteRegister(0x76, 0xBB);																//write 0xBB to the Nominal Carrier Frequency1 register   SpiWriteRegister(0x77, 0x80);  																//write 0x80 to the Nominal Carrier Frequency0 register									/*set the modem parameters according to the exel calculator(parameters: 9.6 kbps, deviation: 45 kHz, channel filter BW: 102.2 kHz*/	SpiWriteRegister(0x1C, 0x1E);																//write 0x1E to the IF Filter Bandwidth register			SpiWriteRegister(0x20, 0xD0);																//write 0xD0 to the Clock Recovery Oversampling Ratio register			SpiWriteRegister(0x21, 0x00);																//write 0x00 to the Clock Recovery Offset 2 register			SpiWriteRegister(0x22, 0x9D);																//write 0x9D to the Clock Recovery Offset 1 register			SpiWriteRegister(0x23, 0x49);																//write 0x49 to the Clock Recovery Offset 0 register			SpiWriteRegister(0x24, 0x00);																//write 0x00 to the Clock Recovery Timing Loop Gain 1 register			SpiWriteRegister(0x25, 0x24);																//write 0x24 to the Clock Recovery Timing Loop Gain 0 register			SpiWriteRegister(0x1D, 0x40);																//write 0x40 to the AFC Loop Gearshift Override register			SpiWriteRegister(0x2A, 0x20);																//write 0x20 to the AFC Limiter register					//set the Modem test register 	SpiWriteRegister(0x56, 0xC1);																//write 0xC1 to the Modem test register							/*Configure the receive packet handler*/	//Disable header bytes; set variable packet length (the length of the payload is defined by the	//received packet length field of the packet); set the synch word to two bytes long   SpiWriteRegister(0x33, 0x02 );																//write 0x02 to the Header Control2 register    	//Disable the receive header filters   SpiWriteRegister(0x32, 0x00 );																//write 0x00 to the Header Control1 register            		//Set the sync word pattern to 0x2DD4	SpiWriteRegister(0x36, 0x2D);																//write 0x2D to the Sync Word 3 register	SpiWriteRegister(0x37, 0xD4);																//write 0xD4 to the Sync Word 2 register	//Enable the receive packet handler and CRC-16 (IBM) check	SpiWriteRegister(0x30, 0x85);																//write 0x85 to the Data Access Control register	//Enable FIFO mode and GFSK modulation	SpiWriteRegister(0x71, 0x63);										 						//write 0x63 to the Modulation Mode Control 2 register	//set preamble detection threshold to 20bits	SpiWriteRegister(0x35, 0x2A); 																//write 0x2A to the Preamble Detection Control  register	//set the preamble length to 10bytes if the antenna diversity is used and set to 5bytes if not #ifdef ANTENNA_DIVERSITY	SpiWriteRegister(0x34, 0x18); 																//write 0x18 to the Preamble Length register 	#else	SpiWriteRegister(0x34, 0x0C);																//write 0x0C to the Preamble Length register#endif#ifdef ANTENNA_DIVERSITY	//Enable antenna diversity mode	SpiWriteRegister(0x08, 0x80);																//write 0x80 to the Operating Function Control 2 register#endif											/*set the GPIO's according the testcard type*/#ifdef ANTENNA_DIVERSITY   SpiWriteRegister(0x0C, 0x17);																//write 0x17 to the GPIO1 Configuration(set the Antenna 1 Switch used for antenna diversity )	SpiWriteRegister(0x0D, 0x18);																//write 0x18 to the GPIO2 Configuration(set the Antenna 2 Switch used for antenna diversity ) #endif#ifdef ONE_SMA_WITH_RF_SWITCH   SpiWriteRegister(0x0C, 0x12);																//write 0x12 to the GPIO1 Configuration(set the TX state)	SpiWriteRegister(0x0D, 0x15);																//write 0x15 to the GPIO2 Configuration(set the RX state) #endif											/*set the non-default Si4431 registers*/	//set the VCO and PLL	SpiWriteRegister(0x57, 0x01);																//write 0x01 to the Chargepump Test register														SpiWriteRegister(0x59, 0x00);																//write 0x00 to the Divider Current Trimming register 		SpiWriteRegister(0x5A, 0x01); 																//write 0x01 to the VCO Current Trimming register 	//set  Crystal Oscillator Load Capacitance register	SpiWriteRegister(0x09, 0xD7);																//write 0xD7 to the Crystal Oscillator Load Capacitance register    	/*enable receiver chain*/	SpiWriteRegister(0x07, 0x05);																//write 0x05 to the Operating Function Control 1 register	//Enable two interrupts: 	// a) one wich shows that a valid preamble received:'ipreaval'	// b) second shows if a sync word received:'iswdet'	SpiWriteRegister(0x05, 0x00); 																//write 0x00 to the Interrupt Enable 1 register	SpiWriteRegister(0x06, 0xC0); 																//write 0xC0 to the Interrupt Enable 2 register	//read interrupt status registers to release all pending interrupts	ItStatus1 = SpiReadRegister(0x03);															//read the Interrupt Status1 register	ItStatus2 = SpiReadRegister(0x04);															//read the Interrupt Status2 register	/*MAIN Loop*/	while(1)	{		//wait for the interrupt event		if( NIRQ == 0 )		{			//read interrupt status registers 			ItStatus1 = SpiReadRegister(0x03);													//read the Interrupt Status1 register			ItStatus2 = SpiReadRegister(0x04);													//read the Interrupt Status2 register			//check whether preamble is detected			if( (ItStatus2 & 0x40) == 0x40 )			{//preamble detected				//wait for the synch word interrupt with timeout -- THIS is the proposed SW workaround				//start a timer in the MCU and during timeout check whether synch word interrupt happened or not				delay = 0;				do {					delay++;				} while((delay < 20000) && (NIRQ == 1));													//check whether the synch word interrupt is detected				if( NIRQ == 0)				{//synch word detected correctly					//read interrupt status registers 					ItStatus1 = SpiReadRegister(0x03);											//read the Interrupt Status1 register					ItStatus2 = SpiReadRegister(0x04);											//read the Interrupt Status2 register									//Enable two interrupts: 					// a) one which shows that a valid packet received: 'ipkval'					// b) second shows if the packet received with incorrect CRC: 'icrcerror' 					SpiWriteRegister(0x05, 0x03); 												//write 0x03 to the Interrupt Enable 1 register					SpiWriteRegister(0x06, 0x00); 												//write 0x00 to the Interrupt Enable 2 register					//read interrupt status registers to release all pending interrupts					ItStatus1 = SpiReadRegister(0x03);											//read the Interrupt Status1 register					ItStatus2 = SpiReadRegister(0x04);						    //wait for the interrupt event					while(NIRQ == 1);						//read interrupt status registers 					ItStatus1 = SpiReadRegister(0x03);											//read the Interrupt Status1 register					ItStatus2 = SpiReadRegister(0x04);											//read the Interrupt Status2 register					/*CRC Error interrupt occured*/					if( (ItStatus1 & 0x01) == 0x01 )					{						//disable the receiver chain 						SpiWriteRegister(0x07, 0x01);											//write 0x01 to the Operating Function Control 1 register						//blink all LEDs to show the error						LED1 = 1;						LED2 = 1;						LED3 = 1;						LED4 = 1;						for(delay = 0; delay < 10000;delay++);						LED1 = 0;						LED2 = 0;						LED3 = 0;						LED4 = 0;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -