Add official software buttons to send and return data

This commit is contained in:
2024-03-11 17:51:17 +08:00
parent c53e96711b
commit df2a6bf623

21
main.c
View File

@@ -55,6 +55,7 @@ void read_data(void)
// 发送数据 // 发送数据
uart_write_blocking(UART0, Tx_Buffer, 8); uart_write_blocking(UART0, Tx_Buffer, 8);
sleep_ms(10);
// 接收数据 // 接收数据
uint8_t _DATA[37] = { 0 }; uint8_t _DATA[37] = { 0 };
@@ -121,6 +122,8 @@ void Print_data(void)
static uint16_t IM1253B(void) static uint16_t IM1253B(void)
{ {
static int i = 0;
// 初始化UART // 初始化UART
uart_init(UART0, BAUD_RATE); uart_init(UART0, BAUD_RATE);
gpio_set_function(UART0_TX_PIN, GPIO_FUNC_UART); gpio_set_function(UART0_TX_PIN, GPIO_FUNC_UART);
@@ -128,7 +131,19 @@ static uint16_t IM1253B(void)
uart_set_hw_flow(UART0, false, false); uart_set_hw_flow(UART0, false, false);
uart_set_format(UART0, DATA_BITS, STOP_BITS, PARITY); uart_set_format(UART0, DATA_BITS, STOP_BITS, PARITY);
sleep_ms(10); sleep_ms(10);
/*
// 官方软件内部按钮发送的数据
// 电能清零 TX[13]:01 10 00 4B 00 02 04 00 00 00 00 B6 2C
// RX[8]:01 10 00 4B 00 02 31 DE
// 读取 TX[8]:00 03 00 01 00 04 14 18
// RX[13]:01 03 08 02 35 01 08 41 30 01 05 44 BD (直流模块)
// 设置 TX[11]:00 10 00 04 00 01 02 01 05 6B D7
// RX[8]:01 10 00 04 00 01 40 08
*/
// 发送 // 发送
read_enable = 1; read_enable = 1;
read_data(); read_data();
@@ -140,7 +155,7 @@ static uint16_t IM1253B(void)
Analysis_data(); Analysis_data();
// 打印原始十六进制数据 // 打印原始十六进制数据
for (int i = 0; i <= 37 - 1; i++) { for (i=0; i <= 37 - 1; i++) {
printf("0x%X ", Rx_Buffer[i]); printf("0x%X ", Rx_Buffer[i]);
} }
printf("\n"); printf("\n");
@@ -166,7 +181,7 @@ int main(void)
watchdog_enable(8300, 1); // 8秒检测是否重新加载看门狗计数器. (不更新计数器则重启硬件, 最高8秒(8秒后不喂狗硬件重启)) watchdog_enable(8300, 1); // 8秒检测是否重新加载看门狗计数器. (不更新计数器则重启硬件, 最高8秒(8秒后不喂狗硬件重启))
watchdog_start_tick(12); watchdog_start_tick(12);
printf("IM1253B module\n");
while (1) { while (1) {
watchdog_update(); // 喂狗 watchdog_update(); // 喂狗