RT,最近在调MAX44009 光照传感器,采用STM32F103采集数据,IIC部分的代码都是以前验证过很多遍的,确保没有问题,按照数据手册上连续读0x03、0x04两各寄存器的时序图写的代码,测试数据没问题,就是寄存器值无法更新,每次按复位键后数据才刷新
看数据手册说只有监测到IIC_STOP信号后寄存器的值才会更新,代码的数据读取部分也体现了这一步操作,调了两天了,是在想不出漏洞在哪,跪求有经验的大神们不吝赐教
unsigned int MAX44009_ReadData(unsigned char RegAddr1, unsigned char RegAddr2)
{
unsigned char lsb;
unsigned char msb;
IIC_Start();
IIC_Write_Byte(SLAVE_ADDRESS<<1); //·¢Ëíé豸D′Ãüáî
IIC_Wait_Ack();
IIC_Write_Byte(RegAddr1); //·¢Ëí¼Ä′æÆ÷1μØÖ·
IIC_Wait_Ack();
IIC_Start();
IIC_Write_Byte((SLAVE_ADDRESS<<1) + 1); //¶áμúò»¸ö¼Ä′æÆ÷êy¾Y
IIC_Wait_Ack();
msb = IIC_Read_Byte(0); //NO ACK
IIC_Start();
IIC_Write_Byte(SLAVE_ADDRESS<<1); //·¢Ëíé豸D′Ãüáî
IIC_Wait_Ack();
IIC_Write_Byte(RegAddr2); //·¢Ëí¼Ä′æÆ÷2μØÖ·
IIC_Wait_Ack();
IIC_Start();
IIC_Write_Byte((SLAVE_ADDRESS<<1) + 1); //¶áμú¶t¸ö¼Ä′æÆ÷êy¾Y
IIC_Wait_Ack();
lsb = IIC_Read_Byte(0); //NO ACK
IIC_Stop(); //2úéúò»¸öí£Ö1ìõ¼t
return (msb << 8) | lsb;
}
//D′¼Ä′æÆ÷
void MAX44009_WriteData(unsigned char RegAddr, unsigned char value)
{
IIC_Start();
IIC_Write_Byte(SLAVE_ADDRESS<<1); //·¢Ëíé豸D′Ãüáî
IIC_Wait_Ack();
IIC_Write_Byte(RegAddr); //·¢Ëí¼Ä′æÆ÷μØÖ·
IIC_Wait_Ack();
IIC_Write_Byte(value); //·¢Ëíêy¾Y
IIC_Wait_Ack();
IIC_Stop(); //2úéúò»¸öí£Ö1ìõ¼t
}
一周热门 更多>