update modbus
This commit is contained in:
@@ -236,7 +236,7 @@ static void bsp_DS1302Init(void)
|
||||
if ((pDS1302->Time.Year > 99) || (pDS1302->Time.Month > 12) || (pDS1302->Time.Day > 31) ||
|
||||
(pDS1302->Time.Hour > 23) || (pDS1302->Time.Minute > 59) || (pDS1302->Time.Second > 59))
|
||||
{
|
||||
pDS1302->Time.Year = 25;
|
||||
pDS1302->Time.Year = 26;
|
||||
pDS1302->Time.Month = 1;
|
||||
pDS1302->Time.Day = 1;
|
||||
pDS1302->Time.Hour = 0;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#include "bsp_Led.h"
|
||||
#include "app_timer.h"
|
||||
|
||||
//#define LED1_ON HAL_GPIO_WritePin (LED1_GPIO_Port, LED1_Pin, GPIO_PIN_RESET)
|
||||
//#define LED1_OFF HAL_GPIO_WritePin (LED1_GPIO_Port, LED1_Pin, GPIO_PIN_SET)
|
||||
//#define LED1_TOGGLE HAL_GPIO_TogglePin(LED1_GPIO_Port, LED1_Pin)
|
||||
#define LED_ON HAL_GPIO_WritePin (LED_GPIO_Port, LED_Pin, GPIO_PIN_RESET)
|
||||
#define LED_OFF HAL_GPIO_WritePin (LED_GPIO_Port, LED_Pin, GPIO_PIN_SET)
|
||||
#define LED_TOGGLE HAL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin)
|
||||
|
||||
//#define LED2_ON HAL_GPIO_WritePin (LED2_GPIO_Port, LED2_Pin, GPIO_PIN_RESET)
|
||||
//#define LED2_OFF HAL_GPIO_WritePin (LED2_GPIO_Port, LED2_Pin, GPIO_PIN_SET)
|
||||
@@ -28,11 +28,11 @@ static void bsp_led_init(void)
|
||||
for(u8 i = 0;i < 20;i++)
|
||||
{
|
||||
delay_ms(50);
|
||||
// HAL_GPIO_TogglePin(LED1_GPIO_Port, LED1_Pin);
|
||||
HAL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin);
|
||||
}
|
||||
}
|
||||
|
||||
static void bsp_led_task(void)
|
||||
{
|
||||
// HAL_GPIO_TogglePin(LED1_GPIO_Port, LED1_Pin);
|
||||
HAL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin);
|
||||
}
|
||||
|
||||
@@ -42,11 +42,11 @@ static void Write_SOCK_Data_Buffer(bsp_W5500_Class_t *pW5500_Class, u8 *dat_ptr,
|
||||
bsp_W5500_t W5500 =
|
||||
{
|
||||
.Gateway_IP = {192,168,1,1},
|
||||
.Sub_Mask = {255,255,255,0},
|
||||
.Sub_Mask = {255,255,255,0},/*子网掩码*/
|
||||
.Phy_Addr = {0x0c,0x29,0xab,0x7c,0x00,0x01},
|
||||
|
||||
//.IP_Addr = {169,254,107,101},
|
||||
.IP_Addr = {192,168,1,101},
|
||||
.IP_Addr = {192,168,100,101},
|
||||
|
||||
.Interrupt_Process = bsp_W5500_Interrupt_Process,
|
||||
|
||||
@@ -61,7 +61,7 @@ bsp_W5500_t W5500 =
|
||||
.ConfigData.Sub_Mask = {255,255,255,0},
|
||||
.ConfigData.Phy_Addr = {0x0c,0x29,0xab,0x7c,0x00,0x01},
|
||||
|
||||
.ConfigData.IP_Addr = {192,168,1,101},
|
||||
.ConfigData.IP_Addr = {192,168,100,101},
|
||||
.ConfigData.Port = {0x13,0x88},
|
||||
|
||||
// .ConfigData.DIP = {192,168,1,32},
|
||||
@@ -776,7 +776,7 @@ static void bsp_W5500_Init()
|
||||
{
|
||||
bsp_W5500_Socket_Init(&pW5500->W5500_Class[i]);
|
||||
pW5500->W5500_Class[i].Run_State = 0; /*复位状态*/
|
||||
//bsp_W5500_Socket_Set(&pW5500->W5500_Class[i]); /*W5500端口初始化配置*/
|
||||
// bsp_W5500_Socket_Set(&pW5500->W5500_Class[i]); /*W5500端口初始化配置*/
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -205,14 +205,14 @@
|
||||
#define S_TX_SIZE 2048 /*定义Socket发送缓冲区的大小,可以根据W5500_TMSR的设置修改 */
|
||||
|
||||
/***************----- W5500 GPIO定义 -----***************/
|
||||
#define W5500_SCS GPIO_PIN_0 // 定义W5500的CS引脚
|
||||
#define W5500_SCS_PORT GPIOB
|
||||
#define W5500_SCS W5500_SPI1_CS_Pin // 定义W5500的CS引脚
|
||||
#define W5500_SCS_PORT W5500_SPI1_CS_GPIO_Port
|
||||
|
||||
#define W5500_RST GPIO_PIN_4 // 定义W5500的RST引脚
|
||||
#define W5500_RST_PORT GPIOA
|
||||
#define W5500_RST W5500_RST_Pin // 定义W5500的RST引脚
|
||||
#define W5500_RST_PORT W5500_RST_GPIO_Port
|
||||
|
||||
#define W5500_INT GPIO_PIN_1 // 定义W5500的INT引脚
|
||||
#define W5500_INT_PORT GPIOA
|
||||
#define W5500_INT W5500_INT_Pin // 定义W5500的INT引脚
|
||||
#define W5500_INT_PORT W5500_INT_GPIO_Port
|
||||
|
||||
///***************----- 网络参数变量定义 -----***************/
|
||||
//extern u8 Gateway_IP[4]; // 网关IP地址
|
||||
|
||||
@@ -2,8 +2,14 @@
|
||||
#include "string.h"
|
||||
|
||||
/* RS485控制宏定义 */
|
||||
#define RS485_RX HAL_GPIO_WritePin(RS485_EN_GPIO_Port, RS485_EN_Pin, GPIO_PIN_SET)
|
||||
#define RS485_TX HAL_GPIO_WritePin(RS485_EN_GPIO_Port, RS485_EN_Pin, GPIO_PIN_SET)
|
||||
#define RS485_1_RX HAL_GPIO_WritePin(RS485_1_EN_GPIO_Port, RS485_1_EN_Pin, GPIO_PIN_RESET)
|
||||
#define RS485_1_TX HAL_GPIO_WritePin(RS485_1_EN_GPIO_Port, RS485_1_EN_Pin, GPIO_PIN_SET)
|
||||
#define RS485_2_RX HAL_GPIO_WritePin(RS485_2_EN_GPIO_Port, RS485_2_EN_Pin, GPIO_PIN_RESET)
|
||||
#define RS485_2_TX HAL_GPIO_WritePin(RS485_2_EN_GPIO_Port, RS485_2_EN_Pin, GPIO_PIN_SET)
|
||||
#define RS485_3_RX HAL_GPIO_WritePin(RS485_3_EN_GPIO_Port, RS485_3_EN_Pin, GPIO_PIN_RESET)
|
||||
#define RS485_3_TX HAL_GPIO_WritePin(RS485_3_EN_GPIO_Port, RS485_3_EN_Pin, GPIO_PIN_SET)
|
||||
#define RS485_4_RX HAL_GPIO_WritePin(RS485_4_EN_GPIO_Port, RS485_4_EN_Pin, GPIO_PIN_RESET)
|
||||
#define RS485_4_TX HAL_GPIO_WritePin(RS485_4_EN_GPIO_Port, RS485_4_EN_Pin, GPIO_PIN_SET)
|
||||
|
||||
/* 缓冲收发区大小 */
|
||||
#define RX_TEMP_BUFF_NUM (3000U)
|
||||
@@ -181,6 +187,14 @@ static void bsp_uart_dma_send(bsp_uart_t *p_uart, u8 *p_data, u16 len)
|
||||
{
|
||||
u32 tick_start, tick;
|
||||
|
||||
if(p_uart == &com_uart4)
|
||||
{
|
||||
RS485_1_TX;
|
||||
}else if(p_uart == &com_uart2)
|
||||
{
|
||||
RS485_2_TX;
|
||||
}
|
||||
|
||||
p_uart->tx_dma_complete_flag = 0;
|
||||
|
||||
/* 如果请求发送的长度大于缓冲区长度,则截断 */
|
||||
@@ -221,7 +235,12 @@ static void bsp_uart_send(bsp_uart_t *p_uart, u8 *p_data, u16 len)
|
||||
|
||||
/* RS485切换到发送模式 */
|
||||
if(p_uart == &com_uart4)
|
||||
RS485_TX;
|
||||
{
|
||||
RS485_1_TX;
|
||||
}else if(p_uart == &com_uart2)
|
||||
{
|
||||
RS485_2_TX;
|
||||
}
|
||||
|
||||
/* 计算需要发送的次数 */
|
||||
send_num = len / p_uart->tx_dma_len;
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
#include "main.h"
|
||||
|
||||
/* spi flash 片选引脚 - pb12 */
|
||||
#define W25Q32_CS_LOW() HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_RESET)
|
||||
#define W25Q32_CS_HIGH() HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_SET)
|
||||
#define W25Q32_CS_LOW() HAL_GPIO_WritePin(SPI2_CS_GPIO_Port, SPI2_CS_Pin, GPIO_PIN_RESET)
|
||||
#define W25Q32_CS_HIGH() HAL_GPIO_WritePin(SPI2_CS_GPIO_Port, SPI2_CS_Pin, GPIO_PIN_SET)
|
||||
|
||||
/* spi 传输函数 */
|
||||
static void w25q32_spi_transmit(uint8_t *data, uint16_t size) {
|
||||
@@ -30,7 +30,6 @@ static void w25q32_write_enable(void);
|
||||
static void w25q32_write_disable(void);
|
||||
static uint8_t w25q32_read_status_reg(void);
|
||||
static void w25q32_wait_for_write_end(void);
|
||||
static void w25q32_sector_erase(uint32_t sector_addr);
|
||||
static void w25q32_block_erase(uint32_t block_addr);
|
||||
static void w25q32_page_write(uint32_t addr, uint8_t *data, uint16_t len);
|
||||
static uint8_t w25q32_read_id(void);
|
||||
@@ -43,6 +42,7 @@ w25q32_t w25q32 = {
|
||||
.read = w25q32_read,
|
||||
.write = w25q32_write,
|
||||
.chip_erase = w25q32_chip_erase,
|
||||
.sector_erase = w25q32_sector_erase,
|
||||
};
|
||||
|
||||
|
||||
@@ -106,7 +106,8 @@ static void w25q32_wait_for_write_end(void) {
|
||||
}
|
||||
|
||||
/* 扇区擦除 (4kb) */
|
||||
static void w25q32_sector_erase(uint32_t sector_addr) {
|
||||
void w25q32_sector_erase(uint32_t sector_addr)
|
||||
{
|
||||
uint8_t cmd[4];
|
||||
|
||||
/* 确保地址是4k对齐 */
|
||||
|
||||
@@ -31,6 +31,8 @@ extern "C" {
|
||||
#define W25Q32_MANUFACTURER_ID 0x90
|
||||
#define W25Q32_JEDEC_ID 0x9F
|
||||
|
||||
void w25q32_sector_erase(uint32_t sector_addr);
|
||||
|
||||
/* 状态寄存器位 */
|
||||
#define W25Q32_STATUS_BUSY (1 << 0)
|
||||
#define W25Q32_STATUS_WRITE_EN (1 << 1)
|
||||
@@ -39,12 +41,25 @@ extern "C" {
|
||||
#define W25Q32_USER_DATA_ADDR 0x000000 /* 用户数据存储起始地址 */
|
||||
#define W25Q32_USER_DATA_SIZE 0x100000 /* 大约1mb空间用于用户数据 */
|
||||
|
||||
#define W25Q32_DEVICE_INFO_ADDR (0x001000) /* 设备信息存储地址 - 扇区1,4K对齐 */
|
||||
#define DEVICE_INFO_STORAGE_SIZE (APP_LEAKAGE_SUB_DEVICE_NUM * sizeof(app_leakage_sub_device_flash_data_t)) /*设备信息存储大小*/
|
||||
|
||||
/* 历史报警存储地址和大小 */
|
||||
#define W25Q32_HISTORY_ALARM_METADATA_ADDR 0x002000 /* 历史报警元数据存储地址 - 扇区2 */
|
||||
#define W25Q32_HISTORY_ALARM_DATA_ADDR 0x003000 /* 历史报警数据存储地址 - 从扇区3开始 */
|
||||
|
||||
#define HISTORY_ALARM_RECORD_SIZE (sizeof(app_leakage_history_alarm_t)) /* 每条记录大小 */
|
||||
#define HISTORY_ALARM_RECORDS_PER_SECTOR (W25Q32_SECTOR_SIZE / HISTORY_ALARM_RECORD_SIZE) /* 每扇区记录数 */
|
||||
#define MAX_HISTORY_ALARM_RECORDS (1000) /* 最大历史报警记录数 */
|
||||
#define HISTORY_ALARM_SECTORS_NEEDED ((MAX_HISTORY_ALARM_RECORDS * HISTORY_ALARM_RECORD_SIZE + W25Q32_SECTOR_SIZE - 1) / W25Q32_SECTOR_SIZE)
|
||||
|
||||
/* w25q32 对象结构体 */
|
||||
typedef struct {
|
||||
void (*init)(void);
|
||||
void (*read)(uint32_t addr, uint8_t *data, uint32_t len);
|
||||
void (*write)(uint32_t addr, uint8_t *data, uint32_t len);
|
||||
void (*chip_erase)(void);
|
||||
void (*sector_erase)(uint32_t sector_addr);
|
||||
} w25q32_t;
|
||||
|
||||
/* 全局对象 */
|
||||
|
||||
Reference in New Issue
Block a user