使用ESP-IDF搭建北斗二代模块进行北斗RDSS通信。
TM8650 集成了博纳雨田自主研制的射频收发芯片BN622,功放芯片、基带芯片和LNA 电路,配合SIM卡及无源天线即可实现北斗一代的短报文通信功能及定位功能。模块同时集成了BDS B1/GPS L1接收电路,可实现北斗/GPS联合定位或单北斗、单GPS定位。
低噪放电路可对RX端口输入的射频信号进行滤波及放大,客户无需外置LNA 及滤波器,直接通过RX端口连接无源天线即可接收RDSS信号。功放电路提供10W发射功率。支持2.1(定位总站2011-8) 协议兼容4.0协议(总参测绘局2007-4)。
模块采用工业级的铝制壳体,结构强度高,功耗低,非常适合如特种车辆的导航监控、海洋渔业终端、气象探测仪以及手持终端等应用。
1、开发板的UART1与上位机连接;
2、开发板的UART2与模块测试底板的RDSS-RX、TX连接。
mian.c
/*
* @FilePath: main.c
* @Author: Master.Peng
* @Date: 2023-08-04 12:59:23
* @LastEditTime: 2023-08-09 15:57:27
* Copyright: 2023 江苏博纳雨田通信电子有限公司
*/
#include <stdio.h>
#include "sdkconfig.h"
#include "stdbool.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_log.h"
#include "driver/uart.h"
#include "myapp/led.h"
#include "myapp/uart.h"
#include "main.h"
bool logShow = true; // true:打印日志。false:不打印
extern USER_T user;
extern RDSS_T rdss;
void app_main(void)
{
ledConfig();
// uart0Config(115200);
uart1Config(115200);
uart2Config(115200);
xTaskCreate(&ledTask, "ledTask", 1024, NULL, 1, NULL);
xTaskCreate(&uart1EventTask, "uartTask", 1024 * 2, NULL, 2, NULL);
xTaskCreate(&uart2EventTask, "uartTask", 1024 * 2, NULL, 3, NULL);
}
void ledTask(void *pvParameter)
{
ledBlink();
}
static void uart1EventTask(void *pvParameter)
{
uart1Event();
}
static void uart2EventTask(void *pvParameter)
{
uart2Event();
}
uart.c
#include "driver/gpio.h"
#include "driver/uart.h"
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"
#include "stdio.h"
#include "string.h"
#include "esp_log.h"
#include "esp_task_wdt.h"
#include "uart.h"
USER_T user;
RDSS_T rdss;
RX_FRAME_T user_rx_frame = {{0}, 0, 0, true};
RX_FRAME_T rdss_rx_frame = {{0}, 0, 0, true};
void uart0Config(int baude)
{
uart_config_t myUart = {};
myUart.baud_rate = baude;
myUart.data_bits = UART_DATA_8_BITS;
myUart.parity = UART_PARITY_DISABLE;
myUart.stop_bits = UART_STOP_BITS_1;
myUart.flow_ctrl = UART_HW_FLOWCTRL_DISABLE;
myUart.source_clk = UART_SCLK_APB;
uart_param_config(UART0, &myUart);
uart_set_pin(UART0, GPIO_NUM_43, GPIO_NUM_44, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
uart_driver_install(UART0, LINE_BUF_SIZE, LINE_BUF_SIZE, 0, NULL, 0);
}
void uart1Config(int baude)
{
uart_config_t myUart = {};
myUart.baud_rate = baude;
myUart.data_bits = UART_DATA_8_BITS;
myUart.parity = UART_PARITY_DISABLE;
myUart.stop_bits = UART_STOP_BITS_1;
myUart.flow_ctrl = UART_HW_FLOWCTRL_DISABLE;
myUart.source_clk = UART_SCLK_APB;
uart_param_config(UART1, &myUart);
uart_set_pin(UART1, GPIO_NUM_17, GPIO_NUM_18, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
uart_driver_install(UART1, LINE_BUF_SIZE, LINE_BUF_SIZE, 0, NULL, 0);
}
void uart2Config(int baude)
{
uart_config_t myUart = {};
myUart.baud_rate = baude;
myUart.data_bits = UART_DATA_8_BITS;
myUart.parity = UART_PARITY_DISABLE;
myUart.stop_bits = UART_STOP_BITS_1;
myUart.flow_ctrl = UART_HW_FLOWCTRL_DISABLE;
myUart.source_clk = UART_SCLK_APB;
uart_param_config(UART2, &myUart);
uart_set_pin(UART2, GPIO_NUM_12, GPIO_NUM_13, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
uart_driver_install(UART2, LINE_BUF_SIZE, LINE_BUF_SIZE, 0, NULL, 0);
}
void uart1Event(void)
{
while (1)
{
user.rx_buf.wrIdx = uart_read_bytes(UART1, user.rx_buf.data, LINE_BUF_SIZE - 1, 20 / portTICK_PERIOD_MS);
decap_user_rx_buf();
}
}
void uart2Event(void)
{
while (1)
{
rdss.rx_buf.wrIdx = uart_read_bytes(UART2, rdss.rx_buf.data, LINE_BUF_SIZE - 1, 20 / portTICK_PERIOD_MS);
decap_rdss_rx_buf();
}
}
void decap_user_rx_buf(void)
{
split_user_rx_buf();
parse_user_rx_frame();
}
void decap_rdss_rx_buf(void)
{
split_rdss_rx_buf();
parse_rdss_rx_frame();
}
void split_user_rx_buf(void)
{
if (!user_rx_frame.empty)
return;
uint8_t rx_char = 0;
while (RING_BUF_NEMPTY(user.rx_buf) && user_rx_frame.empty)
{
rx_char = RING_BUF_RD(user.rx_buf);
user_rx_frame.buf[user_rx_frame.idx] = rx_char;
if (user_rx_frame.idx == 0)
user_rx_frame.idx = (rx_char == '$') ? 1 : 0;
else
{
if ((rx_char == 0x0A && user_rx_frame.buf[user_rx_frame.idx - 1] == 0x0D) || user_rx_frame.idx >= 2048)
{
user_rx_frame.len = user_rx_frame.idx + 1;
user_rx_frame.idx = 0;
user.rx_buf.wrIdx = 0;
uint8_t xorsum = 0;
for (int16_t i = 1; i < user_rx_frame.len - 5; i++)
xorsum ^= user_rx_frame.buf[i];
if (xorsum == strtoul((char *)(user_rx_frame.buf + user_rx_frame.len - 4), NULL, 16))
{
user_rx_frame.empty = false;
return;
}
}
else
user_rx_frame.idx++;
}
}
}
void split_rdss_rx_buf(void)
{
if (!rdss_rx_frame.empty)
return;
uint8_t rx_char = 0;
while (RING_BUF_NEMPTY(rdss.rx_buf) && rdss_rx_frame.empty)
{
rx_char = RING_BUF_RD(rdss.rx_buf);
rdss_rx_frame.buf[rdss_rx_frame.idx] = rx_char;
if (rdss_rx_frame.idx == 0)
rdss_rx_frame.idx = (rx_char == '$') ? 1 : 0;
else
{
if ((rx_char == 0x0A && rdss_rx_frame.buf[rdss_rx_frame.idx - 1] == 0x0D) || rdss_rx_frame.idx >= 2048)
{
rdss_rx_frame.len = rdss_rx_frame.idx + 1;
rdss_rx_frame.idx = 0;
rdss.rx_buf.wrIdx = 0;
uint8_t xorsum = 0;
for (int16_t i = 1; i < rdss_rx_frame.len - 5; i++)
xorsum ^= rdss_rx_frame.buf[i];
if (xorsum == strtoul((char *)(rdss_rx_frame.buf + rdss_rx_frame.len - 4), NULL, 16))
{
rdss_rx_frame.empty = false;
return;
}
}
else
rdss_rx_frame.idx++;
}
}
}
void parse_user_rx_frame(void)
{
if (user_rx_frame.empty)
return;
parse_user_send_rdss();
}
void parse_rdss_rx_frame(void)
{
if (rdss_rx_frame.empty)
return;
parse_rdss_send_user();
}
void parse_user_send_rdss(void)
{
if (LINE_BUF_NEMPTY(rdss.tx_buf))
return; // 后级缓存阻塞,退出函数
LINE_BUF_CONCAT(rdss.tx_buf, user_rx_frame.buf, user_rx_frame.len); // 复制到发送缓存
uart_write_bytes(UART2, rdss.tx_buf.buf, rdss.tx_buf.wrIdx);
user_rx_frame.empty = true;
LINE_BUF_RESET(rdss.tx_buf);
}
void parse_rdss_send_user(void)
{
if (LINE_BUF_NEMPTY(user.tx_buf))
return; // 后级缓存阻塞,退出函数
LINE_BUF_CONCAT(user.tx_buf, rdss_rx_frame.buf, rdss_rx_frame.len); // 复制到发送缓存
uart_write_bytes(UART1, user.tx_buf.buf, user.tx_buf.wrIdx);
rdss_rx_frame.empty = true;
LINE_BUF_RESET(user.tx_buf);
}
未接天线与北斗卡,只测试开发板与模块之间串口通信效果
更多回帖