RS485
编译
./load.sh # 选择目前自己参考的开发板,参考示例对应ZX3D50CE02S_USRC_4832
cd examples/demo_rs485
idf.py build
idf.py flash
说明
具体功能参考工程下的REAMDE.md
串口初始化
如果没有RTS/CTS,请将相关pin脚设置为-1,如果有修改其他引脚,请进行相关设置
static void qmsd_rs485_init(void)
{
qmsd_uart_config_t uconfig = {
.uart_buffer_size = 1024,
.queue_size = 20,
.uart_native_config = {
.baud_rate = 115200,
.data_bits = UART_DATA_8_BITS,
.parity = UART_PARITY_DISABLE,
.stop_bits = UART_STOP_BITS_1,
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
.rx_flow_ctrl_thresh = 0,
.source_clk = UART_SCLK_APB,
},
#ifdef CONFIG_ZX3D50CE02S_USRC_4832
.uart_tx_pin = 42,
.uart_rx_pin = 1,
.uart_rts_pin = 2,
.uart_cts_pin = -1,
#endif
#ifdef CONFIG_ZX4D30NE01S_UR_4827
.uart_tx_pin = 0,
.uart_rx_pin = 39,
.uart_rts_pin = 38,
.uart_cts_pin = -1,
#endif
.uart_mode = UART_MODE_RS485_HALF_DUPLEX,
};
qmsd_uart_start(UART_NUM_1, &uconfig);
}
串口接收
串口的接收将通过通知链,调用注册的cb函数,QMSD_UART_EVENT_DATA为串口收到数据的事件
static int __qmsd_nb_func(struct qmsd_notifier_block *nb, unsigned int action, void *data)
{
if (action == QMSD_UART_EVENT_DATA) {
int i;
struct qmsd_uart_rx_data *param = (struct qmsd_uart_rx_data *)data;
/*
* dump uart rx data
*/
for (i =0; i < param->size; i++) {
printf("%02X ", param->data[i]);
}
printf("\n");
/*
* parse uart rx data
*/
if (param->data[0] == 1) {
/*
* call ui api
*/
screen_main_show();
} else if (param->data[0] == 2) {
/*
* call ui api
*/
screen_test_show();
}
}
return QMSD_NOTIFY_OK;
}
串口发送
使用如下API,进行串口的发送
int qmsd_uart_write(int unum, const char *buf, size_t len);