generated from hulk/gd32e23x_template
Compare commits
4 Commits
93b24cc454
...
a0ba0c6bd1
Author | SHA1 | Date | |
---|---|---|---|
a0ba0c6bd1 | |||
389d480da7 | |||
c12273fd46 | |||
e86f8b0dd3 |
@ -6,13 +6,13 @@ set(PROJECT_NAME "XLSW_3DP_US-IR")
|
|||||||
project(${PROJECT_NAME})
|
project(${PROJECT_NAME})
|
||||||
|
|
||||||
set(VERSION_MAJOR 0)
|
set(VERSION_MAJOR 0)
|
||||||
set(VERSION_MINOR 0)
|
set(VERSION_MINOR 1)
|
||||||
set(VERSION_PATCH 1)
|
set(VERSION_PATCH 0)
|
||||||
set(VERSION "V${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
|
set(VERSION "V${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
|
||||||
string(TIMESTAMP CURRENT_DATE "%Y-%m-%d")
|
string(TIMESTAMP CURRENT_DATE "%Y-%m-%d")
|
||||||
|
|
||||||
# Options 1
|
# Options 1
|
||||||
set(OPT1 "")
|
set(OPT1 "_[HW_IIC]")
|
||||||
#set(OPT1 "_[SW_IIC]")
|
#set(OPT1 "_[SW_IIC]")
|
||||||
|
|
||||||
# Options 2
|
# Options 2
|
||||||
@ -40,6 +40,7 @@ set(TARGET_C_SRC
|
|||||||
${CMAKE_SOURCE_DIR}/src/i2c.c
|
${CMAKE_SOURCE_DIR}/src/i2c.c
|
||||||
${CMAKE_SOURCE_DIR}/src/fwdgt.c
|
${CMAKE_SOURCE_DIR}/src/fwdgt.c
|
||||||
${CMAKE_SOURCE_DIR}/src/rs485_protocol.c
|
${CMAKE_SOURCE_DIR}/src/rs485_protocol.c
|
||||||
|
${CMAKE_SOURCE_DIR}/src/gd60914.c
|
||||||
)
|
)
|
||||||
|
|
||||||
add_executable(${PROJECT_NAME} ${TARGET_C_SRC})
|
add_executable(${PROJECT_NAME} ${TARGET_C_SRC})
|
||||||
|
34
inc/gd60914.h
Normal file
34
inc/gd60914.h
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
//
|
||||||
|
// Created by dell on 25-1-7.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef GD60914_H
|
||||||
|
#define GD60914_H
|
||||||
|
|
||||||
|
#include "gd32e23x_it.h"
|
||||||
|
#include "gd32e23x.h"
|
||||||
|
|
||||||
|
#include "board_config.h"
|
||||||
|
|
||||||
|
#ifdef SOFTWARE_IIC
|
||||||
|
#include "soft_i2c.h"
|
||||||
|
#else
|
||||||
|
#include "i2c.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
|
#define GD60914_ADDR (0x18 << 1)
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
|
#define GD60914_HUM_TEMP 0x1A
|
||||||
|
#define GD60914_OBJ_TEMP 0x1F
|
||||||
|
#define GD60914_AMB_TEMP 0x1E
|
||||||
|
#define GD60914_TEMP_REG 0x1C
|
||||||
|
|
||||||
|
void gd60914_get_object_tempture(void);
|
||||||
|
|
||||||
|
void gd60914_read_temp(void);
|
||||||
|
|
||||||
|
#endif //GD60914_H
|
@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
#define I2C_SPEED 20000
|
#define I2C_SPEED 100000
|
||||||
|
|
||||||
#define I2C_TIME_OUT (uint16_t)(5000)
|
#define I2C_TIME_OUT (uint16_t)(5000)
|
||||||
#define I2C_OK 1
|
#define I2C_OK 1
|
||||||
|
@ -43,6 +43,7 @@ OF SUCH DAMAGE.
|
|||||||
#include "usart.h"
|
#include "usart.h"
|
||||||
#include "fwdgt.h"
|
#include "fwdgt.h"
|
||||||
#include "board_config.h"
|
#include "board_config.h"
|
||||||
|
#include "gd60914.h"
|
||||||
|
|
||||||
#ifdef SOFTWARE_IIC
|
#ifdef SOFTWARE_IIC
|
||||||
#include "soft_i2c.h"
|
#include "soft_i2c.h"
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
#define RX_BUFFER_SIZE 32
|
#define RX_BUFFER_SIZE 32
|
||||||
|
|
||||||
#define PROTOCOL_PACKAGE_HEADER 0xD5
|
#define PROTOCOL_PACKAGE_HEADER 0xD5
|
||||||
#define PROTOCOL_BOARD_TYPE 0x03
|
#define PROTOCOL_BOARD_TYPE 0x04
|
||||||
#define PROTOCOL_PACKAGE_LENGTH 0x02
|
#define PROTOCOL_PACKAGE_LENGTH 0x02
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
@ -48,4 +48,6 @@ validation_result_t validate_package_type(uint8_t* data);
|
|||||||
|
|
||||||
validation_result_t validate_data_length(uint8_t* data);
|
validation_result_t validate_data_length(uint8_t* data);
|
||||||
|
|
||||||
|
void gd60914_tempture_report(void);
|
||||||
|
|
||||||
#endif //RS485_PROTOCOL_H
|
#endif //RS485_PROTOCOL_H
|
||||||
|
51
src/gd60914.c
Normal file
51
src/gd60914.c
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
//
|
||||||
|
// Created by dell on 25-1-7.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "gd60914.h"
|
||||||
|
|
||||||
|
void gd60914_get_object_tempture(void) {
|
||||||
|
#ifdef SOFTWARE_IIC
|
||||||
|
soft_i2c_config();
|
||||||
|
#else
|
||||||
|
i2c_config();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static uint8_t sensor_validation_data[2];
|
||||||
|
extern uint8_t g_temperature_uint8[2];
|
||||||
|
|
||||||
|
#ifdef SOFTWARE_IIC
|
||||||
|
soft_i2c_read_16bits(GD60914_ADDR, GD60914_OBJ_TEMP, data);
|
||||||
|
#else
|
||||||
|
i2c_read_16bits(GD60914_ADDR, GD60914_OBJ_TEMP, sensor_validation_data);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (sensor_validation_data[0] != 0xAA || sensor_validation_data[1] != 0x55) {
|
||||||
|
#ifdef DEBUG_VERBOES
|
||||||
|
printf("sensor error\r\n");
|
||||||
|
#endif
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
delay_ms(350);
|
||||||
|
|
||||||
|
#ifdef SOFTWARE_IIC
|
||||||
|
soft_i2c_read_16bits(GD60914_ADDR, GD60914_TEMP_REG, g_temperature_uint8);
|
||||||
|
#else
|
||||||
|
i2c_read_16bits(GD60914_ADDR, GD60914_TEMP_REG, g_temperature_uint8);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// printf("%d\r\n", g_temperature_uint8[1] << 8 | g_temperature_uint8[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void gd60914_read_temp(void) {
|
||||||
|
|
||||||
|
uint8_t value[2] = {0};
|
||||||
|
#ifdef SOFTWARE_IIC
|
||||||
|
soft_i2c_read_16bits(GD60914_ADDR, GD60914_OBJ_TEMP, value);
|
||||||
|
#else
|
||||||
|
i2c_read_16bits(GD60914_ADDR, GD60914_TEMP_REG, value);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
printf("%x %x\r\n", value[1], value[0]);
|
||||||
|
}
|
12
src/main.c
12
src/main.c
@ -6,6 +6,8 @@
|
|||||||
*/
|
*/
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
|
volatile uint8_t g_temperature_uint8[2] = {0};
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief main function
|
\brief main function
|
||||||
\param[in] none
|
\param[in] none
|
||||||
@ -24,12 +26,20 @@ int main(void)
|
|||||||
/* configure FWDGT */
|
/* configure FWDGT */
|
||||||
watchdog_init();
|
watchdog_init();
|
||||||
|
|
||||||
|
#ifdef SOFTWARE_IIC
|
||||||
|
soft_i2c_config();
|
||||||
|
#else
|
||||||
|
i2c_config();
|
||||||
|
#endif
|
||||||
|
|
||||||
printf("system start!\r\n");
|
printf("system start!\r\n");
|
||||||
|
|
||||||
// gpio_bit_write(RS485_EN_PORT, RS485_EN_PIN, RESET);
|
|
||||||
while(1){
|
while(1){
|
||||||
// printf("hello world!\r\n");
|
// printf("hello world!\r\n");
|
||||||
// delay_ms(500);
|
// delay_ms(500);
|
||||||
|
gd60914_get_object_tempture();
|
||||||
|
// delay_ms(100);
|
||||||
|
// printf("%d\r\n", g_temperature_uint8[1] << 8 | g_temperature_uint8[0]);
|
||||||
|
|
||||||
watchdog_reload();
|
watchdog_reload();
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
#include "rs485_protocol.h"
|
#include "rs485_protocol.h"
|
||||||
|
|
||||||
|
extern uint8_t g_temperature_uint8[2];
|
||||||
|
|
||||||
void process_command(uint8_t *cmd, size_t length) {
|
void process_command(uint8_t *cmd, size_t length) {
|
||||||
char combined_str[3];
|
char combined_str[3];
|
||||||
validation_result_t validate = VALIDATION_SUCCESS;
|
validation_result_t validate = VALIDATION_SUCCESS;
|
||||||
@ -20,9 +22,9 @@ void process_command(uint8_t *cmd, size_t length) {
|
|||||||
if (strcmp(combined_str, "M1") == 0) {
|
if (strcmp(combined_str, "M1") == 0) {
|
||||||
printf("%c%c%c%c%c%c", 0xB5, 0xF1, 0x02, 0x6F, 0x6B, 0xCC);
|
printf("%c%c%c%c%c%c", 0xB5, 0xF1, 0x02, 0x6F, 0x6B, 0xCC);
|
||||||
// eddy_current_value_report();
|
// eddy_current_value_report();
|
||||||
} else if (strcmp(combined_str, "M2") == 0) {
|
} else if (strcmp(combined_str, "M2") == 0)
|
||||||
printf("%c%c%c%c%c%c%c", 0xB5, 0xF1, 0x02, 0x6F, 0x6B, 0x6B, 0xCC);
|
{
|
||||||
// tempture_value_report();
|
gd60914_tempture_report();
|
||||||
} else if (strcmp(combined_str, "M3") == 0)
|
} else if (strcmp(combined_str, "M3") == 0)
|
||||||
{
|
{
|
||||||
printf("%c%c%c%c%c%c", 0xB5, 0xF1, 0x02, 0x6F, 0x6B, 0xCC);
|
printf("%c%c%c%c%c%c", 0xB5, 0xF1, 0x02, 0x6F, 0x6B, 0xCC);
|
||||||
@ -90,3 +92,15 @@ validation_result_t validate_data_length(uint8_t *data) {
|
|||||||
return VALIDATION_LENGTH_ERROR;
|
return VALIDATION_LENGTH_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void gd60914_tempture_report(void) {
|
||||||
|
static uint8_t package_header[3] = {0xB5, 0xF0, 0x02};
|
||||||
|
|
||||||
|
uint8_t combined_data[5];
|
||||||
|
memcpy(combined_data, package_header, 3);
|
||||||
|
memcpy(combined_data + 3, g_temperature_uint8, 2);
|
||||||
|
|
||||||
|
printf("%c%c%c", package_header[0], package_header[1], package_header[2]);
|
||||||
|
printf("%c%c", g_temperature_uint8[1], g_temperature_uint8[0]);
|
||||||
|
printf("%c", calculate_crc(combined_data, 6));
|
||||||
|
}
|
@ -11,7 +11,7 @@
|
|||||||
\retval none
|
\retval none
|
||||||
*/
|
*/
|
||||||
void soft_i2c_delay(void) {
|
void soft_i2c_delay(void) {
|
||||||
delay_us(20); // Adjust delay as needed
|
delay_us(1); // Adjust delay as needed
|
||||||
/* delay to freq
|
/* delay to freq
|
||||||
* 15KHz: delay_us(20);
|
* 15KHz: delay_us(20);
|
||||||
* 65KHz: delay_us(1);
|
* 65KHz: delay_us(1);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user