📄 2120_driver.c
字号:
//***********************************************************************
//***********************EVKIT FUNCTIONS *******************************
//***********************************************************************
/*
Name: 2120_Driver.cpp
Copyright: Maxim IC
Author: Paul Nichol
Date: 14/03/06 12:35
Description: Contains functions to communicate and control the MAX2120 IC.
This unit depends on Lpt and I2c functions located in the file Lpt_Functions.cpp
These Lpt and I2c functions are only needed for the PC->parallel port->MAX2120 control
and can be replaced with the microprocessor specific I/O functions to write to
the IC.
*/
//***********************************************************************
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <windows.h> //microsoft specific
#include "2120_Driver.h"
#include "LPT_Functions.h" //Relates to printer port driver. Omit for microprocessor based applications
// Assign default values for each register
unsigned char N_High = 0x3;
unsigned char N_Low = 0xB6;
unsigned char Frac2 = 0x2;
unsigned char Frac1 = 0xF6;
unsigned char Frac0 = 0x84;
unsigned char Xtal = 0x04; //Rdiv = 2
unsigned char PLL_Conf = 0xA8;
unsigned char VCO_Cont = 0xCF;
unsigned char BB_LPF = 0x4b;
unsigned char Standby = 0x40; //lower 4 bits set the baseband gain!
unsigned char Shutdown = 0x00;
unsigned char Test = 0x08;
unsigned char Status = 0x00;
unsigned char AutoTune = 0x00;
unsigned char TrimConfig = 0x00;
unsigned char BiasTrim = 0x27;
unsigned char BB_FiltTrim = 0xd;
unsigned char RF_ContTrim1 = 0x5d;
unsigned char RF_ContTrim2 = 0x5;
double XtalRef = 4; //Frequency in MHz applied to MAX2120 Xtal pin.
//PC functions to close communications with the MAX2120,
//omit for microprocessor based applications
void MAX2120Close(void)
{
LPT_Close();
}
//******************************************************************************
//This Init routine must always be called before any I2C Communication can occur.
//It sets up the register defaults for the Max2120 in order to operate properly.
//******************************************************************************
void MAX2120Init(void)
{
//PC functions to set up communications with MAX2120,
//omit for microprocessor based applications
LPT_Init("MAX2120_cpp");
I2C_SCLKO_PIN ( 3 );
I2C_SDAO_PIN ( 2 );
I2C_SDAI_PIN ( 10 );
//Initialize the registers in the MAX2120:
MAX2120Write(MAX2120_N_HIGH, N_High);
MAX2120Write(MAX2120_N_LOW, N_Low);
MAX2120Write(MAX2120_CP_FRAC2, Frac2);
MAX2120Write(MAX2120_FRAC1, Frac1);
MAX2120Write(MAX2120_FRAC0, Frac0);
MAX2120Write(MAX2120_XTAL, Xtal);
MAX2120Write(MAX2120_PLL, PLL_Conf);
MAX2120Write(MAX2120_VCOCONT, VCO_Cont);
MAX2120Write(MAX2120_BASEBAND, BB_LPF);
MAX2120Write(MAX2120_STANDBY, Standby);
MAX2120Write(MAX2120_SHUTDWN, Shutdown);
MAX2120Write(MAX2120_TEST, Test);
MAX2120Write(MAX2120_TRIMCONF, TrimConfig);
MAX2120Write(MAX2120_BIASTRIM, BiasTrim);
MAX2120Write(MAX2120_BBFILTTRIM, BB_FiltTrim);
MAX2120Write(MAX2120_RFCONTTRIM1, RF_ContTrim1);
MAX2120Write(MAX2120_RFCONTTRIM2, RF_ContTrim2);
}
//******************************************************************************
//
//The routine MAX2120SetFrequency will set the following registers based
//on the input Frequency (MHz)
//
//******************************************************************************
void MAX2120SetFrequency(double Frequency)
{
int VCO_Divider=1;
int Rdiv;
long NDiv;
const RDIV_MASK = 0x1f; //Rdiv is Reg 5 D0-D4
//Set the DIV24 bit, 1 = LO divided by 4, 0 = LO divided by 2.
if ( Frequency <= 1125 )
{
PLL_Conf |= 0x80; //DIV24 Bit = 1
}
else{
PLL_Conf &= 0x7f; //DIV24 Bit = 0
}
Rdiv = Xtal & RDIV_MASK;
NDiv = (long)(Frequency * Rdiv) / (XtalRef); //Find the multiplier (n + fracn) ex. 50.27234
N_High = (unsigned char)((NDiv & 0x7f00) >> 8); //Retain the upper bit which is the FRAC Bit.
N_Low = (unsigned char)NDiv & 0xff;
//Write out the new register changes to the IC
MAX2120Write(MAX2120_PLL, PLL_Conf);
MAX2120Write(MAX2120_N_HIGH, N_High);
MAX2120Write(MAX2120_N_LOW, N_Low);
}
//******************************************************************************
// Reads the LD or lock detect bit, Returns 1 if th PLL is locked, 0 if not locked.
//******************************************************************************
unsigned char MAX2120_LockDetect(void){
return (MAX2120Read(MAX2120_STATUS) & LD_BIT) >> 4;
}
//
//MAX2120Read will read and return the value in register 'reg_index'
//Customer's I-squared-C read function would go in place of this wrapper
//function. This funciton takes a register index to indicate which register
//to read from.
//See the Max2120 data sheet for the I-squared-C read sequence.
//
unsigned char MAX2120Read(unsigned char reg_index)
{
return I2C_IReadByte(MAX2120_ADDR,reg_index);
}
//
//MAX2120Write will write to register 'reg_index' the value 'value'
//Customer's I-squared-C write function would go in place of this wrapper
//function. This funciton takes a register index to indicate which register
//to read from and a value to put into the register.
//See the Max2120 data sheet for the I-squared-C write sequence.
//
void MAX2120Write(unsigned char reg_index,unsigned char value)
{
I2C_IWriteByte(MAX2120_ADDR, reg_index, value);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -