feat: 完成通信配置

This commit is contained in:
bmy
2024-03-02 16:02:22 +08:00
parent 785f674ada
commit ee1ef42676
6 changed files with 25 additions and 13 deletions

View File

@@ -93,6 +93,9 @@ void USART1_IRQHandler(void)
void USART2_IRQHandler(void)
{
if (USART_GetITStatus(USART2, USART_IT_RXNE) != RESET) {
uint8_t data_s = 0;
uart_query_byte(UART_2, &data_s);
by_tiny_frame_parse_uart_handle(data_s);
USART_ClearITPendingBit(USART2, USART_IT_RXNE);
}
}
@@ -102,9 +105,6 @@ void USART3_IRQHandler(void)
#if DEBUG_UART_USE_INTERRUPT // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> debug <20><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
// debug_interrupr_handler(); // <20><><EFBFBD><EFBFBD> debug <20><><EFBFBD>ڽ<EFBFBD><DABD>մ<EFBFBD><D5B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>ݻᱻ debug <20><><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ
#endif // <20><><EFBFBD><EFBFBD><EFBFBD>޸<EFBFBD><DEB8><EFBFBD> DEBUG_UART_INDEX <20><><EFBFBD><EFBFBD><EFBFBD>δ<EFBFBD><CEB4><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD>ŵ<EFBFBD><C5B5><EFBFBD>Ӧ<EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD>ж<EFBFBD>ȥ
uint8_t data_s = 0;
uart_query_byte(UART_3, &data_s);
by_tiny_frame_parse_uart_handle(data_s);
USART_ClearITPendingBit(USART3, USART_IT_RXNE);
}
}

View File

@@ -3,9 +3,9 @@
#define BY_TF_DEBUG (1)
#define BY_TF_UART_TX_PIN (UART3_MAP0_TX_B10)
#define BY_TF_UART_RX_PIN (UART3_MAP0_RX_B11)
#define BY_TF_UART_INDEX (UART_3)
#define BY_TF_UART_TX_PIN (UART2_MAP0_TX_A2)
#define BY_TF_UART_RX_PIN (UART2_MAP0_RX_A3)
#define BY_TF_UART_INDEX (UART_2)
#define BY_TF_UART_BAUDRATE (115200)
#define BY_TF_PARSE_BUFFER_SIZE (50)

View File

@@ -2,7 +2,6 @@
#if defined(BY_TF_DEVICE_MASTER)
uint8_t read_processing_flag;
uint32_t *data_p;
void by_tiny_frame_read_run(void)
@@ -11,6 +10,11 @@ void by_tiny_frame_read_run(void)
void by_tiny_frame_read(uint8_t slave_id, uint16_t reg_addr, uint32_t *data)
{
if (by_tiny_frame_pack_lock) {
// 写入忙处理
return;
}
// 填充数据
by_tf_pack_frame_t frame_s;
frame_s.slave_id = slave_id;
@@ -27,13 +31,13 @@ void by_tiny_frame_read(uint8_t slave_id, uint16_t reg_addr, uint32_t *data)
// 开启响应监听
by_tiny_frame_parse_start_listen();
read_processing_flag = 1;
by_tiny_frame_pack_lock = 0;
}
void by_tiny_frame_read_handle(by_tf_parse_frame_t frame_s, uint8_t status)
{
read_processing_flag = 0;
by_tiny_frame_pack_lock = 0;
if (!status) {
*data_p = frame_s.data;
}

View File

@@ -5,8 +5,6 @@
#include "by_tiny_frame_pack.h"
#include "by_tiny_frame_parse.h"
uint8_t write_processing_flag;
void by_tiny_frame_write_run(void)
{
// nothing
@@ -14,6 +12,11 @@ void by_tiny_frame_write_run(void)
void by_tiny_frame_write(uint8_t slave_id, uint16_t reg_addr, uint32_t data)
{
if(by_tiny_frame_pack_lock){
//写入忙处理
return;
}
// 填充数据
by_tf_pack_frame_t frame_s;
frame_s.slave_id = slave_id;
@@ -30,12 +33,12 @@ void by_tiny_frame_write(uint8_t slave_id, uint16_t reg_addr, uint32_t data)
// 开启响应监听
by_tiny_frame_parse_start_listen();
write_processing_flag = 1;
by_tiny_frame_pack_lock = 1;
}
void by_tiny_frame_write_handle(by_tf_parse_frame_t frame_s, uint8_t status)
{
write_processing_flag = 0;
by_tiny_frame_pack_lock = 0;
#if (BY_TF_DEBUG)
printf("****** WRITE REGISTER DONE ******\r\n");

View File

@@ -4,9 +4,12 @@
#include "zf_common_headfile.h"
#include "crc16.h"
uint8_t by_tiny_frame_pack_lock;
void by_tiny_frame_pack_init(void)
{
/** nothing to init **/
by_tiny_frame_pack_lock = 0;
}
void by_tiny_frame_pack_send(by_tf_pack_frame_t *frame_s)

View File

@@ -21,4 +21,6 @@ typedef struct by_tf_pack_frame_t {
extern void by_tiny_frame_pack_init(void);
extern void by_tiny_frame_pack_send(by_tf_pack_frame_t *frame_s);
extern uint8_t by_tiny_frame_pack_lock;
#endif