Преглед на файлове

增加RS485收发引脚的宏,默认关闭

liangzohar преди 2 години
родител
ревизия
7d2869ac41
променени са 1 файла, в които са добавени 17 реда и са изтрити 3 реда
  1. 17 3
      port/dlt645_port.c

+ 17 - 3
port/dlt645_port.c

@@ -15,6 +15,8 @@
 
 //DLT645采集使用的串口名
 #define DLT645_SERIAL_NAME "uart4"
+//RS485的收发控制引脚,如果驱动层已有485驱动,不使用填-1
+#define DLT645_RS485_DE_PIN -1  //如果用PA15,改为15
 
 //DL/T 645硬件拓展结构体
 typedef struct
@@ -98,10 +100,18 @@ static int dlt645_hw_read(dlt645_t *ctx, uint8_t *msg ,uint16_t len)
  */
 static int dlt645_hw_write(dlt645_t *ctx, uint8_t *buf, uint16_t len)
 {
+    if(DLT645_RS485_DE_PIN != -1)
+    {
+        rt_pin_write(DLT645_RS485_DE_PIN, PIN_HIGH);
+    }
+
     //串口发送数据
-    rt_pin_write(GET_PIN(A,15), PIN_HIGH);
     int ret = rt_device_write(dlt645_device,0,buf,len);
-    rt_pin_write(GET_PIN(A,15), PIN_LOW);
+
+    if(DLT645_RS485_DE_PIN != -1)
+    {
+        rt_pin_write(DLT645_RS485_DE_PIN, PIN_LOW);
+    }
     return ret;
 }
 
@@ -149,8 +159,12 @@ int dlt645_port_init(void)
 
     //设置串口接收回调函数
     rt_device_set_rx_indicate(dlt645_device, uart_handler);
+
     //485控制引脚初始化
-    rt_pin_mode(GET_PIN(A,15),PIN_MODE_OUTPUT);
+    if(DLT645_RS485_DE_PIN != -1)
+    {
+        rt_pin_mode(DLT645_RS485_DE_PIN, PIN_MODE_OUTPUT);
+    }
     return  RT_EOK;
 }