新手上路
- 积分
- 41
- 金钱
- 41
- 注册时间
- 2017-1-12
- 在线时间
- 9 小时
|
使用LDC1314,读的时候一直读到255和5535,不只是数据寄存器,其他寄存器也都是。
用的STM32F407,这是初始化代码。
LDC的7bit地址是什么意思?0x2A 和0x2B ,没太看懂
void LDC1314_Init(void) //³õʼ»¯LDC1314ºÍI2C
{
IIC_Init(); //IIC³õʼ»¯
LDC_ADDR = 0; //LDCµÄ7bitµØַΪ0X2A£¬×¢ÒâÊÇ7bit ¼´ 0101 010_ ×îµÍλΪ¶Áдλ
LDC_SD = 0; //Í˳öShutdown Mode
delay_ms(500); //ÑÓʱ500ms
LDC_write_16bit(LDC13xx16xx_CMD_REF_COUNT_CH0,0X04D6);
LDC_write_16bit(LDC13xx16xx_CMD_REF_COUNT_CH1,0X04D6);
LDC_write_16bit(LDC13xx16xx_CMD_REF_COUNT_CH2,0X04D6);
LDC_write_16bit(LDC13xx16xx_CMD_REF_COUNT_CH3,0X04D6);
LDC_write_16bit(LDC13xx16xx_CMD_SETTLE_COUNT_CH0,0X000A);
LDC_write_16bit(LDC13xx16xx_CMD_SETTLE_COUNT_CH1,0X000A);
LDC_write_16bit(LDC13xx16xx_CMD_SETTLE_COUNT_CH2,0X000A);
LDC_write_16bit(LDC13xx16xx_CMD_SETTLE_COUNT_CH3,0X000A);
LDC_write_16bit(LDC13xx16xx_CMD_CLOCK_DIVIDERS_CH0,0X1002);
LDC_write_16bit(LDC13xx16xx_CMD_CLOCK_DIVIDERS_CH1,0X1002);
LDC_write_16bit(LDC13xx16xx_CMD_CLOCK_DIVIDERS_CH2,0X1002);
LDC_write_16bit(LDC13xx16xx_CMD_CLOCK_DIVIDERS_CH3,0X1002);
LDC_write_16bit(LDC13xx16xx_CMD_ERROR_CONFIG,0X0000);
LDC_write_16bit(LDC13xx16xx_CMD_MUX_CONFIG,0X0820C);
LDC_write_16bit(LDC13xx16xx_CMD_DRIVE_CURRENT_CH0,0x9000);
LDC_write_16bit(LDC13xx16xx_CMD_DRIVE_CURRENT_CH1,0x9000);
LDC_write_16bit(LDC13xx16xx_CMD_DRIVE_CURRENT_CH2,0x9000);
LDC_write_16bit(LDC13xx16xx_CMD_DRIVE_CURRENT_CH3,0x9000);
LDC_write_16bit(LDC13xx16xx_CMD_CONFIG,0x1601); //bit13 ÇåÁã Í˳ö˯Ãßģʽ
}
这是读寄存器的代码:
u16 LDC_read_16bit(u8 regaddr)
{
u16 data_temp = 0;
u16 data_temp1 = 0;
IIC_Start();
IIC_Send_Byte(LDC1314_ADDR_WRITE);
IIC_Wait_Ack();
IIC_Send_Byte(regaddr); //¼Ä´æÆ÷µØÖ·
IIC_Wait_Ack();
IIC_Start();
IIC_Send_Byte(LDC1314_ADDR_READ);
IIC_Wait_Ack();
data_temp1 = IIC_Read_Byte(0);
data_temp = IIC_Read_Byte(0);
IIC_Stop();
data_temp = data_temp + (data_temp1<<8) ;
return data_temp;
}
|
|