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

📄 drv1_cc1000.c

📁 CC1000 Rf modem C codes for philips sLpc213X ARM MCU.
💻 C
📖 第 1 页 / 共 2 页
字号:
/****************************************************************************/  

void Reset_CC1000(void)
{
uint8 MainValue;
  
  Uart0SendString("Reset CC1000");
  MainValue=ReadFromCC1000Register(CC1000_MAIN);
  WriteToCC1000Register(CC1000_MAIN,MainValue & 0xFE);         // Reset CC1000
  WriteToCC1000Register(CC1000_MAIN,MainValue | 0x01);         // Bring CC1000 out of reset
}

/****************************************************************************/
/*  This routine calibrates the CC1000                                      */
/*  Returns 0 if calibration fails, non-zero otherwise. Checks the LOCK     */
/*  to check for success.                                                   */
/****************************************************************************/

uint8 CalibrateCC1000(void)
{
//uint32 TimeOutCounter;
	Uart0SendString("Calibrate CC1000");
	WriteToCC1000Register(CC1000_PA_POW,0x00); 		// Turn off PA to avoid spurs during calibration in TX mode
	WriteToCC1000Register(CC1000_CAL,0xA6); 			// Start calibration
  
// Wait for calibration complete
/*
	for(TimeOutCounter=CAL_TIMEOUT;
		((ReadFromCC1000Register(CC1000_CAL)&0x08)==0)&&(TimeOutCounter>0);
		TimeOutCounter--);
*/
	WatchDog_Start(CAL_TIMEOUT+1000);	// watchDog reset time 11 seconds
	mSecondTick=CAL_TIMEOUT;
//	while(mSecondTick>1);				// for debug
	while(((ReadFromCC1000Register(CC1000_CAL)&0x08)==0)&&(mSecondTick>1));
	if(mSecondTick<=1) Uart0SendString("Time overflow in CAL state");

// Wait for lock
/*
	for(TimeOutCounter=LOCK_TIMEOUT; 
		((ReadFromCC1000Register(CC1000_LOCK)&0x01)==0)&&(TimeOutCounter>0); 
		TimeOutCounter--);
*/
	WatchDog_Start(LOCK_TIMEOUT+1000);	// watchDog reset time 11 seconds
	mSecondTick=LOCK_TIMEOUT;
//	while(mSecondTick>1);				// for debug
	while(((ReadFromCC1000Register(CC1000_LOCK)&0x01)==0)&&(mSecondTick>1));
	if(mSecondTick<=1) Uart0SendString("Time overflow in LOCK state");
	
	WriteToCC1000Register(CC1000_CAL,0x26); 			/* End calibration */
	WriteToCC1000Register(CC1000_PA_POW,PA_VALUE); 	/* Restore PA setting */
  // only for print information
	if(((ReadFromCC1000Register(CC1000_LOCK)&0x01)==1)){
		Uart0SendString("CC1000_LOCK success");
  	}else{
		Uart0SendString("CC1000_LOCK failed");
  	}

//	return ((ReadFromCC1000Register(CC1000_LOCK)&0x01)==1);
  	return (ReadFromCC1000Register(CC1000_LOCK)&0x01);  
}

/****************************************************************************/
/*  This routine puts the CC1000 into RX mode (from TX). When switching to  */
/*  RX from PD, use WakeupC1000ToRX first                                   */
/****************************************************************************/

uint8 SetupCC1000RX(uint8 RxCurrent,uint8 RF_RxPll)
{
//uint32 i;
uint8 lock_status;

//Uart0SendString("SetupCC1000RX");
	
  WriteToCC1000Register(CC1000_MAIN,0x11);    		// Switch into RX, switch to freq. reg A
  WriteToCC1000Register(CC1000_PLL,RF_RxPll);   	// Use RX refdiv setting
  WriteToCC1000Register(CC1000_CURRENT,RxCurrent); 	// Program VCO current for RX

// Wait 250us before monitoring LOCK  // for (i=0;i<0x1000;i++);
  DelayMS_(1);			  				// Wait for lock
/*
  for(i=LOCK_TIMEOUT; 
      ((ReadFromCC1000Register(CC1000_LOCK)&0x01)==0)&&(i>0);
        i--);
*/
  WatchDog_Start(LOCK_TIMEOUT+1000);		// watchDog reset time 11 seconds
  mSecondTick=LOCK_TIMEOUT;
  while(((ReadFromCC1000Register(CC1000_LOCK)&0x01)==0)&&(mSecondTick>1));
  if(mSecondTick<=1) Uart0SendString("Time overflow in SetupCC1000RX");

// If PLL in lock
  if ((ReadFromCC1000Register(CC1000_LOCK)&0x01)==0x01){
// Indicate PLL in LOCK
    lock_status = LOCK_OK;
// Uart0SendString("lock_status = LOCK_OK!");

  }else{						// Else (PLL out of LOCK)
    							// If recalibration ok
    Uart0SendString("Re_calibrate CC1000");
    if(CalibrateCC1000()){
      							// Indicate PLL in LOCK
      lock_status = LOCK_RECAL_OK;
      Uart0SendString("LOCK_RECAL_OK"); 
    }else{						// Else (recalibration failed)
// Reset frequency syncthesizer (ref.: Errata Note 01)
      RF_ResetFreqSynth();
// Indicate PLL out of LOCK
      lock_status = LOCK_NOK;
      Uart0SendString("LOCK_NOK");
    }
  }

  return (lock_status);			// Return LOCK status to application
}

/****************************************************************************/
/*  This routine puts the CC1000 into TX mode (from RX). When switching to  */
/*  TX from PD, use WakeupCC1000ToTX first                                  */
/****************************************************************************/

uint8 SetupCC1000TX(uint8 TxCurrent, uint8 RF_TxPll)
{
//int i;
uint8 lock_status;

  WriteToCC1000Register(CC1000_PA_POW,0x00);   		// Turn off PA to avoid frequency splatter
  WriteToCC1000Register(CC1000_MAIN,0xE1);     		// Switch into TX, switch to freq. reg B
  WriteToCC1000Register(CC1000_PLL,RF_TxPll);     	// Use TX refdiv setting
  WriteToCC1000Register(CC1000_CURRENT,TxCurrent); 	// Program VCO current for TX

// Wait 250us before monitoring LOCK  // for (i=0;i<0x1000;i++);
  DelayMS_(1); 							// Wait for lock
/*
  for(i=LOCK_TIMEOUT; 
      ((ReadFromCC1000Register(CC1000_LOCK)&0x01)==0x00)&&(i>0); 
        i--);
*/
  WatchDog_Start(LOCK_TIMEOUT+1000);		// watchDog reset time 11 seconds
  mSecondTick=LOCK_TIMEOUT;
  while(((ReadFromCC1000Register(CC1000_LOCK)&0x01)==0)&&(mSecondTick>1));
  if(mSecondTick<=1) Uart0SendString("Time overflow in SetupCC1000TX");
  
// If PLL in lock
  if ((ReadFromCC1000Register(CC1000_LOCK)&0x01)==0x01){
// Indicate PLL in LOCK
    lock_status = LOCK_OK;
// Uart0SendString("lock_status = LOCK_OK!");   
  }else{									// Else (PLL out of LOCK)
    										// If recalibration ok
    if(CalibrateCC1000()){					// Indicate PLL in LOCK
      lock_status = LOCK_RECAL_OK;
      Uart0SendString("LOCK_RECAL_OK");
    }else{	// Else (recalibration failed)
// Reset frequency syncthesizer (ref.: Errata Note 01)
      RF_ResetFreqSynth();
// Indicate PLL out of LOCK
      lock_status = LOCK_NOK;
      Uart0SendString("LOCK_NOK");
    }
  }
  													// Increase output power
  WriteToCC1000Register(CC1000_PA_POW,PA_VALUE);	// Restore PA setting

  return (lock_status);								// Return LOCK status to application
}

/****************************************************************************/
/*  This routine puts the CC1000 into power down mode. Use WakeUpCC1000ToRX */
/*  followed by SetupCC1000RX or WakeupCC1000ToTX followed by SetupCC1000TX */
/*  to wake up from power down                                              */
/****************************************************************************/

void SetupCC1000PD(void)
{
  Uart0SendString("SetupCC1000PD");
  WriteToCC1000Register(CC1000_MAIN,0x3F);    		// Put CC1000 into power-down
  WriteToCC1000Register(CC1000_PA_POW,0x00);  		// Turn off PA to minimise current draw
}

/****************************************************************************/
/*  This routine wakes the CC1000 up from PD mode to RX mode, call          */
/*  SetupCC1000RX after this routine is finished.                           */
/****************************************************************************/

void WakeUpCC1000ToRX(uint8 RxCurrent, uint8 RF_RxPll)
{
  
  Uart0SendEnter();	Uart0SendString("WakeUpCC1000ToRX");
  WriteToCC1000Register(CC1000_MAIN,0x3B);  // Turn on xtal oscillator core
  WriteToCC1000Register(CC1000_CURRENT,RxCurrent); // Program VCO current for RX 
  WriteToCC1000Register(CC1000_PLL,RF_RxPll); // Use RX refdiv setting
  
// Insert wait routine here, must wait for xtal oscillator to stabilise, 
// typically takes 2-5ms.  // for (i=0;i<0x7FFE;i++);
  DelayMS_(5);
  
  WriteToCC1000Register(CC1000_MAIN,0x39);  // Turn on bias generator
  											// Wait for 250us, insert wait loop here
  DelayMS_(1);
  
  WriteToCC1000Register(CC1000_MAIN,0x31);  // Turn on frequency synthesiser
}

/****************************************************************************/
/*  This routine wakes the CC1000 up from PD mode to TX mode, call          */
/*  SetupCC1000TX after this routine is finished.                           */
/****************************************************************************/

void WakeUpCC1000ToTX(uint8 TxCurrent, uint8 RF_TxPll)
{
  Uart0SendEnter();	Uart0SendString("WakeUpCC1000ToTX");
  WriteToCC1000Register(CC1000_MAIN,0xFB);  		// Turn on xtal oscillator core
  WriteToCC1000Register(CC1000_CURRENT,TxCurrent); 	// Program VCO current for TX
  WriteToCC1000Register(CC1000_PLL,RF_TxPll); 			// Use TX refdiv setting
  
// Insert wait routine here, must wait for xtal oscillator to stabilise, 
// typically takes 2-5ms. // for (i=0;i<0x7FFE;i++);
  DelayMS_(5);
  DelayMS_(5);      
  
  WriteToCC1000Register(CC1000_MAIN,0xF9);  		// Turn on bias generator
  													// Wait for 250us, insert wait loop here
  DelayMS_(1);
  
  WriteToCC1000Register(CC1000_PA_POW,PA_VALUE); 	// Turn on PA
  WriteToCC1000Register(CC1000_MAIN,0xF1); 			// Turn on frequency synthesiser
}

/****************************************************************************/
/*  This routine locks the averaging filter of the CC1000                   */
/****************************************************************************/
/*
void AverageManualLockCC1000(void)
{
  Uart0SendString("AverageManualLockCC1000");
  WriteToCC1000Register(CC1000_MODEM1,0x19);
}
*/
/****************************************************************************/
/*  This routine unlocks the averaging filter of the CC1000                 */
/****************************************************************************/
/*
void AverageFreeRunCC1000(void)
{
  Uart0SendString("AverageFreeRunCC10000");
  WriteToCC1000Register(CC1000_MODEM1,0x09);
}
*/
/****************************************************************************/
/*  This routine sets up the averaging filter of the CC1000 for automatic   */
/*  lock. This can be used in polled receivers.                             */
/****************************************************************************/
/*
void AverageAutoLockCC1000(void)
{
  Uart0SendString("AverageAutoLockCC1000");
  Uart0SendString("AverageAutoLockCC1000");
  WriteToCC1000Register(CC1000_MODEM1,0x01);
}
*/
/****************************************************************************/
/*  This routine reads the current calibration values from the CC1000       */
/****************************************************************************/
/*
void ReadCurrentCalibration(uint8 *val1, uint8 *val2)
{
  Uart0SendString("ReadCurrentCalibration");
  *val1=ReadFromCC1000Register(CC1000_TEST0);
  *val2=ReadFromCC1000Register(CC1000_TEST2);
}
*/
/****************************************************************************/
/*  This routine overrides the current calibration of the CC1000            */
/****************************************************************************/
/*
void OverrideCurrentCalibration(uint8 val1, uint8 val2)
{
  Uart0SendString("OverrideCurrentCalibration");    
  WriteToCC1000Register(CC1000_TEST5,(val1&0x0F)|0x10);
  WriteToCC1000Register(CC1000_TEST6,(val2&0x1F)|0x20);
}
*/
/****************************************************************************/
/*  This routine stops override of the CC1000 calibration values            */
/****************************************************************************/
/*
void StopOverridingCalibration(void)
{
  Uart0SendString("StopOverridingCalibration");    
  WriteToCC1000Register(CC1000_TEST5,0x00);
  WriteToCC1000Register(CC1000_TEST6,0x00);
}
*/
/****************************************************************************/
//// end of file

⌨️ 快捷键说明

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