这是AD5245的控制字节,我的程序如下:
1.首先是 I2C初始化
void I2CA_Init(void)
{
// Initialize I2C
I2caRegs.I2CSAR = 0x58;
#if (CPU_FRQ_150MHZ) // Default - For 150MHz SYSCLKOUT
I2caRegs.I2CPSC.all = 14; // Prescaler - need 7-12 Mhz on module clk (150/15 = 10MHz)
#endif
#if (CPU_FRQ_100MHZ) // For 100 MHz SYSCLKOUT
I2caRegs.I2CPSC.all = 9; // Prescaler - need 7-12 Mhz on module clk (100/10 = 10MHz)
#endif
I2caRegs.I2CCLKL = 10; // NOTE: must be non zero
I2caRegs.I2CCLKH = 5; // NOTE: must be non zero
//I2caRegs.I2CIER.all = 0x24; // Enable SCD & ARDY interrupts
I2caRegs.I2CIER.all = 0x00; // Disable I2CA interrupts
I2caRegs.I2CMDR.all = 0x0020; // Take I2C out of reset
// Stop I2C when suspended
//I2caRegs.I2CFFTX.all = 0x6000; // Enable FIFO mode and TXFIFO
//I2caRegs.I2CFFRX.all = 0x2040; // Enable RXFIFO, clear RXFFINT,
I2caRegs.I2CFFTX.all = 0x0000; // Disable FIFO mode
I2caRegs.I2CFFRX.all = 0x0000; // Disable RXFIFO
return;
}
2.GPIO初始化省略,但配置正确。
3.写入AD5245控制字节的函数
void write_AD5245(Uint16 slaveAddr, Uint16 Instruction, Uint16 regDat)
{
// Wait until the STP bit is cleared from any previous master communication.
// Clearing of this bit by the module is delayed until after the SCD bit is
// set. If this bit is not checked prior to initiating a new message, the
// I2C could get confused.
while(I2caRegs.I2CMDR.bit.STP == 1);
// Setup slave address
I2caRegs.I2CSAR = slaveAddr;
// Check if bus busy
while(I2caRegs.I2CSTR.bit.BB == 1);
// Setup number of bytes to send(datLen + 1)
I2caRegs.I2CCNT = 2;
// Setup the address to send
I2caRegs.I2CDXR = Instruction;
// Send start as master transmitter
I2caRegs.I2CMDR.all = 0x6E20;
// Setup data to send
while(I2caRegs.I2CSTR.bit.XRDY == 0);卡在这里不动
I2caRegs.I2CDXR = regDat;
DELAY_US(100);
}
4.调用函数
write_AD5245(0x58, 0x00, GAIN_B_2);
因为AD5245的AD0引脚接地,所以AD5245的地址为0x58。
不知道什么原因,希望大神指点,谢谢!
此帖出自
小平头技术问答
是我地址写错了,我一直以为地址里也包含W/R那一位,后来仔细看书才明白W/R自动给的,地址只有0~6位是有效的。
可以,QQ601696045
一周热门 更多>