Merge pull request 'detached' (#1) from detached into US&IR
Reviewed-on: #1
This commit is contained in:
commit
be81eb0c2e
@ -5,6 +5,8 @@
|
|||||||
#ifndef MLX90614_H
|
#ifndef MLX90614_H
|
||||||
#define MLX90614_H
|
#define MLX90614_H
|
||||||
|
|
||||||
|
#define I2C_EVENT_MASTER_MODE_SELECT ((uint32_t)(I2C_FLAG_I2CBSY | I2C_FLAG_MASTER | I2C_FLAG_RBNE))
|
||||||
|
|
||||||
void i2c_config(void);
|
void i2c_config(void);
|
||||||
int read_ir_mlx90614(void);
|
int read_ir_mlx90614(void);
|
||||||
|
|
||||||
|
@ -5,9 +5,9 @@
|
|||||||
#include "mlx90614.h"
|
#include "mlx90614.h"
|
||||||
#include "gd32e23x.h"
|
#include "gd32e23x.h"
|
||||||
#include "systick.h"
|
#include "systick.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
void i2c_config(void)
|
void i2c_config(void) {
|
||||||
{
|
|
||||||
rcu_periph_clock_enable(RCU_I2C0);
|
rcu_periph_clock_enable(RCU_I2C0);
|
||||||
rcu_periph_clock_enable(GPIOF);
|
rcu_periph_clock_enable(GPIOF);
|
||||||
|
|
||||||
@ -23,34 +23,34 @@ void i2c_config(void)
|
|||||||
nvic_irq_enable(I2C0_ER_IRQn, 2);
|
nvic_irq_enable(I2C0_ER_IRQn, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
int read_ir_mlx90614(void)
|
int read_ir_mlx90614(void) {
|
||||||
{
|
|
||||||
uint8_t Data[5];
|
uint8_t Data[5];
|
||||||
int inttemp_ir = 0;
|
int inttemp_ir = 0;
|
||||||
uint32_t TIMEOUT = 0;
|
uint32_t TIMEOUT = 0;
|
||||||
while (TIMEOUT < 10000 && i2c_flag_get(I2C0, I2C_FLAG_I2CBSY))
|
while (TIMEOUT < 10000 && i2c_flag_get(I2C0, I2C_FLAG_I2CBSY))
|
||||||
TIMEOUT++;
|
TIMEOUT++;
|
||||||
if (TIMEOUT >= 10000)
|
if (TIMEOUT >= 10000) {
|
||||||
{
|
|
||||||
//printf("ERROR0\r\n");
|
//printf("ERROR0\r\n");
|
||||||
return -410;
|
return -410;
|
||||||
}
|
}
|
||||||
TIMEOUT = 0;
|
TIMEOUT = 0;
|
||||||
I2C_GenerateSTART(I2C0, ENABLE);
|
// I2C_GenerateSTART(I2C0, ENABLE);
|
||||||
while (TIMEOUT < 10000 && !I2C_CheckEvent(I2C0, I2C_EVENT_MASTER_MODE_SELECT))
|
i2c_start_on_bus(I2C0);
|
||||||
|
// while (TIMEOUT < 10000 && !I2C_CheckEvent(I2C0, I2C_EVENT_MASTER_MODE_SELECT))
|
||||||
|
while (TIMEOUT < 10000 && !i2c_flag_get(I2C0, I2C_EVENT_MASTER_MODE_SELECT))
|
||||||
TIMEOUT++;
|
TIMEOUT++;
|
||||||
if (TIMEOUT >= 10000)
|
if (TIMEOUT >= 10000) {
|
||||||
{
|
|
||||||
//printf("ERROR1\r\n");
|
//printf("ERROR1\r\n");
|
||||||
return -410;
|
return -410;
|
||||||
}
|
}
|
||||||
// I2C_AcknowledgeConfig(I2C0,DISABLE);
|
// I2C_AcknowledgeConfig(I2C0,DISABLE);
|
||||||
TIMEOUT = 0;
|
TIMEOUT = 0;
|
||||||
I2C_Send7bitAddress(I2C0, 0XB4, I2C_Direction_Transmitter);
|
// I2C_Send7bitAddress(I2C0, 0XB4, I2C_Direction_Transmitter);
|
||||||
while (TIMEOUT < 10000 && !I2C_CheckEvent(I2C0, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED))
|
i2c_master_addressing(I2C0, 0XB4, I2C_TRANSMITTER);
|
||||||
|
// while (TIMEOUT < 10000 && !I2C_CheckEvent(I2C0, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED))
|
||||||
|
while (TIMEOUT < 10000 && !i2c_flag_get(I2C0, I2C_FLAG_TR))
|
||||||
TIMEOUT++;
|
TIMEOUT++;
|
||||||
if (TIMEOUT >= 10000)
|
if (TIMEOUT >= 10000) {
|
||||||
{
|
|
||||||
printf("ERROR2\r\n");
|
printf("ERROR2\r\n");
|
||||||
return -410;
|
return -410;
|
||||||
}
|
}
|
||||||
@ -60,8 +60,7 @@ int read_ir_mlx90614(void)
|
|||||||
I2C_GenerateSTART(I2C0, ENABLE);
|
I2C_GenerateSTART(I2C0, ENABLE);
|
||||||
while (TIMEOUT < 10000 && !I2C_CheckEvent(I2C0, I2C_EVENT_MASTER_MODE_SELECT))
|
while (TIMEOUT < 10000 && !I2C_CheckEvent(I2C0, I2C_EVENT_MASTER_MODE_SELECT))
|
||||||
TIMEOUT++;
|
TIMEOUT++;
|
||||||
if (TIMEOUT >= 10000)
|
if (TIMEOUT >= 10000) {
|
||||||
{
|
|
||||||
//printf("ERROR3\r\n");
|
//printf("ERROR3\r\n");
|
||||||
return -410;
|
return -410;
|
||||||
}
|
}
|
||||||
@ -69,8 +68,7 @@ int read_ir_mlx90614(void)
|
|||||||
I2C_Send7bitAddress(I2C0, 0XB4, I2C_Direction_Receiver);
|
I2C_Send7bitAddress(I2C0, 0XB4, I2C_Direction_Receiver);
|
||||||
while (TIMEOUT < 10000 && !I2C_CheckEvent(I2C0, I2C_EVENT_MASTER_BYTE_RECEIVED))
|
while (TIMEOUT < 10000 && !I2C_CheckEvent(I2C0, I2C_EVENT_MASTER_BYTE_RECEIVED))
|
||||||
TIMEOUT++;
|
TIMEOUT++;
|
||||||
if (TIMEOUT >= 10000)
|
if (TIMEOUT >= 10000) {
|
||||||
{
|
|
||||||
//printf("ERROR4\r\n");
|
//printf("ERROR4\r\n");
|
||||||
return -410;
|
return -410;
|
||||||
}
|
}
|
||||||
@ -79,8 +77,7 @@ int read_ir_mlx90614(void)
|
|||||||
Data[0] = I2C_ReceiveData(I2C0);
|
Data[0] = I2C_ReceiveData(I2C0);
|
||||||
while (TIMEOUT < 10000 && !I2C_CheckEvent(I2C0, I2C_EVENT_MASTER_BYTE_RECEIVED))
|
while (TIMEOUT < 10000 && !I2C_CheckEvent(I2C0, I2C_EVENT_MASTER_BYTE_RECEIVED))
|
||||||
TIMEOUT++;
|
TIMEOUT++;
|
||||||
if (TIMEOUT >= 10000)
|
if (TIMEOUT >= 10000) {
|
||||||
{
|
|
||||||
//printf("ERROR5\r\n");
|
//printf("ERROR5\r\n");
|
||||||
return -410;
|
return -410;
|
||||||
}
|
}
|
||||||
@ -89,8 +86,7 @@ int read_ir_mlx90614(void)
|
|||||||
Data[1] = I2C_ReceiveData(I2C0);
|
Data[1] = I2C_ReceiveData(I2C0);
|
||||||
while (TIMEOUT < 10000 && !I2C_CheckEvent(I2C0, I2C_EVENT_MASTER_BYTE_RECEIVED))
|
while (TIMEOUT < 10000 && !I2C_CheckEvent(I2C0, I2C_EVENT_MASTER_BYTE_RECEIVED))
|
||||||
TIMEOUT++;
|
TIMEOUT++;
|
||||||
if (TIMEOUT >= 10000)
|
if (TIMEOUT >= 10000) {
|
||||||
{
|
|
||||||
//printf("ERROR6\r\n");
|
//printf("ERROR6\r\n");
|
||||||
return -410;
|
return -410;
|
||||||
}
|
}
|
||||||
@ -99,8 +95,7 @@ int read_ir_mlx90614(void)
|
|||||||
Data[2] = I2C_ReceiveData(I2C0);
|
Data[2] = I2C_ReceiveData(I2C0);
|
||||||
while (TIMEOUT < 10000 && !I2C_CheckEvent(I2C0, I2C_EVENT_MASTER_BYTE_RECEIVED))
|
while (TIMEOUT < 10000 && !I2C_CheckEvent(I2C0, I2C_EVENT_MASTER_BYTE_RECEIVED))
|
||||||
TIMEOUT++;
|
TIMEOUT++;
|
||||||
if (TIMEOUT >= 10000)
|
if (TIMEOUT >= 10000) {
|
||||||
{
|
|
||||||
//printf("ERROR7\r\n");
|
//printf("ERROR7\r\n");
|
||||||
return -410;
|
return -410;
|
||||||
}
|
}
|
||||||
@ -110,8 +105,7 @@ int read_ir_mlx90614(void)
|
|||||||
Data[3] = I2C_ReceiveData(I2C0);
|
Data[3] = I2C_ReceiveData(I2C0);
|
||||||
while (TIMEOUT < 10000 && !I2C_CheckEvent(I2C0, I2C_EVENT_MASTER_BYTE_RECEIVED))
|
while (TIMEOUT < 10000 && !I2C_CheckEvent(I2C0, I2C_EVENT_MASTER_BYTE_RECEIVED))
|
||||||
TIMEOUT++;
|
TIMEOUT++;
|
||||||
if (TIMEOUT >= 10000)
|
if (TIMEOUT >= 10000) {
|
||||||
{
|
|
||||||
//printf("ERROR11\r\n");
|
//printf("ERROR11\r\n");
|
||||||
return -410;
|
return -410;
|
||||||
}
|
}
|
||||||
@ -120,7 +114,7 @@ int read_ir_mlx90614(void)
|
|||||||
I2C_GenerateSTOP(I2C0, ENABLE);
|
I2C_GenerateSTOP(I2C0, ENABLE);
|
||||||
I2C_AcknowledgeConfig(I2C0, ENABLE);
|
I2C_AcknowledgeConfig(I2C0, ENABLE);
|
||||||
//printf("data:%x,%x,%x\r\n",Data[0],Data[1],Data[2]);
|
//printf("data:%x,%x,%x\r\n",Data[0],Data[1],Data[2]);
|
||||||
inttemp_ir = (int)((Data[0] + Data[1] * 255) * 0.2 - 2731.5);
|
inttemp_ir = (int) ((Data[0] + Data[1] * 255) * 0.2 - 2731.5);
|
||||||
// printf("temp:%d\r\n",inttemp_ir);
|
// printf("temp:%d\r\n",inttemp_ir);
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user