⼈体测温melexis迈来芯linux平台
mlx90614mlx90621mlx90641驱动调试 2020年的春节因为疫情的原因⼀直出不了门,听说melexis测温头价格从40块涨到400块,并且还买不到货;正好有同事要求调到驱动:mlx测温模块驱动,基于android平台: 3. app:
这个客户已经做好了,并且提供的应⽤接⼝,我只要在jni⾥实现接⼝就⾏了; 2. JNI 接⼝的封装:
open()
read()
write()
close()
1. 驱动调试:
由于规格书上说mlx使⽤smbus接⼝,本⼈⽤硬件i2c驱动来调试时遇到了⿇烦,搞了两天都通讯不成功,不得已放弃了;于是只能改⽤io,⽤io来模拟i2c,这种⽅式很好⽤。
#if 8 // 888
static void SMBus_Delay(u16 time);
static void SMBus_StartBit(void);
static void SMBus_StopBit(void);
static void SMBus_SendBit(u8);
static u8 SMBus_SendByte(u8);
static u8 SMBus_ReceiveBit(void);
static u8 SMBus_ReceiveByte(u8);
static void SMBus_Delay(u16);
static int SMBus_Init(void);
static u16 SMBus_ReadMemory(u8, u8);
static u8 PEC_Calculation(u8*);
static unsigned long SMBus_ReadTemp(void); //
static void SMBus_DisplayTemperature(void); //?LCD?5,6
static int SMBus_Write(u8 slaveAddress, u8 command, u8 dataL,u8 dataH);
static unsigned long int mlx90616_value;
static char smbus_io_first = 1;
static void mlx90616_main(void)
抗干扰滤波器{排放因子
unsigned long int DATA;
电池钢壳if(smbus_io_first == 1){
smbus_io_first = 0;
SMBus_Init();//rk_gpio_init();
}
mlx90616_value = SMBus_ReadTemp();
//#include "myiic.h"
//#include "delay.h"
#define ACK 0
#define NACK 1
#define SA 0x00 //,??MLX906140x00,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 113 //251 //GPIO_Pin_6
#define SMBUS_SDA 8 //237 //GPIO_Pin_7
#define RCC_APB2Periph_SMBUS_PORT RCC_APB2Periph_GPIOB
#define SMBUS_SCK_H() gpio_direction_output(SMBUS_SCK, 1) //SMBUS_PORT->BSRR = SMBUS_SCK #define SMBUS_SCK_L() gpio_direction_output(SMBUS_SCK, 0) //SMBUS_PORT->BRR = SMBUS_SCK #define SMBUS_SDA_H() gpio_direction_output(SMBUS_SDA, 1) //SMBUS_PORT->BSRR = SMBUS_SDA #define SMBUS_SDA_L() gpio_direction_output(SMBUS_SDA, 0) //SMBUS_PORT->BRR = SMBUS_SDA
//#define SMBUS_SDA_PIN() SMBUS_PORT->IDR & SMBUS_SDA //
static int SMBUS_SDA_PIN(void)
{
int ret = 0;
gpio_direction_input(SMBUS_SDA);
ret = gpio_get_value(SMBUS_SDA);
return ret;
}
/*******************************************************************************
* : SMBus_StartBit
* ?? :
* Input : None
* Output : None
* Return : None
*******************************************************************************/
static void SMBus_StartBit(void)
{
if(smbus_io_first == 1){
smbus_io_first = 0;
if(0 != SMBus_Init()) {
smbus_io_first =0xff; // io init failed
}
}
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)
SMBUS_SCK_L(); // Clear SCL line
SMBus_Delay(5); // Wait a few microseconds
* ??: Generate STOP condition on SMBus
* Input : None
* Output : None
* Return : None
*******************************************************************************/
static void SMBus_StopBit(void)
{
if(smbus_io_first == 1){
smbus_io_first = 0;
if(0 != SMBus_Init()) {
smbus_io_first =0xff; // io init failed
}
}
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
}
/*******************************************************************************
智能平衡代步车* : SMBus_SendByte
* ??: Send a byte on SMBus
* Input : Tx_buffer
* Output : None
* Return : None
*******************************************************************************/
static 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;
* ??: Send a bit on SMBus 82.5kHz
* Input : bit_out
* Output : None
* Return : None
*******************************************************************************/ static 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_R
eceiveBit
* Description : Receive a bit on SMBus
* Input : None
* Output : None
* Return : Ack_bit
*******************************************************************************/ static u8 SMBus_ReceiveBit(void)
{
u8 Ack_bit;
SMBUS_SDA_H(); //,????
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;
* : SMBus_ReceiveByte
* ??: Receive a byte on SMBus
* Input : ack_nack
* Output : None
* Return : RX_buffer
*******************************************************************************/
static 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;
}
/*******************************************************************************
* : SMBus_Delay
* ??: ?? ?????1us
* Input : time
* Output : None
* Return : None
*******************************************************************************/
static void SMBus_Delay(u16 time)
{
u16 i, j;
for (i=0; i<5; i++)
{
udelay(time);//for (j=0; j<time; j++);
}
}
/*******************************************************************************
* : SMBus_Init
* ??: SMBus
* Input : None
* Output : None
* Return : None
*******************************************************************************/
static int SMBus_Init()