GY906温度的传感器

GY906温度的传感器⽬录
外形
注意事项
引脚设置为开漏输出
模块可以3.3v供电
代码
代码来⾃
这位⼤哥的
main
temp=SMBus_ReadTemp();
printf("ζÈֵΪ£º%.2f\r\n",temp);
HAL_Delay(100);
.c
#include"mlx90614.h"
#include"mlx90614.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
#define ACK  0
#define NACK 1
#define SA    0x00 //Slave address x
#define RAM_ACCESS  0x00 //RAM access command RAM´æÈ¡ÃüÁî
#define EEPROM_ACCESS 0x20 //EEPROM access command EEPROM´æÈ¡ÃüÁî
#define RAM_TOBJ1  0x07 //To1 address in the eeprom Ä¿±ê1ζÈ,¼ì²âµ½µÄºìÍâÎÂ¶È -70.01 ~ 382.19¶È
#define SMBUS_PORT GPIOB      //PB¶Ë¿Ú(¶Ë¿ÚºÍÏÂÃæµÄÁ½¸öÕë½Å¿É×Ô¶¨Òå)
#define SMBUS_SCK  GPIO_PIN_6 //PB6£ºSCL
#define SMBUS_SDA  GPIO_PIN_7 //PB7£ºSDA2
#define RCC_APB2Periph_SMBUS_PORT  RCC_APB2Periph_GPIOB
#define SMBUS_SCK_H()    SMBUS_PORT->BSRR = SMBUS_SCK //Öøߵçƽ
#define SMBUS_SCK_L()    SMBUS_PORT->BRR = SMBUS_SCK  //Öõ͵çƽ
#define SMBUS_SDA_H()    SMBUS_PORT->BSRR = SMBUS_SDA
#define SMBUS_SDA_L()    SMBUS_PORT->BRR = SMBUS_SDA
#define SMBUS_SDA_PIN()    SMBUS_PORT->IDR & SMBUS_SDA //¶ÁÈ¡Òý½Åµçƽ
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/*******************************************************************************
* Function Name  : SMBus_StartBit
* Description    : Generate START condition on SMBus
* Input          : None
* Output        : None
* Return        : None
大功率变频电源*******************************************************************************/
void SMBus_StartBit(void)
{
SMBUS_SDA_H();// Set SDA line
SMBus_Delay(5);// Wait a few microseconds
SMBUS_SCK_H();// Set SCL line
SMBus_Delay(5);// Generate bus free time between Stop
SMBUS_SDA_L();// Clear SDA line
SMBus_Delay(5);// Hold time after (Repeated) Start
// Condition. After this period, the first clock is generated.
//(Thd:sta=4.0us min)ÔÚSCK=1ʱ£¬¼ì²âµ½SDAÓÉ1µ½0±íʾͨÐÅ¿ªÊ¼£¨Ï½µÑØ£©
SMBUS_SCK_L();// Clear SCL line
SMBus_Delay(5);// Wait a few microseconds
}
/*******************************************************************************
* Function Name  : SMBus_StopBit
* Description    : Generate STOP condition on SMBus
* Input          : None
* Output        : None
* Return        : None
*******************************************************************************/
void SMBus_StopBit(void)
{
SMBUS_SCK_L();// Clear SCL line
SMBus_Delay(5);// Wait a few microseconds
SMBUS_SDA_L();// Clear SDA line
SMBus_Delay(5);// Wait a few microseconds
SMBUS_SCK_H();// Set SCL line
SMBus_Delay(5);// Stop condition setup time(Tsu:sto=4.0us min)阻燃双面胶
SMBUS_SDA_H();// Set SDA lineÔÚSCK=1ʱ£¬¼ì²âµ½SDAÓÉ0µ½1±íʾͨÐŽáÊø£¨ÉÏÉýÑØ£©
}
/*******************************************************************************
* Function Name  : SMBus_SendByte
* Function Name  : SMBus_SendByte
* Description    : Send a byte on SMBus
* Input          : Tx_buffer
* Output        : None
* Return        : None
*******************************************************************************/ u8 SMBus_SendByte(u8 Tx_buffer)
{
u8 Bit_counter;
u8 Ack_bit;
u8 bit_out;
for(Bit_counter=8; Bit_counter; Bit_counter--)
{
if(Tx_buffer&0x80)
拖曳臂式悬架
{
bit_out=1;// If the current bit of Tx_buffer is 1 set bit_out }
else
{
bit_out=0;// else clear bit_out
}
SMBus_SendBit(bit_out);// Send the current bit on SDA
Tx_buffer<<=1;// Get next bit for checking
}
Ack_bit=SMBus_ReceiveBit();// Get acknowledgment bit return Ack_bit;
}
/******************************************************************************* * Function Name  : SMBus_SendBit
* Description    : Send a bit on SMBus 82.5kHz
* Input          : bit_out
* Output        : None
* Return        : None
*******************************************************************************/ void SMBus_SendBit(u8 bit_out)
{
if(bit_out==0)
{
SMBUS_SDA_L();
}
else
{
SMBUS_SDA_H();
}
SMBus_Delay(2);// Tsu:dat = 250ns minimum
SMBUS_SCK_H();// Set SCL line
SMBus_Delay(6);// High Level of Clock Pulse
SMBUS_SCK_L();// Clear SCL line
SMBus_Delay(3);// Low Level of Clock Pulse
// SMBUS_SDA_H();        // Master release SDA line ,
return;
}
/******************************************************************************* * Function Name  : SMBus_ReceiveBit
* Description    : Receive a bit on SMBus
* Input          : None
* Output        : None
* Return        : Ack_bit
*******************************************************************************/ u8 SMBus_ReceiveBit(void)
{
u8 Ack_bit;
SMBUS_SDA_H();//Òý½Å¿¿Íⲿµç×èÉÏÀ£¬µ±×÷ÊäÈëSMBus_Delay(2);// High Level of Clock Pulse
SMBus_Delay(2);// High Level of Clock Pulse
SMBUS_SCK_H();// Set SCL line
SMBus_Delay(5);// High Level of Clock Pulse
if(SMBUS_SDA_PIN())
{
Ack_bit=1;
}
else
{
Ack_bit=0;
}
SMBUS_SCK_L();// Clear SCL line
碱性脱漆剂
SMBus_Delay(3);// Low Level of Clock Pulse
return Ack_bit;
dtt使用浓度}
/******************************************************************************* * Function Name  : SMBus_ReceiveByte
* Description    : Receive a byte on SMBus
* Input          : ack_nack
* Output        : None
* Return        : RX_buffer
*******************************************************************************/
u8 SMBus_ReceiveByte(u8 ack_nack)
{
u8  RX_buffer;
u8 Bit_Counter;
for(Bit_Counter=8; Bit_Counter; Bit_Counter--)
{
if(SMBus_ReceiveBit())// Get a bit from the SDA line
{
RX_buffer <<=1;// If the bit is HIGH save 1  in RX_buffer            RX_buffer |=0x01;
}
else
{
RX_buffer <<=1;// If the bit is LOW save 0 in RX_buffer            RX_buffer &=0xfe;
}
}
SMBus_SendBit(ack_nack);// Sends acknowledgment bit return RX_buffer;
}
/
******************************************************************************* * Function Name  : SMBus_Delay
* Description    : ÑÓʱ  Ò»´ÎÑ»·Ô¼1us
* Input          : time
* Output        : None
* Return        : None
*******************************************************************************/ void SMBus_Delay(u16 time)
{
delay_us(time);
}
/******************************************************************************* * Function Name  : SMBus_Init
* Description    : SMBus³õʼ»¯
* Input          : None
* Output        : None
* Return        : None
*******************************************************************************/ void SMBus_Init()
{
SMBUS_SCK_H();
SMBUS_SDA_H();
}
/*******************************************************************************
* Function Name  : SMBus_ReadMemory
* Description    : READ DATA FROM RAM/EEPROM
* Input          : slaveAddress, command
* Output        : None
* Return        : Data
*******************************************************************************/
u16 SMBus_ReadMemory(u8 slaveAddress, u8 command)
{
u16 data;// Data storage (DataH:DataL)
u8 Pec;// PEC byte storage
u8 DataL=0;// Low data byte storage
u8 DataH=0;// High data byte storage
u8 arr[6];// Buffer for the sent bytes
u8 PecReg;// Calculated PEC byte storage
u8 ErrorCounter;// Defines the number of the attempts for communication with MLX90614
ErrorCounter=0x00;// Initialising of ErrorCounter耳机延长线
slaveAddress <<=1;//2-7λ±íʾ´Ó»úµØÖ·
do
{
repeat:
SMBus_StopBit();//If slave send NACK stop comunication
--ErrorCounter;//Pre-decrement ErrorCounter
if(!ErrorCounter)//ErrorCounter=0?
{
break;//Yes,go out from do-while{}
}
SMBus_StartBit();//Start condition
if(SMBus_SendByte(slaveAddress))//Send SlaveAddress ×îµÍλWr=0±íʾ½ÓÏÂÀ´Ð´ÃüÁî{
goto repeat;//Repeat comunication again
}
if(SMBus_SendByte(command))//Send command
{
goto repeat;//Repeat comunication again
}
SMBus_StartBit();//Repeated Start condition
if(SMBus_SendByte(slaveAddress+1))//Send SlaveAddress ×îµÍλRd=1±íʾ½ÓÏÂÀ´¶ÁÊý¾Ý{
goto repeat;//Repeat comunication again
}
DataL =SMBus_ReceiveByte(ACK);//Read low data,master must send ACK
DataH =SMBus_ReceiveByte(ACK);//Read high data,master must send ACK
Pec =SMBus_ReceiveByte(NACK);//Read PEC byte, master must send NACK SMBus_StopBit();//Stop condition
arr[5]= slaveAddress;//
arr[4]= command;//
arr[3]= slaveAddress+1;//Load array arr
arr[2]= DataL;//
arr[1]= DataH;//
arr[0]=0;//
PecReg=PEC_Calculation(arr);//Calculate CRC
}
while(PecReg != Pec);//If received and calculated CRC are equal go out from do-while{}
data =(DataH<<8)| DataL;//data=DataH:DataL
return data;
}

本文发布于:2024-09-23 13:25:59,感谢您对本站的认可!

本文链接:https://www.17tex.com/tex/4/126281.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:输出   电源   臂式   温度   模块
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议