[feat] add addr and baudrate setting
This commit is contained in:
parent
e743e09fbe
commit
9261aaa842
@ -31,7 +31,7 @@ void system_init(void)
|
|||||||
led_init();
|
led_init();
|
||||||
system_tick_init();
|
system_tick_init();
|
||||||
// lcd_init();
|
// lcd_init();
|
||||||
rs485_init();
|
// rs485_init();
|
||||||
dwin_init();
|
dwin_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -4,6 +4,7 @@
|
|||||||
#include "stm32f4xx_dma.h"
|
#include "stm32f4xx_dma.h"
|
||||||
#include "lark1s.h"
|
#include "lark1s.h"
|
||||||
#include "dwin.h"
|
#include "dwin.h"
|
||||||
|
#include "rs485.h"
|
||||||
|
|
||||||
#define DWIN_TX_STREAM DMA1_Stream6
|
#define DWIN_TX_STREAM DMA1_Stream6
|
||||||
#define DWIN_RX_STREAM DMA1_Stream5
|
#define DWIN_RX_STREAM DMA1_Stream5
|
||||||
@ -11,6 +12,7 @@
|
|||||||
#define DWIN_BUFF_RX_LEN (4096)
|
#define DWIN_BUFF_RX_LEN (4096)
|
||||||
uint8_t dwin_buff_tx[DWIN_BUFF_TX_LEN] __attribute__((aligned(16)));
|
uint8_t dwin_buff_tx[DWIN_BUFF_TX_LEN] __attribute__((aligned(16)));
|
||||||
uint8_t dwin_buff_rx[DWIN_BUFF_RX_LEN] __attribute__((aligned(16)));
|
uint8_t dwin_buff_rx[DWIN_BUFF_RX_LEN] __attribute__((aligned(16)));
|
||||||
|
static int __attribute__((section(".bss_ccm"))) sm = 0;
|
||||||
|
|
||||||
extern uint32_t system_tick_cnt;
|
extern uint32_t system_tick_cnt;
|
||||||
|
|
||||||
@ -105,10 +107,29 @@ static void dwin_endian_reverse_2byte(uint8_t *buffer, uint16_t val)
|
|||||||
buffer[1] = (uint8_t)(val & 0xFF);
|
buffer[1] = (uint8_t)(val & 0xFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void dwin_rx_parse(uint8_t *buffer, uint16_t len)
|
||||||
|
{
|
||||||
|
uint32_t baudrate;
|
||||||
|
uint8_t *p = buffer;
|
||||||
|
|
||||||
|
sm++;
|
||||||
|
if (sm > 1) {
|
||||||
|
sm = 0;
|
||||||
|
}
|
||||||
|
if (p[0] != 0x5A || p[1] != 0xA5 || p[2] != 0x12 || p[3] != 0x83 || p[4] != 0x51 || p[5] != 0x00 || p[6] != 0x07) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
rs485_mb_addr = p[16];
|
||||||
|
baudrate = (uint32_t)p[20];
|
||||||
|
baudrate |= (uint32_t)p[19] << 8;
|
||||||
|
baudrate |= (uint32_t)p[18] << 16;
|
||||||
|
baudrate |= (uint32_t)p[17] << 24;
|
||||||
|
rs485_baudrate = baudrate;
|
||||||
|
}
|
||||||
|
|
||||||
void dwin_loop(void)
|
void dwin_loop(void)
|
||||||
{
|
{
|
||||||
static uint32_t ms = 0;
|
static uint32_t ms = 0;
|
||||||
static int flag = 0;
|
|
||||||
uint16_t len;
|
uint16_t len;
|
||||||
uint16_t i;
|
uint16_t i;
|
||||||
|
|
||||||
@ -117,7 +138,7 @@ void dwin_loop(void)
|
|||||||
}
|
}
|
||||||
ms = system_tick_cnt;
|
ms = system_tick_cnt;
|
||||||
len = 0;
|
len = 0;
|
||||||
if (flag == 0) {
|
if (sm == 0) {
|
||||||
/* read control data */
|
/* read control data */
|
||||||
dwin_buff_tx[len++] = 0x5A;
|
dwin_buff_tx[len++] = 0x5A;
|
||||||
dwin_buff_tx[len++] = 0xA5; /* frame head */
|
dwin_buff_tx[len++] = 0xA5; /* frame head */
|
||||||
@ -222,7 +243,6 @@ void dwin_loop(void)
|
|||||||
len += 4;
|
len += 4;
|
||||||
}
|
}
|
||||||
dwin_send(len);
|
dwin_send(len);
|
||||||
flag++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void USART2_IRQHandler(void)
|
void USART2_IRQHandler(void)
|
||||||
@ -249,9 +269,6 @@ void USART2_IRQHandler(void)
|
|||||||
DMA_ClearFlag(DWIN_RX_STREAM, DMA_FLAG_TCIF5 | DMA_FLAG_HTIF5 | DMA_FLAG_TEIF5 | DMA_FLAG_DMEIF5 | DMA_FLAG_FEIF5);
|
DMA_ClearFlag(DWIN_RX_STREAM, DMA_FLAG_TCIF5 | DMA_FLAG_HTIF5 | DMA_FLAG_TEIF5 | DMA_FLAG_DMEIF5 | DMA_FLAG_FEIF5);
|
||||||
len = DMA_GetCurrDataCounter(DWIN_RX_STREAM);
|
len = DMA_GetCurrDataCounter(DWIN_RX_STREAM);
|
||||||
len = DWIN_BUFF_RX_LEN - len;
|
len = DWIN_BUFF_RX_LEN - len;
|
||||||
for (uint16_t i = 0; i < len; i++) {
|
dwin_rx_parse(dwin_buff_rx, len);
|
||||||
dwin_buff_tx[i] = dwin_buff_rx[i] + 1;
|
|
||||||
}
|
|
||||||
dwin_send(len);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#define DWIN_DATA_DISP_ADDR (0x5000)
|
#define DWIN_DATA_DISP_ADDR (0x5000)
|
||||||
#define DWIN_DATA_DISP_LENG (0x38)
|
#define DWIN_DATA_DISP_LENG (0x3A)
|
||||||
#define DWIN_DATA_CTRL_ADDR (0x5100)
|
#define DWIN_DATA_CTRL_ADDR (0x5100)
|
||||||
#define DWIN_DATA_CTRL_LENG (0x07)
|
#define DWIN_DATA_CTRL_LENG (0x07)
|
||||||
|
|
||||||
|
|||||||
@ -13,6 +13,8 @@
|
|||||||
uint8_t rs485_buff_tx[RS485_BUFF_TX_LEN] __attribute__((aligned(16)));
|
uint8_t rs485_buff_tx[RS485_BUFF_TX_LEN] __attribute__((aligned(16)));
|
||||||
uint8_t rs485_buff_rx[RS485_BUFF_RX_LEN] __attribute__((aligned(16)));
|
uint8_t rs485_buff_rx[RS485_BUFF_RX_LEN] __attribute__((aligned(16)));
|
||||||
static int __attribute__((section(".bss_ccm"))) sm = 0;
|
static int __attribute__((section(".bss_ccm"))) sm = 0;
|
||||||
|
uint32_t rs485_baudrate __attribute__((section(".bss_ccm"))) = 19200;
|
||||||
|
uint8_t rs485_mb_addr __attribute__((section(".bss_ccm"))) = 1;
|
||||||
|
|
||||||
char sn[16] __attribute__((section(".bss_ccm")));
|
char sn[16] __attribute__((section(".bss_ccm")));
|
||||||
struct lark1s_gas_info_s lark1s_gas_info __attribute__((section(".bss_ccm")));
|
struct lark1s_gas_info_s lark1s_gas_info __attribute__((section(".bss_ccm")));
|
||||||
@ -62,7 +64,7 @@ void rs485_init(void)
|
|||||||
|
|
||||||
USART_DeInit(USART3);
|
USART_DeInit(USART3);
|
||||||
USART_OverSampling8Cmd(USART3, ENABLE);
|
USART_OverSampling8Cmd(USART3, ENABLE);
|
||||||
USART_InitStructure.USART_BaudRate = RS485_BAUDRATE;
|
USART_InitStructure.USART_BaudRate = rs485_baudrate;
|
||||||
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
|
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
|
||||||
USART_InitStructure.USART_Parity = USART_Parity_No;
|
USART_InitStructure.USART_Parity = USART_Parity_No;
|
||||||
USART_InitStructure.USART_StopBits = USART_StopBits_1;
|
USART_InitStructure.USART_StopBits = USART_StopBits_1;
|
||||||
@ -107,12 +109,11 @@ void rs485_init(void)
|
|||||||
USART_ReceiveData(USART3);
|
USART_ReceiveData(USART3);
|
||||||
USART_ClearITPendingBit(USART3, USART_IT_IDLE);
|
USART_ClearITPendingBit(USART3, USART_IT_IDLE);
|
||||||
USART_ClearITPendingBit(USART3, USART_IT_TC);
|
USART_ClearITPendingBit(USART3, USART_IT_TC);
|
||||||
|
|
||||||
// rs485_send(15);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void rs485_send(uint16_t len)
|
void rs485_send(uint16_t len)
|
||||||
{
|
{
|
||||||
|
USART_ITConfig(USART3, USART_IT_IDLE, DISABLE);
|
||||||
rs485_mode_tx();
|
rs485_mode_tx();
|
||||||
DMA_SetCurrDataCounter(RS485_TX_STREAM, len);
|
DMA_SetCurrDataCounter(RS485_TX_STREAM, len);
|
||||||
DMA_Cmd(RS485_TX_STREAM, ENABLE);
|
DMA_Cmd(RS485_TX_STREAM, ENABLE);
|
||||||
@ -157,11 +158,21 @@ void rs485_state_machine_rx(int len)
|
|||||||
void rs485_loop(void)
|
void rs485_loop(void)
|
||||||
{
|
{
|
||||||
static uint32_t ms = 0;
|
static uint32_t ms = 0;
|
||||||
|
static uint32_t baudrate = 0;
|
||||||
|
static uint8_t addr = 0;
|
||||||
|
|
||||||
if (system_tick_cnt < (ms + 200)) {
|
if (system_tick_cnt < (ms + 200)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ms = system_tick_cnt;
|
ms = system_tick_cnt;
|
||||||
|
if (baudrate != rs485_baudrate) {
|
||||||
|
baudrate = rs485_baudrate;
|
||||||
|
rs485_init();
|
||||||
|
}
|
||||||
|
if (addr != rs485_mb_addr) {
|
||||||
|
addr = rs485_mb_addr;
|
||||||
|
lark1s_set_mb_address(addr);
|
||||||
|
}
|
||||||
rs485_state_machine_tx();
|
rs485_state_machine_tx();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -12,8 +12,8 @@
|
|||||||
#define RS485_PIN_RX (GPIO_Pin_11)
|
#define RS485_PIN_RX (GPIO_Pin_11)
|
||||||
#define RS485_PIN_DIR (GPIO_Pin_1)
|
#define RS485_PIN_DIR (GPIO_Pin_1)
|
||||||
|
|
||||||
#define RS485_BAUDRATE (115200)
|
extern uint32_t rs485_baudrate;
|
||||||
#define RS485_MB_ADDR (9)
|
extern uint8_t rs485_mb_addr;
|
||||||
|
|
||||||
void rs485_init(void);
|
void rs485_init(void);
|
||||||
void rs485_send(uint16_t len);
|
void rs485_send(uint16_t len);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user