资源简介
网上很多都是基于F1的,不能直接用于F4,故改写后分享
代码片段和文件信息
#include “Mlx90614.h“
#include “Systick.h“
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
#define ACK 0
#define NACK 1
#define SA 0x00 //Slave address ??MLX90614????0x00????????0x5a
#define RAM_ACCESS 0x00 //RAM access command
#define EEPROM_ACCESS 0x20 //EEPROM access command
#define RAM_TOBJ1 0x07 //To1 address in the eeprom
#define SMBUS_PORT GPIOB
#define SMBUS_SCK GPIO_Pin_4
#define SMBUS_SDA GPIO_Pin_3
#define RCC_AHB1Periph_SMBUS_PORT RCC_AHB1Periph_GPIOB
#define SMBUS_SCK_H() SMBUS_PORT->BSRRL = SMBUS_SCK
#define SMBUS_SCK_L() SMBUS_PORT->BSRRH = SMBUS_SCK
#define SMBUS_SDA_H() SMBUS_PORT->BSRRL = SMBUS_SDA
#define SMBUS_SDA_L() SMBUS_PORT->BSRRH = 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_OUTMode();
Delay_us(2);
SMBUS_SDA_H(); // Set SDA line
SMBus_Delay(1); // 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(10); // Hold time after (Repeated) Start
// Condition. After this period the first clock is generated.
//(Thd:sta=4.0us min)
SMBUS_SCK_L(); // Clear SCL line
SMBus_Delay(2); // 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_SDA_OUTMode();
Delay_us(2);
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
}
/*****
评论
共有 条评论