update to sdk5.1.2

This commit is contained in:
Holy 2024-02-19 10:15:04 +08:00
commit 49877801f4
18 changed files with 409 additions and 96 deletions

View File

@ -1,6 +0,0 @@
{
"ExpandedNodes": [
""
],
"PreviewInSolutionExplorer": false
}

Binary file not shown.

Binary file not shown.

View File

@ -1,6 +0,0 @@
{
"idf.adapterTargetName": "esp32s3",
"files.associations": {
"can_network.h": "c"
}
}

View File

@ -16,7 +16,6 @@ extern "C" {
#include "freertos/FreeRTOS.h"
#include "freertos/queue.h"
#include "driver/timer.h"
typedef struct {
int (*get_pulse_callback)(void *);
void *callback_args;

View File

@ -6,7 +6,6 @@
CONDITIONS OF ANY KIND, either express or implied.
*/
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/event_groups.h"
@ -22,6 +21,7 @@
#include "esp_bt_defs.h"
#include "esp_bt_main.h"
#include "bt_server.h"
#define SPP_DEBUG_MODE 1
#define GATTS_TABLE_TAG "GATTS_SPP_DEMO"

View File

@ -70,6 +70,8 @@
#define WIFI_CONNECTED_BIT BIT0
#define WIFI_FAIL_BIT BIT1
#define GPIO_4G_PWR GPIO_NUM_4
#define PWR_4G_ON (0)
#define PWR_4G_OFF (1)
static const char *TAG = "main";
@ -77,7 +79,6 @@ static const char *TAG = "main";
extern void wifi_init_softap(void);
void ads1220_init(void);
void PWR_4G_Init(void);
extern void can_init(void);
extern void FLOW_init();
@ -103,7 +104,7 @@ void app_main(void)
}
ESP_ERROR_CHECK(ret);
ESP_ERROR_CHECK(i2c_master_init());
config_load();
config_load();//读取保存在FRAM里的数据
ESP_LOGI(TAG, "ESP_WIFI_MODE_STA");
// rtc_clk_apb_freq = rtc_clk_apb_freq_get();
// ESP_LOGI(TAG, "rtc_clk_apb_freq=%u", rtc_clk_apb_freq);
@ -130,19 +131,22 @@ void app_main(void)
void PWR_4G_Init(void)
{
// zero-initialize the config structure.
gpio_config_t io_conf = {};
// disable interrupt
io_conf.intr_type = GPIO_INTR_DISABLE;
// set as output mode
io_conf.mode = GPIO_MODE_OUTPUT;
// bit mask of the pins that you want to set,e.g.GPIO18/19
io_conf.pin_bit_mask = GPIO_4G_PWR;
// disable pull-down mode
io_conf.pull_down_en = 0;
// disable pull-up mode
io_conf.pull_up_en = 0;
gpio_config_t io_conf = {
// disable interrupt
.intr_type = GPIO_INTR_DISABLE,
// set as output mode
.mode = GPIO_MODE_OUTPUT,
// bit mask of the pins that you want to set,e.g.GPIO18/19
.pin_bit_mask = GPIO_4G_PWR,
// disable pull-down mode
.pull_down_en = 0,
// disable pull-up mode
.pull_up_en = 0,
};
// configure GPIO with the given settings
gpio_config(&io_conf);
gpio_set_level(GPIO_4G_PWR, 0);
gpio_set_level(GPIO_4G_PWR, PWR_4G_OFF);
vTaskDelay(pdMS_TO_TICKS(1000));
gpio_set_level(GPIO_4G_PWR, PWR_4G_ON);
}

View File

@ -131,10 +131,10 @@ void ModBusWordWriteHook(uint16_t addr, uint16_t length)
save_flow_cfg();
}
else if(addr == DEPTH_CONFIG_ADDR && gWordVar[DEPTH_CONFIG_ADDR] == 0x55aa){
save_depth_cfg();
save_depth_cfg();
}
else if(addr == CAL_4_20MA_ADDR && gWordVar[CAL_4_20MA_ADDR] == 0x55aa){
save_cal_4_20ma();
save_cal_4_20ma();
}
else if(addr == REBOOT_REW_ADDR ){
if(gWordVar[REBOOT_REW_ADDR] == 0x55aa){
@ -166,21 +166,24 @@ int ModbusSlaveProcess(uint8_t *txbuf, uint8_t *rxbuf, uint16_t rxLen, int is_cr
int i;
uint8_t *pDat;
uint16_t *pWordVar;
if(rxLen<4)
if(rxLen<4){
return 0;
if((rxbuf[0]==modbus_addr) || (rxbuf[0]==255))
{
if(is_crc != 0)
{
}
/*地址校验*/
if((rxbuf[0]==modbus_addr) || (rxbuf[0]==255)){
/*crc校验*/
if(is_crc != 0){
crcData = rxbuf[rxLen-1]+(rxbuf[rxLen-2]<<8);
crcChk = crc16(rxbuf,rxLen-2);
if( crcData != crcChk)
{
if( crcData != crcChk){
return 0;
}
}
add = ((uint16_t)rxbuf[2]<<8)+ rxbuf[3];
//if(Length !=
length = (rxbuf[4]<<8) | rxbuf[5];
txbuf[0] = rxbuf[0];
@ -275,7 +278,7 @@ int ModbusSlaveProcess(uint8_t *txbuf, uint8_t *rxbuf, uint16_t rxLen, int is_cr
out_len = 3;
break;
}
gWordVar[add] = (rxbuf[4]<<8)+rxbuf[5];
gWordVar[add] = (rxbuf[4]<<8)+rxbuf[5];
memcpy(txbuf,rxbuf,6);
ModBusWordWriteHook(add,1);
out_len = 6;

View File

@ -387,10 +387,11 @@ extern flow_config_t *flow_config;
extern flow_t *pflow;
extern uint8_t timeout[2];
extern int flow_rem[2];
void ads1220_task(void)
{
uint32_t io_num;
static uint32_t ad_flow_tick = 10;
// static uint32_t ad_flow_tick = 10;
while (1)
{
// ESP_LOGI(TAG, "xQueueReceive before\n ");

View File

@ -103,7 +103,7 @@ void capture_flow2_init()
.user_data = NULL};
ESP_ERROR_CHECK(mcpwm_capture_enable_channel(MCPWM_UNIT_1, MCPWM_SELECT_CAP2, &conf));
mcpwm_set_frequency(MCPWM_UNIT_1, MCPWM_TIMER_2, 1000000);
ESP_LOGI(TAG, "capture_flow_init");
// ESP_LOGI(TAG, "capture_flow_init");
}
// void capture_task(void)

View File

@ -6,7 +6,6 @@
// #include "SEGGER_RTT.h"
#include "ModbusM.h"
uint32_t TickDiff(uint32_t comptime);
extern void modbus_master_poll(int n);
extern int modbus_master_on_revice(int ch, uint8_t *rxbuf, int length);

View File

@ -136,6 +136,7 @@ void config_load(void)
}
}
//恢复默认配置
void restore_default(void)
{
memcpy(cal_4_20ma, &default_cal_4_20ma, sizeof(default_cal_4_20ma));

View File

@ -27,7 +27,7 @@
#define DEPTH_RESET_ADDR 510
#define REBOOT_REW_ADDR 511
#define TIME 264
typedef struct
{
uint16_t magic;

View File

@ -12,13 +12,13 @@
#include "ModbusS.h"
#include "rotary_encoder.h"
#include "esp_log.h"
#include "esp_check.h"
#include "soc/rtc.h"
#include "driver/mcpwm.h"
// #include "driver/mcpwm_prelude.h"
#include "config.h"
#include "esp_gatts_api.h"
#include "../../../../components/bt/host/bluedroid/api/include/api/esp_gatts_api.h"
#include "bt_server.h"
#include "esp_system.h"
@ -57,6 +57,14 @@ typedef struct capture_event
#define DEPTH_PIN_ENC_B 41 // 深度控制GPIO端口 TIM3_CH2
#define SEND_DATA_TEST 0
#define PILE_STATE_STOP 0x0100
#define PILE_STATE_PAUSE 0x0200
#define PILE_STATE_WORK 0x0300
#define PILE_DIR_NONE 0x01
#define PILE_DIR_UP 0x02
#define PILE_DIR_DOWN 0x03
// #define DEPTH_PIN_ENC_A 36 // 深度脉冲GPIO端口
// #define DEPTH_PIN_ENC_B 35 // 深度控制GPIO端口
@ -158,13 +166,14 @@ typedef struct
typedef struct
{
int16_t up_down; // 12
uint16_t pile_work_state_and_direction; // 12
int16_t speed; // 13
int16_t depth; // 14
uint16_t sample_count; // 15
uint16_t depth_flow[2]; // 16~17
uint32_t last_total_flow[2]; // 18~21
uint32_t last_total_flow[2]; //
int16_t depth_offset; // 22
uint16_t one_pile_work_time;//23 系统工作时间
// uint32_t update_time;
// int16_t tilt_x;
// int16_t tilt_y;
@ -219,7 +228,8 @@ void capture_depth_init()
.cap_edge = MCPWM_NEG_EDGE,
.cap_prescale = 1,
.capture_cb = depth_isr_handler, // 绑定深度中断处理函数
.user_data = NULL};
.user_data = NULL
};
if (depth_config->input_type > 1)
{
conf.cap_edge = MCPWM_BOTH_EDGE;
@ -285,7 +295,7 @@ void depth_init(void)
// // HAL_TIM_Encoder_Start(&htim3, TIM_CHANNEL_ALL);
// }
depth_data->depth_offset = -depth_config->depth_offset;
depth_data->up_down = 1; // 默认工作
depth_data->pile_work_state_and_direction = (PILE_STATE_STOP | PILE_DIR_NONE); // 默认不工作
}
enum
@ -404,21 +414,32 @@ void send_data_to_bt(void)
// }
}
/**
* _enc1_update_time 1
* enc1_update_time 1
* time_diff
* depth_config
* enc1_value 1
* prev_depth
*/
void depth_task(void *arg)
{
ESP_LOGI(TAG, "go to depth_task sucessfully\n");
// int enc_value;
ESP_LOGI(TAG, "depth_task start\n");
int time_diff = 0;
int speed_timeout = 0;
int last_speed_enc_value = 0; // 上次速度计算的编码器值
int speed_enc_update_time = 0; // 上次速度计算的编码器值
int speed_enc_update_time = 0;
int speed_calc_count = 0;
int enc_value = 0;
// int count = 0;
int bt_time_count = 0;
depth_data->depth_offset = -depth_config->depth_offset;
depth_data->up_down = 1; // 默认工作
int64_t work_start_time = 0;
uint16_t last_work_state = 0;
depth_data->depth_offset = -depth_config->depth_offset;
depth_data->pile_work_state_and_direction = 0x0300;
last_work_state = depth_data->pile_work_state_and_direction;
record->pile_id = ++last_pile_id;
// send_to_bt1.pile_id = ++last_pile_id;
@ -429,7 +450,6 @@ void depth_task(void *arg)
if (_enc1_update_time != enc1_update_time)
{
ESP_LOGI(TAG, "_enc1_update_time != enc1_update_time\n");
// int enc_update_time = enc1_update_time;
enc_update_time = enc1_update_time;
enc_value = enc1_value;
time_diff = abs_sub(enc_update_time, _enc1_update_time);
@ -438,9 +458,11 @@ void depth_task(void *arg)
if (time_diff != 0)
{
ESP_LOGI(TAG, "time_diff != 0\n");
ESP_LOGI(TAG, "time_diff = %d\n",time_diff);
int16_t depth = enc_value * depth_config->N / depth_config->M; // 1mm
depth_data->depth = depth - depth_data->depth_offset;
/*深度补偿修正*/
if (depth_data->depth > depth_config->max_depth)
{
ESP_LOGI(TAG, "depth_data->depth > depth_config->max_depth\n");
@ -453,13 +475,17 @@ void depth_task(void *arg)
depth_data->depth_offset = depth - depth_config->min_depth;
depth_data->depth = depth_config->min_depth;
}
/*更新记录值*/
if (depth_data->depth > record->max_depth)
{
ESP_LOGI(TAG, "depth_data->depth > record->max_depth\n");
record->max_depth = depth_data->depth;
// send_to_bt1.max_depth = depth_data->depth;
}
if (speed_calc_count++ > 50) // 500ms计算一次速度
// 500ms计算一次速度
if (speed_calc_count++ > 50)
{
ESP_LOGI(TAG, "speed_calc_count++ > 50\n");
speed_calc_count = 0;
@ -485,22 +511,291 @@ void depth_task(void *arg)
}
}
}
if (depth_data->up_down > STOP)
uint16_t pile_work_state = (depth_data->pile_work_state_and_direction & 0xff00);
if (pile_work_state == PILE_STATE_WORK)
{
ESP_LOGI(TAG, "depth_data->up_down > STOP\n");
ESP_LOGI(TAG, "pile_work_state == PILE_STATE_WORK\n");
/*如果机器从停止状态->工作状态,则重新记录工作开始时间*/
if(last_work_state == PILE_STATE_STOP){
// work_start_time = esp_timer_get_time();
depth_data->one_pile_work_time = 0;
}
// int64_t current_work_time = esp_timer_get_time();
// if(work_start_time != 0){
// depth_data->one_pile_work_time = (uint16_t)((current_work_time - work_start_time)/1000000);
// }
/*下钻,深度增加*/
if (enc_value > last_enc_value)
{ // 下钻,深度增加
if (depth_data->up_down != 1)
{ // 方向改变
depth_data->up_down = 1;
{
ESP_LOGI(TAG, "enc_value > last_enc_value\n");
uint8_t pile_work_dir = (depth_data->pile_work_state_and_direction & 0xff);
if(pile_work_dir != PILE_DIR_DOWN)
{
// 方向改变,更新目标采样深度
depth_data->pile_work_state_and_direction = ((depth_data->pile_work_state_and_direction & 0xff00) | PILE_DIR_DOWN);
target_sample_depth = (depth_data->depth / depth_config->sample_depth) * depth_config->sample_depth;
// 小于半个采样长度的合并到下一个采样点
if (abs(depth_data->depth - target_sample_depth) < depth_config->sample_depth / 2)
{ // 小于半个采样长度的合并到下一个采样点
{
target_sample_depth += depth_config->sample_depth;
}
}
// 到达或超过目标采样点
if (depth_data->depth >= target_sample_depth)
{ // 到达或超过目标采样点
{
// 由于编码器精度问题不能确保数据在采样点上,需要通过插值计算采样点
// 当使用10线编码器时每个脉冲深度达6.25cm当采样间隔为10cm时抖动值太大
if ((prev_depth - depth_data->depth) != 0)
{
int i;
//uint32_t time = (target_sample_depth - prev_depth) * (enc_update_time - prev_update_time) / (depth_data->depth - prev_depth) + prev_update_time;
for (i = 0; i < 2; i++)
{
// int total_flow = get_total_flow_by_time(i, time);
int total_flow = get_total_flow_by_time(i, pflow[i].update_time);
int flow = total_flow - depth_data->last_total_flow[i];
if (flow < 0)
{
flow = 0;
}
depth_data->depth_flow[i] = flow;
depth_data->last_total_flow[i] = total_flow;
}
depth_data->sample_count++;
target_sample_depth += depth_config->sample_depth;
add_recod_item();
}
}
}
/*上钻,深度减少*/
else if (enc_value < last_enc_value)
{
ESP_LOGI(TAG, "enc_value < last_enc_value\n");
uint8_t pile_work_dir = (depth_data->pile_work_state_and_direction & 0xff);
if (pile_work_dir != PILE_DIR_UP)
{
// 方向改变
depth_data->pile_work_state_and_direction = ((depth_data->pile_work_state_and_direction & 0xff00) | PILE_DIR_UP);
target_sample_depth = (depth_data->depth / depth_config->sample_depth - 1) * depth_config->sample_depth;
if (abs(depth_data->depth - target_sample_depth) < depth_config->sample_depth / 2)
{
// 小于半个采样长度的合并到下一个采样点
target_sample_depth -= depth_config->sample_depth;
}
}
if (depth_data->depth <= target_sample_depth)
{
// 由于编码器精度问题不能确保数据在采样点上,需要通过插值计算采样点
// 当使用10线编码器时每个脉冲深度达7.6cm当采样间隔为10cm时抖动值太大
if ((prev_depth - depth_data->depth) != 0)
{
int i;
//uint32_t time = (prev_depth - target_sample_depth) * (enc_update_time - prev_update_time) / (prev_depth - depth_data->depth) + prev_update_time;
for (i = 0; i < 2; i++)
{
// int total_flow = get_total_flow_by_time(i, time);
int total_flow = get_total_flow_by_time(i, pflow[i].update_time);
int flow = total_flow - depth_data->last_total_flow[i];
if (flow < 0)
{
flow = 0;
}
depth_data->depth_flow[i] = flow;
depth_data->last_total_flow[i] = total_flow;
}
depth_data->sample_count++;
add_recod_item();
target_sample_depth -= depth_config->sample_depth;
}
}
}
else
{
depth_data->pile_work_state_and_direction = ((depth_data->pile_work_state_and_direction & 0xff00) | PILE_DIR_NONE);
}
if (depth_data->depth < depth_config->inc_pile_depth) // 小于指定深度时才允许行走清零
{
if (pMoveCtx->pile_inc_req == 1)
{
pMoveCtx->pile_inc_req = 0;
reset_depth();
}
}
else
{
if (pMoveCtx->pile_inc_req == 1)
{
pMoveCtx->pile_inc_req = 0;
}
}
}
else if((depth_data->pile_work_state_and_direction & 0xff00) == PILE_STATE_PAUSE)
{
}
else if((depth_data->pile_work_state_and_direction & 0xff00) == PILE_STATE_STOP)
{
work_start_time = 0;
}
last_work_state = pile_work_state;
prev_depth = depth_data->depth;
prev_update_time = enc_update_time;
last_enc_value = enc_value;
}
else{
ESP_LOGI(TAG, "time diff = 0\n");
vTaskDelay(100);
}
//每隔500ms向蓝牙发送一次数据
// if(bt_time_count++ > 50){
// ESP_LOGI(TAG, "bt_time_count++ > 50\n");
// bt_time_count = 0;
// send_data_to_bt();
// }
vTaskDelay(10);
}
}
#if 0
void depth_task(void *arg)
{
ESP_LOGI(TAG, "go to depth_task sucessfully\n");
// int enc_value;
int time_diff = 0;
int speed_timeout = 0;
int last_speed_enc_value = 0; // 上次速度计算的编码器值
int speed_enc_update_time = 0;
int speed_calc_count = 0;
int enc_value = 0;
//int count = 0;
int bt_time_count = 0;
depth_data->depth_offset = -depth_config->depth_offset;
depth_data->up_down = 1; // 默认工作
record->pile_id = ++last_pile_id;
//send_to_bt1.pile_id = ++last_pile_id;
gWordVar[LAST_PILE_ID_ADDR] = last_pile_id;
/*获取当前时间*/
uint16_t work_start_time = 0;
uint8_t is_work = 0;
while (1)
{
if (_enc1_update_time != enc1_update_time)
{
ESP_LOGI(TAG, "_enc1_update_time != enc1_update_time\n");
// int enc_update_time = enc1_update_time;
enc_update_time = enc1_update_time;
enc_value = enc1_value;
time_diff = abs_sub(enc_update_time, _enc1_update_time);
_enc1_update_time = enc_update_time;
}
if (time_diff != 0)
{
ESP_LOGI(TAG, "time_diff = %d\n",time_diff);
int16_t depth = enc_value * depth_config->N / depth_config->M; // 1mm
depth_data->depth = depth - depth_data->depth_offset;//为什么要减去深度偏移
/*深度补偿修正*/
if (depth_data->depth > depth_config->max_depth)
{
ESP_LOGI(TAG, "depth_data->depth > depth_config->max_depth\n");
depth_data->depth_offset = depth - depth_config->max_depth;
depth_data->depth = depth_config->max_depth;
}
else if (depth_data->depth < depth_config->min_depth)
{
ESP_LOGI(TAG, "depth_data->depth < depth_config->min_depth\n");
depth_data->depth_offset = depth - depth_config->min_depth;
depth_data->depth = depth_config->min_depth;
}
/*更新记录值*/
if (depth_data->depth > record->max_depth)
{
ESP_LOGI(TAG, "depth_data->depth > record->max_depth\n");
record->max_depth = depth_data->depth;
//send_to_bt1.max_depth = depth_data->depth;
}
// 500ms计算一次速度
if (speed_calc_count++ > 50)
{
ESP_LOGI(TAG, "speed_calc_count++ > 50\n");
speed_calc_count = 0;
int speed_time_diff = abs_sub(enc_update_time, speed_enc_update_time);
int time_diff_us = speed_time_diff / (APB_CLK_FREQ / 1000000);
if (time_diff_us > 0 && time_diff_us < 5000000)
{
ESP_LOGI(TAG, "time_diff_us:%d,dist_diff=%d", time_diff_us, enc_value - last_speed_enc_value);
// speed = dist_diff / speed_time_diff speed 单位mm/min dist_diff 单位mm speed_time_diff 单位us
depth_data->speed = (enc_value - last_speed_enc_value) * depth_config->N / depth_config->M * 600000ll / time_diff_us;
speed_timeout = 0;
speed_enc_update_time = enc_update_time;
last_speed_enc_value = enc_value;
}
else
{
if (++speed_timeout > 10)
{
depth_data->speed = 0;
speed_timeout = 0;
speed_enc_update_time = enc_update_time;
last_speed_enc_value = enc_value;
}
}
}
if (depth_data->up_down > STOP)
{
is_work ++;
if(is_work == 1){
int64_t time = esp_timer_get_time();
if(time < 0){
work_start_time = 0;
}
work_start_time = (uint16_t)(time/1000000);
depth_data->one_pile_work_time = 0;
}
else{
int64_t time = esp_timer_get_time();
if(time > 0){
if((uint16_t)(time/1000000) > work_start_time){
depth_data->one_pile_work_time = ((uint16_t)(time/1000000) - work_start_time);
}
}
}
ESP_LOGI(TAG, "depth_data->up_down > STOP\n");
// 下钻,深度增加
if (enc_value > last_enc_value)
{
if (depth_data->up_down != 1)
{
// 方向改变,更新目标采样深度
depth_data->up_down = 1;
target_sample_depth = (depth_data->depth / depth_config->sample_depth) * depth_config->sample_depth;
// 小于半个采样长度的合并到下一个采样点
if (abs(depth_data->depth - target_sample_depth) < depth_config->sample_depth / 2)
{
target_sample_depth += depth_config->sample_depth;
}
}
// 到达或超过目标采样点
if (depth_data->depth >= target_sample_depth)
{
// 由于编码器精度问题不能确保数据在采样点上,需要通过插值计算采样点
// 当使用10线编码器时每个脉冲深度达6.25cm当采样间隔为10cm时抖动值太大
if ((prev_depth - depth_data->depth) != 0)
@ -584,6 +879,10 @@ void depth_task(void *arg)
}
}
}
else{
is_work = 0;
depth_data->one_pile_work_time = 0;
}
prev_depth = depth_data->depth;
prev_update_time = enc_update_time;
last_enc_value = enc_value;
@ -605,7 +904,7 @@ void depth_task(void *arg)
vTaskDelay(10);
}
}
#endif
void add_recod_item(void)
{
// 每10cm计算一次
@ -669,7 +968,7 @@ void reset_depth(void)
depth_data->depth = depth_config->depth_offset;
enc1_value = 0;
enc1_update_time = 0;
depth_data->up_down = 1; // 默认工作
depth_data->pile_work_state_and_direction = PILE_STATE_STOP | PILE_DIR_NONE; // 默认不工作
}
void DEPTH_init()

View File

@ -27,6 +27,22 @@ static const char *TAG = "UART0";
uint8_t txbuf[BUF_SIZE];
uint8_t rxbuf[BUF_SIZE];
extern int ModbusSlaveProcess(uint8_t *txbuf, uint8_t *rxbuf, uint16_t rxLen, int is_crc);
extern uint16_t gWordVar[];
void LED1_Toggle(void)
{
static unsigned char flg = 1;
if (flg)
{
gpio_set_level(LED1_GPIO_PIN, 0);
flg = 0;
}
else
{
gpio_set_level(LED1_GPIO_PIN, 1);
flg = 1;
}
}
void uart0_init(void)
{
@ -61,26 +77,14 @@ void uart0_init(void)
ESP_ERROR_CHECK(uart_set_rx_timeout(uart_num, UART_READ_TOUT));
}
void LED1_Toggle(void)
{
static unsigned char flg = 1;
if (flg)
{
gpio_set_level(LED1_GPIO_PIN, 0);
flg = 0;
}
else
{
gpio_set_level(LED1_GPIO_PIN, 1);
flg = 1;
}
}
void uart0_modbus_slave_task(void *arg)
{
uart0_init();
// uint8_t count = 0;
while (1)
{
// ESP_LOGI("modbus_slave","enter while");
// Read data from UART
int txlen = 0;
int len = uart_read_bytes(UART_PORT_NUM, rxbuf, BUF_SIZE, UART_READ_TOUT);
@ -88,15 +92,20 @@ void uart0_modbus_slave_task(void *arg)
// Write data back to UART
if (len > 0)
{
ESP_LOGI("modbus_slave","len = %d",len);
// uart_write_bytes(UART_PORT_NUM, rxbuf, len);
// ESP_LOGI(TAG, "uart_read_bytes len=%d", len);
txlen = ModbusSlaveProcess(txbuf, rxbuf, len, 1);
if (txlen > 0)
{
ESP_LOGI("modbus_slave","txlen = %d",txlen);
LED1_Toggle();
uart_write_bytes(UART_PORT_NUM, txbuf, txlen);
int uart_write_length = uart_write_bytes(UART_PORT_NUM, txbuf, txlen);
ESP_LOGI("modbus_slave","uart_write_length = %d",uart_write_length);
ESP_LOGI("modbus_slave","gWordVar[12] = 0x%04x",gWordVar[12]);
}
}
// if (tick - last_rxtick >= PACKET_READ_TICS)
// {
// com_poll_modbus_master_poll(0);
@ -120,6 +129,5 @@ void uart0_modbus_slave_task(void *arg)
void uart0_modbus_slave_init(void)
{
uart0_init();
xTaskCreate(uart0_modbus_slave_task, "uart0_modbus_slave_task", 4096, NULL, 10, NULL);
}

View File

@ -50,7 +50,7 @@
#define PRINT_UART_BAUD_RATE (115200)
#define PRINT_TASK_STACK_SIZE (1024)
static const char *TAG = "UART";
// static const char *TAG = "UART";
#define BUF_SIZE (1024)

View File

@ -11,17 +11,16 @@
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "esp_wifi.h"
#include "../../../components/esp_wifi/include/esp_wifi.h"
#include "esp_event.h"
#include "esp_log.h"
#include "nvs_flash.h"
#include "lwip/err.h"
#include "lwip/sys.h"
#include "driver/ledc.h"
#include "esp_err.h"
#include "../../../components/esp_hw_support/include/esp_mac.h"
/* The examples use WiFi configuration that you can set via project configuration menu.
If you'd rather not, just change the below entries to strings with

View File

@ -221,7 +221,10 @@ CONFIG_BT_CTRL_HCI_MODE_VHCI=y
# CONFIG_BT_CTRL_HCI_MODE_UART_H4 is not set
CONFIG_BT_CTRL_HCI_TL=1
CONFIG_BT_CTRL_ADV_DUP_FILT_MAX=30
# CONFIG_BT_CTRL_HW_CCA is not set
CONFIG_BT_BLE_CCA_MODE_NONE=y
# CONFIG_BT_BLE_CCA_MODE_HW is not set
# CONFIG_BT_BLE_CCA_MODE_SW is not set
CONFIG_BT_BLE_CCA_MODE=0
CONFIG_BT_CTRL_HW_CCA_VAL=20
CONFIG_BT_CTRL_HW_CCA_EFF=0
CONFIG_BT_CTRL_CE_LENGTH_TYPE_ORIG=y
@ -301,6 +304,9 @@ CONFIG_BT_GATT_MAX_SR_ATTRIBUTES=100
# CONFIG_BT_GATTS_SEND_SERVICE_CHANGE_MANUAL is not set
CONFIG_BT_GATTS_SEND_SERVICE_CHANGE_AUTO=y
CONFIG_BT_GATTS_SEND_SERVICE_CHANGE_MODE=0
# CONFIG_BT_GATTS_ROBUST_CACHING_ENABLED is not set
# CONFIG_BT_GATTS_DEVICE_NAME_WRITABLE is not set
# CONFIG_BT_GATTS_APPEARANCE_WRITABLE is not set
CONFIG_BT_GATTC_ENABLE=y
CONFIG_BT_GATTC_MAX_CACHE_CHAR=40
# CONFIG_BT_GATTC_CACHE_NVS_FLASH is not set
@ -491,8 +497,10 @@ CONFIG_BT_SMP_ENABLE=y
# CONFIG_BT_BLE_ACT_SCAN_REP_ADV_SCAN is not set
CONFIG_BT_BLE_ESTAB_LINK_CONN_TOUT=30
CONFIG_BT_MAX_DEVICE_NAME_LEN=32
CONFIG_BT_BLE_RPA_TIMEOUT=900
# CONFIG_BT_BLE_50_FEATURES_SUPPORTED is not set
CONFIG_BT_BLE_42_FEATURES_SUPPORTED=y
# CONFIG_BT_BLE_HIGH_DUTY_ADV_INTERVAL is not set
# end of Bluedroid Options
# end of Bluetooth
@ -781,6 +789,7 @@ CONFIG_ESP_PHY_CALIBRATION_AND_DATA_STORAGE=y
# CONFIG_ESP_PHY_INIT_DATA_IN_PARTITION is not set
CONFIG_ESP_PHY_MAX_WIFI_TX_POWER=20
CONFIG_ESP_PHY_MAX_TX_POWER=20
# CONFIG_ESP_PHY_REDUCE_TX_POWER is not set
CONFIG_ESP_PHY_ENABLE_USB=y
CONFIG_ESP_PHY_RF_CAL_PARTIAL=y
# CONFIG_ESP_PHY_RF_CAL_NONE is not set
@ -827,14 +836,17 @@ CONFIG_ESP_MAIN_TASK_AFFINITY_CPU0=y
# CONFIG_ESP_MAIN_TASK_AFFINITY_NO_AFFINITY is not set
CONFIG_ESP_MAIN_TASK_AFFINITY=0x0
CONFIG_ESP_MINIMAL_SHARED_STACK_SIZE=2048
# CONFIG_ESP_CONSOLE_UART_DEFAULT is not set
CONFIG_ESP_CONSOLE_UART_DEFAULT=y
# CONFIG_ESP_CONSOLE_USB_CDC is not set
CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG=y
# CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG is not set
# CONFIG_ESP_CONSOLE_UART_CUSTOM is not set
# CONFIG_ESP_CONSOLE_NONE is not set
CONFIG_ESP_CONSOLE_SECONDARY_NONE=y
# CONFIG_ESP_CONSOLE_SECONDARY_NONE is not set
CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG=y
CONFIG_ESP_CONSOLE_UART=y
CONFIG_ESP_CONSOLE_MULTIPLE_UART=y
CONFIG_ESP_CONSOLE_UART_NUM=-1
CONFIG_ESP_CONSOLE_UART_NUM=0
CONFIG_ESP_CONSOLE_UART_BAUDRATE=115200
CONFIG_ESP_INT_WDT=y
CONFIG_ESP_INT_WDT_TIMEOUT_MS=300
CONFIG_ESP_INT_WDT_CHECK_CPU1=y