1:从MLX90615的芯片手册可以看到,芯片是16为adc数据,兼容Smbus和PWM协议
其中温度的数据是存在于Ram中的,而相应的芯片配置,ID,模式选择,发射率等是存在芯片的EEprom中的,其中需要注意的是EEprom中尽量不要去操作的是04到0D地址之间,其芯片默认出厂地址为0x5B ,其中0x00地址是每个芯片都会响应的
如下配置寄存器所说,config地址为eeprom的02地址,其中响应配置位对应的如下表所示,bit0为芯片选择驱动模式,(默认出产设置模式是Smbus),但假如模式选为PWM时要切换为SMbus模式需要将SCL拉低Treq时间,才可以切换成SMbus模式
Ram说明:,06H地址是环境的温度,07H地址才是所测物体的温度
注意一点的是ram在芯片中只能用于读取,EEprom才可以读写操作
从芯片手册知,我们在操作读写的命令组成是这样的:
即EEprom的命令是0001_xxxx,(xxxx即使用户需要操作的地址,也即其操作命令又前缀+地址组成)
Ram: 0010_xxxx;
从芯片的手册得知,芯片在Smbus模式下,数据的传输是需要PEC校验的
其中PEC校验内容如下:(注意数据的传输都是高位在前)
其读取传输协议:
另,当用户需要操作芯片睡眠的时候,SCL必须拉高,当需要唤醒芯片的时候,SCL必须拉低超过50ms,SDA不做要求
从以上信息可以知道芯片地址为7位,频率不高于100Khz,可进行IIC通信,结合以上信息,得出如下驱动程序(库函数处理)
其读操作:
void I2C_BufferRead(u8* pBuffer, u16 NumByteToRead,u8 Comman,u8 SlaveAddr)
{
/* Send START condition */
I2C_GenerateSTART(I2C1, ENABLE);
/* Test on EV5 and clear it */
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT));
/* Send EEPROM address for write */
I2C_Send7bitAddress(I2C1, SlaveAddr, I2C_Direction_Transmitter);
/* Test on EV6 and clear it */
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
// /* Clear EV6 by setting again the PE bit */
// I2C_Cmd(I2C1, ENABLE);
/* Send the EEPROM's internal address to write to */
I2C_SendData(I2C1, Comman);
/* Test on EV8 and clear it */
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
/* Send STRAT condition a second time */
I2C_GenerateSTART(I2C1, ENABLE);
/* Test on EV5 and clear it */
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT));
/* Send EEPROM address for read */
I2C_Send7bitAddress(I2C1, SlaveAddr, I2C_Direction_Receiver);
/* Test on EV6 and clear it */
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED));
/* While there is data to be read */
while(NumByteToRead)
{
if(NumByteToRead == 1)
{
/* Disable Acknowledgement */
I2C_AcknowledgeConfig(I2C1, DISABLE);
/* Send STOP Condition */
I2C_GenerateSTOP(I2C1, ENABLE);
}
/* Test on EV7 and clear it */
if(I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_RECEIVED))
{
/* Read a byte from the EEPROM */
*pBuffer = I2C_ReceiveData(I2C1);
/* Point to the next location where the byte read will be saved */
pBuffer++;
/* Decrement the read bytes counter */
NumByteToRead--;
}
}
/* Enable Acknowledgement to be ready for another reception */
I2C_AcknowledgeConfig(I2C1, ENABLE);
}
写操作:
void I2C_ByteWrite(u8* pBuffer, u8 SlaveAddr,u8 Comman,u8 Pec)
{
/* Send STRAT condition */
I2C_GenerateSTART(I2C1, ENABLE);
/* Test on EV5 and clear it */
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT));
/* Send EEPROM address for write */
I2C_Send7bitAddress(I2C1, SlaveAddr, I2C_Direction_Transmitter);
/* Test on EV6 and clear it */
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
/* Send the EEPROM's internal address to write to */
I2C_SendData(I2C1, Comman);
/* Test on EV8 and clear it */
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
/* Send the byte to be written */
I2C_SendData(I2C1, *pBuffer);
/* Test on EV8 and clear it */
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
/* Send the byte to be written */
I2C_SendData(I2C1, Pec);
/* Test on EV8 and clear it */
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
/* Send STOP condition */
I2C_GenerateSTOP(I2C1, ENABLE);
}
头文件:
#define SA 0x00 // Slave address £¬ËùÓÐÉ豸¶¼¿ÉÒÔÏìÓ¦0x00µÄµØÖ·Öµ
#define SA_Default 0x5B //³ö³§Ä¬ÈÏÖµ
#define RAM_Access 0x20 // RAM access command
#define EEPROM_Access 0x10 // EEPROM access command
#define SLEEP_Comman 0xC6 // sleep command
//////////ÒÔÏÂÅäÖõØÖ·ÐèÒª½áºÏEEPROM_AccessʹÓã¬EEPROM_AccessΪ¸ß4λ
#define CONFIG_Access 0x02
#define FAQ_Access 0x03
#define ID1_Access 0x0E //´ËÁ½¸öid¶ÁÈ¡Ò»¸ö¼´¿É
#define ID2_Access 0x0F
//////////ÒÔϵØÖ·ÐèÒªÅäºÏRAM_AccessʹÓã¬RAM_Accessλ¸ß4λ
#define RAM_Ta 0x06 // Ta address in the ram
#define RAM_To 0x07 // To address in the ram