diff --git a/Example/ADC_Demo/.cproject b/Example/ADC_Demo/.cproject index 8c5b642..6059a91 100644 --- a/Example/ADC_Demo/.cproject +++ b/Example/ADC_Demo/.cproject @@ -3,9 +3,9 @@ - + - + @@ -25,50 +25,76 @@ - + - + - + - @@ -352,12 +362,14 @@ + + - + - + @@ -377,43 +389,1895 @@ - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -431,13 +2295,37 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + @@ -461,6 +2349,18 @@ + + + + + + + + + + + + diff --git a/Example/ADC_Demo/.project b/Example/ADC_Demo/.project index b1bd2f8..bfec189 100644 --- a/Example/ADC_Demo/.project +++ b/Example/ADC_Demo/.project @@ -5,6 +5,18 @@ + + com.infineon.aurix.buildsystem.builders.booster + full,incremental, + + + + + com.infineon.aurix.buildsystem.builders.autodiscovery + full,incremental, + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder clean,full,incremental, diff --git a/Example/ADC_Demo/.settings/com.infineon.aurix.buildsystem.prefs b/Example/ADC_Demo/.settings/com.infineon.aurix.buildsystem.prefs new file mode 100644 index 0000000..be61bc1 --- /dev/null +++ b/Example/ADC_Demo/.settings/com.infineon.aurix.buildsystem.prefs @@ -0,0 +1,10 @@ +AURIX-LIBRARY-PATH=Libraries/iLLD\#Libraries/Infra\#Libraries/Service +DEVICE-ID=TC26B +DEVICE-ID-FULL=TC26xD_B-Step +ILLD-SET=full +IncludesAutodiscovery=true +LIBRARIES-ROOT-PATH=Libraries +NEVER-EXCLUDE-FROM-BUILD=/Libraries/iLLD/TC26B/Tricore/Cpu/CStart\#/Libraries/iLLD/TC26B/Tricore/Cpu/Trap\#/Configurations\#/Configurations/Debug +PROJECT-VERSION=1.0 +aurixDevice=TC26xD_B-Step +eclipse.preferences.version=1 diff --git a/Example/ADC_Demo/Libraries/doc/version.txt b/Example/ADC_Demo/Libraries/doc/version.txt index ab79909..11ab82e 100644 --- a/Example/ADC_Demo/Libraries/doc/version.txt +++ b/Example/ADC_Demo/Libraries/doc/version.txt @@ -1,3 +1,13 @@ +V1.2.0 + 增加CH9141蓝牙转串口模块的驱动 + 添加无线类型的枚举变量 + 修改 删除临时文件.bat 执行完操作后自动关闭窗口 + 修改 删除临时文件.bat 避免删除新版本所需文件 + 修改工程项目文件,以支持新版本编译 + +V1.1.10 + 修复通过#pragma section all "cpux_dsram"指定变量位置失效的问题 + V1.1.9 将串口的发送buff增加到128字节 diff --git a/Example/ADC_Demo/Libraries/seekfree_libraries/common/common.c b/Example/ADC_Demo/Libraries/seekfree_libraries/common/common.c index 0b9931e..7620ce6 100644 --- a/Example/ADC_Demo/Libraries/seekfree_libraries/common/common.c +++ b/Example/ADC_Demo/Libraries/seekfree_libraries/common/common.c @@ -27,6 +27,8 @@ CAMERA_TYPE_enum camera_type; //摄像头型号 uint8 *camera_buffer_addr; //摄像头数组地址 +WIRELESS_TYPE_enum wireless_type;//无线转串口类型 + IFX_ALIGN(4) IfxCpu_syncEvent g_cpuSyncEvent = 0;//事件同步变量 App_Cpu0 g_AppCpu0; //频率信息变量 diff --git a/Example/ADC_Demo/Libraries/seekfree_libraries/common/common.h b/Example/ADC_Demo/Libraries/seekfree_libraries/common/common.h index 84c43ee..5b741c0 100644 --- a/Example/ADC_Demo/Libraries/seekfree_libraries/common/common.h +++ b/Example/ADC_Demo/Libraries/seekfree_libraries/common/common.h @@ -113,6 +113,12 @@ typedef enum //枚 CAMERA_COLOR, //凌瞳 }CAMERA_TYPE_enum; +typedef enum //无线模块 +{ + WIRELESS_SI24R1 = 1, //无线转串口 + WIRELESS_CH9141, //蓝牙转串口 +}WIRELESS_TYPE_enum; + #include #include #include "IfxCpu.h" @@ -120,6 +126,8 @@ typedef enum //枚 extern CAMERA_TYPE_enum camera_type; //摄像头型号 extern uint8 *camera_buffer_addr; //摄像头数组地址 +extern WIRELESS_TYPE_enum wireless_type; + extern IfxCpu_syncEvent g_cpuSyncEvent; void get_clk(void); diff --git a/Example/ADC_Demo/Libraries/seekfree_libraries/headfile.h b/Example/ADC_Demo/Libraries/seekfree_libraries/headfile.h index 404ee0a..b745302 100644 --- a/Example/ADC_Demo/Libraries/seekfree_libraries/headfile.h +++ b/Example/ADC_Demo/Libraries/seekfree_libraries/headfile.h @@ -65,6 +65,7 @@ #include "SEEKFREE_7725.h" #include "SEEKFREE_RDA5807.h" #include "SEEKFREE_7725_UART.h" +#include "SEEKFREE_BLUETOOTH_CH9141.h" #endif diff --git a/Example/ADC_Demo/Libraries/seekfree_peripheral/SEEKFREE_BLUETOOTH_CH9141.c b/Example/ADC_Demo/Libraries/seekfree_peripheral/SEEKFREE_BLUETOOTH_CH9141.c new file mode 100644 index 0000000..b4ec2df --- /dev/null +++ b/Example/ADC_Demo/Libraries/seekfree_peripheral/SEEKFREE_BLUETOOTH_CH9141.c @@ -0,0 +1,509 @@ +/********************************************************************************************************************* + * COPYRIGHT NOTICE + * Copyright (c) 2021,逐飞科技 + * All rights reserved. + * 技术讨论QQ群:一群:179029047(已满) 二群:244861897 + * + * 以下所有内容版权均属逐飞科技所有,未经允许不得用于商业用途, + * 欢迎各位使用并传播本程序,修改内容时必须保留逐飞科技的版权声明。 + * + * @file 逐飞科技蓝牙转串口模块 + * @company 成都逐飞科技有限公司 + * @author 逐飞科技(QQ3184284598) + * @version 查看doc内version文件 版本说明 + * @Software IAR 8.3 or MDK 5.33 + * @Taobao https://seekfree.taobao.com/ + * @date 2021-08-27 + * @note + 接线定义: + ------------------------------------ + 蓝牙转串口 单片机 + RX 查看SEEKFREE_BLUETOOTH_CH9141.h文件中的BLUETOOTH_CH9141_UART_TX宏定义 + TX 查看SEEKFREE_BLUETOOTH_CH9141.h文件中的BLUETOOTH_CH9141_UART_RX宏定义 + RTS 查看SEEKFREE_BLUETOOTH_CH9141.h文件中的BLUETOOTH_CH9141_RTS_PIN宏定义 + CTS 悬空 + CMD 悬空或者上拉 + ------------------------------------ + ********************************************************************************************************************/ +#include "zf_stm_systick.h" +#include "zf_gpio.h" +#include "zf_uart.h" +#include "zf_assert.h" +#include "SEEKFREE_BLUETOOTH_CH9141.h" + +uint8 uart_flag; +uint8 uart_data; + +vuint8 at_mode = 0; //0:蓝牙透传模式 1:AT模式 2:模块复位中 +vuint8 at_mode_num; //at模式时用于指示数据接收的数量 +vuint8 at_mode_data[30]; //接收at命令的缓存 +vuint8 at_mode_cmd_flag; //OK应答命令接收成功的标志位 + +uint8 mac_address[17]; //本机mac地址 + + +uint8 bluetooth_ch9141_rx_buffer; + + +void bluetooth_ch9141_check_response(void); + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块 串口中断回调函数 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note 该函数在ISR文件 串口8中断程序被调用 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_uart_callback() +{ + while(uart_query(BLUETOOTH_CH9141_UART, &bluetooth_ch9141_rx_buffer)) + { + if(1 == at_mode) + { + //进入AT模式 接收应答信号 此处if语句内代码用户不要改动 + at_mode_data[at_mode_num++] = bluetooth_ch9141_rx_buffer; + bluetooth_ch9141_check_response(); + } + else if(2 == at_mode) + { + //模块正在复位中 此处if语句内代码用户不要改动 + at_mode_num++; + } + else + { + //透传模式 用户在此处接收配对的蓝牙发送过来的额数据 + //接到一个字节后单片机将会进入此处,通过在此处读取bluetooth_ch9141_rx_buffer可以取走数据 + + // 读取无线串口的数据 并且置位接收标志 + uart_flag = 1; + uart_data = bluetooth_ch9141_rx_buffer; + } + + } +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块检查OK应答信号 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_check_response(void) +{ + if(4 <= at_mode_num) + { + if(0 == strncmp("OK\r\n", (int8 *)&at_mode_data[at_mode_num-4], 4)) + { + at_mode_cmd_flag = 1; + } + } +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块发送一个没有参数的命令并等待应答信号 +// @param *str 需要发送的命令 完整字符串 +// @return void +// @since v1.0 +// Sample usage: +// @note 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_send_at_command(const int8 *str) +{ + at_mode_num = 0; //接收数量清零 + uart_putstr(BLUETOOTH_CH9141_UART, str); + uart_putstr(BLUETOOTH_CH9141_UART, "\r\n"); + + //等待收到应答信号 + while(!at_mode_cmd_flag); + at_mode_cmd_flag = 0; +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块发送一个带有参数的命令并等待应答信号 +// @param *cmd 需要发送的命令名称 +// @param *data 需要发送的数据 +// @return void +// @since v1.0 +// Sample usage: +// @note 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_send_at_command_parameter(const int8 *cmd, const int8 *data) +{ + at_mode_num = 0; //接收数量清零 + uart_putstr(BLUETOOTH_CH9141_UART, "AT+"); + uart_putstr(BLUETOOTH_CH9141_UART, cmd); + uart_putstr(BLUETOOTH_CH9141_UART, "="); + uart_putstr(BLUETOOTH_CH9141_UART, data); + uart_putstr(BLUETOOTH_CH9141_UART, "\r\n"); + + //等待收到应答信号 + while(!at_mode_cmd_flag); + at_mode_cmd_flag = 0; +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块进入AT模式 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_enter_at_mode(void) +{ + systick_delay_ms(STM0, 550); //发送进入AT模式的命令前需要保证模块在550ms内没有接收过任何数据 + at_mode = 1; //进入AT模式 + bluetooth_ch9141_send_at_command("AT..."); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块退出AT模式 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_exit_at_mode(void) +{ + bluetooth_ch9141_send_at_command("AT+EXIT"); + at_mode = 0; //进入透传模式 + systick_delay_ms(STM0, 300); //等待成功进入AT模式 +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块复位 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_reset(void) +{ + bluetooth_ch9141_send_at_command("AT+RESET"); + at_mode = 2; //进入重启成功检测 + at_mode_num = 0; + while(7 > at_mode_num); //等待蓝牙模块完成复位 + at_mode = 0; //复位之后模块自动进入透传模式 +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块获取本机MAC地址 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note 调用此函数需要先调用bluetooth_ch9141_enter_at_mode或者拉低CMD引脚 进入AT模式 +// 需要特别注意bluetooth_ch9141_enter_at_mode函数内部有500ms的延时 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_get_mac_address(void) +{ + bluetooth_ch9141_send_at_command("AT+MAC?"); + + //mac地址为小段格式,mac_address[0]保存的是mac地址最低位 + memcpy(mac_address, (uint8 *)at_mode_data, 17); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块设置发送功率 +// @param tx_power 设置发送功率,可设置选项查看CH9141_TX_POWEER_enum枚举成员 +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_set_tx_power(CH9141_TX_POWEER_enum tx_power) +{ + int8 tx_power_data; + + tx_power_data = (uint8)tx_power + '0'; + bluetooth_ch9141_send_at_command_parameter("TPL", &tx_power_data); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块设置模式 +// @param mode 模式设置,可设置选项查看CH9141_MODE_enum枚举成员 +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_set_mode(CH9141_MODE_enum mode) +{ + int8 mode_data; + + mode_data = (uint8)mode + '0'; + bluetooth_ch9141_send_at_command_parameter("BLEMODE", &mode_data); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块获取状态 +// @param mode 模式设置,可设置选项查看CH9141_MODE_enum枚举成员 +// @return CH9141_STATUS_enum 返回状态信息 +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +CH9141_STATUS_enum bluetooth_ch9141_get_status(CH9141_MODE_enum mode) +{ + CH9141_STATUS_enum ch9141_status; + int8 mode_data; + + mode_data = (uint8)mode + '0'; + bluetooth_ch9141_send_at_command_parameter("BLEMODE", &mode_data); + + bluetooth_ch9141_send_at_command("AT+BLESTA?"); + + ch9141_status = (at_mode_data[0] - '0') * 10 + (at_mode_data[1] - '0'); + if(SLAVE_MODE == mode) + { + ch9141_status += SLAVE_NO_INIT; + } + + return ch9141_status; +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块设置设备名称 +// @param *str 蓝牙名称 +// @return void +// @since v1.0 +// Sample usage: +// @note 名称长度不能超过18个字符 且只能为英文与数字 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_set_name(const int8 *str) +{ + bluetooth_ch9141_send_at_command_parameter("NAME", str); + bluetooth_ch9141_send_at_command_parameter("PNAME", str); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块密码设置 +// @param enable 使能密码 0:不使用密码,1:使用密码才能连接本设备 +// @param *password 密码的字符串 必须为6个字符 +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_set_password(uint8 enable, const int8 *password) +{ + if(0 == enable) + { + //关闭密码 + bluetooth_ch9141_send_at_command_parameter("PASEN", "OFF"); + } + else + { + //设置密码并使能 + bluetooth_ch9141_send_at_command_parameter("PASEN", "ON"); + bluetooth_ch9141_send_at_command_parameter("PASS", password); + } +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块指定MAC地址并立即进行连接 +// @param *mac_and_password 需要连接的设备mac地址与密码 +// @return void +// @since v1.0 +// Sample usage: +// @note bluetooth_ch9141_connect("58:B7:33:E4:C2:84,000000"); +// 58:B7:33:E4:C2:84为mac地址 ,为分隔符 000000为从机蓝牙密码 +// ===================特别注意================== +// 如果使用手机查看蓝牙的mac地址,则使用本函数连接的时候请将mac倒置一下 +// 例如手机查看到的mac地址为61:62:63:64:65:66,则使用本函数连接的时候应该写 +// bluetooth_ch9141_connect("66:65:64:63:62:61,000000"); +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_connect(const int8 *mac_and_password) +{ + bluetooth_ch9141_send_at_command_parameter("CONN", mac_and_password); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块默认连接参数设置(设置好后,每次开机蓝牙会自动链接这个设备) +// @param *mac_and_password 需要连接的设备mac地址与密码 +// @return void +// @since v1.0 +// Sample usage: +// @note bluetooth_ch9141_default_connect("58:B7:33:E4:C2:84,000000"); +// 58:B7:33:E4:C2:84为mac地址 ,为分隔符 000000为从机蓝牙密码 +// ===================特别注意================== +// 如果使用手机查看CH9141的mac地址,将CH9141设置为从机,使用手机连接 +// 则使用本函数连接的时候请将mac倒置一下 +// 例如手机查看到的mac地址为61:62:63:64:65:67,则使用本函数连接的时候应该写 +// bluetooth_ch9141_default_connect("67:65:64:63:62:61,000000"); +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_default_connect(const int8 *mac_and_password) +{ + bluetooth_ch9141_send_at_command_parameter("CONADD", mac_and_password); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块获取rssi(信号强度) +// @param void +// @return int8 返回信号强度0到-127 +// @since v1.0 +// Sample usage: +// @note 调用此函数需要先调用bluetooth_ch9141_enter_at_mode或者拉低CMD引脚 进入AT模式 +// 需要特别注意bluetooth_ch9141_enter_at_mode函数内部有500ms的延时 +//------------------------------------------------------------------------------------------------------------------- +int16 bluetooth_ch9141_get_rssi(void) +{ + uint8 i; + size_t length; + int16 rssi; + bluetooth_ch9141_send_at_command_parameter("RSSI", "ON,0"); + length = strlen((int8 *)at_mode_data); + length -= 12;//计算RSSI 有多少位 + + rssi = 0; + for(i=0; i30) { - if(gpio_get(RTS_PIN)) - { - return len;//模块忙,如果允许当前程序使用while等待 则可以使用后面注释的while等待语句替换本if语句 - } - //while(gpio_get(RTS_PIN)); //如果RTS为低电平,则继续发送数据 +// if(gpio_get(RTS_PIN)) +// { +// return len;//模块忙,如果允许当前程序使用while等待 则可以使用后面注释的while等待语句替换本if语句 +// } + while(gpio_get(RTS_PIN)); //如果RTS为低电平,则继续发送数据 uart_putbuff(WIRELESS_UART,buff,30); buff += 30; //地址偏移 len -= 30;//数量 } - if(gpio_get(RTS_PIN)) - { - return len;//模块忙,如果允许当前程序使用while等待 则可以使用后面注释的while等待语句替换本if语句 - } - //while(gpio_get(RTS_PIN)); //如果RTS为低电平,则继续发送数据 +// if(gpio_get(RTS_PIN)) +// { +// return len;//模块忙,如果允许当前程序使用while等待 则可以使用后面注释的while等待语句替换本if语句 +// } + while(gpio_get(RTS_PIN)); //如果RTS为低电平,则继续发送数据 uart_putbuff(WIRELESS_UART,buff,len);//发送最后的数据 return 0; diff --git a/Example/ADC_Demo/Libraries/seekfree_peripheral/SEEKFREE_WIRELESS.h b/Example/ADC_Demo/Libraries/seekfree_peripheral/SEEKFREE_WIRELESS.h index 42c0832..d80339d 100644 --- a/Example/ADC_Demo/Libraries/seekfree_peripheral/SEEKFREE_WIRELESS.h +++ b/Example/ADC_Demo/Libraries/seekfree_peripheral/SEEKFREE_WIRELESS.h @@ -38,8 +38,26 @@ #define WIRELESS_UART_RX UART2_RX_P10_6 #define WIRELESS_UART_BAUD 115200 -#define RTS_PIN P10_2 //定义流控位引脚 指示当前模块是否可以接受数据 0可以继续接收 1不可以继续接收 +// ------------------------------------ 自动波特率 ------------------------------------ +// 注意事项1:无线转串口模块版本是V2.0以下的是无法开启自动波特率的。 +// 注意事项2:开启自动波特率务必连接RTS引脚,否则会开启失败。 +// 注意事项3:模块自动波特率失败的话,可以尝试断电重启 +// 开启自动波特率务必阅读上面两条 注意事项 +// 开启自动波特率务必阅读上面两条 注意事项 +// 开启自动波特率务必阅读上面两条 注意事项 + +// 0:关闭自动波特率 +// 1:开启自动波特率 自动波特率的作用是修改WIRELESS_UART_BAUD之后不需要对模块进行配置,模块会自动设置为对应的波特率 + +#define WIRELESS_AUTO_UART_BAUD 0 +// ------------------------------------ 自动波特率 ------------------------------------ + +#define RTS_PIN P10_2 //定义流控位引脚 指示当前模块是否可以接受数据 0可以继续接收 1不可以继续接收 +#define WIRELESS_BUFFER_SIZE 16 + +extern uint8 wireless_send_buffer[WIRELESS_BUFFER_SIZE]; +extern uint32 wireless_rx_index; void wireless_uart_callback(void); void seekfree_wireless_init(void); diff --git a/Example/ADC_Demo/USER/isr.c b/Example/ADC_Demo/USER/isr.c index c55a012..16bff98 100644 --- a/Example/ADC_Demo/USER/isr.c +++ b/Example/ADC_Demo/USER/isr.c @@ -179,7 +179,20 @@ IFX_INTERRUPT(uart2_rx_isr, 0, UART2_RX_INT_PRIO) { enableInterrupts();//开启中断嵌套 IfxAsclin_Asc_isrReceive(&uart2_handle); - wireless_uart_callback(); + switch(wireless_type) + { + case WIRELESS_SI24R1: + { + wireless_uart_callback(); + }break; + + case WIRELESS_CH9141: + { + bluetooth_ch9141_uart_callback(); + }break; + default:break; + } + } IFX_INTERRUPT(uart2_er_isr, 0, UART2_ER_INT_PRIO) { diff --git a/Example/ADC_Demo/鍒犻櫎涓存椂鏂囦欢.bat b/Example/ADC_Demo/鍒犻櫎涓存椂鏂囦欢.bat index 5323dd9..fa499b1 100644 --- a/Example/ADC_Demo/鍒犻櫎涓存椂鏂囦欢.bat +++ b/Example/ADC_Demo/鍒犻櫎涓存椂鏂囦欢.bat @@ -1,9 +1,6 @@ -rmdir .settings /s /q rmdir Debug /s /q del *.launch /s - -pause exit diff --git a/Example/Cpu1_Handles_Interrupts_Demo/.cproject b/Example/Cpu1_Handles_Interrupts_Demo/.cproject index cd881a9..a61c5fc 100644 --- a/Example/Cpu1_Handles_Interrupts_Demo/.cproject +++ b/Example/Cpu1_Handles_Interrupts_Demo/.cproject @@ -3,9 +3,9 @@ - + - + @@ -25,50 +25,76 @@ - + - + - + - + + + + + + @@ -355,9 +371,9 @@ - + - + @@ -377,43 +393,1895 @@ - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -431,13 +2299,37 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + @@ -458,21 +2350,5 @@ - - - - - - - - - - - - - - - - diff --git a/Example/Cpu1_Handles_Interrupts_Demo/.project b/Example/Cpu1_Handles_Interrupts_Demo/.project index fd3a5ef..e482dad 100644 --- a/Example/Cpu1_Handles_Interrupts_Demo/.project +++ b/Example/Cpu1_Handles_Interrupts_Demo/.project @@ -5,6 +5,18 @@ + + com.infineon.aurix.buildsystem.builders.booster + full,incremental, + + + + + com.infineon.aurix.buildsystem.builders.autodiscovery + full,incremental, + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder clean,full,incremental, diff --git a/Example/Cpu1_Handles_Interrupts_Demo/.settings/com.infineon.aurix.buildsystem.prefs b/Example/Cpu1_Handles_Interrupts_Demo/.settings/com.infineon.aurix.buildsystem.prefs new file mode 100644 index 0000000..be61bc1 --- /dev/null +++ b/Example/Cpu1_Handles_Interrupts_Demo/.settings/com.infineon.aurix.buildsystem.prefs @@ -0,0 +1,10 @@ +AURIX-LIBRARY-PATH=Libraries/iLLD\#Libraries/Infra\#Libraries/Service +DEVICE-ID=TC26B +DEVICE-ID-FULL=TC26xD_B-Step +ILLD-SET=full +IncludesAutodiscovery=true +LIBRARIES-ROOT-PATH=Libraries +NEVER-EXCLUDE-FROM-BUILD=/Libraries/iLLD/TC26B/Tricore/Cpu/CStart\#/Libraries/iLLD/TC26B/Tricore/Cpu/Trap\#/Configurations\#/Configurations/Debug +PROJECT-VERSION=1.0 +aurixDevice=TC26xD_B-Step +eclipse.preferences.version=1 diff --git a/Example/Cpu1_Handles_Interrupts_Demo/Libraries/doc/version.txt b/Example/Cpu1_Handles_Interrupts_Demo/Libraries/doc/version.txt index ab79909..11ab82e 100644 --- a/Example/Cpu1_Handles_Interrupts_Demo/Libraries/doc/version.txt +++ b/Example/Cpu1_Handles_Interrupts_Demo/Libraries/doc/version.txt @@ -1,3 +1,13 @@ +V1.2.0 + 增加CH9141蓝牙转串口模块的驱动 + 添加无线类型的枚举变量 + 修改 删除临时文件.bat 执行完操作后自动关闭窗口 + 修改 删除临时文件.bat 避免删除新版本所需文件 + 修改工程项目文件,以支持新版本编译 + +V1.1.10 + 修复通过#pragma section all "cpux_dsram"指定变量位置失效的问题 + V1.1.9 将串口的发送buff增加到128字节 diff --git a/Example/Cpu1_Handles_Interrupts_Demo/Libraries/seekfree_libraries/common/common.c b/Example/Cpu1_Handles_Interrupts_Demo/Libraries/seekfree_libraries/common/common.c index 0b9931e..7620ce6 100644 --- a/Example/Cpu1_Handles_Interrupts_Demo/Libraries/seekfree_libraries/common/common.c +++ b/Example/Cpu1_Handles_Interrupts_Demo/Libraries/seekfree_libraries/common/common.c @@ -27,6 +27,8 @@ CAMERA_TYPE_enum camera_type; //摄像头型号 uint8 *camera_buffer_addr; //摄像头数组地址 +WIRELESS_TYPE_enum wireless_type;//无线转串口类型 + IFX_ALIGN(4) IfxCpu_syncEvent g_cpuSyncEvent = 0;//事件同步变量 App_Cpu0 g_AppCpu0; //频率信息变量 diff --git a/Example/Cpu1_Handles_Interrupts_Demo/Libraries/seekfree_libraries/common/common.h b/Example/Cpu1_Handles_Interrupts_Demo/Libraries/seekfree_libraries/common/common.h index 84c43ee..5b741c0 100644 --- a/Example/Cpu1_Handles_Interrupts_Demo/Libraries/seekfree_libraries/common/common.h +++ b/Example/Cpu1_Handles_Interrupts_Demo/Libraries/seekfree_libraries/common/common.h @@ -113,6 +113,12 @@ typedef enum //枚 CAMERA_COLOR, //凌瞳 }CAMERA_TYPE_enum; +typedef enum //无线模块 +{ + WIRELESS_SI24R1 = 1, //无线转串口 + WIRELESS_CH9141, //蓝牙转串口 +}WIRELESS_TYPE_enum; + #include #include #include "IfxCpu.h" @@ -120,6 +126,8 @@ typedef enum //枚 extern CAMERA_TYPE_enum camera_type; //摄像头型号 extern uint8 *camera_buffer_addr; //摄像头数组地址 +extern WIRELESS_TYPE_enum wireless_type; + extern IfxCpu_syncEvent g_cpuSyncEvent; void get_clk(void); diff --git a/Example/Cpu1_Handles_Interrupts_Demo/Libraries/seekfree_libraries/headfile.h b/Example/Cpu1_Handles_Interrupts_Demo/Libraries/seekfree_libraries/headfile.h index 404ee0a..b745302 100644 --- a/Example/Cpu1_Handles_Interrupts_Demo/Libraries/seekfree_libraries/headfile.h +++ b/Example/Cpu1_Handles_Interrupts_Demo/Libraries/seekfree_libraries/headfile.h @@ -65,6 +65,7 @@ #include "SEEKFREE_7725.h" #include "SEEKFREE_RDA5807.h" #include "SEEKFREE_7725_UART.h" +#include "SEEKFREE_BLUETOOTH_CH9141.h" #endif diff --git a/Example/Cpu1_Handles_Interrupts_Demo/Libraries/seekfree_peripheral/SEEKFREE_BLUETOOTH_CH9141.c b/Example/Cpu1_Handles_Interrupts_Demo/Libraries/seekfree_peripheral/SEEKFREE_BLUETOOTH_CH9141.c new file mode 100644 index 0000000..b4ec2df --- /dev/null +++ b/Example/Cpu1_Handles_Interrupts_Demo/Libraries/seekfree_peripheral/SEEKFREE_BLUETOOTH_CH9141.c @@ -0,0 +1,509 @@ +/********************************************************************************************************************* + * COPYRIGHT NOTICE + * Copyright (c) 2021,逐飞科技 + * All rights reserved. + * 技术讨论QQ群:一群:179029047(已满) 二群:244861897 + * + * 以下所有内容版权均属逐飞科技所有,未经允许不得用于商业用途, + * 欢迎各位使用并传播本程序,修改内容时必须保留逐飞科技的版权声明。 + * + * @file 逐飞科技蓝牙转串口模块 + * @company 成都逐飞科技有限公司 + * @author 逐飞科技(QQ3184284598) + * @version 查看doc内version文件 版本说明 + * @Software IAR 8.3 or MDK 5.33 + * @Taobao https://seekfree.taobao.com/ + * @date 2021-08-27 + * @note + 接线定义: + ------------------------------------ + 蓝牙转串口 单片机 + RX 查看SEEKFREE_BLUETOOTH_CH9141.h文件中的BLUETOOTH_CH9141_UART_TX宏定义 + TX 查看SEEKFREE_BLUETOOTH_CH9141.h文件中的BLUETOOTH_CH9141_UART_RX宏定义 + RTS 查看SEEKFREE_BLUETOOTH_CH9141.h文件中的BLUETOOTH_CH9141_RTS_PIN宏定义 + CTS 悬空 + CMD 悬空或者上拉 + ------------------------------------ + ********************************************************************************************************************/ +#include "zf_stm_systick.h" +#include "zf_gpio.h" +#include "zf_uart.h" +#include "zf_assert.h" +#include "SEEKFREE_BLUETOOTH_CH9141.h" + +uint8 uart_flag; +uint8 uart_data; + +vuint8 at_mode = 0; //0:蓝牙透传模式 1:AT模式 2:模块复位中 +vuint8 at_mode_num; //at模式时用于指示数据接收的数量 +vuint8 at_mode_data[30]; //接收at命令的缓存 +vuint8 at_mode_cmd_flag; //OK应答命令接收成功的标志位 + +uint8 mac_address[17]; //本机mac地址 + + +uint8 bluetooth_ch9141_rx_buffer; + + +void bluetooth_ch9141_check_response(void); + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块 串口中断回调函数 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note 该函数在ISR文件 串口8中断程序被调用 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_uart_callback() +{ + while(uart_query(BLUETOOTH_CH9141_UART, &bluetooth_ch9141_rx_buffer)) + { + if(1 == at_mode) + { + //进入AT模式 接收应答信号 此处if语句内代码用户不要改动 + at_mode_data[at_mode_num++] = bluetooth_ch9141_rx_buffer; + bluetooth_ch9141_check_response(); + } + else if(2 == at_mode) + { + //模块正在复位中 此处if语句内代码用户不要改动 + at_mode_num++; + } + else + { + //透传模式 用户在此处接收配对的蓝牙发送过来的额数据 + //接到一个字节后单片机将会进入此处,通过在此处读取bluetooth_ch9141_rx_buffer可以取走数据 + + // 读取无线串口的数据 并且置位接收标志 + uart_flag = 1; + uart_data = bluetooth_ch9141_rx_buffer; + } + + } +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块检查OK应答信号 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_check_response(void) +{ + if(4 <= at_mode_num) + { + if(0 == strncmp("OK\r\n", (int8 *)&at_mode_data[at_mode_num-4], 4)) + { + at_mode_cmd_flag = 1; + } + } +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块发送一个没有参数的命令并等待应答信号 +// @param *str 需要发送的命令 完整字符串 +// @return void +// @since v1.0 +// Sample usage: +// @note 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_send_at_command(const int8 *str) +{ + at_mode_num = 0; //接收数量清零 + uart_putstr(BLUETOOTH_CH9141_UART, str); + uart_putstr(BLUETOOTH_CH9141_UART, "\r\n"); + + //等待收到应答信号 + while(!at_mode_cmd_flag); + at_mode_cmd_flag = 0; +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块发送一个带有参数的命令并等待应答信号 +// @param *cmd 需要发送的命令名称 +// @param *data 需要发送的数据 +// @return void +// @since v1.0 +// Sample usage: +// @note 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_send_at_command_parameter(const int8 *cmd, const int8 *data) +{ + at_mode_num = 0; //接收数量清零 + uart_putstr(BLUETOOTH_CH9141_UART, "AT+"); + uart_putstr(BLUETOOTH_CH9141_UART, cmd); + uart_putstr(BLUETOOTH_CH9141_UART, "="); + uart_putstr(BLUETOOTH_CH9141_UART, data); + uart_putstr(BLUETOOTH_CH9141_UART, "\r\n"); + + //等待收到应答信号 + while(!at_mode_cmd_flag); + at_mode_cmd_flag = 0; +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块进入AT模式 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_enter_at_mode(void) +{ + systick_delay_ms(STM0, 550); //发送进入AT模式的命令前需要保证模块在550ms内没有接收过任何数据 + at_mode = 1; //进入AT模式 + bluetooth_ch9141_send_at_command("AT..."); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块退出AT模式 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_exit_at_mode(void) +{ + bluetooth_ch9141_send_at_command("AT+EXIT"); + at_mode = 0; //进入透传模式 + systick_delay_ms(STM0, 300); //等待成功进入AT模式 +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块复位 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_reset(void) +{ + bluetooth_ch9141_send_at_command("AT+RESET"); + at_mode = 2; //进入重启成功检测 + at_mode_num = 0; + while(7 > at_mode_num); //等待蓝牙模块完成复位 + at_mode = 0; //复位之后模块自动进入透传模式 +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块获取本机MAC地址 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note 调用此函数需要先调用bluetooth_ch9141_enter_at_mode或者拉低CMD引脚 进入AT模式 +// 需要特别注意bluetooth_ch9141_enter_at_mode函数内部有500ms的延时 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_get_mac_address(void) +{ + bluetooth_ch9141_send_at_command("AT+MAC?"); + + //mac地址为小段格式,mac_address[0]保存的是mac地址最低位 + memcpy(mac_address, (uint8 *)at_mode_data, 17); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块设置发送功率 +// @param tx_power 设置发送功率,可设置选项查看CH9141_TX_POWEER_enum枚举成员 +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_set_tx_power(CH9141_TX_POWEER_enum tx_power) +{ + int8 tx_power_data; + + tx_power_data = (uint8)tx_power + '0'; + bluetooth_ch9141_send_at_command_parameter("TPL", &tx_power_data); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块设置模式 +// @param mode 模式设置,可设置选项查看CH9141_MODE_enum枚举成员 +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_set_mode(CH9141_MODE_enum mode) +{ + int8 mode_data; + + mode_data = (uint8)mode + '0'; + bluetooth_ch9141_send_at_command_parameter("BLEMODE", &mode_data); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块获取状态 +// @param mode 模式设置,可设置选项查看CH9141_MODE_enum枚举成员 +// @return CH9141_STATUS_enum 返回状态信息 +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +CH9141_STATUS_enum bluetooth_ch9141_get_status(CH9141_MODE_enum mode) +{ + CH9141_STATUS_enum ch9141_status; + int8 mode_data; + + mode_data = (uint8)mode + '0'; + bluetooth_ch9141_send_at_command_parameter("BLEMODE", &mode_data); + + bluetooth_ch9141_send_at_command("AT+BLESTA?"); + + ch9141_status = (at_mode_data[0] - '0') * 10 + (at_mode_data[1] - '0'); + if(SLAVE_MODE == mode) + { + ch9141_status += SLAVE_NO_INIT; + } + + return ch9141_status; +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块设置设备名称 +// @param *str 蓝牙名称 +// @return void +// @since v1.0 +// Sample usage: +// @note 名称长度不能超过18个字符 且只能为英文与数字 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_set_name(const int8 *str) +{ + bluetooth_ch9141_send_at_command_parameter("NAME", str); + bluetooth_ch9141_send_at_command_parameter("PNAME", str); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块密码设置 +// @param enable 使能密码 0:不使用密码,1:使用密码才能连接本设备 +// @param *password 密码的字符串 必须为6个字符 +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_set_password(uint8 enable, const int8 *password) +{ + if(0 == enable) + { + //关闭密码 + bluetooth_ch9141_send_at_command_parameter("PASEN", "OFF"); + } + else + { + //设置密码并使能 + bluetooth_ch9141_send_at_command_parameter("PASEN", "ON"); + bluetooth_ch9141_send_at_command_parameter("PASS", password); + } +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块指定MAC地址并立即进行连接 +// @param *mac_and_password 需要连接的设备mac地址与密码 +// @return void +// @since v1.0 +// Sample usage: +// @note bluetooth_ch9141_connect("58:B7:33:E4:C2:84,000000"); +// 58:B7:33:E4:C2:84为mac地址 ,为分隔符 000000为从机蓝牙密码 +// ===================特别注意================== +// 如果使用手机查看蓝牙的mac地址,则使用本函数连接的时候请将mac倒置一下 +// 例如手机查看到的mac地址为61:62:63:64:65:66,则使用本函数连接的时候应该写 +// bluetooth_ch9141_connect("66:65:64:63:62:61,000000"); +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_connect(const int8 *mac_and_password) +{ + bluetooth_ch9141_send_at_command_parameter("CONN", mac_and_password); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块默认连接参数设置(设置好后,每次开机蓝牙会自动链接这个设备) +// @param *mac_and_password 需要连接的设备mac地址与密码 +// @return void +// @since v1.0 +// Sample usage: +// @note bluetooth_ch9141_default_connect("58:B7:33:E4:C2:84,000000"); +// 58:B7:33:E4:C2:84为mac地址 ,为分隔符 000000为从机蓝牙密码 +// ===================特别注意================== +// 如果使用手机查看CH9141的mac地址,将CH9141设置为从机,使用手机连接 +// 则使用本函数连接的时候请将mac倒置一下 +// 例如手机查看到的mac地址为61:62:63:64:65:67,则使用本函数连接的时候应该写 +// bluetooth_ch9141_default_connect("67:65:64:63:62:61,000000"); +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_default_connect(const int8 *mac_and_password) +{ + bluetooth_ch9141_send_at_command_parameter("CONADD", mac_and_password); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块获取rssi(信号强度) +// @param void +// @return int8 返回信号强度0到-127 +// @since v1.0 +// Sample usage: +// @note 调用此函数需要先调用bluetooth_ch9141_enter_at_mode或者拉低CMD引脚 进入AT模式 +// 需要特别注意bluetooth_ch9141_enter_at_mode函数内部有500ms的延时 +//------------------------------------------------------------------------------------------------------------------- +int16 bluetooth_ch9141_get_rssi(void) +{ + uint8 i; + size_t length; + int16 rssi; + bluetooth_ch9141_send_at_command_parameter("RSSI", "ON,0"); + length = strlen((int8 *)at_mode_data); + length -= 12;//计算RSSI 有多少位 + + rssi = 0; + for(i=0; i30) { - if(gpio_get(RTS_PIN)) - { - return len;//模块忙,如果允许当前程序使用while等待 则可以使用后面注释的while等待语句替换本if语句 - } - //while(gpio_get(RTS_PIN)); //如果RTS为低电平,则继续发送数据 +// if(gpio_get(RTS_PIN)) +// { +// return len;//模块忙,如果允许当前程序使用while等待 则可以使用后面注释的while等待语句替换本if语句 +// } + while(gpio_get(RTS_PIN)); //如果RTS为低电平,则继续发送数据 uart_putbuff(WIRELESS_UART,buff,30); buff += 30; //地址偏移 len -= 30;//数量 } - if(gpio_get(RTS_PIN)) - { - return len;//模块忙,如果允许当前程序使用while等待 则可以使用后面注释的while等待语句替换本if语句 - } - //while(gpio_get(RTS_PIN)); //如果RTS为低电平,则继续发送数据 +// if(gpio_get(RTS_PIN)) +// { +// return len;//模块忙,如果允许当前程序使用while等待 则可以使用后面注释的while等待语句替换本if语句 +// } + while(gpio_get(RTS_PIN)); //如果RTS为低电平,则继续发送数据 uart_putbuff(WIRELESS_UART,buff,len);//发送最后的数据 return 0; diff --git a/Example/Cpu1_Handles_Interrupts_Demo/Libraries/seekfree_peripheral/SEEKFREE_WIRELESS.h b/Example/Cpu1_Handles_Interrupts_Demo/Libraries/seekfree_peripheral/SEEKFREE_WIRELESS.h index 42c0832..d80339d 100644 --- a/Example/Cpu1_Handles_Interrupts_Demo/Libraries/seekfree_peripheral/SEEKFREE_WIRELESS.h +++ b/Example/Cpu1_Handles_Interrupts_Demo/Libraries/seekfree_peripheral/SEEKFREE_WIRELESS.h @@ -38,8 +38,26 @@ #define WIRELESS_UART_RX UART2_RX_P10_6 #define WIRELESS_UART_BAUD 115200 -#define RTS_PIN P10_2 //定义流控位引脚 指示当前模块是否可以接受数据 0可以继续接收 1不可以继续接收 +// ------------------------------------ 自动波特率 ------------------------------------ +// 注意事项1:无线转串口模块版本是V2.0以下的是无法开启自动波特率的。 +// 注意事项2:开启自动波特率务必连接RTS引脚,否则会开启失败。 +// 注意事项3:模块自动波特率失败的话,可以尝试断电重启 +// 开启自动波特率务必阅读上面两条 注意事项 +// 开启自动波特率务必阅读上面两条 注意事项 +// 开启自动波特率务必阅读上面两条 注意事项 + +// 0:关闭自动波特率 +// 1:开启自动波特率 自动波特率的作用是修改WIRELESS_UART_BAUD之后不需要对模块进行配置,模块会自动设置为对应的波特率 + +#define WIRELESS_AUTO_UART_BAUD 0 +// ------------------------------------ 自动波特率 ------------------------------------ + +#define RTS_PIN P10_2 //定义流控位引脚 指示当前模块是否可以接受数据 0可以继续接收 1不可以继续接收 +#define WIRELESS_BUFFER_SIZE 16 + +extern uint8 wireless_send_buffer[WIRELESS_BUFFER_SIZE]; +extern uint32 wireless_rx_index; void wireless_uart_callback(void); void seekfree_wireless_init(void); diff --git a/Example/Cpu1_Handles_Interrupts_Demo/USER/isr.c b/Example/Cpu1_Handles_Interrupts_Demo/USER/isr.c index 50acc67..42c2fc7 100644 --- a/Example/Cpu1_Handles_Interrupts_Demo/USER/isr.c +++ b/Example/Cpu1_Handles_Interrupts_Demo/USER/isr.c @@ -191,7 +191,20 @@ IFX_INTERRUPT(uart2_rx_isr, 0, UART2_RX_INT_PRIO) { enableInterrupts();//开启中断嵌套 IfxAsclin_Asc_isrReceive(&uart2_handle); - wireless_uart_callback(); + switch(wireless_type) + { + case WIRELESS_SI24R1: + { + wireless_uart_callback(); + }break; + + case WIRELESS_CH9141: + { + bluetooth_ch9141_uart_callback(); + }break; + default:break; + } + } IFX_INTERRUPT(uart2_er_isr, 0, UART2_ER_INT_PRIO) { diff --git a/Example/Cpu1_Handles_Interrupts_Demo/鍒犻櫎涓存椂鏂囦欢.bat b/Example/Cpu1_Handles_Interrupts_Demo/鍒犻櫎涓存椂鏂囦欢.bat index 5323dd9..fa499b1 100644 --- a/Example/Cpu1_Handles_Interrupts_Demo/鍒犻櫎涓存椂鏂囦欢.bat +++ b/Example/Cpu1_Handles_Interrupts_Demo/鍒犻櫎涓存椂鏂囦欢.bat @@ -1,9 +1,6 @@ -rmdir .settings /s /q rmdir Debug /s /q del *.launch /s - -pause exit diff --git a/Example/Dual_Core_Demo/.cproject b/Example/Dual_Core_Demo/.cproject index 095dede..95670fd 100644 --- a/Example/Dual_Core_Demo/.cproject +++ b/Example/Dual_Core_Demo/.cproject @@ -3,9 +3,9 @@ - + - + @@ -25,50 +25,76 @@ - + - + - + - + + + + + + @@ -355,9 +371,9 @@ - + - + @@ -377,43 +393,1895 @@ - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -431,13 +2299,37 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + @@ -458,21 +2350,5 @@ - - - - - - - - - - - - - - - - diff --git a/Example/Dual_Core_Demo/.project b/Example/Dual_Core_Demo/.project index 794dc2b..f5a2144 100644 --- a/Example/Dual_Core_Demo/.project +++ b/Example/Dual_Core_Demo/.project @@ -5,6 +5,18 @@ + + com.infineon.aurix.buildsystem.builders.booster + full,incremental, + + + + + com.infineon.aurix.buildsystem.builders.autodiscovery + full,incremental, + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder clean,full,incremental, diff --git a/Example/Dual_Core_Demo/.settings/com.infineon.aurix.buildsystem.prefs b/Example/Dual_Core_Demo/.settings/com.infineon.aurix.buildsystem.prefs new file mode 100644 index 0000000..be61bc1 --- /dev/null +++ b/Example/Dual_Core_Demo/.settings/com.infineon.aurix.buildsystem.prefs @@ -0,0 +1,10 @@ +AURIX-LIBRARY-PATH=Libraries/iLLD\#Libraries/Infra\#Libraries/Service +DEVICE-ID=TC26B +DEVICE-ID-FULL=TC26xD_B-Step +ILLD-SET=full +IncludesAutodiscovery=true +LIBRARIES-ROOT-PATH=Libraries +NEVER-EXCLUDE-FROM-BUILD=/Libraries/iLLD/TC26B/Tricore/Cpu/CStart\#/Libraries/iLLD/TC26B/Tricore/Cpu/Trap\#/Configurations\#/Configurations/Debug +PROJECT-VERSION=1.0 +aurixDevice=TC26xD_B-Step +eclipse.preferences.version=1 diff --git a/Example/Dual_Core_Demo/Libraries/doc/version.txt b/Example/Dual_Core_Demo/Libraries/doc/version.txt index ab79909..11ab82e 100644 --- a/Example/Dual_Core_Demo/Libraries/doc/version.txt +++ b/Example/Dual_Core_Demo/Libraries/doc/version.txt @@ -1,3 +1,13 @@ +V1.2.0 + 增加CH9141蓝牙转串口模块的驱动 + 添加无线类型的枚举变量 + 修改 删除临时文件.bat 执行完操作后自动关闭窗口 + 修改 删除临时文件.bat 避免删除新版本所需文件 + 修改工程项目文件,以支持新版本编译 + +V1.1.10 + 修复通过#pragma section all "cpux_dsram"指定变量位置失效的问题 + V1.1.9 将串口的发送buff增加到128字节 diff --git a/Example/Dual_Core_Demo/Libraries/seekfree_libraries/common/common.c b/Example/Dual_Core_Demo/Libraries/seekfree_libraries/common/common.c index 0b9931e..7620ce6 100644 --- a/Example/Dual_Core_Demo/Libraries/seekfree_libraries/common/common.c +++ b/Example/Dual_Core_Demo/Libraries/seekfree_libraries/common/common.c @@ -27,6 +27,8 @@ CAMERA_TYPE_enum camera_type; //摄像头型号 uint8 *camera_buffer_addr; //摄像头数组地址 +WIRELESS_TYPE_enum wireless_type;//无线转串口类型 + IFX_ALIGN(4) IfxCpu_syncEvent g_cpuSyncEvent = 0;//事件同步变量 App_Cpu0 g_AppCpu0; //频率信息变量 diff --git a/Example/Dual_Core_Demo/Libraries/seekfree_libraries/common/common.h b/Example/Dual_Core_Demo/Libraries/seekfree_libraries/common/common.h index 84c43ee..5b741c0 100644 --- a/Example/Dual_Core_Demo/Libraries/seekfree_libraries/common/common.h +++ b/Example/Dual_Core_Demo/Libraries/seekfree_libraries/common/common.h @@ -113,6 +113,12 @@ typedef enum //枚 CAMERA_COLOR, //凌瞳 }CAMERA_TYPE_enum; +typedef enum //无线模块 +{ + WIRELESS_SI24R1 = 1, //无线转串口 + WIRELESS_CH9141, //蓝牙转串口 +}WIRELESS_TYPE_enum; + #include #include #include "IfxCpu.h" @@ -120,6 +126,8 @@ typedef enum //枚 extern CAMERA_TYPE_enum camera_type; //摄像头型号 extern uint8 *camera_buffer_addr; //摄像头数组地址 +extern WIRELESS_TYPE_enum wireless_type; + extern IfxCpu_syncEvent g_cpuSyncEvent; void get_clk(void); diff --git a/Example/Dual_Core_Demo/Libraries/seekfree_libraries/headfile.h b/Example/Dual_Core_Demo/Libraries/seekfree_libraries/headfile.h index 404ee0a..b745302 100644 --- a/Example/Dual_Core_Demo/Libraries/seekfree_libraries/headfile.h +++ b/Example/Dual_Core_Demo/Libraries/seekfree_libraries/headfile.h @@ -65,6 +65,7 @@ #include "SEEKFREE_7725.h" #include "SEEKFREE_RDA5807.h" #include "SEEKFREE_7725_UART.h" +#include "SEEKFREE_BLUETOOTH_CH9141.h" #endif diff --git a/Example/Dual_Core_Demo/Libraries/seekfree_peripheral/SEEKFREE_BLUETOOTH_CH9141.c b/Example/Dual_Core_Demo/Libraries/seekfree_peripheral/SEEKFREE_BLUETOOTH_CH9141.c new file mode 100644 index 0000000..b4ec2df --- /dev/null +++ b/Example/Dual_Core_Demo/Libraries/seekfree_peripheral/SEEKFREE_BLUETOOTH_CH9141.c @@ -0,0 +1,509 @@ +/********************************************************************************************************************* + * COPYRIGHT NOTICE + * Copyright (c) 2021,逐飞科技 + * All rights reserved. + * 技术讨论QQ群:一群:179029047(已满) 二群:244861897 + * + * 以下所有内容版权均属逐飞科技所有,未经允许不得用于商业用途, + * 欢迎各位使用并传播本程序,修改内容时必须保留逐飞科技的版权声明。 + * + * @file 逐飞科技蓝牙转串口模块 + * @company 成都逐飞科技有限公司 + * @author 逐飞科技(QQ3184284598) + * @version 查看doc内version文件 版本说明 + * @Software IAR 8.3 or MDK 5.33 + * @Taobao https://seekfree.taobao.com/ + * @date 2021-08-27 + * @note + 接线定义: + ------------------------------------ + 蓝牙转串口 单片机 + RX 查看SEEKFREE_BLUETOOTH_CH9141.h文件中的BLUETOOTH_CH9141_UART_TX宏定义 + TX 查看SEEKFREE_BLUETOOTH_CH9141.h文件中的BLUETOOTH_CH9141_UART_RX宏定义 + RTS 查看SEEKFREE_BLUETOOTH_CH9141.h文件中的BLUETOOTH_CH9141_RTS_PIN宏定义 + CTS 悬空 + CMD 悬空或者上拉 + ------------------------------------ + ********************************************************************************************************************/ +#include "zf_stm_systick.h" +#include "zf_gpio.h" +#include "zf_uart.h" +#include "zf_assert.h" +#include "SEEKFREE_BLUETOOTH_CH9141.h" + +uint8 uart_flag; +uint8 uart_data; + +vuint8 at_mode = 0; //0:蓝牙透传模式 1:AT模式 2:模块复位中 +vuint8 at_mode_num; //at模式时用于指示数据接收的数量 +vuint8 at_mode_data[30]; //接收at命令的缓存 +vuint8 at_mode_cmd_flag; //OK应答命令接收成功的标志位 + +uint8 mac_address[17]; //本机mac地址 + + +uint8 bluetooth_ch9141_rx_buffer; + + +void bluetooth_ch9141_check_response(void); + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块 串口中断回调函数 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note 该函数在ISR文件 串口8中断程序被调用 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_uart_callback() +{ + while(uart_query(BLUETOOTH_CH9141_UART, &bluetooth_ch9141_rx_buffer)) + { + if(1 == at_mode) + { + //进入AT模式 接收应答信号 此处if语句内代码用户不要改动 + at_mode_data[at_mode_num++] = bluetooth_ch9141_rx_buffer; + bluetooth_ch9141_check_response(); + } + else if(2 == at_mode) + { + //模块正在复位中 此处if语句内代码用户不要改动 + at_mode_num++; + } + else + { + //透传模式 用户在此处接收配对的蓝牙发送过来的额数据 + //接到一个字节后单片机将会进入此处,通过在此处读取bluetooth_ch9141_rx_buffer可以取走数据 + + // 读取无线串口的数据 并且置位接收标志 + uart_flag = 1; + uart_data = bluetooth_ch9141_rx_buffer; + } + + } +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块检查OK应答信号 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_check_response(void) +{ + if(4 <= at_mode_num) + { + if(0 == strncmp("OK\r\n", (int8 *)&at_mode_data[at_mode_num-4], 4)) + { + at_mode_cmd_flag = 1; + } + } +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块发送一个没有参数的命令并等待应答信号 +// @param *str 需要发送的命令 完整字符串 +// @return void +// @since v1.0 +// Sample usage: +// @note 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_send_at_command(const int8 *str) +{ + at_mode_num = 0; //接收数量清零 + uart_putstr(BLUETOOTH_CH9141_UART, str); + uart_putstr(BLUETOOTH_CH9141_UART, "\r\n"); + + //等待收到应答信号 + while(!at_mode_cmd_flag); + at_mode_cmd_flag = 0; +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块发送一个带有参数的命令并等待应答信号 +// @param *cmd 需要发送的命令名称 +// @param *data 需要发送的数据 +// @return void +// @since v1.0 +// Sample usage: +// @note 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_send_at_command_parameter(const int8 *cmd, const int8 *data) +{ + at_mode_num = 0; //接收数量清零 + uart_putstr(BLUETOOTH_CH9141_UART, "AT+"); + uart_putstr(BLUETOOTH_CH9141_UART, cmd); + uart_putstr(BLUETOOTH_CH9141_UART, "="); + uart_putstr(BLUETOOTH_CH9141_UART, data); + uart_putstr(BLUETOOTH_CH9141_UART, "\r\n"); + + //等待收到应答信号 + while(!at_mode_cmd_flag); + at_mode_cmd_flag = 0; +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块进入AT模式 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_enter_at_mode(void) +{ + systick_delay_ms(STM0, 550); //发送进入AT模式的命令前需要保证模块在550ms内没有接收过任何数据 + at_mode = 1; //进入AT模式 + bluetooth_ch9141_send_at_command("AT..."); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块退出AT模式 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_exit_at_mode(void) +{ + bluetooth_ch9141_send_at_command("AT+EXIT"); + at_mode = 0; //进入透传模式 + systick_delay_ms(STM0, 300); //等待成功进入AT模式 +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块复位 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_reset(void) +{ + bluetooth_ch9141_send_at_command("AT+RESET"); + at_mode = 2; //进入重启成功检测 + at_mode_num = 0; + while(7 > at_mode_num); //等待蓝牙模块完成复位 + at_mode = 0; //复位之后模块自动进入透传模式 +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块获取本机MAC地址 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note 调用此函数需要先调用bluetooth_ch9141_enter_at_mode或者拉低CMD引脚 进入AT模式 +// 需要特别注意bluetooth_ch9141_enter_at_mode函数内部有500ms的延时 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_get_mac_address(void) +{ + bluetooth_ch9141_send_at_command("AT+MAC?"); + + //mac地址为小段格式,mac_address[0]保存的是mac地址最低位 + memcpy(mac_address, (uint8 *)at_mode_data, 17); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块设置发送功率 +// @param tx_power 设置发送功率,可设置选项查看CH9141_TX_POWEER_enum枚举成员 +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_set_tx_power(CH9141_TX_POWEER_enum tx_power) +{ + int8 tx_power_data; + + tx_power_data = (uint8)tx_power + '0'; + bluetooth_ch9141_send_at_command_parameter("TPL", &tx_power_data); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块设置模式 +// @param mode 模式设置,可设置选项查看CH9141_MODE_enum枚举成员 +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_set_mode(CH9141_MODE_enum mode) +{ + int8 mode_data; + + mode_data = (uint8)mode + '0'; + bluetooth_ch9141_send_at_command_parameter("BLEMODE", &mode_data); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块获取状态 +// @param mode 模式设置,可设置选项查看CH9141_MODE_enum枚举成员 +// @return CH9141_STATUS_enum 返回状态信息 +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +CH9141_STATUS_enum bluetooth_ch9141_get_status(CH9141_MODE_enum mode) +{ + CH9141_STATUS_enum ch9141_status; + int8 mode_data; + + mode_data = (uint8)mode + '0'; + bluetooth_ch9141_send_at_command_parameter("BLEMODE", &mode_data); + + bluetooth_ch9141_send_at_command("AT+BLESTA?"); + + ch9141_status = (at_mode_data[0] - '0') * 10 + (at_mode_data[1] - '0'); + if(SLAVE_MODE == mode) + { + ch9141_status += SLAVE_NO_INIT; + } + + return ch9141_status; +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块设置设备名称 +// @param *str 蓝牙名称 +// @return void +// @since v1.0 +// Sample usage: +// @note 名称长度不能超过18个字符 且只能为英文与数字 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_set_name(const int8 *str) +{ + bluetooth_ch9141_send_at_command_parameter("NAME", str); + bluetooth_ch9141_send_at_command_parameter("PNAME", str); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块密码设置 +// @param enable 使能密码 0:不使用密码,1:使用密码才能连接本设备 +// @param *password 密码的字符串 必须为6个字符 +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_set_password(uint8 enable, const int8 *password) +{ + if(0 == enable) + { + //关闭密码 + bluetooth_ch9141_send_at_command_parameter("PASEN", "OFF"); + } + else + { + //设置密码并使能 + bluetooth_ch9141_send_at_command_parameter("PASEN", "ON"); + bluetooth_ch9141_send_at_command_parameter("PASS", password); + } +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块指定MAC地址并立即进行连接 +// @param *mac_and_password 需要连接的设备mac地址与密码 +// @return void +// @since v1.0 +// Sample usage: +// @note bluetooth_ch9141_connect("58:B7:33:E4:C2:84,000000"); +// 58:B7:33:E4:C2:84为mac地址 ,为分隔符 000000为从机蓝牙密码 +// ===================特别注意================== +// 如果使用手机查看蓝牙的mac地址,则使用本函数连接的时候请将mac倒置一下 +// 例如手机查看到的mac地址为61:62:63:64:65:66,则使用本函数连接的时候应该写 +// bluetooth_ch9141_connect("66:65:64:63:62:61,000000"); +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_connect(const int8 *mac_and_password) +{ + bluetooth_ch9141_send_at_command_parameter("CONN", mac_and_password); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块默认连接参数设置(设置好后,每次开机蓝牙会自动链接这个设备) +// @param *mac_and_password 需要连接的设备mac地址与密码 +// @return void +// @since v1.0 +// Sample usage: +// @note bluetooth_ch9141_default_connect("58:B7:33:E4:C2:84,000000"); +// 58:B7:33:E4:C2:84为mac地址 ,为分隔符 000000为从机蓝牙密码 +// ===================特别注意================== +// 如果使用手机查看CH9141的mac地址,将CH9141设置为从机,使用手机连接 +// 则使用本函数连接的时候请将mac倒置一下 +// 例如手机查看到的mac地址为61:62:63:64:65:67,则使用本函数连接的时候应该写 +// bluetooth_ch9141_default_connect("67:65:64:63:62:61,000000"); +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_default_connect(const int8 *mac_and_password) +{ + bluetooth_ch9141_send_at_command_parameter("CONADD", mac_and_password); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块获取rssi(信号强度) +// @param void +// @return int8 返回信号强度0到-127 +// @since v1.0 +// Sample usage: +// @note 调用此函数需要先调用bluetooth_ch9141_enter_at_mode或者拉低CMD引脚 进入AT模式 +// 需要特别注意bluetooth_ch9141_enter_at_mode函数内部有500ms的延时 +//------------------------------------------------------------------------------------------------------------------- +int16 bluetooth_ch9141_get_rssi(void) +{ + uint8 i; + size_t length; + int16 rssi; + bluetooth_ch9141_send_at_command_parameter("RSSI", "ON,0"); + length = strlen((int8 *)at_mode_data); + length -= 12;//计算RSSI 有多少位 + + rssi = 0; + for(i=0; i30) { - if(gpio_get(RTS_PIN)) - { - return len;//模块忙,如果允许当前程序使用while等待 则可以使用后面注释的while等待语句替换本if语句 - } - //while(gpio_get(RTS_PIN)); //如果RTS为低电平,则继续发送数据 +// if(gpio_get(RTS_PIN)) +// { +// return len;//模块忙,如果允许当前程序使用while等待 则可以使用后面注释的while等待语句替换本if语句 +// } + while(gpio_get(RTS_PIN)); //如果RTS为低电平,则继续发送数据 uart_putbuff(WIRELESS_UART,buff,30); buff += 30; //地址偏移 len -= 30;//数量 } - if(gpio_get(RTS_PIN)) - { - return len;//模块忙,如果允许当前程序使用while等待 则可以使用后面注释的while等待语句替换本if语句 - } - //while(gpio_get(RTS_PIN)); //如果RTS为低电平,则继续发送数据 +// if(gpio_get(RTS_PIN)) +// { +// return len;//模块忙,如果允许当前程序使用while等待 则可以使用后面注释的while等待语句替换本if语句 +// } + while(gpio_get(RTS_PIN)); //如果RTS为低电平,则继续发送数据 uart_putbuff(WIRELESS_UART,buff,len);//发送最后的数据 return 0; diff --git a/Example/Dual_Core_Demo/Libraries/seekfree_peripheral/SEEKFREE_WIRELESS.h b/Example/Dual_Core_Demo/Libraries/seekfree_peripheral/SEEKFREE_WIRELESS.h index 42c0832..d80339d 100644 --- a/Example/Dual_Core_Demo/Libraries/seekfree_peripheral/SEEKFREE_WIRELESS.h +++ b/Example/Dual_Core_Demo/Libraries/seekfree_peripheral/SEEKFREE_WIRELESS.h @@ -38,8 +38,26 @@ #define WIRELESS_UART_RX UART2_RX_P10_6 #define WIRELESS_UART_BAUD 115200 -#define RTS_PIN P10_2 //定义流控位引脚 指示当前模块是否可以接受数据 0可以继续接收 1不可以继续接收 +// ------------------------------------ 自动波特率 ------------------------------------ +// 注意事项1:无线转串口模块版本是V2.0以下的是无法开启自动波特率的。 +// 注意事项2:开启自动波特率务必连接RTS引脚,否则会开启失败。 +// 注意事项3:模块自动波特率失败的话,可以尝试断电重启 +// 开启自动波特率务必阅读上面两条 注意事项 +// 开启自动波特率务必阅读上面两条 注意事项 +// 开启自动波特率务必阅读上面两条 注意事项 + +// 0:关闭自动波特率 +// 1:开启自动波特率 自动波特率的作用是修改WIRELESS_UART_BAUD之后不需要对模块进行配置,模块会自动设置为对应的波特率 + +#define WIRELESS_AUTO_UART_BAUD 0 +// ------------------------------------ 自动波特率 ------------------------------------ + +#define RTS_PIN P10_2 //定义流控位引脚 指示当前模块是否可以接受数据 0可以继续接收 1不可以继续接收 +#define WIRELESS_BUFFER_SIZE 16 + +extern uint8 wireless_send_buffer[WIRELESS_BUFFER_SIZE]; +extern uint32 wireless_rx_index; void wireless_uart_callback(void); void seekfree_wireless_init(void); diff --git a/Example/Dual_Core_Demo/USER/isr.c b/Example/Dual_Core_Demo/USER/isr.c index c55a012..16bff98 100644 --- a/Example/Dual_Core_Demo/USER/isr.c +++ b/Example/Dual_Core_Demo/USER/isr.c @@ -179,7 +179,20 @@ IFX_INTERRUPT(uart2_rx_isr, 0, UART2_RX_INT_PRIO) { enableInterrupts();//开启中断嵌套 IfxAsclin_Asc_isrReceive(&uart2_handle); - wireless_uart_callback(); + switch(wireless_type) + { + case WIRELESS_SI24R1: + { + wireless_uart_callback(); + }break; + + case WIRELESS_CH9141: + { + bluetooth_ch9141_uart_callback(); + }break; + default:break; + } + } IFX_INTERRUPT(uart2_er_isr, 0, UART2_ER_INT_PRIO) { diff --git a/Example/Dual_Core_Demo/鍒犻櫎涓存椂鏂囦欢.bat b/Example/Dual_Core_Demo/鍒犻櫎涓存椂鏂囦欢.bat index 5323dd9..fa499b1 100644 --- a/Example/Dual_Core_Demo/鍒犻櫎涓存椂鏂囦欢.bat +++ b/Example/Dual_Core_Demo/鍒犻櫎涓存椂鏂囦欢.bat @@ -1,9 +1,6 @@ -rmdir .settings /s /q rmdir Debug /s /q del *.launch /s - -pause exit diff --git a/Example/EEPROM_Demo/.cproject b/Example/EEPROM_Demo/.cproject index dfa511c..719d825 100644 --- a/Example/EEPROM_Demo/.cproject +++ b/Example/EEPROM_Demo/.cproject @@ -3,9 +3,9 @@ - + - + @@ -25,50 +25,76 @@ - + - + - + - + + + + + + @@ -355,9 +371,9 @@ - + - + @@ -377,43 +393,1895 @@ - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -431,13 +2299,37 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + @@ -459,14 +2351,6 @@ - - - - - - - - - + diff --git a/Example/EEPROM_Demo/.project b/Example/EEPROM_Demo/.project index 7d949cd..0f2fe7e 100644 --- a/Example/EEPROM_Demo/.project +++ b/Example/EEPROM_Demo/.project @@ -5,6 +5,18 @@ + + com.infineon.aurix.buildsystem.builders.booster + full,incremental, + + + + + com.infineon.aurix.buildsystem.builders.autodiscovery + full,incremental, + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder clean,full,incremental, diff --git a/Example/EEPROM_Demo/.settings/com.infineon.aurix.buildsystem.prefs b/Example/EEPROM_Demo/.settings/com.infineon.aurix.buildsystem.prefs new file mode 100644 index 0000000..be61bc1 --- /dev/null +++ b/Example/EEPROM_Demo/.settings/com.infineon.aurix.buildsystem.prefs @@ -0,0 +1,10 @@ +AURIX-LIBRARY-PATH=Libraries/iLLD\#Libraries/Infra\#Libraries/Service +DEVICE-ID=TC26B +DEVICE-ID-FULL=TC26xD_B-Step +ILLD-SET=full +IncludesAutodiscovery=true +LIBRARIES-ROOT-PATH=Libraries +NEVER-EXCLUDE-FROM-BUILD=/Libraries/iLLD/TC26B/Tricore/Cpu/CStart\#/Libraries/iLLD/TC26B/Tricore/Cpu/Trap\#/Configurations\#/Configurations/Debug +PROJECT-VERSION=1.0 +aurixDevice=TC26xD_B-Step +eclipse.preferences.version=1 diff --git a/Example/EEPROM_Demo/Libraries/doc/version.txt b/Example/EEPROM_Demo/Libraries/doc/version.txt index ab79909..11ab82e 100644 --- a/Example/EEPROM_Demo/Libraries/doc/version.txt +++ b/Example/EEPROM_Demo/Libraries/doc/version.txt @@ -1,3 +1,13 @@ +V1.2.0 + 增加CH9141蓝牙转串口模块的驱动 + 添加无线类型的枚举变量 + 修改 删除临时文件.bat 执行完操作后自动关闭窗口 + 修改 删除临时文件.bat 避免删除新版本所需文件 + 修改工程项目文件,以支持新版本编译 + +V1.1.10 + 修复通过#pragma section all "cpux_dsram"指定变量位置失效的问题 + V1.1.9 将串口的发送buff增加到128字节 diff --git a/Example/EEPROM_Demo/Libraries/seekfree_libraries/common/common.c b/Example/EEPROM_Demo/Libraries/seekfree_libraries/common/common.c index 0b9931e..7620ce6 100644 --- a/Example/EEPROM_Demo/Libraries/seekfree_libraries/common/common.c +++ b/Example/EEPROM_Demo/Libraries/seekfree_libraries/common/common.c @@ -27,6 +27,8 @@ CAMERA_TYPE_enum camera_type; //摄像头型号 uint8 *camera_buffer_addr; //摄像头数组地址 +WIRELESS_TYPE_enum wireless_type;//无线转串口类型 + IFX_ALIGN(4) IfxCpu_syncEvent g_cpuSyncEvent = 0;//事件同步变量 App_Cpu0 g_AppCpu0; //频率信息变量 diff --git a/Example/EEPROM_Demo/Libraries/seekfree_libraries/common/common.h b/Example/EEPROM_Demo/Libraries/seekfree_libraries/common/common.h index 84c43ee..5b741c0 100644 --- a/Example/EEPROM_Demo/Libraries/seekfree_libraries/common/common.h +++ b/Example/EEPROM_Demo/Libraries/seekfree_libraries/common/common.h @@ -113,6 +113,12 @@ typedef enum //枚 CAMERA_COLOR, //凌瞳 }CAMERA_TYPE_enum; +typedef enum //无线模块 +{ + WIRELESS_SI24R1 = 1, //无线转串口 + WIRELESS_CH9141, //蓝牙转串口 +}WIRELESS_TYPE_enum; + #include #include #include "IfxCpu.h" @@ -120,6 +126,8 @@ typedef enum //枚 extern CAMERA_TYPE_enum camera_type; //摄像头型号 extern uint8 *camera_buffer_addr; //摄像头数组地址 +extern WIRELESS_TYPE_enum wireless_type; + extern IfxCpu_syncEvent g_cpuSyncEvent; void get_clk(void); diff --git a/Example/EEPROM_Demo/Libraries/seekfree_libraries/headfile.h b/Example/EEPROM_Demo/Libraries/seekfree_libraries/headfile.h index 404ee0a..b745302 100644 --- a/Example/EEPROM_Demo/Libraries/seekfree_libraries/headfile.h +++ b/Example/EEPROM_Demo/Libraries/seekfree_libraries/headfile.h @@ -65,6 +65,7 @@ #include "SEEKFREE_7725.h" #include "SEEKFREE_RDA5807.h" #include "SEEKFREE_7725_UART.h" +#include "SEEKFREE_BLUETOOTH_CH9141.h" #endif diff --git a/Example/EEPROM_Demo/Libraries/seekfree_peripheral/SEEKFREE_BLUETOOTH_CH9141.c b/Example/EEPROM_Demo/Libraries/seekfree_peripheral/SEEKFREE_BLUETOOTH_CH9141.c new file mode 100644 index 0000000..b4ec2df --- /dev/null +++ b/Example/EEPROM_Demo/Libraries/seekfree_peripheral/SEEKFREE_BLUETOOTH_CH9141.c @@ -0,0 +1,509 @@ +/********************************************************************************************************************* + * COPYRIGHT NOTICE + * Copyright (c) 2021,逐飞科技 + * All rights reserved. + * 技术讨论QQ群:一群:179029047(已满) 二群:244861897 + * + * 以下所有内容版权均属逐飞科技所有,未经允许不得用于商业用途, + * 欢迎各位使用并传播本程序,修改内容时必须保留逐飞科技的版权声明。 + * + * @file 逐飞科技蓝牙转串口模块 + * @company 成都逐飞科技有限公司 + * @author 逐飞科技(QQ3184284598) + * @version 查看doc内version文件 版本说明 + * @Software IAR 8.3 or MDK 5.33 + * @Taobao https://seekfree.taobao.com/ + * @date 2021-08-27 + * @note + 接线定义: + ------------------------------------ + 蓝牙转串口 单片机 + RX 查看SEEKFREE_BLUETOOTH_CH9141.h文件中的BLUETOOTH_CH9141_UART_TX宏定义 + TX 查看SEEKFREE_BLUETOOTH_CH9141.h文件中的BLUETOOTH_CH9141_UART_RX宏定义 + RTS 查看SEEKFREE_BLUETOOTH_CH9141.h文件中的BLUETOOTH_CH9141_RTS_PIN宏定义 + CTS 悬空 + CMD 悬空或者上拉 + ------------------------------------ + ********************************************************************************************************************/ +#include "zf_stm_systick.h" +#include "zf_gpio.h" +#include "zf_uart.h" +#include "zf_assert.h" +#include "SEEKFREE_BLUETOOTH_CH9141.h" + +uint8 uart_flag; +uint8 uart_data; + +vuint8 at_mode = 0; //0:蓝牙透传模式 1:AT模式 2:模块复位中 +vuint8 at_mode_num; //at模式时用于指示数据接收的数量 +vuint8 at_mode_data[30]; //接收at命令的缓存 +vuint8 at_mode_cmd_flag; //OK应答命令接收成功的标志位 + +uint8 mac_address[17]; //本机mac地址 + + +uint8 bluetooth_ch9141_rx_buffer; + + +void bluetooth_ch9141_check_response(void); + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块 串口中断回调函数 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note 该函数在ISR文件 串口8中断程序被调用 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_uart_callback() +{ + while(uart_query(BLUETOOTH_CH9141_UART, &bluetooth_ch9141_rx_buffer)) + { + if(1 == at_mode) + { + //进入AT模式 接收应答信号 此处if语句内代码用户不要改动 + at_mode_data[at_mode_num++] = bluetooth_ch9141_rx_buffer; + bluetooth_ch9141_check_response(); + } + else if(2 == at_mode) + { + //模块正在复位中 此处if语句内代码用户不要改动 + at_mode_num++; + } + else + { + //透传模式 用户在此处接收配对的蓝牙发送过来的额数据 + //接到一个字节后单片机将会进入此处,通过在此处读取bluetooth_ch9141_rx_buffer可以取走数据 + + // 读取无线串口的数据 并且置位接收标志 + uart_flag = 1; + uart_data = bluetooth_ch9141_rx_buffer; + } + + } +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块检查OK应答信号 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_check_response(void) +{ + if(4 <= at_mode_num) + { + if(0 == strncmp("OK\r\n", (int8 *)&at_mode_data[at_mode_num-4], 4)) + { + at_mode_cmd_flag = 1; + } + } +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块发送一个没有参数的命令并等待应答信号 +// @param *str 需要发送的命令 完整字符串 +// @return void +// @since v1.0 +// Sample usage: +// @note 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_send_at_command(const int8 *str) +{ + at_mode_num = 0; //接收数量清零 + uart_putstr(BLUETOOTH_CH9141_UART, str); + uart_putstr(BLUETOOTH_CH9141_UART, "\r\n"); + + //等待收到应答信号 + while(!at_mode_cmd_flag); + at_mode_cmd_flag = 0; +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块发送一个带有参数的命令并等待应答信号 +// @param *cmd 需要发送的命令名称 +// @param *data 需要发送的数据 +// @return void +// @since v1.0 +// Sample usage: +// @note 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_send_at_command_parameter(const int8 *cmd, const int8 *data) +{ + at_mode_num = 0; //接收数量清零 + uart_putstr(BLUETOOTH_CH9141_UART, "AT+"); + uart_putstr(BLUETOOTH_CH9141_UART, cmd); + uart_putstr(BLUETOOTH_CH9141_UART, "="); + uart_putstr(BLUETOOTH_CH9141_UART, data); + uart_putstr(BLUETOOTH_CH9141_UART, "\r\n"); + + //等待收到应答信号 + while(!at_mode_cmd_flag); + at_mode_cmd_flag = 0; +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块进入AT模式 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_enter_at_mode(void) +{ + systick_delay_ms(STM0, 550); //发送进入AT模式的命令前需要保证模块在550ms内没有接收过任何数据 + at_mode = 1; //进入AT模式 + bluetooth_ch9141_send_at_command("AT..."); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块退出AT模式 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_exit_at_mode(void) +{ + bluetooth_ch9141_send_at_command("AT+EXIT"); + at_mode = 0; //进入透传模式 + systick_delay_ms(STM0, 300); //等待成功进入AT模式 +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块复位 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_reset(void) +{ + bluetooth_ch9141_send_at_command("AT+RESET"); + at_mode = 2; //进入重启成功检测 + at_mode_num = 0; + while(7 > at_mode_num); //等待蓝牙模块完成复位 + at_mode = 0; //复位之后模块自动进入透传模式 +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块获取本机MAC地址 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note 调用此函数需要先调用bluetooth_ch9141_enter_at_mode或者拉低CMD引脚 进入AT模式 +// 需要特别注意bluetooth_ch9141_enter_at_mode函数内部有500ms的延时 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_get_mac_address(void) +{ + bluetooth_ch9141_send_at_command("AT+MAC?"); + + //mac地址为小段格式,mac_address[0]保存的是mac地址最低位 + memcpy(mac_address, (uint8 *)at_mode_data, 17); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块设置发送功率 +// @param tx_power 设置发送功率,可设置选项查看CH9141_TX_POWEER_enum枚举成员 +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_set_tx_power(CH9141_TX_POWEER_enum tx_power) +{ + int8 tx_power_data; + + tx_power_data = (uint8)tx_power + '0'; + bluetooth_ch9141_send_at_command_parameter("TPL", &tx_power_data); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块设置模式 +// @param mode 模式设置,可设置选项查看CH9141_MODE_enum枚举成员 +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_set_mode(CH9141_MODE_enum mode) +{ + int8 mode_data; + + mode_data = (uint8)mode + '0'; + bluetooth_ch9141_send_at_command_parameter("BLEMODE", &mode_data); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块获取状态 +// @param mode 模式设置,可设置选项查看CH9141_MODE_enum枚举成员 +// @return CH9141_STATUS_enum 返回状态信息 +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +CH9141_STATUS_enum bluetooth_ch9141_get_status(CH9141_MODE_enum mode) +{ + CH9141_STATUS_enum ch9141_status; + int8 mode_data; + + mode_data = (uint8)mode + '0'; + bluetooth_ch9141_send_at_command_parameter("BLEMODE", &mode_data); + + bluetooth_ch9141_send_at_command("AT+BLESTA?"); + + ch9141_status = (at_mode_data[0] - '0') * 10 + (at_mode_data[1] - '0'); + if(SLAVE_MODE == mode) + { + ch9141_status += SLAVE_NO_INIT; + } + + return ch9141_status; +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块设置设备名称 +// @param *str 蓝牙名称 +// @return void +// @since v1.0 +// Sample usage: +// @note 名称长度不能超过18个字符 且只能为英文与数字 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_set_name(const int8 *str) +{ + bluetooth_ch9141_send_at_command_parameter("NAME", str); + bluetooth_ch9141_send_at_command_parameter("PNAME", str); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块密码设置 +// @param enable 使能密码 0:不使用密码,1:使用密码才能连接本设备 +// @param *password 密码的字符串 必须为6个字符 +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_set_password(uint8 enable, const int8 *password) +{ + if(0 == enable) + { + //关闭密码 + bluetooth_ch9141_send_at_command_parameter("PASEN", "OFF"); + } + else + { + //设置密码并使能 + bluetooth_ch9141_send_at_command_parameter("PASEN", "ON"); + bluetooth_ch9141_send_at_command_parameter("PASS", password); + } +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块指定MAC地址并立即进行连接 +// @param *mac_and_password 需要连接的设备mac地址与密码 +// @return void +// @since v1.0 +// Sample usage: +// @note bluetooth_ch9141_connect("58:B7:33:E4:C2:84,000000"); +// 58:B7:33:E4:C2:84为mac地址 ,为分隔符 000000为从机蓝牙密码 +// ===================特别注意================== +// 如果使用手机查看蓝牙的mac地址,则使用本函数连接的时候请将mac倒置一下 +// 例如手机查看到的mac地址为61:62:63:64:65:66,则使用本函数连接的时候应该写 +// bluetooth_ch9141_connect("66:65:64:63:62:61,000000"); +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_connect(const int8 *mac_and_password) +{ + bluetooth_ch9141_send_at_command_parameter("CONN", mac_and_password); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块默认连接参数设置(设置好后,每次开机蓝牙会自动链接这个设备) +// @param *mac_and_password 需要连接的设备mac地址与密码 +// @return void +// @since v1.0 +// Sample usage: +// @note bluetooth_ch9141_default_connect("58:B7:33:E4:C2:84,000000"); +// 58:B7:33:E4:C2:84为mac地址 ,为分隔符 000000为从机蓝牙密码 +// ===================特别注意================== +// 如果使用手机查看CH9141的mac地址,将CH9141设置为从机,使用手机连接 +// 则使用本函数连接的时候请将mac倒置一下 +// 例如手机查看到的mac地址为61:62:63:64:65:67,则使用本函数连接的时候应该写 +// bluetooth_ch9141_default_connect("67:65:64:63:62:61,000000"); +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_default_connect(const int8 *mac_and_password) +{ + bluetooth_ch9141_send_at_command_parameter("CONADD", mac_and_password); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块获取rssi(信号强度) +// @param void +// @return int8 返回信号强度0到-127 +// @since v1.0 +// Sample usage: +// @note 调用此函数需要先调用bluetooth_ch9141_enter_at_mode或者拉低CMD引脚 进入AT模式 +// 需要特别注意bluetooth_ch9141_enter_at_mode函数内部有500ms的延时 +//------------------------------------------------------------------------------------------------------------------- +int16 bluetooth_ch9141_get_rssi(void) +{ + uint8 i; + size_t length; + int16 rssi; + bluetooth_ch9141_send_at_command_parameter("RSSI", "ON,0"); + length = strlen((int8 *)at_mode_data); + length -= 12;//计算RSSI 有多少位 + + rssi = 0; + for(i=0; i30) { - if(gpio_get(RTS_PIN)) - { - return len;//模块忙,如果允许当前程序使用while等待 则可以使用后面注释的while等待语句替换本if语句 - } - //while(gpio_get(RTS_PIN)); //如果RTS为低电平,则继续发送数据 +// if(gpio_get(RTS_PIN)) +// { +// return len;//模块忙,如果允许当前程序使用while等待 则可以使用后面注释的while等待语句替换本if语句 +// } + while(gpio_get(RTS_PIN)); //如果RTS为低电平,则继续发送数据 uart_putbuff(WIRELESS_UART,buff,30); buff += 30; //地址偏移 len -= 30;//数量 } - if(gpio_get(RTS_PIN)) - { - return len;//模块忙,如果允许当前程序使用while等待 则可以使用后面注释的while等待语句替换本if语句 - } - //while(gpio_get(RTS_PIN)); //如果RTS为低电平,则继续发送数据 +// if(gpio_get(RTS_PIN)) +// { +// return len;//模块忙,如果允许当前程序使用while等待 则可以使用后面注释的while等待语句替换本if语句 +// } + while(gpio_get(RTS_PIN)); //如果RTS为低电平,则继续发送数据 uart_putbuff(WIRELESS_UART,buff,len);//发送最后的数据 return 0; diff --git a/Example/EEPROM_Demo/Libraries/seekfree_peripheral/SEEKFREE_WIRELESS.h b/Example/EEPROM_Demo/Libraries/seekfree_peripheral/SEEKFREE_WIRELESS.h index 42c0832..d80339d 100644 --- a/Example/EEPROM_Demo/Libraries/seekfree_peripheral/SEEKFREE_WIRELESS.h +++ b/Example/EEPROM_Demo/Libraries/seekfree_peripheral/SEEKFREE_WIRELESS.h @@ -38,8 +38,26 @@ #define WIRELESS_UART_RX UART2_RX_P10_6 #define WIRELESS_UART_BAUD 115200 -#define RTS_PIN P10_2 //定义流控位引脚 指示当前模块是否可以接受数据 0可以继续接收 1不可以继续接收 +// ------------------------------------ 自动波特率 ------------------------------------ +// 注意事项1:无线转串口模块版本是V2.0以下的是无法开启自动波特率的。 +// 注意事项2:开启自动波特率务必连接RTS引脚,否则会开启失败。 +// 注意事项3:模块自动波特率失败的话,可以尝试断电重启 +// 开启自动波特率务必阅读上面两条 注意事项 +// 开启自动波特率务必阅读上面两条 注意事项 +// 开启自动波特率务必阅读上面两条 注意事项 + +// 0:关闭自动波特率 +// 1:开启自动波特率 自动波特率的作用是修改WIRELESS_UART_BAUD之后不需要对模块进行配置,模块会自动设置为对应的波特率 + +#define WIRELESS_AUTO_UART_BAUD 0 +// ------------------------------------ 自动波特率 ------------------------------------ + +#define RTS_PIN P10_2 //定义流控位引脚 指示当前模块是否可以接受数据 0可以继续接收 1不可以继续接收 +#define WIRELESS_BUFFER_SIZE 16 + +extern uint8 wireless_send_buffer[WIRELESS_BUFFER_SIZE]; +extern uint32 wireless_rx_index; void wireless_uart_callback(void); void seekfree_wireless_init(void); diff --git a/Example/EEPROM_Demo/USER/isr.c b/Example/EEPROM_Demo/USER/isr.c index c55a012..16bff98 100644 --- a/Example/EEPROM_Demo/USER/isr.c +++ b/Example/EEPROM_Demo/USER/isr.c @@ -179,7 +179,20 @@ IFX_INTERRUPT(uart2_rx_isr, 0, UART2_RX_INT_PRIO) { enableInterrupts();//开启中断嵌套 IfxAsclin_Asc_isrReceive(&uart2_handle); - wireless_uart_callback(); + switch(wireless_type) + { + case WIRELESS_SI24R1: + { + wireless_uart_callback(); + }break; + + case WIRELESS_CH9141: + { + bluetooth_ch9141_uart_callback(); + }break; + default:break; + } + } IFX_INTERRUPT(uart2_er_isr, 0, UART2_ER_INT_PRIO) { diff --git a/Example/EEPROM_Demo/鍒犻櫎涓存椂鏂囦欢.bat b/Example/EEPROM_Demo/鍒犻櫎涓存椂鏂囦欢.bat index 5323dd9..fa499b1 100644 --- a/Example/EEPROM_Demo/鍒犻櫎涓存椂鏂囦欢.bat +++ b/Example/EEPROM_Demo/鍒犻櫎涓存椂鏂囦欢.bat @@ -1,9 +1,6 @@ -rmdir .settings /s /q rmdir Debug /s /q del *.launch /s - -pause exit diff --git a/Example/Encoder_Demo/.cproject b/Example/Encoder_Demo/.cproject index c2cc55d..e8d9741 100644 --- a/Example/Encoder_Demo/.cproject +++ b/Example/Encoder_Demo/.cproject @@ -3,9 +3,9 @@ - + - + @@ -25,50 +25,76 @@ - + - + - + - + + + + + + @@ -355,9 +371,9 @@ - + - + @@ -377,43 +393,1895 @@ - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -431,13 +2299,37 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + @@ -459,20 +2351,6 @@ - - - - - - - - - - - - - - - + diff --git a/Example/Encoder_Demo/.project b/Example/Encoder_Demo/.project index 63a24e2..0853efe 100644 --- a/Example/Encoder_Demo/.project +++ b/Example/Encoder_Demo/.project @@ -5,6 +5,18 @@ + + com.infineon.aurix.buildsystem.builders.booster + full,incremental, + + + + + com.infineon.aurix.buildsystem.builders.autodiscovery + full,incremental, + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder clean,full,incremental, diff --git a/Example/Encoder_Demo/.settings/com.infineon.aurix.buildsystem.prefs b/Example/Encoder_Demo/.settings/com.infineon.aurix.buildsystem.prefs new file mode 100644 index 0000000..be61bc1 --- /dev/null +++ b/Example/Encoder_Demo/.settings/com.infineon.aurix.buildsystem.prefs @@ -0,0 +1,10 @@ +AURIX-LIBRARY-PATH=Libraries/iLLD\#Libraries/Infra\#Libraries/Service +DEVICE-ID=TC26B +DEVICE-ID-FULL=TC26xD_B-Step +ILLD-SET=full +IncludesAutodiscovery=true +LIBRARIES-ROOT-PATH=Libraries +NEVER-EXCLUDE-FROM-BUILD=/Libraries/iLLD/TC26B/Tricore/Cpu/CStart\#/Libraries/iLLD/TC26B/Tricore/Cpu/Trap\#/Configurations\#/Configurations/Debug +PROJECT-VERSION=1.0 +aurixDevice=TC26xD_B-Step +eclipse.preferences.version=1 diff --git a/Example/Encoder_Demo/Libraries/doc/version.txt b/Example/Encoder_Demo/Libraries/doc/version.txt index ab79909..11ab82e 100644 --- a/Example/Encoder_Demo/Libraries/doc/version.txt +++ b/Example/Encoder_Demo/Libraries/doc/version.txt @@ -1,3 +1,13 @@ +V1.2.0 + 增加CH9141蓝牙转串口模块的驱动 + 添加无线类型的枚举变量 + 修改 删除临时文件.bat 执行完操作后自动关闭窗口 + 修改 删除临时文件.bat 避免删除新版本所需文件 + 修改工程项目文件,以支持新版本编译 + +V1.1.10 + 修复通过#pragma section all "cpux_dsram"指定变量位置失效的问题 + V1.1.9 将串口的发送buff增加到128字节 diff --git a/Example/Encoder_Demo/Libraries/seekfree_libraries/common/common.c b/Example/Encoder_Demo/Libraries/seekfree_libraries/common/common.c index 0b9931e..7620ce6 100644 --- a/Example/Encoder_Demo/Libraries/seekfree_libraries/common/common.c +++ b/Example/Encoder_Demo/Libraries/seekfree_libraries/common/common.c @@ -27,6 +27,8 @@ CAMERA_TYPE_enum camera_type; //摄像头型号 uint8 *camera_buffer_addr; //摄像头数组地址 +WIRELESS_TYPE_enum wireless_type;//无线转串口类型 + IFX_ALIGN(4) IfxCpu_syncEvent g_cpuSyncEvent = 0;//事件同步变量 App_Cpu0 g_AppCpu0; //频率信息变量 diff --git a/Example/Encoder_Demo/Libraries/seekfree_libraries/common/common.h b/Example/Encoder_Demo/Libraries/seekfree_libraries/common/common.h index 84c43ee..5b741c0 100644 --- a/Example/Encoder_Demo/Libraries/seekfree_libraries/common/common.h +++ b/Example/Encoder_Demo/Libraries/seekfree_libraries/common/common.h @@ -113,6 +113,12 @@ typedef enum //枚 CAMERA_COLOR, //凌瞳 }CAMERA_TYPE_enum; +typedef enum //无线模块 +{ + WIRELESS_SI24R1 = 1, //无线转串口 + WIRELESS_CH9141, //蓝牙转串口 +}WIRELESS_TYPE_enum; + #include #include #include "IfxCpu.h" @@ -120,6 +126,8 @@ typedef enum //枚 extern CAMERA_TYPE_enum camera_type; //摄像头型号 extern uint8 *camera_buffer_addr; //摄像头数组地址 +extern WIRELESS_TYPE_enum wireless_type; + extern IfxCpu_syncEvent g_cpuSyncEvent; void get_clk(void); diff --git a/Example/Encoder_Demo/Libraries/seekfree_libraries/headfile.h b/Example/Encoder_Demo/Libraries/seekfree_libraries/headfile.h index 404ee0a..b745302 100644 --- a/Example/Encoder_Demo/Libraries/seekfree_libraries/headfile.h +++ b/Example/Encoder_Demo/Libraries/seekfree_libraries/headfile.h @@ -65,6 +65,7 @@ #include "SEEKFREE_7725.h" #include "SEEKFREE_RDA5807.h" #include "SEEKFREE_7725_UART.h" +#include "SEEKFREE_BLUETOOTH_CH9141.h" #endif diff --git a/Example/Encoder_Demo/Libraries/seekfree_peripheral/SEEKFREE_BLUETOOTH_CH9141.c b/Example/Encoder_Demo/Libraries/seekfree_peripheral/SEEKFREE_BLUETOOTH_CH9141.c new file mode 100644 index 0000000..b4ec2df --- /dev/null +++ b/Example/Encoder_Demo/Libraries/seekfree_peripheral/SEEKFREE_BLUETOOTH_CH9141.c @@ -0,0 +1,509 @@ +/********************************************************************************************************************* + * COPYRIGHT NOTICE + * Copyright (c) 2021,逐飞科技 + * All rights reserved. + * 技术讨论QQ群:一群:179029047(已满) 二群:244861897 + * + * 以下所有内容版权均属逐飞科技所有,未经允许不得用于商业用途, + * 欢迎各位使用并传播本程序,修改内容时必须保留逐飞科技的版权声明。 + * + * @file 逐飞科技蓝牙转串口模块 + * @company 成都逐飞科技有限公司 + * @author 逐飞科技(QQ3184284598) + * @version 查看doc内version文件 版本说明 + * @Software IAR 8.3 or MDK 5.33 + * @Taobao https://seekfree.taobao.com/ + * @date 2021-08-27 + * @note + 接线定义: + ------------------------------------ + 蓝牙转串口 单片机 + RX 查看SEEKFREE_BLUETOOTH_CH9141.h文件中的BLUETOOTH_CH9141_UART_TX宏定义 + TX 查看SEEKFREE_BLUETOOTH_CH9141.h文件中的BLUETOOTH_CH9141_UART_RX宏定义 + RTS 查看SEEKFREE_BLUETOOTH_CH9141.h文件中的BLUETOOTH_CH9141_RTS_PIN宏定义 + CTS 悬空 + CMD 悬空或者上拉 + ------------------------------------ + ********************************************************************************************************************/ +#include "zf_stm_systick.h" +#include "zf_gpio.h" +#include "zf_uart.h" +#include "zf_assert.h" +#include "SEEKFREE_BLUETOOTH_CH9141.h" + +uint8 uart_flag; +uint8 uart_data; + +vuint8 at_mode = 0; //0:蓝牙透传模式 1:AT模式 2:模块复位中 +vuint8 at_mode_num; //at模式时用于指示数据接收的数量 +vuint8 at_mode_data[30]; //接收at命令的缓存 +vuint8 at_mode_cmd_flag; //OK应答命令接收成功的标志位 + +uint8 mac_address[17]; //本机mac地址 + + +uint8 bluetooth_ch9141_rx_buffer; + + +void bluetooth_ch9141_check_response(void); + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块 串口中断回调函数 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note 该函数在ISR文件 串口8中断程序被调用 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_uart_callback() +{ + while(uart_query(BLUETOOTH_CH9141_UART, &bluetooth_ch9141_rx_buffer)) + { + if(1 == at_mode) + { + //进入AT模式 接收应答信号 此处if语句内代码用户不要改动 + at_mode_data[at_mode_num++] = bluetooth_ch9141_rx_buffer; + bluetooth_ch9141_check_response(); + } + else if(2 == at_mode) + { + //模块正在复位中 此处if语句内代码用户不要改动 + at_mode_num++; + } + else + { + //透传模式 用户在此处接收配对的蓝牙发送过来的额数据 + //接到一个字节后单片机将会进入此处,通过在此处读取bluetooth_ch9141_rx_buffer可以取走数据 + + // 读取无线串口的数据 并且置位接收标志 + uart_flag = 1; + uart_data = bluetooth_ch9141_rx_buffer; + } + + } +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块检查OK应答信号 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_check_response(void) +{ + if(4 <= at_mode_num) + { + if(0 == strncmp("OK\r\n", (int8 *)&at_mode_data[at_mode_num-4], 4)) + { + at_mode_cmd_flag = 1; + } + } +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块发送一个没有参数的命令并等待应答信号 +// @param *str 需要发送的命令 完整字符串 +// @return void +// @since v1.0 +// Sample usage: +// @note 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_send_at_command(const int8 *str) +{ + at_mode_num = 0; //接收数量清零 + uart_putstr(BLUETOOTH_CH9141_UART, str); + uart_putstr(BLUETOOTH_CH9141_UART, "\r\n"); + + //等待收到应答信号 + while(!at_mode_cmd_flag); + at_mode_cmd_flag = 0; +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块发送一个带有参数的命令并等待应答信号 +// @param *cmd 需要发送的命令名称 +// @param *data 需要发送的数据 +// @return void +// @since v1.0 +// Sample usage: +// @note 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_send_at_command_parameter(const int8 *cmd, const int8 *data) +{ + at_mode_num = 0; //接收数量清零 + uart_putstr(BLUETOOTH_CH9141_UART, "AT+"); + uart_putstr(BLUETOOTH_CH9141_UART, cmd); + uart_putstr(BLUETOOTH_CH9141_UART, "="); + uart_putstr(BLUETOOTH_CH9141_UART, data); + uart_putstr(BLUETOOTH_CH9141_UART, "\r\n"); + + //等待收到应答信号 + while(!at_mode_cmd_flag); + at_mode_cmd_flag = 0; +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块进入AT模式 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_enter_at_mode(void) +{ + systick_delay_ms(STM0, 550); //发送进入AT模式的命令前需要保证模块在550ms内没有接收过任何数据 + at_mode = 1; //进入AT模式 + bluetooth_ch9141_send_at_command("AT..."); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块退出AT模式 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_exit_at_mode(void) +{ + bluetooth_ch9141_send_at_command("AT+EXIT"); + at_mode = 0; //进入透传模式 + systick_delay_ms(STM0, 300); //等待成功进入AT模式 +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块复位 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_reset(void) +{ + bluetooth_ch9141_send_at_command("AT+RESET"); + at_mode = 2; //进入重启成功检测 + at_mode_num = 0; + while(7 > at_mode_num); //等待蓝牙模块完成复位 + at_mode = 0; //复位之后模块自动进入透传模式 +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块获取本机MAC地址 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note 调用此函数需要先调用bluetooth_ch9141_enter_at_mode或者拉低CMD引脚 进入AT模式 +// 需要特别注意bluetooth_ch9141_enter_at_mode函数内部有500ms的延时 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_get_mac_address(void) +{ + bluetooth_ch9141_send_at_command("AT+MAC?"); + + //mac地址为小段格式,mac_address[0]保存的是mac地址最低位 + memcpy(mac_address, (uint8 *)at_mode_data, 17); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块设置发送功率 +// @param tx_power 设置发送功率,可设置选项查看CH9141_TX_POWEER_enum枚举成员 +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_set_tx_power(CH9141_TX_POWEER_enum tx_power) +{ + int8 tx_power_data; + + tx_power_data = (uint8)tx_power + '0'; + bluetooth_ch9141_send_at_command_parameter("TPL", &tx_power_data); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块设置模式 +// @param mode 模式设置,可设置选项查看CH9141_MODE_enum枚举成员 +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_set_mode(CH9141_MODE_enum mode) +{ + int8 mode_data; + + mode_data = (uint8)mode + '0'; + bluetooth_ch9141_send_at_command_parameter("BLEMODE", &mode_data); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块获取状态 +// @param mode 模式设置,可设置选项查看CH9141_MODE_enum枚举成员 +// @return CH9141_STATUS_enum 返回状态信息 +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +CH9141_STATUS_enum bluetooth_ch9141_get_status(CH9141_MODE_enum mode) +{ + CH9141_STATUS_enum ch9141_status; + int8 mode_data; + + mode_data = (uint8)mode + '0'; + bluetooth_ch9141_send_at_command_parameter("BLEMODE", &mode_data); + + bluetooth_ch9141_send_at_command("AT+BLESTA?"); + + ch9141_status = (at_mode_data[0] - '0') * 10 + (at_mode_data[1] - '0'); + if(SLAVE_MODE == mode) + { + ch9141_status += SLAVE_NO_INIT; + } + + return ch9141_status; +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块设置设备名称 +// @param *str 蓝牙名称 +// @return void +// @since v1.0 +// Sample usage: +// @note 名称长度不能超过18个字符 且只能为英文与数字 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_set_name(const int8 *str) +{ + bluetooth_ch9141_send_at_command_parameter("NAME", str); + bluetooth_ch9141_send_at_command_parameter("PNAME", str); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块密码设置 +// @param enable 使能密码 0:不使用密码,1:使用密码才能连接本设备 +// @param *password 密码的字符串 必须为6个字符 +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_set_password(uint8 enable, const int8 *password) +{ + if(0 == enable) + { + //关闭密码 + bluetooth_ch9141_send_at_command_parameter("PASEN", "OFF"); + } + else + { + //设置密码并使能 + bluetooth_ch9141_send_at_command_parameter("PASEN", "ON"); + bluetooth_ch9141_send_at_command_parameter("PASS", password); + } +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块指定MAC地址并立即进行连接 +// @param *mac_and_password 需要连接的设备mac地址与密码 +// @return void +// @since v1.0 +// Sample usage: +// @note bluetooth_ch9141_connect("58:B7:33:E4:C2:84,000000"); +// 58:B7:33:E4:C2:84为mac地址 ,为分隔符 000000为从机蓝牙密码 +// ===================特别注意================== +// 如果使用手机查看蓝牙的mac地址,则使用本函数连接的时候请将mac倒置一下 +// 例如手机查看到的mac地址为61:62:63:64:65:66,则使用本函数连接的时候应该写 +// bluetooth_ch9141_connect("66:65:64:63:62:61,000000"); +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_connect(const int8 *mac_and_password) +{ + bluetooth_ch9141_send_at_command_parameter("CONN", mac_and_password); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块默认连接参数设置(设置好后,每次开机蓝牙会自动链接这个设备) +// @param *mac_and_password 需要连接的设备mac地址与密码 +// @return void +// @since v1.0 +// Sample usage: +// @note bluetooth_ch9141_default_connect("58:B7:33:E4:C2:84,000000"); +// 58:B7:33:E4:C2:84为mac地址 ,为分隔符 000000为从机蓝牙密码 +// ===================特别注意================== +// 如果使用手机查看CH9141的mac地址,将CH9141设置为从机,使用手机连接 +// 则使用本函数连接的时候请将mac倒置一下 +// 例如手机查看到的mac地址为61:62:63:64:65:67,则使用本函数连接的时候应该写 +// bluetooth_ch9141_default_connect("67:65:64:63:62:61,000000"); +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_default_connect(const int8 *mac_and_password) +{ + bluetooth_ch9141_send_at_command_parameter("CONADD", mac_and_password); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块获取rssi(信号强度) +// @param void +// @return int8 返回信号强度0到-127 +// @since v1.0 +// Sample usage: +// @note 调用此函数需要先调用bluetooth_ch9141_enter_at_mode或者拉低CMD引脚 进入AT模式 +// 需要特别注意bluetooth_ch9141_enter_at_mode函数内部有500ms的延时 +//------------------------------------------------------------------------------------------------------------------- +int16 bluetooth_ch9141_get_rssi(void) +{ + uint8 i; + size_t length; + int16 rssi; + bluetooth_ch9141_send_at_command_parameter("RSSI", "ON,0"); + length = strlen((int8 *)at_mode_data); + length -= 12;//计算RSSI 有多少位 + + rssi = 0; + for(i=0; i30) { - if(gpio_get(RTS_PIN)) - { - return len;//模块忙,如果允许当前程序使用while等待 则可以使用后面注释的while等待语句替换本if语句 - } - //while(gpio_get(RTS_PIN)); //如果RTS为低电平,则继续发送数据 +// if(gpio_get(RTS_PIN)) +// { +// return len;//模块忙,如果允许当前程序使用while等待 则可以使用后面注释的while等待语句替换本if语句 +// } + while(gpio_get(RTS_PIN)); //如果RTS为低电平,则继续发送数据 uart_putbuff(WIRELESS_UART,buff,30); buff += 30; //地址偏移 len -= 30;//数量 } - if(gpio_get(RTS_PIN)) - { - return len;//模块忙,如果允许当前程序使用while等待 则可以使用后面注释的while等待语句替换本if语句 - } - //while(gpio_get(RTS_PIN)); //如果RTS为低电平,则继续发送数据 +// if(gpio_get(RTS_PIN)) +// { +// return len;//模块忙,如果允许当前程序使用while等待 则可以使用后面注释的while等待语句替换本if语句 +// } + while(gpio_get(RTS_PIN)); //如果RTS为低电平,则继续发送数据 uart_putbuff(WIRELESS_UART,buff,len);//发送最后的数据 return 0; diff --git a/Example/Encoder_Demo/Libraries/seekfree_peripheral/SEEKFREE_WIRELESS.h b/Example/Encoder_Demo/Libraries/seekfree_peripheral/SEEKFREE_WIRELESS.h index 42c0832..d80339d 100644 --- a/Example/Encoder_Demo/Libraries/seekfree_peripheral/SEEKFREE_WIRELESS.h +++ b/Example/Encoder_Demo/Libraries/seekfree_peripheral/SEEKFREE_WIRELESS.h @@ -38,8 +38,26 @@ #define WIRELESS_UART_RX UART2_RX_P10_6 #define WIRELESS_UART_BAUD 115200 -#define RTS_PIN P10_2 //定义流控位引脚 指示当前模块是否可以接受数据 0可以继续接收 1不可以继续接收 +// ------------------------------------ 自动波特率 ------------------------------------ +// 注意事项1:无线转串口模块版本是V2.0以下的是无法开启自动波特率的。 +// 注意事项2:开启自动波特率务必连接RTS引脚,否则会开启失败。 +// 注意事项3:模块自动波特率失败的话,可以尝试断电重启 +// 开启自动波特率务必阅读上面两条 注意事项 +// 开启自动波特率务必阅读上面两条 注意事项 +// 开启自动波特率务必阅读上面两条 注意事项 + +// 0:关闭自动波特率 +// 1:开启自动波特率 自动波特率的作用是修改WIRELESS_UART_BAUD之后不需要对模块进行配置,模块会自动设置为对应的波特率 + +#define WIRELESS_AUTO_UART_BAUD 0 +// ------------------------------------ 自动波特率 ------------------------------------ + +#define RTS_PIN P10_2 //定义流控位引脚 指示当前模块是否可以接受数据 0可以继续接收 1不可以继续接收 +#define WIRELESS_BUFFER_SIZE 16 + +extern uint8 wireless_send_buffer[WIRELESS_BUFFER_SIZE]; +extern uint32 wireless_rx_index; void wireless_uart_callback(void); void seekfree_wireless_init(void); diff --git a/Example/Encoder_Demo/USER/isr.c b/Example/Encoder_Demo/USER/isr.c index c55a012..16bff98 100644 --- a/Example/Encoder_Demo/USER/isr.c +++ b/Example/Encoder_Demo/USER/isr.c @@ -179,7 +179,20 @@ IFX_INTERRUPT(uart2_rx_isr, 0, UART2_RX_INT_PRIO) { enableInterrupts();//开启中断嵌套 IfxAsclin_Asc_isrReceive(&uart2_handle); - wireless_uart_callback(); + switch(wireless_type) + { + case WIRELESS_SI24R1: + { + wireless_uart_callback(); + }break; + + case WIRELESS_CH9141: + { + bluetooth_ch9141_uart_callback(); + }break; + default:break; + } + } IFX_INTERRUPT(uart2_er_isr, 0, UART2_ER_INT_PRIO) { diff --git a/Example/Encoder_Demo/鍒犻櫎涓存椂鏂囦欢.bat b/Example/Encoder_Demo/鍒犻櫎涓存椂鏂囦欢.bat index 5323dd9..fa499b1 100644 --- a/Example/Encoder_Demo/鍒犻櫎涓存椂鏂囦欢.bat +++ b/Example/Encoder_Demo/鍒犻櫎涓存椂鏂囦欢.bat @@ -1,9 +1,6 @@ -rmdir .settings /s /q rmdir Debug /s /q del *.launch /s - -pause exit diff --git a/Example/FFT_Demo/.cproject b/Example/FFT_Demo/.cproject index dd69b8f..07e693c 100644 --- a/Example/FFT_Demo/.cproject +++ b/Example/FFT_Demo/.cproject @@ -3,9 +3,9 @@ - + - + @@ -25,50 +25,76 @@ - + - + - + - + + + + + + @@ -355,9 +371,9 @@ - + - + @@ -377,43 +393,1895 @@ - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -431,13 +2299,37 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + @@ -458,21 +2350,5 @@ - - - - - - - - - - - - - - - - diff --git a/Example/FFT_Demo/.project b/Example/FFT_Demo/.project index ff99e6c..d7a9f25 100644 --- a/Example/FFT_Demo/.project +++ b/Example/FFT_Demo/.project @@ -5,6 +5,18 @@ + + com.infineon.aurix.buildsystem.builders.booster + full,incremental, + + + + + com.infineon.aurix.buildsystem.builders.autodiscovery + full,incremental, + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder clean,full,incremental, diff --git a/Example/FFT_Demo/.settings/com.infineon.aurix.buildsystem.prefs b/Example/FFT_Demo/.settings/com.infineon.aurix.buildsystem.prefs new file mode 100644 index 0000000..be61bc1 --- /dev/null +++ b/Example/FFT_Demo/.settings/com.infineon.aurix.buildsystem.prefs @@ -0,0 +1,10 @@ +AURIX-LIBRARY-PATH=Libraries/iLLD\#Libraries/Infra\#Libraries/Service +DEVICE-ID=TC26B +DEVICE-ID-FULL=TC26xD_B-Step +ILLD-SET=full +IncludesAutodiscovery=true +LIBRARIES-ROOT-PATH=Libraries +NEVER-EXCLUDE-FROM-BUILD=/Libraries/iLLD/TC26B/Tricore/Cpu/CStart\#/Libraries/iLLD/TC26B/Tricore/Cpu/Trap\#/Configurations\#/Configurations/Debug +PROJECT-VERSION=1.0 +aurixDevice=TC26xD_B-Step +eclipse.preferences.version=1 diff --git a/Example/FFT_Demo/Libraries/doc/version.txt b/Example/FFT_Demo/Libraries/doc/version.txt index ab79909..11ab82e 100644 --- a/Example/FFT_Demo/Libraries/doc/version.txt +++ b/Example/FFT_Demo/Libraries/doc/version.txt @@ -1,3 +1,13 @@ +V1.2.0 + 增加CH9141蓝牙转串口模块的驱动 + 添加无线类型的枚举变量 + 修改 删除临时文件.bat 执行完操作后自动关闭窗口 + 修改 删除临时文件.bat 避免删除新版本所需文件 + 修改工程项目文件,以支持新版本编译 + +V1.1.10 + 修复通过#pragma section all "cpux_dsram"指定变量位置失效的问题 + V1.1.9 将串口的发送buff增加到128字节 diff --git a/Example/FFT_Demo/Libraries/seekfree_libraries/common/common.c b/Example/FFT_Demo/Libraries/seekfree_libraries/common/common.c index 0b9931e..7620ce6 100644 --- a/Example/FFT_Demo/Libraries/seekfree_libraries/common/common.c +++ b/Example/FFT_Demo/Libraries/seekfree_libraries/common/common.c @@ -27,6 +27,8 @@ CAMERA_TYPE_enum camera_type; //摄像头型号 uint8 *camera_buffer_addr; //摄像头数组地址 +WIRELESS_TYPE_enum wireless_type;//无线转串口类型 + IFX_ALIGN(4) IfxCpu_syncEvent g_cpuSyncEvent = 0;//事件同步变量 App_Cpu0 g_AppCpu0; //频率信息变量 diff --git a/Example/FFT_Demo/Libraries/seekfree_libraries/common/common.h b/Example/FFT_Demo/Libraries/seekfree_libraries/common/common.h index 84c43ee..5b741c0 100644 --- a/Example/FFT_Demo/Libraries/seekfree_libraries/common/common.h +++ b/Example/FFT_Demo/Libraries/seekfree_libraries/common/common.h @@ -113,6 +113,12 @@ typedef enum //枚 CAMERA_COLOR, //凌瞳 }CAMERA_TYPE_enum; +typedef enum //无线模块 +{ + WIRELESS_SI24R1 = 1, //无线转串口 + WIRELESS_CH9141, //蓝牙转串口 +}WIRELESS_TYPE_enum; + #include #include #include "IfxCpu.h" @@ -120,6 +126,8 @@ typedef enum //枚 extern CAMERA_TYPE_enum camera_type; //摄像头型号 extern uint8 *camera_buffer_addr; //摄像头数组地址 +extern WIRELESS_TYPE_enum wireless_type; + extern IfxCpu_syncEvent g_cpuSyncEvent; void get_clk(void); diff --git a/Example/FFT_Demo/Libraries/seekfree_libraries/headfile.h b/Example/FFT_Demo/Libraries/seekfree_libraries/headfile.h index 404ee0a..b745302 100644 --- a/Example/FFT_Demo/Libraries/seekfree_libraries/headfile.h +++ b/Example/FFT_Demo/Libraries/seekfree_libraries/headfile.h @@ -65,6 +65,7 @@ #include "SEEKFREE_7725.h" #include "SEEKFREE_RDA5807.h" #include "SEEKFREE_7725_UART.h" +#include "SEEKFREE_BLUETOOTH_CH9141.h" #endif diff --git a/Example/FFT_Demo/Libraries/seekfree_peripheral/SEEKFREE_BLUETOOTH_CH9141.c b/Example/FFT_Demo/Libraries/seekfree_peripheral/SEEKFREE_BLUETOOTH_CH9141.c new file mode 100644 index 0000000..b4ec2df --- /dev/null +++ b/Example/FFT_Demo/Libraries/seekfree_peripheral/SEEKFREE_BLUETOOTH_CH9141.c @@ -0,0 +1,509 @@ +/********************************************************************************************************************* + * COPYRIGHT NOTICE + * Copyright (c) 2021,逐飞科技 + * All rights reserved. + * 技术讨论QQ群:一群:179029047(已满) 二群:244861897 + * + * 以下所有内容版权均属逐飞科技所有,未经允许不得用于商业用途, + * 欢迎各位使用并传播本程序,修改内容时必须保留逐飞科技的版权声明。 + * + * @file 逐飞科技蓝牙转串口模块 + * @company 成都逐飞科技有限公司 + * @author 逐飞科技(QQ3184284598) + * @version 查看doc内version文件 版本说明 + * @Software IAR 8.3 or MDK 5.33 + * @Taobao https://seekfree.taobao.com/ + * @date 2021-08-27 + * @note + 接线定义: + ------------------------------------ + 蓝牙转串口 单片机 + RX 查看SEEKFREE_BLUETOOTH_CH9141.h文件中的BLUETOOTH_CH9141_UART_TX宏定义 + TX 查看SEEKFREE_BLUETOOTH_CH9141.h文件中的BLUETOOTH_CH9141_UART_RX宏定义 + RTS 查看SEEKFREE_BLUETOOTH_CH9141.h文件中的BLUETOOTH_CH9141_RTS_PIN宏定义 + CTS 悬空 + CMD 悬空或者上拉 + ------------------------------------ + ********************************************************************************************************************/ +#include "zf_stm_systick.h" +#include "zf_gpio.h" +#include "zf_uart.h" +#include "zf_assert.h" +#include "SEEKFREE_BLUETOOTH_CH9141.h" + +uint8 uart_flag; +uint8 uart_data; + +vuint8 at_mode = 0; //0:蓝牙透传模式 1:AT模式 2:模块复位中 +vuint8 at_mode_num; //at模式时用于指示数据接收的数量 +vuint8 at_mode_data[30]; //接收at命令的缓存 +vuint8 at_mode_cmd_flag; //OK应答命令接收成功的标志位 + +uint8 mac_address[17]; //本机mac地址 + + +uint8 bluetooth_ch9141_rx_buffer; + + +void bluetooth_ch9141_check_response(void); + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块 串口中断回调函数 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note 该函数在ISR文件 串口8中断程序被调用 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_uart_callback() +{ + while(uart_query(BLUETOOTH_CH9141_UART, &bluetooth_ch9141_rx_buffer)) + { + if(1 == at_mode) + { + //进入AT模式 接收应答信号 此处if语句内代码用户不要改动 + at_mode_data[at_mode_num++] = bluetooth_ch9141_rx_buffer; + bluetooth_ch9141_check_response(); + } + else if(2 == at_mode) + { + //模块正在复位中 此处if语句内代码用户不要改动 + at_mode_num++; + } + else + { + //透传模式 用户在此处接收配对的蓝牙发送过来的额数据 + //接到一个字节后单片机将会进入此处,通过在此处读取bluetooth_ch9141_rx_buffer可以取走数据 + + // 读取无线串口的数据 并且置位接收标志 + uart_flag = 1; + uart_data = bluetooth_ch9141_rx_buffer; + } + + } +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块检查OK应答信号 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_check_response(void) +{ + if(4 <= at_mode_num) + { + if(0 == strncmp("OK\r\n", (int8 *)&at_mode_data[at_mode_num-4], 4)) + { + at_mode_cmd_flag = 1; + } + } +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块发送一个没有参数的命令并等待应答信号 +// @param *str 需要发送的命令 完整字符串 +// @return void +// @since v1.0 +// Sample usage: +// @note 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_send_at_command(const int8 *str) +{ + at_mode_num = 0; //接收数量清零 + uart_putstr(BLUETOOTH_CH9141_UART, str); + uart_putstr(BLUETOOTH_CH9141_UART, "\r\n"); + + //等待收到应答信号 + while(!at_mode_cmd_flag); + at_mode_cmd_flag = 0; +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块发送一个带有参数的命令并等待应答信号 +// @param *cmd 需要发送的命令名称 +// @param *data 需要发送的数据 +// @return void +// @since v1.0 +// Sample usage: +// @note 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_send_at_command_parameter(const int8 *cmd, const int8 *data) +{ + at_mode_num = 0; //接收数量清零 + uart_putstr(BLUETOOTH_CH9141_UART, "AT+"); + uart_putstr(BLUETOOTH_CH9141_UART, cmd); + uart_putstr(BLUETOOTH_CH9141_UART, "="); + uart_putstr(BLUETOOTH_CH9141_UART, data); + uart_putstr(BLUETOOTH_CH9141_UART, "\r\n"); + + //等待收到应答信号 + while(!at_mode_cmd_flag); + at_mode_cmd_flag = 0; +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块进入AT模式 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_enter_at_mode(void) +{ + systick_delay_ms(STM0, 550); //发送进入AT模式的命令前需要保证模块在550ms内没有接收过任何数据 + at_mode = 1; //进入AT模式 + bluetooth_ch9141_send_at_command("AT..."); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块退出AT模式 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_exit_at_mode(void) +{ + bluetooth_ch9141_send_at_command("AT+EXIT"); + at_mode = 0; //进入透传模式 + systick_delay_ms(STM0, 300); //等待成功进入AT模式 +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块复位 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_reset(void) +{ + bluetooth_ch9141_send_at_command("AT+RESET"); + at_mode = 2; //进入重启成功检测 + at_mode_num = 0; + while(7 > at_mode_num); //等待蓝牙模块完成复位 + at_mode = 0; //复位之后模块自动进入透传模式 +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块获取本机MAC地址 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note 调用此函数需要先调用bluetooth_ch9141_enter_at_mode或者拉低CMD引脚 进入AT模式 +// 需要特别注意bluetooth_ch9141_enter_at_mode函数内部有500ms的延时 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_get_mac_address(void) +{ + bluetooth_ch9141_send_at_command("AT+MAC?"); + + //mac地址为小段格式,mac_address[0]保存的是mac地址最低位 + memcpy(mac_address, (uint8 *)at_mode_data, 17); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块设置发送功率 +// @param tx_power 设置发送功率,可设置选项查看CH9141_TX_POWEER_enum枚举成员 +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_set_tx_power(CH9141_TX_POWEER_enum tx_power) +{ + int8 tx_power_data; + + tx_power_data = (uint8)tx_power + '0'; + bluetooth_ch9141_send_at_command_parameter("TPL", &tx_power_data); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块设置模式 +// @param mode 模式设置,可设置选项查看CH9141_MODE_enum枚举成员 +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_set_mode(CH9141_MODE_enum mode) +{ + int8 mode_data; + + mode_data = (uint8)mode + '0'; + bluetooth_ch9141_send_at_command_parameter("BLEMODE", &mode_data); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块获取状态 +// @param mode 模式设置,可设置选项查看CH9141_MODE_enum枚举成员 +// @return CH9141_STATUS_enum 返回状态信息 +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +CH9141_STATUS_enum bluetooth_ch9141_get_status(CH9141_MODE_enum mode) +{ + CH9141_STATUS_enum ch9141_status; + int8 mode_data; + + mode_data = (uint8)mode + '0'; + bluetooth_ch9141_send_at_command_parameter("BLEMODE", &mode_data); + + bluetooth_ch9141_send_at_command("AT+BLESTA?"); + + ch9141_status = (at_mode_data[0] - '0') * 10 + (at_mode_data[1] - '0'); + if(SLAVE_MODE == mode) + { + ch9141_status += SLAVE_NO_INIT; + } + + return ch9141_status; +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块设置设备名称 +// @param *str 蓝牙名称 +// @return void +// @since v1.0 +// Sample usage: +// @note 名称长度不能超过18个字符 且只能为英文与数字 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_set_name(const int8 *str) +{ + bluetooth_ch9141_send_at_command_parameter("NAME", str); + bluetooth_ch9141_send_at_command_parameter("PNAME", str); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块密码设置 +// @param enable 使能密码 0:不使用密码,1:使用密码才能连接本设备 +// @param *password 密码的字符串 必须为6个字符 +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_set_password(uint8 enable, const int8 *password) +{ + if(0 == enable) + { + //关闭密码 + bluetooth_ch9141_send_at_command_parameter("PASEN", "OFF"); + } + else + { + //设置密码并使能 + bluetooth_ch9141_send_at_command_parameter("PASEN", "ON"); + bluetooth_ch9141_send_at_command_parameter("PASS", password); + } +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块指定MAC地址并立即进行连接 +// @param *mac_and_password 需要连接的设备mac地址与密码 +// @return void +// @since v1.0 +// Sample usage: +// @note bluetooth_ch9141_connect("58:B7:33:E4:C2:84,000000"); +// 58:B7:33:E4:C2:84为mac地址 ,为分隔符 000000为从机蓝牙密码 +// ===================特别注意================== +// 如果使用手机查看蓝牙的mac地址,则使用本函数连接的时候请将mac倒置一下 +// 例如手机查看到的mac地址为61:62:63:64:65:66,则使用本函数连接的时候应该写 +// bluetooth_ch9141_connect("66:65:64:63:62:61,000000"); +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_connect(const int8 *mac_and_password) +{ + bluetooth_ch9141_send_at_command_parameter("CONN", mac_and_password); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块默认连接参数设置(设置好后,每次开机蓝牙会自动链接这个设备) +// @param *mac_and_password 需要连接的设备mac地址与密码 +// @return void +// @since v1.0 +// Sample usage: +// @note bluetooth_ch9141_default_connect("58:B7:33:E4:C2:84,000000"); +// 58:B7:33:E4:C2:84为mac地址 ,为分隔符 000000为从机蓝牙密码 +// ===================特别注意================== +// 如果使用手机查看CH9141的mac地址,将CH9141设置为从机,使用手机连接 +// 则使用本函数连接的时候请将mac倒置一下 +// 例如手机查看到的mac地址为61:62:63:64:65:67,则使用本函数连接的时候应该写 +// bluetooth_ch9141_default_connect("67:65:64:63:62:61,000000"); +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_default_connect(const int8 *mac_and_password) +{ + bluetooth_ch9141_send_at_command_parameter("CONADD", mac_and_password); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块获取rssi(信号强度) +// @param void +// @return int8 返回信号强度0到-127 +// @since v1.0 +// Sample usage: +// @note 调用此函数需要先调用bluetooth_ch9141_enter_at_mode或者拉低CMD引脚 进入AT模式 +// 需要特别注意bluetooth_ch9141_enter_at_mode函数内部有500ms的延时 +//------------------------------------------------------------------------------------------------------------------- +int16 bluetooth_ch9141_get_rssi(void) +{ + uint8 i; + size_t length; + int16 rssi; + bluetooth_ch9141_send_at_command_parameter("RSSI", "ON,0"); + length = strlen((int8 *)at_mode_data); + length -= 12;//计算RSSI 有多少位 + + rssi = 0; + for(i=0; i30) { - if(gpio_get(RTS_PIN)) - { - return len;//模块忙,如果允许当前程序使用while等待 则可以使用后面注释的while等待语句替换本if语句 - } - //while(gpio_get(RTS_PIN)); //如果RTS为低电平,则继续发送数据 +// if(gpio_get(RTS_PIN)) +// { +// return len;//模块忙,如果允许当前程序使用while等待 则可以使用后面注释的while等待语句替换本if语句 +// } + while(gpio_get(RTS_PIN)); //如果RTS为低电平,则继续发送数据 uart_putbuff(WIRELESS_UART,buff,30); buff += 30; //地址偏移 len -= 30;//数量 } - if(gpio_get(RTS_PIN)) - { - return len;//模块忙,如果允许当前程序使用while等待 则可以使用后面注释的while等待语句替换本if语句 - } - //while(gpio_get(RTS_PIN)); //如果RTS为低电平,则继续发送数据 +// if(gpio_get(RTS_PIN)) +// { +// return len;//模块忙,如果允许当前程序使用while等待 则可以使用后面注释的while等待语句替换本if语句 +// } + while(gpio_get(RTS_PIN)); //如果RTS为低电平,则继续发送数据 uart_putbuff(WIRELESS_UART,buff,len);//发送最后的数据 return 0; diff --git a/Example/FFT_Demo/Libraries/seekfree_peripheral/SEEKFREE_WIRELESS.h b/Example/FFT_Demo/Libraries/seekfree_peripheral/SEEKFREE_WIRELESS.h index 42c0832..d80339d 100644 --- a/Example/FFT_Demo/Libraries/seekfree_peripheral/SEEKFREE_WIRELESS.h +++ b/Example/FFT_Demo/Libraries/seekfree_peripheral/SEEKFREE_WIRELESS.h @@ -38,8 +38,26 @@ #define WIRELESS_UART_RX UART2_RX_P10_6 #define WIRELESS_UART_BAUD 115200 -#define RTS_PIN P10_2 //定义流控位引脚 指示当前模块是否可以接受数据 0可以继续接收 1不可以继续接收 +// ------------------------------------ 自动波特率 ------------------------------------ +// 注意事项1:无线转串口模块版本是V2.0以下的是无法开启自动波特率的。 +// 注意事项2:开启自动波特率务必连接RTS引脚,否则会开启失败。 +// 注意事项3:模块自动波特率失败的话,可以尝试断电重启 +// 开启自动波特率务必阅读上面两条 注意事项 +// 开启自动波特率务必阅读上面两条 注意事项 +// 开启自动波特率务必阅读上面两条 注意事项 + +// 0:关闭自动波特率 +// 1:开启自动波特率 自动波特率的作用是修改WIRELESS_UART_BAUD之后不需要对模块进行配置,模块会自动设置为对应的波特率 + +#define WIRELESS_AUTO_UART_BAUD 0 +// ------------------------------------ 自动波特率 ------------------------------------ + +#define RTS_PIN P10_2 //定义流控位引脚 指示当前模块是否可以接受数据 0可以继续接收 1不可以继续接收 +#define WIRELESS_BUFFER_SIZE 16 + +extern uint8 wireless_send_buffer[WIRELESS_BUFFER_SIZE]; +extern uint32 wireless_rx_index; void wireless_uart_callback(void); void seekfree_wireless_init(void); diff --git a/Example/FFT_Demo/USER/isr.c b/Example/FFT_Demo/USER/isr.c index c55a012..16bff98 100644 --- a/Example/FFT_Demo/USER/isr.c +++ b/Example/FFT_Demo/USER/isr.c @@ -179,7 +179,20 @@ IFX_INTERRUPT(uart2_rx_isr, 0, UART2_RX_INT_PRIO) { enableInterrupts();//开启中断嵌套 IfxAsclin_Asc_isrReceive(&uart2_handle); - wireless_uart_callback(); + switch(wireless_type) + { + case WIRELESS_SI24R1: + { + wireless_uart_callback(); + }break; + + case WIRELESS_CH9141: + { + bluetooth_ch9141_uart_callback(); + }break; + default:break; + } + } IFX_INTERRUPT(uart2_er_isr, 0, UART2_ER_INT_PRIO) { diff --git a/Example/FFT_Demo/鍒犻櫎涓存椂鏂囦欢.bat b/Example/FFT_Demo/鍒犻櫎涓存椂鏂囦欢.bat index 5323dd9..fa499b1 100644 --- a/Example/FFT_Demo/鍒犻櫎涓存椂鏂囦欢.bat +++ b/Example/FFT_Demo/鍒犻櫎涓存椂鏂囦欢.bat @@ -1,9 +1,6 @@ -rmdir .settings /s /q rmdir Debug /s /q del *.launch /s - -pause exit diff --git a/Example/GPIO_Interrupt_Demo/.cproject b/Example/GPIO_Interrupt_Demo/.cproject index c4f672b..35371d8 100644 --- a/Example/GPIO_Interrupt_Demo/.cproject +++ b/Example/GPIO_Interrupt_Demo/.cproject @@ -3,9 +3,9 @@ - + - + @@ -25,50 +25,76 @@ - + - + - + - + + + + + + @@ -355,9 +371,9 @@ - + - + @@ -377,43 +393,1895 @@ - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -431,13 +2299,37 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + @@ -458,21 +2350,5 @@ - - - - - - - - - - - - - - - - diff --git a/Example/GPIO_Interrupt_Demo/.project b/Example/GPIO_Interrupt_Demo/.project index 5223db4..fcdddec 100644 --- a/Example/GPIO_Interrupt_Demo/.project +++ b/Example/GPIO_Interrupt_Demo/.project @@ -5,6 +5,18 @@ + + com.infineon.aurix.buildsystem.builders.booster + full,incremental, + + + + + com.infineon.aurix.buildsystem.builders.autodiscovery + full,incremental, + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder clean,full,incremental, diff --git a/Example/GPIO_Interrupt_Demo/.settings/com.infineon.aurix.buildsystem.prefs b/Example/GPIO_Interrupt_Demo/.settings/com.infineon.aurix.buildsystem.prefs new file mode 100644 index 0000000..be61bc1 --- /dev/null +++ b/Example/GPIO_Interrupt_Demo/.settings/com.infineon.aurix.buildsystem.prefs @@ -0,0 +1,10 @@ +AURIX-LIBRARY-PATH=Libraries/iLLD\#Libraries/Infra\#Libraries/Service +DEVICE-ID=TC26B +DEVICE-ID-FULL=TC26xD_B-Step +ILLD-SET=full +IncludesAutodiscovery=true +LIBRARIES-ROOT-PATH=Libraries +NEVER-EXCLUDE-FROM-BUILD=/Libraries/iLLD/TC26B/Tricore/Cpu/CStart\#/Libraries/iLLD/TC26B/Tricore/Cpu/Trap\#/Configurations\#/Configurations/Debug +PROJECT-VERSION=1.0 +aurixDevice=TC26xD_B-Step +eclipse.preferences.version=1 diff --git a/Example/GPIO_Interrupt_Demo/Libraries/doc/version.txt b/Example/GPIO_Interrupt_Demo/Libraries/doc/version.txt index ab79909..11ab82e 100644 --- a/Example/GPIO_Interrupt_Demo/Libraries/doc/version.txt +++ b/Example/GPIO_Interrupt_Demo/Libraries/doc/version.txt @@ -1,3 +1,13 @@ +V1.2.0 + 增加CH9141蓝牙转串口模块的驱动 + 添加无线类型的枚举变量 + 修改 删除临时文件.bat 执行完操作后自动关闭窗口 + 修改 删除临时文件.bat 避免删除新版本所需文件 + 修改工程项目文件,以支持新版本编译 + +V1.1.10 + 修复通过#pragma section all "cpux_dsram"指定变量位置失效的问题 + V1.1.9 将串口的发送buff增加到128字节 diff --git a/Example/GPIO_Interrupt_Demo/Libraries/seekfree_libraries/common/common.c b/Example/GPIO_Interrupt_Demo/Libraries/seekfree_libraries/common/common.c index 0b9931e..7620ce6 100644 --- a/Example/GPIO_Interrupt_Demo/Libraries/seekfree_libraries/common/common.c +++ b/Example/GPIO_Interrupt_Demo/Libraries/seekfree_libraries/common/common.c @@ -27,6 +27,8 @@ CAMERA_TYPE_enum camera_type; //摄像头型号 uint8 *camera_buffer_addr; //摄像头数组地址 +WIRELESS_TYPE_enum wireless_type;//无线转串口类型 + IFX_ALIGN(4) IfxCpu_syncEvent g_cpuSyncEvent = 0;//事件同步变量 App_Cpu0 g_AppCpu0; //频率信息变量 diff --git a/Example/GPIO_Interrupt_Demo/Libraries/seekfree_libraries/common/common.h b/Example/GPIO_Interrupt_Demo/Libraries/seekfree_libraries/common/common.h index 84c43ee..5b741c0 100644 --- a/Example/GPIO_Interrupt_Demo/Libraries/seekfree_libraries/common/common.h +++ b/Example/GPIO_Interrupt_Demo/Libraries/seekfree_libraries/common/common.h @@ -113,6 +113,12 @@ typedef enum //枚 CAMERA_COLOR, //凌瞳 }CAMERA_TYPE_enum; +typedef enum //无线模块 +{ + WIRELESS_SI24R1 = 1, //无线转串口 + WIRELESS_CH9141, //蓝牙转串口 +}WIRELESS_TYPE_enum; + #include #include #include "IfxCpu.h" @@ -120,6 +126,8 @@ typedef enum //枚 extern CAMERA_TYPE_enum camera_type; //摄像头型号 extern uint8 *camera_buffer_addr; //摄像头数组地址 +extern WIRELESS_TYPE_enum wireless_type; + extern IfxCpu_syncEvent g_cpuSyncEvent; void get_clk(void); diff --git a/Example/GPIO_Interrupt_Demo/Libraries/seekfree_libraries/headfile.h b/Example/GPIO_Interrupt_Demo/Libraries/seekfree_libraries/headfile.h index 404ee0a..b745302 100644 --- a/Example/GPIO_Interrupt_Demo/Libraries/seekfree_libraries/headfile.h +++ b/Example/GPIO_Interrupt_Demo/Libraries/seekfree_libraries/headfile.h @@ -65,6 +65,7 @@ #include "SEEKFREE_7725.h" #include "SEEKFREE_RDA5807.h" #include "SEEKFREE_7725_UART.h" +#include "SEEKFREE_BLUETOOTH_CH9141.h" #endif diff --git a/Example/GPIO_Interrupt_Demo/Libraries/seekfree_peripheral/SEEKFREE_BLUETOOTH_CH9141.c b/Example/GPIO_Interrupt_Demo/Libraries/seekfree_peripheral/SEEKFREE_BLUETOOTH_CH9141.c new file mode 100644 index 0000000..b4ec2df --- /dev/null +++ b/Example/GPIO_Interrupt_Demo/Libraries/seekfree_peripheral/SEEKFREE_BLUETOOTH_CH9141.c @@ -0,0 +1,509 @@ +/********************************************************************************************************************* + * COPYRIGHT NOTICE + * Copyright (c) 2021,逐飞科技 + * All rights reserved. + * 技术讨论QQ群:一群:179029047(已满) 二群:244861897 + * + * 以下所有内容版权均属逐飞科技所有,未经允许不得用于商业用途, + * 欢迎各位使用并传播本程序,修改内容时必须保留逐飞科技的版权声明。 + * + * @file 逐飞科技蓝牙转串口模块 + * @company 成都逐飞科技有限公司 + * @author 逐飞科技(QQ3184284598) + * @version 查看doc内version文件 版本说明 + * @Software IAR 8.3 or MDK 5.33 + * @Taobao https://seekfree.taobao.com/ + * @date 2021-08-27 + * @note + 接线定义: + ------------------------------------ + 蓝牙转串口 单片机 + RX 查看SEEKFREE_BLUETOOTH_CH9141.h文件中的BLUETOOTH_CH9141_UART_TX宏定义 + TX 查看SEEKFREE_BLUETOOTH_CH9141.h文件中的BLUETOOTH_CH9141_UART_RX宏定义 + RTS 查看SEEKFREE_BLUETOOTH_CH9141.h文件中的BLUETOOTH_CH9141_RTS_PIN宏定义 + CTS 悬空 + CMD 悬空或者上拉 + ------------------------------------ + ********************************************************************************************************************/ +#include "zf_stm_systick.h" +#include "zf_gpio.h" +#include "zf_uart.h" +#include "zf_assert.h" +#include "SEEKFREE_BLUETOOTH_CH9141.h" + +uint8 uart_flag; +uint8 uart_data; + +vuint8 at_mode = 0; //0:蓝牙透传模式 1:AT模式 2:模块复位中 +vuint8 at_mode_num; //at模式时用于指示数据接收的数量 +vuint8 at_mode_data[30]; //接收at命令的缓存 +vuint8 at_mode_cmd_flag; //OK应答命令接收成功的标志位 + +uint8 mac_address[17]; //本机mac地址 + + +uint8 bluetooth_ch9141_rx_buffer; + + +void bluetooth_ch9141_check_response(void); + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块 串口中断回调函数 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note 该函数在ISR文件 串口8中断程序被调用 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_uart_callback() +{ + while(uart_query(BLUETOOTH_CH9141_UART, &bluetooth_ch9141_rx_buffer)) + { + if(1 == at_mode) + { + //进入AT模式 接收应答信号 此处if语句内代码用户不要改动 + at_mode_data[at_mode_num++] = bluetooth_ch9141_rx_buffer; + bluetooth_ch9141_check_response(); + } + else if(2 == at_mode) + { + //模块正在复位中 此处if语句内代码用户不要改动 + at_mode_num++; + } + else + { + //透传模式 用户在此处接收配对的蓝牙发送过来的额数据 + //接到一个字节后单片机将会进入此处,通过在此处读取bluetooth_ch9141_rx_buffer可以取走数据 + + // 读取无线串口的数据 并且置位接收标志 + uart_flag = 1; + uart_data = bluetooth_ch9141_rx_buffer; + } + + } +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块检查OK应答信号 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_check_response(void) +{ + if(4 <= at_mode_num) + { + if(0 == strncmp("OK\r\n", (int8 *)&at_mode_data[at_mode_num-4], 4)) + { + at_mode_cmd_flag = 1; + } + } +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块发送一个没有参数的命令并等待应答信号 +// @param *str 需要发送的命令 完整字符串 +// @return void +// @since v1.0 +// Sample usage: +// @note 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_send_at_command(const int8 *str) +{ + at_mode_num = 0; //接收数量清零 + uart_putstr(BLUETOOTH_CH9141_UART, str); + uart_putstr(BLUETOOTH_CH9141_UART, "\r\n"); + + //等待收到应答信号 + while(!at_mode_cmd_flag); + at_mode_cmd_flag = 0; +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块发送一个带有参数的命令并等待应答信号 +// @param *cmd 需要发送的命令名称 +// @param *data 需要发送的数据 +// @return void +// @since v1.0 +// Sample usage: +// @note 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_send_at_command_parameter(const int8 *cmd, const int8 *data) +{ + at_mode_num = 0; //接收数量清零 + uart_putstr(BLUETOOTH_CH9141_UART, "AT+"); + uart_putstr(BLUETOOTH_CH9141_UART, cmd); + uart_putstr(BLUETOOTH_CH9141_UART, "="); + uart_putstr(BLUETOOTH_CH9141_UART, data); + uart_putstr(BLUETOOTH_CH9141_UART, "\r\n"); + + //等待收到应答信号 + while(!at_mode_cmd_flag); + at_mode_cmd_flag = 0; +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块进入AT模式 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_enter_at_mode(void) +{ + systick_delay_ms(STM0, 550); //发送进入AT模式的命令前需要保证模块在550ms内没有接收过任何数据 + at_mode = 1; //进入AT模式 + bluetooth_ch9141_send_at_command("AT..."); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块退出AT模式 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_exit_at_mode(void) +{ + bluetooth_ch9141_send_at_command("AT+EXIT"); + at_mode = 0; //进入透传模式 + systick_delay_ms(STM0, 300); //等待成功进入AT模式 +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块复位 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_reset(void) +{ + bluetooth_ch9141_send_at_command("AT+RESET"); + at_mode = 2; //进入重启成功检测 + at_mode_num = 0; + while(7 > at_mode_num); //等待蓝牙模块完成复位 + at_mode = 0; //复位之后模块自动进入透传模式 +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块获取本机MAC地址 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note 调用此函数需要先调用bluetooth_ch9141_enter_at_mode或者拉低CMD引脚 进入AT模式 +// 需要特别注意bluetooth_ch9141_enter_at_mode函数内部有500ms的延时 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_get_mac_address(void) +{ + bluetooth_ch9141_send_at_command("AT+MAC?"); + + //mac地址为小段格式,mac_address[0]保存的是mac地址最低位 + memcpy(mac_address, (uint8 *)at_mode_data, 17); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块设置发送功率 +// @param tx_power 设置发送功率,可设置选项查看CH9141_TX_POWEER_enum枚举成员 +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_set_tx_power(CH9141_TX_POWEER_enum tx_power) +{ + int8 tx_power_data; + + tx_power_data = (uint8)tx_power + '0'; + bluetooth_ch9141_send_at_command_parameter("TPL", &tx_power_data); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块设置模式 +// @param mode 模式设置,可设置选项查看CH9141_MODE_enum枚举成员 +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_set_mode(CH9141_MODE_enum mode) +{ + int8 mode_data; + + mode_data = (uint8)mode + '0'; + bluetooth_ch9141_send_at_command_parameter("BLEMODE", &mode_data); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块获取状态 +// @param mode 模式设置,可设置选项查看CH9141_MODE_enum枚举成员 +// @return CH9141_STATUS_enum 返回状态信息 +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +CH9141_STATUS_enum bluetooth_ch9141_get_status(CH9141_MODE_enum mode) +{ + CH9141_STATUS_enum ch9141_status; + int8 mode_data; + + mode_data = (uint8)mode + '0'; + bluetooth_ch9141_send_at_command_parameter("BLEMODE", &mode_data); + + bluetooth_ch9141_send_at_command("AT+BLESTA?"); + + ch9141_status = (at_mode_data[0] - '0') * 10 + (at_mode_data[1] - '0'); + if(SLAVE_MODE == mode) + { + ch9141_status += SLAVE_NO_INIT; + } + + return ch9141_status; +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块设置设备名称 +// @param *str 蓝牙名称 +// @return void +// @since v1.0 +// Sample usage: +// @note 名称长度不能超过18个字符 且只能为英文与数字 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_set_name(const int8 *str) +{ + bluetooth_ch9141_send_at_command_parameter("NAME", str); + bluetooth_ch9141_send_at_command_parameter("PNAME", str); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块密码设置 +// @param enable 使能密码 0:不使用密码,1:使用密码才能连接本设备 +// @param *password 密码的字符串 必须为6个字符 +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_set_password(uint8 enable, const int8 *password) +{ + if(0 == enable) + { + //关闭密码 + bluetooth_ch9141_send_at_command_parameter("PASEN", "OFF"); + } + else + { + //设置密码并使能 + bluetooth_ch9141_send_at_command_parameter("PASEN", "ON"); + bluetooth_ch9141_send_at_command_parameter("PASS", password); + } +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块指定MAC地址并立即进行连接 +// @param *mac_and_password 需要连接的设备mac地址与密码 +// @return void +// @since v1.0 +// Sample usage: +// @note bluetooth_ch9141_connect("58:B7:33:E4:C2:84,000000"); +// 58:B7:33:E4:C2:84为mac地址 ,为分隔符 000000为从机蓝牙密码 +// ===================特别注意================== +// 如果使用手机查看蓝牙的mac地址,则使用本函数连接的时候请将mac倒置一下 +// 例如手机查看到的mac地址为61:62:63:64:65:66,则使用本函数连接的时候应该写 +// bluetooth_ch9141_connect("66:65:64:63:62:61,000000"); +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_connect(const int8 *mac_and_password) +{ + bluetooth_ch9141_send_at_command_parameter("CONN", mac_and_password); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块默认连接参数设置(设置好后,每次开机蓝牙会自动链接这个设备) +// @param *mac_and_password 需要连接的设备mac地址与密码 +// @return void +// @since v1.0 +// Sample usage: +// @note bluetooth_ch9141_default_connect("58:B7:33:E4:C2:84,000000"); +// 58:B7:33:E4:C2:84为mac地址 ,为分隔符 000000为从机蓝牙密码 +// ===================特别注意================== +// 如果使用手机查看CH9141的mac地址,将CH9141设置为从机,使用手机连接 +// 则使用本函数连接的时候请将mac倒置一下 +// 例如手机查看到的mac地址为61:62:63:64:65:67,则使用本函数连接的时候应该写 +// bluetooth_ch9141_default_connect("67:65:64:63:62:61,000000"); +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_default_connect(const int8 *mac_and_password) +{ + bluetooth_ch9141_send_at_command_parameter("CONADD", mac_and_password); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块获取rssi(信号强度) +// @param void +// @return int8 返回信号强度0到-127 +// @since v1.0 +// Sample usage: +// @note 调用此函数需要先调用bluetooth_ch9141_enter_at_mode或者拉低CMD引脚 进入AT模式 +// 需要特别注意bluetooth_ch9141_enter_at_mode函数内部有500ms的延时 +//------------------------------------------------------------------------------------------------------------------- +int16 bluetooth_ch9141_get_rssi(void) +{ + uint8 i; + size_t length; + int16 rssi; + bluetooth_ch9141_send_at_command_parameter("RSSI", "ON,0"); + length = strlen((int8 *)at_mode_data); + length -= 12;//计算RSSI 有多少位 + + rssi = 0; + for(i=0; i30) { - if(gpio_get(RTS_PIN)) - { - return len;//模块忙,如果允许当前程序使用while等待 则可以使用后面注释的while等待语句替换本if语句 - } - //while(gpio_get(RTS_PIN)); //如果RTS为低电平,则继续发送数据 +// if(gpio_get(RTS_PIN)) +// { +// return len;//模块忙,如果允许当前程序使用while等待 则可以使用后面注释的while等待语句替换本if语句 +// } + while(gpio_get(RTS_PIN)); //如果RTS为低电平,则继续发送数据 uart_putbuff(WIRELESS_UART,buff,30); buff += 30; //地址偏移 len -= 30;//数量 } - if(gpio_get(RTS_PIN)) - { - return len;//模块忙,如果允许当前程序使用while等待 则可以使用后面注释的while等待语句替换本if语句 - } - //while(gpio_get(RTS_PIN)); //如果RTS为低电平,则继续发送数据 +// if(gpio_get(RTS_PIN)) +// { +// return len;//模块忙,如果允许当前程序使用while等待 则可以使用后面注释的while等待语句替换本if语句 +// } + while(gpio_get(RTS_PIN)); //如果RTS为低电平,则继续发送数据 uart_putbuff(WIRELESS_UART,buff,len);//发送最后的数据 return 0; diff --git a/Example/GPIO_Interrupt_Demo/Libraries/seekfree_peripheral/SEEKFREE_WIRELESS.h b/Example/GPIO_Interrupt_Demo/Libraries/seekfree_peripheral/SEEKFREE_WIRELESS.h index 42c0832..d80339d 100644 --- a/Example/GPIO_Interrupt_Demo/Libraries/seekfree_peripheral/SEEKFREE_WIRELESS.h +++ b/Example/GPIO_Interrupt_Demo/Libraries/seekfree_peripheral/SEEKFREE_WIRELESS.h @@ -38,8 +38,26 @@ #define WIRELESS_UART_RX UART2_RX_P10_6 #define WIRELESS_UART_BAUD 115200 -#define RTS_PIN P10_2 //定义流控位引脚 指示当前模块是否可以接受数据 0可以继续接收 1不可以继续接收 +// ------------------------------------ 自动波特率 ------------------------------------ +// 注意事项1:无线转串口模块版本是V2.0以下的是无法开启自动波特率的。 +// 注意事项2:开启自动波特率务必连接RTS引脚,否则会开启失败。 +// 注意事项3:模块自动波特率失败的话,可以尝试断电重启 +// 开启自动波特率务必阅读上面两条 注意事项 +// 开启自动波特率务必阅读上面两条 注意事项 +// 开启自动波特率务必阅读上面两条 注意事项 + +// 0:关闭自动波特率 +// 1:开启自动波特率 自动波特率的作用是修改WIRELESS_UART_BAUD之后不需要对模块进行配置,模块会自动设置为对应的波特率 + +#define WIRELESS_AUTO_UART_BAUD 0 +// ------------------------------------ 自动波特率 ------------------------------------ + +#define RTS_PIN P10_2 //定义流控位引脚 指示当前模块是否可以接受数据 0可以继续接收 1不可以继续接收 +#define WIRELESS_BUFFER_SIZE 16 + +extern uint8 wireless_send_buffer[WIRELESS_BUFFER_SIZE]; +extern uint32 wireless_rx_index; void wireless_uart_callback(void); void seekfree_wireless_init(void); diff --git a/Example/GPIO_Interrupt_Demo/USER/isr.c b/Example/GPIO_Interrupt_Demo/USER/isr.c index 50acc67..42c2fc7 100644 --- a/Example/GPIO_Interrupt_Demo/USER/isr.c +++ b/Example/GPIO_Interrupt_Demo/USER/isr.c @@ -191,7 +191,20 @@ IFX_INTERRUPT(uart2_rx_isr, 0, UART2_RX_INT_PRIO) { enableInterrupts();//开启中断嵌套 IfxAsclin_Asc_isrReceive(&uart2_handle); - wireless_uart_callback(); + switch(wireless_type) + { + case WIRELESS_SI24R1: + { + wireless_uart_callback(); + }break; + + case WIRELESS_CH9141: + { + bluetooth_ch9141_uart_callback(); + }break; + default:break; + } + } IFX_INTERRUPT(uart2_er_isr, 0, UART2_ER_INT_PRIO) { diff --git a/Example/GPIO_Interrupt_Demo/鍒犻櫎涓存椂鏂囦欢.bat b/Example/GPIO_Interrupt_Demo/鍒犻櫎涓存椂鏂囦欢.bat index 5323dd9..fa499b1 100644 --- a/Example/GPIO_Interrupt_Demo/鍒犻櫎涓存椂鏂囦欢.bat +++ b/Example/GPIO_Interrupt_Demo/鍒犻櫎涓存椂鏂囦欢.bat @@ -1,9 +1,6 @@ -rmdir .settings /s /q rmdir Debug /s /q del *.launch /s - -pause exit diff --git a/Example/Interrupt_Priority_Set_Demo/.cproject b/Example/Interrupt_Priority_Set_Demo/.cproject index 0c0d7a3..9b9f6c9 100644 --- a/Example/Interrupt_Priority_Set_Demo/.cproject +++ b/Example/Interrupt_Priority_Set_Demo/.cproject @@ -3,9 +3,9 @@ - + - + @@ -25,50 +25,76 @@ - + - + - + - + + + + + + @@ -355,9 +371,9 @@ - + - + @@ -377,43 +393,1895 @@ - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -431,13 +2299,37 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + @@ -458,21 +2350,5 @@ - - - - - - - - - - - - - - - - diff --git a/Example/Interrupt_Priority_Set_Demo/.project b/Example/Interrupt_Priority_Set_Demo/.project index bc63143..b487c65 100644 --- a/Example/Interrupt_Priority_Set_Demo/.project +++ b/Example/Interrupt_Priority_Set_Demo/.project @@ -5,6 +5,18 @@ + + com.infineon.aurix.buildsystem.builders.booster + full,incremental, + + + + + com.infineon.aurix.buildsystem.builders.autodiscovery + full,incremental, + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder clean,full,incremental, diff --git a/Example/Interrupt_Priority_Set_Demo/.settings/com.infineon.aurix.buildsystem.prefs b/Example/Interrupt_Priority_Set_Demo/.settings/com.infineon.aurix.buildsystem.prefs new file mode 100644 index 0000000..be61bc1 --- /dev/null +++ b/Example/Interrupt_Priority_Set_Demo/.settings/com.infineon.aurix.buildsystem.prefs @@ -0,0 +1,10 @@ +AURIX-LIBRARY-PATH=Libraries/iLLD\#Libraries/Infra\#Libraries/Service +DEVICE-ID=TC26B +DEVICE-ID-FULL=TC26xD_B-Step +ILLD-SET=full +IncludesAutodiscovery=true +LIBRARIES-ROOT-PATH=Libraries +NEVER-EXCLUDE-FROM-BUILD=/Libraries/iLLD/TC26B/Tricore/Cpu/CStart\#/Libraries/iLLD/TC26B/Tricore/Cpu/Trap\#/Configurations\#/Configurations/Debug +PROJECT-VERSION=1.0 +aurixDevice=TC26xD_B-Step +eclipse.preferences.version=1 diff --git a/Example/Interrupt_Priority_Set_Demo/Libraries/doc/version.txt b/Example/Interrupt_Priority_Set_Demo/Libraries/doc/version.txt index ab79909..11ab82e 100644 --- a/Example/Interrupt_Priority_Set_Demo/Libraries/doc/version.txt +++ b/Example/Interrupt_Priority_Set_Demo/Libraries/doc/version.txt @@ -1,3 +1,13 @@ +V1.2.0 + 增加CH9141蓝牙转串口模块的驱动 + 添加无线类型的枚举变量 + 修改 删除临时文件.bat 执行完操作后自动关闭窗口 + 修改 删除临时文件.bat 避免删除新版本所需文件 + 修改工程项目文件,以支持新版本编译 + +V1.1.10 + 修复通过#pragma section all "cpux_dsram"指定变量位置失效的问题 + V1.1.9 将串口的发送buff增加到128字节 diff --git a/Example/Interrupt_Priority_Set_Demo/Libraries/seekfree_libraries/common/common.c b/Example/Interrupt_Priority_Set_Demo/Libraries/seekfree_libraries/common/common.c index 0b9931e..7620ce6 100644 --- a/Example/Interrupt_Priority_Set_Demo/Libraries/seekfree_libraries/common/common.c +++ b/Example/Interrupt_Priority_Set_Demo/Libraries/seekfree_libraries/common/common.c @@ -27,6 +27,8 @@ CAMERA_TYPE_enum camera_type; //摄像头型号 uint8 *camera_buffer_addr; //摄像头数组地址 +WIRELESS_TYPE_enum wireless_type;//无线转串口类型 + IFX_ALIGN(4) IfxCpu_syncEvent g_cpuSyncEvent = 0;//事件同步变量 App_Cpu0 g_AppCpu0; //频率信息变量 diff --git a/Example/Interrupt_Priority_Set_Demo/Libraries/seekfree_libraries/common/common.h b/Example/Interrupt_Priority_Set_Demo/Libraries/seekfree_libraries/common/common.h index 84c43ee..5b741c0 100644 --- a/Example/Interrupt_Priority_Set_Demo/Libraries/seekfree_libraries/common/common.h +++ b/Example/Interrupt_Priority_Set_Demo/Libraries/seekfree_libraries/common/common.h @@ -113,6 +113,12 @@ typedef enum //枚 CAMERA_COLOR, //凌瞳 }CAMERA_TYPE_enum; +typedef enum //无线模块 +{ + WIRELESS_SI24R1 = 1, //无线转串口 + WIRELESS_CH9141, //蓝牙转串口 +}WIRELESS_TYPE_enum; + #include #include #include "IfxCpu.h" @@ -120,6 +126,8 @@ typedef enum //枚 extern CAMERA_TYPE_enum camera_type; //摄像头型号 extern uint8 *camera_buffer_addr; //摄像头数组地址 +extern WIRELESS_TYPE_enum wireless_type; + extern IfxCpu_syncEvent g_cpuSyncEvent; void get_clk(void); diff --git a/Example/Interrupt_Priority_Set_Demo/Libraries/seekfree_libraries/headfile.h b/Example/Interrupt_Priority_Set_Demo/Libraries/seekfree_libraries/headfile.h index 404ee0a..b745302 100644 --- a/Example/Interrupt_Priority_Set_Demo/Libraries/seekfree_libraries/headfile.h +++ b/Example/Interrupt_Priority_Set_Demo/Libraries/seekfree_libraries/headfile.h @@ -65,6 +65,7 @@ #include "SEEKFREE_7725.h" #include "SEEKFREE_RDA5807.h" #include "SEEKFREE_7725_UART.h" +#include "SEEKFREE_BLUETOOTH_CH9141.h" #endif diff --git a/Example/Interrupt_Priority_Set_Demo/Libraries/seekfree_peripheral/SEEKFREE_BLUETOOTH_CH9141.c b/Example/Interrupt_Priority_Set_Demo/Libraries/seekfree_peripheral/SEEKFREE_BLUETOOTH_CH9141.c new file mode 100644 index 0000000..b4ec2df --- /dev/null +++ b/Example/Interrupt_Priority_Set_Demo/Libraries/seekfree_peripheral/SEEKFREE_BLUETOOTH_CH9141.c @@ -0,0 +1,509 @@ +/********************************************************************************************************************* + * COPYRIGHT NOTICE + * Copyright (c) 2021,逐飞科技 + * All rights reserved. + * 技术讨论QQ群:一群:179029047(已满) 二群:244861897 + * + * 以下所有内容版权均属逐飞科技所有,未经允许不得用于商业用途, + * 欢迎各位使用并传播本程序,修改内容时必须保留逐飞科技的版权声明。 + * + * @file 逐飞科技蓝牙转串口模块 + * @company 成都逐飞科技有限公司 + * @author 逐飞科技(QQ3184284598) + * @version 查看doc内version文件 版本说明 + * @Software IAR 8.3 or MDK 5.33 + * @Taobao https://seekfree.taobao.com/ + * @date 2021-08-27 + * @note + 接线定义: + ------------------------------------ + 蓝牙转串口 单片机 + RX 查看SEEKFREE_BLUETOOTH_CH9141.h文件中的BLUETOOTH_CH9141_UART_TX宏定义 + TX 查看SEEKFREE_BLUETOOTH_CH9141.h文件中的BLUETOOTH_CH9141_UART_RX宏定义 + RTS 查看SEEKFREE_BLUETOOTH_CH9141.h文件中的BLUETOOTH_CH9141_RTS_PIN宏定义 + CTS 悬空 + CMD 悬空或者上拉 + ------------------------------------ + ********************************************************************************************************************/ +#include "zf_stm_systick.h" +#include "zf_gpio.h" +#include "zf_uart.h" +#include "zf_assert.h" +#include "SEEKFREE_BLUETOOTH_CH9141.h" + +uint8 uart_flag; +uint8 uart_data; + +vuint8 at_mode = 0; //0:蓝牙透传模式 1:AT模式 2:模块复位中 +vuint8 at_mode_num; //at模式时用于指示数据接收的数量 +vuint8 at_mode_data[30]; //接收at命令的缓存 +vuint8 at_mode_cmd_flag; //OK应答命令接收成功的标志位 + +uint8 mac_address[17]; //本机mac地址 + + +uint8 bluetooth_ch9141_rx_buffer; + + +void bluetooth_ch9141_check_response(void); + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块 串口中断回调函数 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note 该函数在ISR文件 串口8中断程序被调用 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_uart_callback() +{ + while(uart_query(BLUETOOTH_CH9141_UART, &bluetooth_ch9141_rx_buffer)) + { + if(1 == at_mode) + { + //进入AT模式 接收应答信号 此处if语句内代码用户不要改动 + at_mode_data[at_mode_num++] = bluetooth_ch9141_rx_buffer; + bluetooth_ch9141_check_response(); + } + else if(2 == at_mode) + { + //模块正在复位中 此处if语句内代码用户不要改动 + at_mode_num++; + } + else + { + //透传模式 用户在此处接收配对的蓝牙发送过来的额数据 + //接到一个字节后单片机将会进入此处,通过在此处读取bluetooth_ch9141_rx_buffer可以取走数据 + + // 读取无线串口的数据 并且置位接收标志 + uart_flag = 1; + uart_data = bluetooth_ch9141_rx_buffer; + } + + } +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块检查OK应答信号 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_check_response(void) +{ + if(4 <= at_mode_num) + { + if(0 == strncmp("OK\r\n", (int8 *)&at_mode_data[at_mode_num-4], 4)) + { + at_mode_cmd_flag = 1; + } + } +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块发送一个没有参数的命令并等待应答信号 +// @param *str 需要发送的命令 完整字符串 +// @return void +// @since v1.0 +// Sample usage: +// @note 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_send_at_command(const int8 *str) +{ + at_mode_num = 0; //接收数量清零 + uart_putstr(BLUETOOTH_CH9141_UART, str); + uart_putstr(BLUETOOTH_CH9141_UART, "\r\n"); + + //等待收到应答信号 + while(!at_mode_cmd_flag); + at_mode_cmd_flag = 0; +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块发送一个带有参数的命令并等待应答信号 +// @param *cmd 需要发送的命令名称 +// @param *data 需要发送的数据 +// @return void +// @since v1.0 +// Sample usage: +// @note 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_send_at_command_parameter(const int8 *cmd, const int8 *data) +{ + at_mode_num = 0; //接收数量清零 + uart_putstr(BLUETOOTH_CH9141_UART, "AT+"); + uart_putstr(BLUETOOTH_CH9141_UART, cmd); + uart_putstr(BLUETOOTH_CH9141_UART, "="); + uart_putstr(BLUETOOTH_CH9141_UART, data); + uart_putstr(BLUETOOTH_CH9141_UART, "\r\n"); + + //等待收到应答信号 + while(!at_mode_cmd_flag); + at_mode_cmd_flag = 0; +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块进入AT模式 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_enter_at_mode(void) +{ + systick_delay_ms(STM0, 550); //发送进入AT模式的命令前需要保证模块在550ms内没有接收过任何数据 + at_mode = 1; //进入AT模式 + bluetooth_ch9141_send_at_command("AT..."); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块退出AT模式 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_exit_at_mode(void) +{ + bluetooth_ch9141_send_at_command("AT+EXIT"); + at_mode = 0; //进入透传模式 + systick_delay_ms(STM0, 300); //等待成功进入AT模式 +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块复位 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_reset(void) +{ + bluetooth_ch9141_send_at_command("AT+RESET"); + at_mode = 2; //进入重启成功检测 + at_mode_num = 0; + while(7 > at_mode_num); //等待蓝牙模块完成复位 + at_mode = 0; //复位之后模块自动进入透传模式 +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块获取本机MAC地址 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note 调用此函数需要先调用bluetooth_ch9141_enter_at_mode或者拉低CMD引脚 进入AT模式 +// 需要特别注意bluetooth_ch9141_enter_at_mode函数内部有500ms的延时 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_get_mac_address(void) +{ + bluetooth_ch9141_send_at_command("AT+MAC?"); + + //mac地址为小段格式,mac_address[0]保存的是mac地址最低位 + memcpy(mac_address, (uint8 *)at_mode_data, 17); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块设置发送功率 +// @param tx_power 设置发送功率,可设置选项查看CH9141_TX_POWEER_enum枚举成员 +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_set_tx_power(CH9141_TX_POWEER_enum tx_power) +{ + int8 tx_power_data; + + tx_power_data = (uint8)tx_power + '0'; + bluetooth_ch9141_send_at_command_parameter("TPL", &tx_power_data); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块设置模式 +// @param mode 模式设置,可设置选项查看CH9141_MODE_enum枚举成员 +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_set_mode(CH9141_MODE_enum mode) +{ + int8 mode_data; + + mode_data = (uint8)mode + '0'; + bluetooth_ch9141_send_at_command_parameter("BLEMODE", &mode_data); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块获取状态 +// @param mode 模式设置,可设置选项查看CH9141_MODE_enum枚举成员 +// @return CH9141_STATUS_enum 返回状态信息 +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +CH9141_STATUS_enum bluetooth_ch9141_get_status(CH9141_MODE_enum mode) +{ + CH9141_STATUS_enum ch9141_status; + int8 mode_data; + + mode_data = (uint8)mode + '0'; + bluetooth_ch9141_send_at_command_parameter("BLEMODE", &mode_data); + + bluetooth_ch9141_send_at_command("AT+BLESTA?"); + + ch9141_status = (at_mode_data[0] - '0') * 10 + (at_mode_data[1] - '0'); + if(SLAVE_MODE == mode) + { + ch9141_status += SLAVE_NO_INIT; + } + + return ch9141_status; +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块设置设备名称 +// @param *str 蓝牙名称 +// @return void +// @since v1.0 +// Sample usage: +// @note 名称长度不能超过18个字符 且只能为英文与数字 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_set_name(const int8 *str) +{ + bluetooth_ch9141_send_at_command_parameter("NAME", str); + bluetooth_ch9141_send_at_command_parameter("PNAME", str); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块密码设置 +// @param enable 使能密码 0:不使用密码,1:使用密码才能连接本设备 +// @param *password 密码的字符串 必须为6个字符 +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_set_password(uint8 enable, const int8 *password) +{ + if(0 == enable) + { + //关闭密码 + bluetooth_ch9141_send_at_command_parameter("PASEN", "OFF"); + } + else + { + //设置密码并使能 + bluetooth_ch9141_send_at_command_parameter("PASEN", "ON"); + bluetooth_ch9141_send_at_command_parameter("PASS", password); + } +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块指定MAC地址并立即进行连接 +// @param *mac_and_password 需要连接的设备mac地址与密码 +// @return void +// @since v1.0 +// Sample usage: +// @note bluetooth_ch9141_connect("58:B7:33:E4:C2:84,000000"); +// 58:B7:33:E4:C2:84为mac地址 ,为分隔符 000000为从机蓝牙密码 +// ===================特别注意================== +// 如果使用手机查看蓝牙的mac地址,则使用本函数连接的时候请将mac倒置一下 +// 例如手机查看到的mac地址为61:62:63:64:65:66,则使用本函数连接的时候应该写 +// bluetooth_ch9141_connect("66:65:64:63:62:61,000000"); +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_connect(const int8 *mac_and_password) +{ + bluetooth_ch9141_send_at_command_parameter("CONN", mac_and_password); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块默认连接参数设置(设置好后,每次开机蓝牙会自动链接这个设备) +// @param *mac_and_password 需要连接的设备mac地址与密码 +// @return void +// @since v1.0 +// Sample usage: +// @note bluetooth_ch9141_default_connect("58:B7:33:E4:C2:84,000000"); +// 58:B7:33:E4:C2:84为mac地址 ,为分隔符 000000为从机蓝牙密码 +// ===================特别注意================== +// 如果使用手机查看CH9141的mac地址,将CH9141设置为从机,使用手机连接 +// 则使用本函数连接的时候请将mac倒置一下 +// 例如手机查看到的mac地址为61:62:63:64:65:67,则使用本函数连接的时候应该写 +// bluetooth_ch9141_default_connect("67:65:64:63:62:61,000000"); +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_default_connect(const int8 *mac_and_password) +{ + bluetooth_ch9141_send_at_command_parameter("CONADD", mac_and_password); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块获取rssi(信号强度) +// @param void +// @return int8 返回信号强度0到-127 +// @since v1.0 +// Sample usage: +// @note 调用此函数需要先调用bluetooth_ch9141_enter_at_mode或者拉低CMD引脚 进入AT模式 +// 需要特别注意bluetooth_ch9141_enter_at_mode函数内部有500ms的延时 +//------------------------------------------------------------------------------------------------------------------- +int16 bluetooth_ch9141_get_rssi(void) +{ + uint8 i; + size_t length; + int16 rssi; + bluetooth_ch9141_send_at_command_parameter("RSSI", "ON,0"); + length = strlen((int8 *)at_mode_data); + length -= 12;//计算RSSI 有多少位 + + rssi = 0; + for(i=0; i30) { - if(gpio_get(RTS_PIN)) - { - return len;//模块忙,如果允许当前程序使用while等待 则可以使用后面注释的while等待语句替换本if语句 - } - //while(gpio_get(RTS_PIN)); //如果RTS为低电平,则继续发送数据 +// if(gpio_get(RTS_PIN)) +// { +// return len;//模块忙,如果允许当前程序使用while等待 则可以使用后面注释的while等待语句替换本if语句 +// } + while(gpio_get(RTS_PIN)); //如果RTS为低电平,则继续发送数据 uart_putbuff(WIRELESS_UART,buff,30); buff += 30; //地址偏移 len -= 30;//数量 } - if(gpio_get(RTS_PIN)) - { - return len;//模块忙,如果允许当前程序使用while等待 则可以使用后面注释的while等待语句替换本if语句 - } - //while(gpio_get(RTS_PIN)); //如果RTS为低电平,则继续发送数据 +// if(gpio_get(RTS_PIN)) +// { +// return len;//模块忙,如果允许当前程序使用while等待 则可以使用后面注释的while等待语句替换本if语句 +// } + while(gpio_get(RTS_PIN)); //如果RTS为低电平,则继续发送数据 uart_putbuff(WIRELESS_UART,buff,len);//发送最后的数据 return 0; diff --git a/Example/Interrupt_Priority_Set_Demo/Libraries/seekfree_peripheral/SEEKFREE_WIRELESS.h b/Example/Interrupt_Priority_Set_Demo/Libraries/seekfree_peripheral/SEEKFREE_WIRELESS.h index 42c0832..d80339d 100644 --- a/Example/Interrupt_Priority_Set_Demo/Libraries/seekfree_peripheral/SEEKFREE_WIRELESS.h +++ b/Example/Interrupt_Priority_Set_Demo/Libraries/seekfree_peripheral/SEEKFREE_WIRELESS.h @@ -38,8 +38,26 @@ #define WIRELESS_UART_RX UART2_RX_P10_6 #define WIRELESS_UART_BAUD 115200 -#define RTS_PIN P10_2 //定义流控位引脚 指示当前模块是否可以接受数据 0可以继续接收 1不可以继续接收 +// ------------------------------------ 自动波特率 ------------------------------------ +// 注意事项1:无线转串口模块版本是V2.0以下的是无法开启自动波特率的。 +// 注意事项2:开启自动波特率务必连接RTS引脚,否则会开启失败。 +// 注意事项3:模块自动波特率失败的话,可以尝试断电重启 +// 开启自动波特率务必阅读上面两条 注意事项 +// 开启自动波特率务必阅读上面两条 注意事项 +// 开启自动波特率务必阅读上面两条 注意事项 + +// 0:关闭自动波特率 +// 1:开启自动波特率 自动波特率的作用是修改WIRELESS_UART_BAUD之后不需要对模块进行配置,模块会自动设置为对应的波特率 + +#define WIRELESS_AUTO_UART_BAUD 0 +// ------------------------------------ 自动波特率 ------------------------------------ + +#define RTS_PIN P10_2 //定义流控位引脚 指示当前模块是否可以接受数据 0可以继续接收 1不可以继续接收 +#define WIRELESS_BUFFER_SIZE 16 + +extern uint8 wireless_send_buffer[WIRELESS_BUFFER_SIZE]; +extern uint32 wireless_rx_index; void wireless_uart_callback(void); void seekfree_wireless_init(void); diff --git a/Example/Interrupt_Priority_Set_Demo/USER/isr.c b/Example/Interrupt_Priority_Set_Demo/USER/isr.c index c55a012..16bff98 100644 --- a/Example/Interrupt_Priority_Set_Demo/USER/isr.c +++ b/Example/Interrupt_Priority_Set_Demo/USER/isr.c @@ -179,7 +179,20 @@ IFX_INTERRUPT(uart2_rx_isr, 0, UART2_RX_INT_PRIO) { enableInterrupts();//开启中断嵌套 IfxAsclin_Asc_isrReceive(&uart2_handle); - wireless_uart_callback(); + switch(wireless_type) + { + case WIRELESS_SI24R1: + { + wireless_uart_callback(); + }break; + + case WIRELESS_CH9141: + { + bluetooth_ch9141_uart_callback(); + }break; + default:break; + } + } IFX_INTERRUPT(uart2_er_isr, 0, UART2_ER_INT_PRIO) { diff --git a/Example/Interrupt_Priority_Set_Demo/鍒犻櫎涓存椂鏂囦欢.bat b/Example/Interrupt_Priority_Set_Demo/鍒犻櫎涓存椂鏂囦欢.bat index 5323dd9..fa499b1 100644 --- a/Example/Interrupt_Priority_Set_Demo/鍒犻櫎涓存椂鏂囦欢.bat +++ b/Example/Interrupt_Priority_Set_Demo/鍒犻櫎涓存椂鏂囦欢.bat @@ -1,9 +1,6 @@ -rmdir .settings /s /q rmdir Debug /s /q del *.launch /s - -pause exit diff --git a/Example/LED_Blink_Demo/.cproject b/Example/LED_Blink_Demo/.cproject index beaaf7a..9ec6d79 100644 --- a/Example/LED_Blink_Demo/.cproject +++ b/Example/LED_Blink_Demo/.cproject @@ -3,9 +3,9 @@ - + - + @@ -25,50 +25,76 @@ - + - + - + - + + + + + + @@ -355,9 +371,9 @@ - + - + @@ -377,43 +393,1895 @@ - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -431,13 +2299,37 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + @@ -458,21 +2350,5 @@ - - - - - - - - - - - - - - - - diff --git a/Example/LED_Blink_Demo/.project b/Example/LED_Blink_Demo/.project index d235cb3..9553e30 100644 --- a/Example/LED_Blink_Demo/.project +++ b/Example/LED_Blink_Demo/.project @@ -5,6 +5,18 @@ + + com.infineon.aurix.buildsystem.builders.booster + full,incremental, + + + + + com.infineon.aurix.buildsystem.builders.autodiscovery + full,incremental, + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder clean,full,incremental, diff --git a/Example/LED_Blink_Demo/.settings/com.infineon.aurix.buildsystem.prefs b/Example/LED_Blink_Demo/.settings/com.infineon.aurix.buildsystem.prefs new file mode 100644 index 0000000..be61bc1 --- /dev/null +++ b/Example/LED_Blink_Demo/.settings/com.infineon.aurix.buildsystem.prefs @@ -0,0 +1,10 @@ +AURIX-LIBRARY-PATH=Libraries/iLLD\#Libraries/Infra\#Libraries/Service +DEVICE-ID=TC26B +DEVICE-ID-FULL=TC26xD_B-Step +ILLD-SET=full +IncludesAutodiscovery=true +LIBRARIES-ROOT-PATH=Libraries +NEVER-EXCLUDE-FROM-BUILD=/Libraries/iLLD/TC26B/Tricore/Cpu/CStart\#/Libraries/iLLD/TC26B/Tricore/Cpu/Trap\#/Configurations\#/Configurations/Debug +PROJECT-VERSION=1.0 +aurixDevice=TC26xD_B-Step +eclipse.preferences.version=1 diff --git a/Example/LED_Blink_Demo/Libraries/doc/version.txt b/Example/LED_Blink_Demo/Libraries/doc/version.txt index ab79909..11ab82e 100644 --- a/Example/LED_Blink_Demo/Libraries/doc/version.txt +++ b/Example/LED_Blink_Demo/Libraries/doc/version.txt @@ -1,3 +1,13 @@ +V1.2.0 + 增加CH9141蓝牙转串口模块的驱动 + 添加无线类型的枚举变量 + 修改 删除临时文件.bat 执行完操作后自动关闭窗口 + 修改 删除临时文件.bat 避免删除新版本所需文件 + 修改工程项目文件,以支持新版本编译 + +V1.1.10 + 修复通过#pragma section all "cpux_dsram"指定变量位置失效的问题 + V1.1.9 将串口的发送buff增加到128字节 diff --git a/Example/LED_Blink_Demo/Libraries/seekfree_libraries/common/common.c b/Example/LED_Blink_Demo/Libraries/seekfree_libraries/common/common.c index 0b9931e..7620ce6 100644 --- a/Example/LED_Blink_Demo/Libraries/seekfree_libraries/common/common.c +++ b/Example/LED_Blink_Demo/Libraries/seekfree_libraries/common/common.c @@ -27,6 +27,8 @@ CAMERA_TYPE_enum camera_type; //摄像头型号 uint8 *camera_buffer_addr; //摄像头数组地址 +WIRELESS_TYPE_enum wireless_type;//无线转串口类型 + IFX_ALIGN(4) IfxCpu_syncEvent g_cpuSyncEvent = 0;//事件同步变量 App_Cpu0 g_AppCpu0; //频率信息变量 diff --git a/Example/LED_Blink_Demo/Libraries/seekfree_libraries/common/common.h b/Example/LED_Blink_Demo/Libraries/seekfree_libraries/common/common.h index 84c43ee..5b741c0 100644 --- a/Example/LED_Blink_Demo/Libraries/seekfree_libraries/common/common.h +++ b/Example/LED_Blink_Demo/Libraries/seekfree_libraries/common/common.h @@ -113,6 +113,12 @@ typedef enum //枚 CAMERA_COLOR, //凌瞳 }CAMERA_TYPE_enum; +typedef enum //无线模块 +{ + WIRELESS_SI24R1 = 1, //无线转串口 + WIRELESS_CH9141, //蓝牙转串口 +}WIRELESS_TYPE_enum; + #include #include #include "IfxCpu.h" @@ -120,6 +126,8 @@ typedef enum //枚 extern CAMERA_TYPE_enum camera_type; //摄像头型号 extern uint8 *camera_buffer_addr; //摄像头数组地址 +extern WIRELESS_TYPE_enum wireless_type; + extern IfxCpu_syncEvent g_cpuSyncEvent; void get_clk(void); diff --git a/Example/LED_Blink_Demo/Libraries/seekfree_libraries/headfile.h b/Example/LED_Blink_Demo/Libraries/seekfree_libraries/headfile.h index 404ee0a..b745302 100644 --- a/Example/LED_Blink_Demo/Libraries/seekfree_libraries/headfile.h +++ b/Example/LED_Blink_Demo/Libraries/seekfree_libraries/headfile.h @@ -65,6 +65,7 @@ #include "SEEKFREE_7725.h" #include "SEEKFREE_RDA5807.h" #include "SEEKFREE_7725_UART.h" +#include "SEEKFREE_BLUETOOTH_CH9141.h" #endif diff --git a/Example/LED_Blink_Demo/Libraries/seekfree_peripheral/SEEKFREE_BLUETOOTH_CH9141.c b/Example/LED_Blink_Demo/Libraries/seekfree_peripheral/SEEKFREE_BLUETOOTH_CH9141.c new file mode 100644 index 0000000..b4ec2df --- /dev/null +++ b/Example/LED_Blink_Demo/Libraries/seekfree_peripheral/SEEKFREE_BLUETOOTH_CH9141.c @@ -0,0 +1,509 @@ +/********************************************************************************************************************* + * COPYRIGHT NOTICE + * Copyright (c) 2021,逐飞科技 + * All rights reserved. + * 技术讨论QQ群:一群:179029047(已满) 二群:244861897 + * + * 以下所有内容版权均属逐飞科技所有,未经允许不得用于商业用途, + * 欢迎各位使用并传播本程序,修改内容时必须保留逐飞科技的版权声明。 + * + * @file 逐飞科技蓝牙转串口模块 + * @company 成都逐飞科技有限公司 + * @author 逐飞科技(QQ3184284598) + * @version 查看doc内version文件 版本说明 + * @Software IAR 8.3 or MDK 5.33 + * @Taobao https://seekfree.taobao.com/ + * @date 2021-08-27 + * @note + 接线定义: + ------------------------------------ + 蓝牙转串口 单片机 + RX 查看SEEKFREE_BLUETOOTH_CH9141.h文件中的BLUETOOTH_CH9141_UART_TX宏定义 + TX 查看SEEKFREE_BLUETOOTH_CH9141.h文件中的BLUETOOTH_CH9141_UART_RX宏定义 + RTS 查看SEEKFREE_BLUETOOTH_CH9141.h文件中的BLUETOOTH_CH9141_RTS_PIN宏定义 + CTS 悬空 + CMD 悬空或者上拉 + ------------------------------------ + ********************************************************************************************************************/ +#include "zf_stm_systick.h" +#include "zf_gpio.h" +#include "zf_uart.h" +#include "zf_assert.h" +#include "SEEKFREE_BLUETOOTH_CH9141.h" + +uint8 uart_flag; +uint8 uart_data; + +vuint8 at_mode = 0; //0:蓝牙透传模式 1:AT模式 2:模块复位中 +vuint8 at_mode_num; //at模式时用于指示数据接收的数量 +vuint8 at_mode_data[30]; //接收at命令的缓存 +vuint8 at_mode_cmd_flag; //OK应答命令接收成功的标志位 + +uint8 mac_address[17]; //本机mac地址 + + +uint8 bluetooth_ch9141_rx_buffer; + + +void bluetooth_ch9141_check_response(void); + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块 串口中断回调函数 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note 该函数在ISR文件 串口8中断程序被调用 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_uart_callback() +{ + while(uart_query(BLUETOOTH_CH9141_UART, &bluetooth_ch9141_rx_buffer)) + { + if(1 == at_mode) + { + //进入AT模式 接收应答信号 此处if语句内代码用户不要改动 + at_mode_data[at_mode_num++] = bluetooth_ch9141_rx_buffer; + bluetooth_ch9141_check_response(); + } + else if(2 == at_mode) + { + //模块正在复位中 此处if语句内代码用户不要改动 + at_mode_num++; + } + else + { + //透传模式 用户在此处接收配对的蓝牙发送过来的额数据 + //接到一个字节后单片机将会进入此处,通过在此处读取bluetooth_ch9141_rx_buffer可以取走数据 + + // 读取无线串口的数据 并且置位接收标志 + uart_flag = 1; + uart_data = bluetooth_ch9141_rx_buffer; + } + + } +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块检查OK应答信号 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_check_response(void) +{ + if(4 <= at_mode_num) + { + if(0 == strncmp("OK\r\n", (int8 *)&at_mode_data[at_mode_num-4], 4)) + { + at_mode_cmd_flag = 1; + } + } +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块发送一个没有参数的命令并等待应答信号 +// @param *str 需要发送的命令 完整字符串 +// @return void +// @since v1.0 +// Sample usage: +// @note 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_send_at_command(const int8 *str) +{ + at_mode_num = 0; //接收数量清零 + uart_putstr(BLUETOOTH_CH9141_UART, str); + uart_putstr(BLUETOOTH_CH9141_UART, "\r\n"); + + //等待收到应答信号 + while(!at_mode_cmd_flag); + at_mode_cmd_flag = 0; +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块发送一个带有参数的命令并等待应答信号 +// @param *cmd 需要发送的命令名称 +// @param *data 需要发送的数据 +// @return void +// @since v1.0 +// Sample usage: +// @note 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_send_at_command_parameter(const int8 *cmd, const int8 *data) +{ + at_mode_num = 0; //接收数量清零 + uart_putstr(BLUETOOTH_CH9141_UART, "AT+"); + uart_putstr(BLUETOOTH_CH9141_UART, cmd); + uart_putstr(BLUETOOTH_CH9141_UART, "="); + uart_putstr(BLUETOOTH_CH9141_UART, data); + uart_putstr(BLUETOOTH_CH9141_UART, "\r\n"); + + //等待收到应答信号 + while(!at_mode_cmd_flag); + at_mode_cmd_flag = 0; +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块进入AT模式 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_enter_at_mode(void) +{ + systick_delay_ms(STM0, 550); //发送进入AT模式的命令前需要保证模块在550ms内没有接收过任何数据 + at_mode = 1; //进入AT模式 + bluetooth_ch9141_send_at_command("AT..."); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块退出AT模式 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_exit_at_mode(void) +{ + bluetooth_ch9141_send_at_command("AT+EXIT"); + at_mode = 0; //进入透传模式 + systick_delay_ms(STM0, 300); //等待成功进入AT模式 +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块复位 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_reset(void) +{ + bluetooth_ch9141_send_at_command("AT+RESET"); + at_mode = 2; //进入重启成功检测 + at_mode_num = 0; + while(7 > at_mode_num); //等待蓝牙模块完成复位 + at_mode = 0; //复位之后模块自动进入透传模式 +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块获取本机MAC地址 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note 调用此函数需要先调用bluetooth_ch9141_enter_at_mode或者拉低CMD引脚 进入AT模式 +// 需要特别注意bluetooth_ch9141_enter_at_mode函数内部有500ms的延时 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_get_mac_address(void) +{ + bluetooth_ch9141_send_at_command("AT+MAC?"); + + //mac地址为小段格式,mac_address[0]保存的是mac地址最低位 + memcpy(mac_address, (uint8 *)at_mode_data, 17); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块设置发送功率 +// @param tx_power 设置发送功率,可设置选项查看CH9141_TX_POWEER_enum枚举成员 +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_set_tx_power(CH9141_TX_POWEER_enum tx_power) +{ + int8 tx_power_data; + + tx_power_data = (uint8)tx_power + '0'; + bluetooth_ch9141_send_at_command_parameter("TPL", &tx_power_data); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块设置模式 +// @param mode 模式设置,可设置选项查看CH9141_MODE_enum枚举成员 +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_set_mode(CH9141_MODE_enum mode) +{ + int8 mode_data; + + mode_data = (uint8)mode + '0'; + bluetooth_ch9141_send_at_command_parameter("BLEMODE", &mode_data); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块获取状态 +// @param mode 模式设置,可设置选项查看CH9141_MODE_enum枚举成员 +// @return CH9141_STATUS_enum 返回状态信息 +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +CH9141_STATUS_enum bluetooth_ch9141_get_status(CH9141_MODE_enum mode) +{ + CH9141_STATUS_enum ch9141_status; + int8 mode_data; + + mode_data = (uint8)mode + '0'; + bluetooth_ch9141_send_at_command_parameter("BLEMODE", &mode_data); + + bluetooth_ch9141_send_at_command("AT+BLESTA?"); + + ch9141_status = (at_mode_data[0] - '0') * 10 + (at_mode_data[1] - '0'); + if(SLAVE_MODE == mode) + { + ch9141_status += SLAVE_NO_INIT; + } + + return ch9141_status; +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块设置设备名称 +// @param *str 蓝牙名称 +// @return void +// @since v1.0 +// Sample usage: +// @note 名称长度不能超过18个字符 且只能为英文与数字 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_set_name(const int8 *str) +{ + bluetooth_ch9141_send_at_command_parameter("NAME", str); + bluetooth_ch9141_send_at_command_parameter("PNAME", str); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块密码设置 +// @param enable 使能密码 0:不使用密码,1:使用密码才能连接本设备 +// @param *password 密码的字符串 必须为6个字符 +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_set_password(uint8 enable, const int8 *password) +{ + if(0 == enable) + { + //关闭密码 + bluetooth_ch9141_send_at_command_parameter("PASEN", "OFF"); + } + else + { + //设置密码并使能 + bluetooth_ch9141_send_at_command_parameter("PASEN", "ON"); + bluetooth_ch9141_send_at_command_parameter("PASS", password); + } +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块指定MAC地址并立即进行连接 +// @param *mac_and_password 需要连接的设备mac地址与密码 +// @return void +// @since v1.0 +// Sample usage: +// @note bluetooth_ch9141_connect("58:B7:33:E4:C2:84,000000"); +// 58:B7:33:E4:C2:84为mac地址 ,为分隔符 000000为从机蓝牙密码 +// ===================特别注意================== +// 如果使用手机查看蓝牙的mac地址,则使用本函数连接的时候请将mac倒置一下 +// 例如手机查看到的mac地址为61:62:63:64:65:66,则使用本函数连接的时候应该写 +// bluetooth_ch9141_connect("66:65:64:63:62:61,000000"); +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_connect(const int8 *mac_and_password) +{ + bluetooth_ch9141_send_at_command_parameter("CONN", mac_and_password); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块默认连接参数设置(设置好后,每次开机蓝牙会自动链接这个设备) +// @param *mac_and_password 需要连接的设备mac地址与密码 +// @return void +// @since v1.0 +// Sample usage: +// @note bluetooth_ch9141_default_connect("58:B7:33:E4:C2:84,000000"); +// 58:B7:33:E4:C2:84为mac地址 ,为分隔符 000000为从机蓝牙密码 +// ===================特别注意================== +// 如果使用手机查看CH9141的mac地址,将CH9141设置为从机,使用手机连接 +// 则使用本函数连接的时候请将mac倒置一下 +// 例如手机查看到的mac地址为61:62:63:64:65:67,则使用本函数连接的时候应该写 +// bluetooth_ch9141_default_connect("67:65:64:63:62:61,000000"); +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_default_connect(const int8 *mac_and_password) +{ + bluetooth_ch9141_send_at_command_parameter("CONADD", mac_and_password); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块获取rssi(信号强度) +// @param void +// @return int8 返回信号强度0到-127 +// @since v1.0 +// Sample usage: +// @note 调用此函数需要先调用bluetooth_ch9141_enter_at_mode或者拉低CMD引脚 进入AT模式 +// 需要特别注意bluetooth_ch9141_enter_at_mode函数内部有500ms的延时 +//------------------------------------------------------------------------------------------------------------------- +int16 bluetooth_ch9141_get_rssi(void) +{ + uint8 i; + size_t length; + int16 rssi; + bluetooth_ch9141_send_at_command_parameter("RSSI", "ON,0"); + length = strlen((int8 *)at_mode_data); + length -= 12;//计算RSSI 有多少位 + + rssi = 0; + for(i=0; i30) { - if(gpio_get(RTS_PIN)) - { - return len;//模块忙,如果允许当前程序使用while等待 则可以使用后面注释的while等待语句替换本if语句 - } - //while(gpio_get(RTS_PIN)); //如果RTS为低电平,则继续发送数据 +// if(gpio_get(RTS_PIN)) +// { +// return len;//模块忙,如果允许当前程序使用while等待 则可以使用后面注释的while等待语句替换本if语句 +// } + while(gpio_get(RTS_PIN)); //如果RTS为低电平,则继续发送数据 uart_putbuff(WIRELESS_UART,buff,30); buff += 30; //地址偏移 len -= 30;//数量 } - if(gpio_get(RTS_PIN)) - { - return len;//模块忙,如果允许当前程序使用while等待 则可以使用后面注释的while等待语句替换本if语句 - } - //while(gpio_get(RTS_PIN)); //如果RTS为低电平,则继续发送数据 +// if(gpio_get(RTS_PIN)) +// { +// return len;//模块忙,如果允许当前程序使用while等待 则可以使用后面注释的while等待语句替换本if语句 +// } + while(gpio_get(RTS_PIN)); //如果RTS为低电平,则继续发送数据 uart_putbuff(WIRELESS_UART,buff,len);//发送最后的数据 return 0; diff --git a/Example/LED_Blink_Demo/Libraries/seekfree_peripheral/SEEKFREE_WIRELESS.h b/Example/LED_Blink_Demo/Libraries/seekfree_peripheral/SEEKFREE_WIRELESS.h index 42c0832..d80339d 100644 --- a/Example/LED_Blink_Demo/Libraries/seekfree_peripheral/SEEKFREE_WIRELESS.h +++ b/Example/LED_Blink_Demo/Libraries/seekfree_peripheral/SEEKFREE_WIRELESS.h @@ -38,8 +38,26 @@ #define WIRELESS_UART_RX UART2_RX_P10_6 #define WIRELESS_UART_BAUD 115200 -#define RTS_PIN P10_2 //定义流控位引脚 指示当前模块是否可以接受数据 0可以继续接收 1不可以继续接收 +// ------------------------------------ 自动波特率 ------------------------------------ +// 注意事项1:无线转串口模块版本是V2.0以下的是无法开启自动波特率的。 +// 注意事项2:开启自动波特率务必连接RTS引脚,否则会开启失败。 +// 注意事项3:模块自动波特率失败的话,可以尝试断电重启 +// 开启自动波特率务必阅读上面两条 注意事项 +// 开启自动波特率务必阅读上面两条 注意事项 +// 开启自动波特率务必阅读上面两条 注意事项 + +// 0:关闭自动波特率 +// 1:开启自动波特率 自动波特率的作用是修改WIRELESS_UART_BAUD之后不需要对模块进行配置,模块会自动设置为对应的波特率 + +#define WIRELESS_AUTO_UART_BAUD 0 +// ------------------------------------ 自动波特率 ------------------------------------ + +#define RTS_PIN P10_2 //定义流控位引脚 指示当前模块是否可以接受数据 0可以继续接收 1不可以继续接收 +#define WIRELESS_BUFFER_SIZE 16 + +extern uint8 wireless_send_buffer[WIRELESS_BUFFER_SIZE]; +extern uint32 wireless_rx_index; void wireless_uart_callback(void); void seekfree_wireless_init(void); diff --git a/Example/LED_Blink_Demo/USER/isr.c b/Example/LED_Blink_Demo/USER/isr.c index c55a012..16bff98 100644 --- a/Example/LED_Blink_Demo/USER/isr.c +++ b/Example/LED_Blink_Demo/USER/isr.c @@ -179,7 +179,20 @@ IFX_INTERRUPT(uart2_rx_isr, 0, UART2_RX_INT_PRIO) { enableInterrupts();//开启中断嵌套 IfxAsclin_Asc_isrReceive(&uart2_handle); - wireless_uart_callback(); + switch(wireless_type) + { + case WIRELESS_SI24R1: + { + wireless_uart_callback(); + }break; + + case WIRELESS_CH9141: + { + bluetooth_ch9141_uart_callback(); + }break; + default:break; + } + } IFX_INTERRUPT(uart2_er_isr, 0, UART2_ER_INT_PRIO) { diff --git a/Example/LED_Blink_Demo/鍒犻櫎涓存椂鏂囦欢.bat b/Example/LED_Blink_Demo/鍒犻櫎涓存椂鏂囦欢.bat index 5323dd9..fa499b1 100644 --- a/Example/LED_Blink_Demo/鍒犻櫎涓存椂鏂囦欢.bat +++ b/Example/LED_Blink_Demo/鍒犻櫎涓存椂鏂囦欢.bat @@ -1,9 +1,6 @@ -rmdir .settings /s /q rmdir Debug /s /q del *.launch /s - -pause exit diff --git a/Example/PIT_Demo/.cproject b/Example/PIT_Demo/.cproject index 0619901..7c6eeb0 100644 --- a/Example/PIT_Demo/.cproject +++ b/Example/PIT_Demo/.cproject @@ -3,9 +3,9 @@ - + - + @@ -25,50 +25,76 @@ - + - + - + - + + + + + + @@ -355,9 +371,9 @@ - + - + @@ -377,43 +393,1895 @@ - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -431,13 +2299,37 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + @@ -458,21 +2350,5 @@ - - - - - - - - - - - - - - - - diff --git a/Example/PIT_Demo/.project b/Example/PIT_Demo/.project index 726de88..a8071fe 100644 --- a/Example/PIT_Demo/.project +++ b/Example/PIT_Demo/.project @@ -5,6 +5,18 @@ + + com.infineon.aurix.buildsystem.builders.booster + full,incremental, + + + + + com.infineon.aurix.buildsystem.builders.autodiscovery + full,incremental, + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder clean,full,incremental, diff --git a/Example/PIT_Demo/.settings/com.infineon.aurix.buildsystem.prefs b/Example/PIT_Demo/.settings/com.infineon.aurix.buildsystem.prefs new file mode 100644 index 0000000..be61bc1 --- /dev/null +++ b/Example/PIT_Demo/.settings/com.infineon.aurix.buildsystem.prefs @@ -0,0 +1,10 @@ +AURIX-LIBRARY-PATH=Libraries/iLLD\#Libraries/Infra\#Libraries/Service +DEVICE-ID=TC26B +DEVICE-ID-FULL=TC26xD_B-Step +ILLD-SET=full +IncludesAutodiscovery=true +LIBRARIES-ROOT-PATH=Libraries +NEVER-EXCLUDE-FROM-BUILD=/Libraries/iLLD/TC26B/Tricore/Cpu/CStart\#/Libraries/iLLD/TC26B/Tricore/Cpu/Trap\#/Configurations\#/Configurations/Debug +PROJECT-VERSION=1.0 +aurixDevice=TC26xD_B-Step +eclipse.preferences.version=1 diff --git a/Example/PIT_Demo/Libraries/doc/version.txt b/Example/PIT_Demo/Libraries/doc/version.txt index ab79909..11ab82e 100644 --- a/Example/PIT_Demo/Libraries/doc/version.txt +++ b/Example/PIT_Demo/Libraries/doc/version.txt @@ -1,3 +1,13 @@ +V1.2.0 + 增加CH9141蓝牙转串口模块的驱动 + 添加无线类型的枚举变量 + 修改 删除临时文件.bat 执行完操作后自动关闭窗口 + 修改 删除临时文件.bat 避免删除新版本所需文件 + 修改工程项目文件,以支持新版本编译 + +V1.1.10 + 修复通过#pragma section all "cpux_dsram"指定变量位置失效的问题 + V1.1.9 将串口的发送buff增加到128字节 diff --git a/Example/PIT_Demo/Libraries/seekfree_libraries/common/common.c b/Example/PIT_Demo/Libraries/seekfree_libraries/common/common.c index 0b9931e..7620ce6 100644 --- a/Example/PIT_Demo/Libraries/seekfree_libraries/common/common.c +++ b/Example/PIT_Demo/Libraries/seekfree_libraries/common/common.c @@ -27,6 +27,8 @@ CAMERA_TYPE_enum camera_type; //摄像头型号 uint8 *camera_buffer_addr; //摄像头数组地址 +WIRELESS_TYPE_enum wireless_type;//无线转串口类型 + IFX_ALIGN(4) IfxCpu_syncEvent g_cpuSyncEvent = 0;//事件同步变量 App_Cpu0 g_AppCpu0; //频率信息变量 diff --git a/Example/PIT_Demo/Libraries/seekfree_libraries/common/common.h b/Example/PIT_Demo/Libraries/seekfree_libraries/common/common.h index 84c43ee..5b741c0 100644 --- a/Example/PIT_Demo/Libraries/seekfree_libraries/common/common.h +++ b/Example/PIT_Demo/Libraries/seekfree_libraries/common/common.h @@ -113,6 +113,12 @@ typedef enum //枚 CAMERA_COLOR, //凌瞳 }CAMERA_TYPE_enum; +typedef enum //无线模块 +{ + WIRELESS_SI24R1 = 1, //无线转串口 + WIRELESS_CH9141, //蓝牙转串口 +}WIRELESS_TYPE_enum; + #include #include #include "IfxCpu.h" @@ -120,6 +126,8 @@ typedef enum //枚 extern CAMERA_TYPE_enum camera_type; //摄像头型号 extern uint8 *camera_buffer_addr; //摄像头数组地址 +extern WIRELESS_TYPE_enum wireless_type; + extern IfxCpu_syncEvent g_cpuSyncEvent; void get_clk(void); diff --git a/Example/PIT_Demo/Libraries/seekfree_libraries/headfile.h b/Example/PIT_Demo/Libraries/seekfree_libraries/headfile.h index 404ee0a..b745302 100644 --- a/Example/PIT_Demo/Libraries/seekfree_libraries/headfile.h +++ b/Example/PIT_Demo/Libraries/seekfree_libraries/headfile.h @@ -65,6 +65,7 @@ #include "SEEKFREE_7725.h" #include "SEEKFREE_RDA5807.h" #include "SEEKFREE_7725_UART.h" +#include "SEEKFREE_BLUETOOTH_CH9141.h" #endif diff --git a/Example/PIT_Demo/Libraries/seekfree_peripheral/SEEKFREE_BLUETOOTH_CH9141.c b/Example/PIT_Demo/Libraries/seekfree_peripheral/SEEKFREE_BLUETOOTH_CH9141.c new file mode 100644 index 0000000..b4ec2df --- /dev/null +++ b/Example/PIT_Demo/Libraries/seekfree_peripheral/SEEKFREE_BLUETOOTH_CH9141.c @@ -0,0 +1,509 @@ +/********************************************************************************************************************* + * COPYRIGHT NOTICE + * Copyright (c) 2021,逐飞科技 + * All rights reserved. + * 技术讨论QQ群:一群:179029047(已满) 二群:244861897 + * + * 以下所有内容版权均属逐飞科技所有,未经允许不得用于商业用途, + * 欢迎各位使用并传播本程序,修改内容时必须保留逐飞科技的版权声明。 + * + * @file 逐飞科技蓝牙转串口模块 + * @company 成都逐飞科技有限公司 + * @author 逐飞科技(QQ3184284598) + * @version 查看doc内version文件 版本说明 + * @Software IAR 8.3 or MDK 5.33 + * @Taobao https://seekfree.taobao.com/ + * @date 2021-08-27 + * @note + 接线定义: + ------------------------------------ + 蓝牙转串口 单片机 + RX 查看SEEKFREE_BLUETOOTH_CH9141.h文件中的BLUETOOTH_CH9141_UART_TX宏定义 + TX 查看SEEKFREE_BLUETOOTH_CH9141.h文件中的BLUETOOTH_CH9141_UART_RX宏定义 + RTS 查看SEEKFREE_BLUETOOTH_CH9141.h文件中的BLUETOOTH_CH9141_RTS_PIN宏定义 + CTS 悬空 + CMD 悬空或者上拉 + ------------------------------------ + ********************************************************************************************************************/ +#include "zf_stm_systick.h" +#include "zf_gpio.h" +#include "zf_uart.h" +#include "zf_assert.h" +#include "SEEKFREE_BLUETOOTH_CH9141.h" + +uint8 uart_flag; +uint8 uart_data; + +vuint8 at_mode = 0; //0:蓝牙透传模式 1:AT模式 2:模块复位中 +vuint8 at_mode_num; //at模式时用于指示数据接收的数量 +vuint8 at_mode_data[30]; //接收at命令的缓存 +vuint8 at_mode_cmd_flag; //OK应答命令接收成功的标志位 + +uint8 mac_address[17]; //本机mac地址 + + +uint8 bluetooth_ch9141_rx_buffer; + + +void bluetooth_ch9141_check_response(void); + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块 串口中断回调函数 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note 该函数在ISR文件 串口8中断程序被调用 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_uart_callback() +{ + while(uart_query(BLUETOOTH_CH9141_UART, &bluetooth_ch9141_rx_buffer)) + { + if(1 == at_mode) + { + //进入AT模式 接收应答信号 此处if语句内代码用户不要改动 + at_mode_data[at_mode_num++] = bluetooth_ch9141_rx_buffer; + bluetooth_ch9141_check_response(); + } + else if(2 == at_mode) + { + //模块正在复位中 此处if语句内代码用户不要改动 + at_mode_num++; + } + else + { + //透传模式 用户在此处接收配对的蓝牙发送过来的额数据 + //接到一个字节后单片机将会进入此处,通过在此处读取bluetooth_ch9141_rx_buffer可以取走数据 + + // 读取无线串口的数据 并且置位接收标志 + uart_flag = 1; + uart_data = bluetooth_ch9141_rx_buffer; + } + + } +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块检查OK应答信号 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_check_response(void) +{ + if(4 <= at_mode_num) + { + if(0 == strncmp("OK\r\n", (int8 *)&at_mode_data[at_mode_num-4], 4)) + { + at_mode_cmd_flag = 1; + } + } +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块发送一个没有参数的命令并等待应答信号 +// @param *str 需要发送的命令 完整字符串 +// @return void +// @since v1.0 +// Sample usage: +// @note 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_send_at_command(const int8 *str) +{ + at_mode_num = 0; //接收数量清零 + uart_putstr(BLUETOOTH_CH9141_UART, str); + uart_putstr(BLUETOOTH_CH9141_UART, "\r\n"); + + //等待收到应答信号 + while(!at_mode_cmd_flag); + at_mode_cmd_flag = 0; +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块发送一个带有参数的命令并等待应答信号 +// @param *cmd 需要发送的命令名称 +// @param *data 需要发送的数据 +// @return void +// @since v1.0 +// Sample usage: +// @note 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_send_at_command_parameter(const int8 *cmd, const int8 *data) +{ + at_mode_num = 0; //接收数量清零 + uart_putstr(BLUETOOTH_CH9141_UART, "AT+"); + uart_putstr(BLUETOOTH_CH9141_UART, cmd); + uart_putstr(BLUETOOTH_CH9141_UART, "="); + uart_putstr(BLUETOOTH_CH9141_UART, data); + uart_putstr(BLUETOOTH_CH9141_UART, "\r\n"); + + //等待收到应答信号 + while(!at_mode_cmd_flag); + at_mode_cmd_flag = 0; +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块进入AT模式 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_enter_at_mode(void) +{ + systick_delay_ms(STM0, 550); //发送进入AT模式的命令前需要保证模块在550ms内没有接收过任何数据 + at_mode = 1; //进入AT模式 + bluetooth_ch9141_send_at_command("AT..."); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块退出AT模式 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_exit_at_mode(void) +{ + bluetooth_ch9141_send_at_command("AT+EXIT"); + at_mode = 0; //进入透传模式 + systick_delay_ms(STM0, 300); //等待成功进入AT模式 +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块复位 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_reset(void) +{ + bluetooth_ch9141_send_at_command("AT+RESET"); + at_mode = 2; //进入重启成功检测 + at_mode_num = 0; + while(7 > at_mode_num); //等待蓝牙模块完成复位 + at_mode = 0; //复位之后模块自动进入透传模式 +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块获取本机MAC地址 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note 调用此函数需要先调用bluetooth_ch9141_enter_at_mode或者拉低CMD引脚 进入AT模式 +// 需要特别注意bluetooth_ch9141_enter_at_mode函数内部有500ms的延时 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_get_mac_address(void) +{ + bluetooth_ch9141_send_at_command("AT+MAC?"); + + //mac地址为小段格式,mac_address[0]保存的是mac地址最低位 + memcpy(mac_address, (uint8 *)at_mode_data, 17); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块设置发送功率 +// @param tx_power 设置发送功率,可设置选项查看CH9141_TX_POWEER_enum枚举成员 +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_set_tx_power(CH9141_TX_POWEER_enum tx_power) +{ + int8 tx_power_data; + + tx_power_data = (uint8)tx_power + '0'; + bluetooth_ch9141_send_at_command_parameter("TPL", &tx_power_data); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块设置模式 +// @param mode 模式设置,可设置选项查看CH9141_MODE_enum枚举成员 +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_set_mode(CH9141_MODE_enum mode) +{ + int8 mode_data; + + mode_data = (uint8)mode + '0'; + bluetooth_ch9141_send_at_command_parameter("BLEMODE", &mode_data); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块获取状态 +// @param mode 模式设置,可设置选项查看CH9141_MODE_enum枚举成员 +// @return CH9141_STATUS_enum 返回状态信息 +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +CH9141_STATUS_enum bluetooth_ch9141_get_status(CH9141_MODE_enum mode) +{ + CH9141_STATUS_enum ch9141_status; + int8 mode_data; + + mode_data = (uint8)mode + '0'; + bluetooth_ch9141_send_at_command_parameter("BLEMODE", &mode_data); + + bluetooth_ch9141_send_at_command("AT+BLESTA?"); + + ch9141_status = (at_mode_data[0] - '0') * 10 + (at_mode_data[1] - '0'); + if(SLAVE_MODE == mode) + { + ch9141_status += SLAVE_NO_INIT; + } + + return ch9141_status; +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块设置设备名称 +// @param *str 蓝牙名称 +// @return void +// @since v1.0 +// Sample usage: +// @note 名称长度不能超过18个字符 且只能为英文与数字 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_set_name(const int8 *str) +{ + bluetooth_ch9141_send_at_command_parameter("NAME", str); + bluetooth_ch9141_send_at_command_parameter("PNAME", str); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块密码设置 +// @param enable 使能密码 0:不使用密码,1:使用密码才能连接本设备 +// @param *password 密码的字符串 必须为6个字符 +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_set_password(uint8 enable, const int8 *password) +{ + if(0 == enable) + { + //关闭密码 + bluetooth_ch9141_send_at_command_parameter("PASEN", "OFF"); + } + else + { + //设置密码并使能 + bluetooth_ch9141_send_at_command_parameter("PASEN", "ON"); + bluetooth_ch9141_send_at_command_parameter("PASS", password); + } +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块指定MAC地址并立即进行连接 +// @param *mac_and_password 需要连接的设备mac地址与密码 +// @return void +// @since v1.0 +// Sample usage: +// @note bluetooth_ch9141_connect("58:B7:33:E4:C2:84,000000"); +// 58:B7:33:E4:C2:84为mac地址 ,为分隔符 000000为从机蓝牙密码 +// ===================特别注意================== +// 如果使用手机查看蓝牙的mac地址,则使用本函数连接的时候请将mac倒置一下 +// 例如手机查看到的mac地址为61:62:63:64:65:66,则使用本函数连接的时候应该写 +// bluetooth_ch9141_connect("66:65:64:63:62:61,000000"); +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_connect(const int8 *mac_and_password) +{ + bluetooth_ch9141_send_at_command_parameter("CONN", mac_and_password); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块默认连接参数设置(设置好后,每次开机蓝牙会自动链接这个设备) +// @param *mac_and_password 需要连接的设备mac地址与密码 +// @return void +// @since v1.0 +// Sample usage: +// @note bluetooth_ch9141_default_connect("58:B7:33:E4:C2:84,000000"); +// 58:B7:33:E4:C2:84为mac地址 ,为分隔符 000000为从机蓝牙密码 +// ===================特别注意================== +// 如果使用手机查看CH9141的mac地址,将CH9141设置为从机,使用手机连接 +// 则使用本函数连接的时候请将mac倒置一下 +// 例如手机查看到的mac地址为61:62:63:64:65:67,则使用本函数连接的时候应该写 +// bluetooth_ch9141_default_connect("67:65:64:63:62:61,000000"); +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_default_connect(const int8 *mac_and_password) +{ + bluetooth_ch9141_send_at_command_parameter("CONADD", mac_and_password); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块获取rssi(信号强度) +// @param void +// @return int8 返回信号强度0到-127 +// @since v1.0 +// Sample usage: +// @note 调用此函数需要先调用bluetooth_ch9141_enter_at_mode或者拉低CMD引脚 进入AT模式 +// 需要特别注意bluetooth_ch9141_enter_at_mode函数内部有500ms的延时 +//------------------------------------------------------------------------------------------------------------------- +int16 bluetooth_ch9141_get_rssi(void) +{ + uint8 i; + size_t length; + int16 rssi; + bluetooth_ch9141_send_at_command_parameter("RSSI", "ON,0"); + length = strlen((int8 *)at_mode_data); + length -= 12;//计算RSSI 有多少位 + + rssi = 0; + for(i=0; i30) { - if(gpio_get(RTS_PIN)) - { - return len;//模块忙,如果允许当前程序使用while等待 则可以使用后面注释的while等待语句替换本if语句 - } - //while(gpio_get(RTS_PIN)); //如果RTS为低电平,则继续发送数据 +// if(gpio_get(RTS_PIN)) +// { +// return len;//模块忙,如果允许当前程序使用while等待 则可以使用后面注释的while等待语句替换本if语句 +// } + while(gpio_get(RTS_PIN)); //如果RTS为低电平,则继续发送数据 uart_putbuff(WIRELESS_UART,buff,30); buff += 30; //地址偏移 len -= 30;//数量 } - if(gpio_get(RTS_PIN)) - { - return len;//模块忙,如果允许当前程序使用while等待 则可以使用后面注释的while等待语句替换本if语句 - } - //while(gpio_get(RTS_PIN)); //如果RTS为低电平,则继续发送数据 +// if(gpio_get(RTS_PIN)) +// { +// return len;//模块忙,如果允许当前程序使用while等待 则可以使用后面注释的while等待语句替换本if语句 +// } + while(gpio_get(RTS_PIN)); //如果RTS为低电平,则继续发送数据 uart_putbuff(WIRELESS_UART,buff,len);//发送最后的数据 return 0; diff --git a/Example/PIT_Demo/Libraries/seekfree_peripheral/SEEKFREE_WIRELESS.h b/Example/PIT_Demo/Libraries/seekfree_peripheral/SEEKFREE_WIRELESS.h index 42c0832..d80339d 100644 --- a/Example/PIT_Demo/Libraries/seekfree_peripheral/SEEKFREE_WIRELESS.h +++ b/Example/PIT_Demo/Libraries/seekfree_peripheral/SEEKFREE_WIRELESS.h @@ -38,8 +38,26 @@ #define WIRELESS_UART_RX UART2_RX_P10_6 #define WIRELESS_UART_BAUD 115200 -#define RTS_PIN P10_2 //定义流控位引脚 指示当前模块是否可以接受数据 0可以继续接收 1不可以继续接收 +// ------------------------------------ 自动波特率 ------------------------------------ +// 注意事项1:无线转串口模块版本是V2.0以下的是无法开启自动波特率的。 +// 注意事项2:开启自动波特率务必连接RTS引脚,否则会开启失败。 +// 注意事项3:模块自动波特率失败的话,可以尝试断电重启 +// 开启自动波特率务必阅读上面两条 注意事项 +// 开启自动波特率务必阅读上面两条 注意事项 +// 开启自动波特率务必阅读上面两条 注意事项 + +// 0:关闭自动波特率 +// 1:开启自动波特率 自动波特率的作用是修改WIRELESS_UART_BAUD之后不需要对模块进行配置,模块会自动设置为对应的波特率 + +#define WIRELESS_AUTO_UART_BAUD 0 +// ------------------------------------ 自动波特率 ------------------------------------ + +#define RTS_PIN P10_2 //定义流控位引脚 指示当前模块是否可以接受数据 0可以继续接收 1不可以继续接收 +#define WIRELESS_BUFFER_SIZE 16 + +extern uint8 wireless_send_buffer[WIRELESS_BUFFER_SIZE]; +extern uint32 wireless_rx_index; void wireless_uart_callback(void); void seekfree_wireless_init(void); diff --git a/Example/PIT_Demo/USER/isr.c b/Example/PIT_Demo/USER/isr.c index f345040..042670f 100644 --- a/Example/PIT_Demo/USER/isr.c +++ b/Example/PIT_Demo/USER/isr.c @@ -181,7 +181,20 @@ IFX_INTERRUPT(uart2_rx_isr, 0, UART2_RX_INT_PRIO) { enableInterrupts();//开启中断嵌套 IfxAsclin_Asc_isrReceive(&uart2_handle); - wireless_uart_callback(); + switch(wireless_type) + { + case WIRELESS_SI24R1: + { + wireless_uart_callback(); + }break; + + case WIRELESS_CH9141: + { + bluetooth_ch9141_uart_callback(); + }break; + default:break; + } + } IFX_INTERRUPT(uart2_er_isr, 0, UART2_ER_INT_PRIO) { diff --git a/Example/PIT_Demo/鍒犻櫎涓存椂鏂囦欢.bat b/Example/PIT_Demo/鍒犻櫎涓存椂鏂囦欢.bat index 5323dd9..fa499b1 100644 --- a/Example/PIT_Demo/鍒犻櫎涓存椂鏂囦欢.bat +++ b/Example/PIT_Demo/鍒犻櫎涓存椂鏂囦欢.bat @@ -1,9 +1,6 @@ -rmdir .settings /s /q rmdir Debug /s /q del *.launch /s - -pause exit diff --git a/Example/PWM_Demo/.cproject b/Example/PWM_Demo/.cproject index e8a32f0..c0f7ed3 100644 --- a/Example/PWM_Demo/.cproject +++ b/Example/PWM_Demo/.cproject @@ -3,9 +3,9 @@ - + - + @@ -25,50 +25,76 @@ - + - + - + - + + + + + + @@ -355,9 +371,9 @@ - + - + @@ -377,43 +393,1895 @@ - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -431,13 +2299,37 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + @@ -458,21 +2350,5 @@ - - - - - - - - - - - - - - - - diff --git a/Example/PWM_Demo/.project b/Example/PWM_Demo/.project index d14ea9b..ca33250 100644 --- a/Example/PWM_Demo/.project +++ b/Example/PWM_Demo/.project @@ -5,6 +5,18 @@ + + com.infineon.aurix.buildsystem.builders.booster + full,incremental, + + + + + com.infineon.aurix.buildsystem.builders.autodiscovery + full,incremental, + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder clean,full,incremental, diff --git a/Example/PWM_Demo/.settings/com.infineon.aurix.buildsystem.prefs b/Example/PWM_Demo/.settings/com.infineon.aurix.buildsystem.prefs new file mode 100644 index 0000000..be61bc1 --- /dev/null +++ b/Example/PWM_Demo/.settings/com.infineon.aurix.buildsystem.prefs @@ -0,0 +1,10 @@ +AURIX-LIBRARY-PATH=Libraries/iLLD\#Libraries/Infra\#Libraries/Service +DEVICE-ID=TC26B +DEVICE-ID-FULL=TC26xD_B-Step +ILLD-SET=full +IncludesAutodiscovery=true +LIBRARIES-ROOT-PATH=Libraries +NEVER-EXCLUDE-FROM-BUILD=/Libraries/iLLD/TC26B/Tricore/Cpu/CStart\#/Libraries/iLLD/TC26B/Tricore/Cpu/Trap\#/Configurations\#/Configurations/Debug +PROJECT-VERSION=1.0 +aurixDevice=TC26xD_B-Step +eclipse.preferences.version=1 diff --git a/Example/PWM_Demo/Libraries/doc/version.txt b/Example/PWM_Demo/Libraries/doc/version.txt index ab79909..11ab82e 100644 --- a/Example/PWM_Demo/Libraries/doc/version.txt +++ b/Example/PWM_Demo/Libraries/doc/version.txt @@ -1,3 +1,13 @@ +V1.2.0 + 增加CH9141蓝牙转串口模块的驱动 + 添加无线类型的枚举变量 + 修改 删除临时文件.bat 执行完操作后自动关闭窗口 + 修改 删除临时文件.bat 避免删除新版本所需文件 + 修改工程项目文件,以支持新版本编译 + +V1.1.10 + 修复通过#pragma section all "cpux_dsram"指定变量位置失效的问题 + V1.1.9 将串口的发送buff增加到128字节 diff --git a/Example/PWM_Demo/Libraries/seekfree_libraries/common/common.c b/Example/PWM_Demo/Libraries/seekfree_libraries/common/common.c index 0b9931e..7620ce6 100644 --- a/Example/PWM_Demo/Libraries/seekfree_libraries/common/common.c +++ b/Example/PWM_Demo/Libraries/seekfree_libraries/common/common.c @@ -27,6 +27,8 @@ CAMERA_TYPE_enum camera_type; //摄像头型号 uint8 *camera_buffer_addr; //摄像头数组地址 +WIRELESS_TYPE_enum wireless_type;//无线转串口类型 + IFX_ALIGN(4) IfxCpu_syncEvent g_cpuSyncEvent = 0;//事件同步变量 App_Cpu0 g_AppCpu0; //频率信息变量 diff --git a/Example/PWM_Demo/Libraries/seekfree_libraries/common/common.h b/Example/PWM_Demo/Libraries/seekfree_libraries/common/common.h index 84c43ee..5b741c0 100644 --- a/Example/PWM_Demo/Libraries/seekfree_libraries/common/common.h +++ b/Example/PWM_Demo/Libraries/seekfree_libraries/common/common.h @@ -113,6 +113,12 @@ typedef enum //枚 CAMERA_COLOR, //凌瞳 }CAMERA_TYPE_enum; +typedef enum //无线模块 +{ + WIRELESS_SI24R1 = 1, //无线转串口 + WIRELESS_CH9141, //蓝牙转串口 +}WIRELESS_TYPE_enum; + #include #include #include "IfxCpu.h" @@ -120,6 +126,8 @@ typedef enum //枚 extern CAMERA_TYPE_enum camera_type; //摄像头型号 extern uint8 *camera_buffer_addr; //摄像头数组地址 +extern WIRELESS_TYPE_enum wireless_type; + extern IfxCpu_syncEvent g_cpuSyncEvent; void get_clk(void); diff --git a/Example/PWM_Demo/Libraries/seekfree_libraries/headfile.h b/Example/PWM_Demo/Libraries/seekfree_libraries/headfile.h index 404ee0a..b745302 100644 --- a/Example/PWM_Demo/Libraries/seekfree_libraries/headfile.h +++ b/Example/PWM_Demo/Libraries/seekfree_libraries/headfile.h @@ -65,6 +65,7 @@ #include "SEEKFREE_7725.h" #include "SEEKFREE_RDA5807.h" #include "SEEKFREE_7725_UART.h" +#include "SEEKFREE_BLUETOOTH_CH9141.h" #endif diff --git a/Example/PWM_Demo/Libraries/seekfree_peripheral/SEEKFREE_BLUETOOTH_CH9141.c b/Example/PWM_Demo/Libraries/seekfree_peripheral/SEEKFREE_BLUETOOTH_CH9141.c new file mode 100644 index 0000000..b4ec2df --- /dev/null +++ b/Example/PWM_Demo/Libraries/seekfree_peripheral/SEEKFREE_BLUETOOTH_CH9141.c @@ -0,0 +1,509 @@ +/********************************************************************************************************************* + * COPYRIGHT NOTICE + * Copyright (c) 2021,逐飞科技 + * All rights reserved. + * 技术讨论QQ群:一群:179029047(已满) 二群:244861897 + * + * 以下所有内容版权均属逐飞科技所有,未经允许不得用于商业用途, + * 欢迎各位使用并传播本程序,修改内容时必须保留逐飞科技的版权声明。 + * + * @file 逐飞科技蓝牙转串口模块 + * @company 成都逐飞科技有限公司 + * @author 逐飞科技(QQ3184284598) + * @version 查看doc内version文件 版本说明 + * @Software IAR 8.3 or MDK 5.33 + * @Taobao https://seekfree.taobao.com/ + * @date 2021-08-27 + * @note + 接线定义: + ------------------------------------ + 蓝牙转串口 单片机 + RX 查看SEEKFREE_BLUETOOTH_CH9141.h文件中的BLUETOOTH_CH9141_UART_TX宏定义 + TX 查看SEEKFREE_BLUETOOTH_CH9141.h文件中的BLUETOOTH_CH9141_UART_RX宏定义 + RTS 查看SEEKFREE_BLUETOOTH_CH9141.h文件中的BLUETOOTH_CH9141_RTS_PIN宏定义 + CTS 悬空 + CMD 悬空或者上拉 + ------------------------------------ + ********************************************************************************************************************/ +#include "zf_stm_systick.h" +#include "zf_gpio.h" +#include "zf_uart.h" +#include "zf_assert.h" +#include "SEEKFREE_BLUETOOTH_CH9141.h" + +uint8 uart_flag; +uint8 uart_data; + +vuint8 at_mode = 0; //0:蓝牙透传模式 1:AT模式 2:模块复位中 +vuint8 at_mode_num; //at模式时用于指示数据接收的数量 +vuint8 at_mode_data[30]; //接收at命令的缓存 +vuint8 at_mode_cmd_flag; //OK应答命令接收成功的标志位 + +uint8 mac_address[17]; //本机mac地址 + + +uint8 bluetooth_ch9141_rx_buffer; + + +void bluetooth_ch9141_check_response(void); + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块 串口中断回调函数 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note 该函数在ISR文件 串口8中断程序被调用 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_uart_callback() +{ + while(uart_query(BLUETOOTH_CH9141_UART, &bluetooth_ch9141_rx_buffer)) + { + if(1 == at_mode) + { + //进入AT模式 接收应答信号 此处if语句内代码用户不要改动 + at_mode_data[at_mode_num++] = bluetooth_ch9141_rx_buffer; + bluetooth_ch9141_check_response(); + } + else if(2 == at_mode) + { + //模块正在复位中 此处if语句内代码用户不要改动 + at_mode_num++; + } + else + { + //透传模式 用户在此处接收配对的蓝牙发送过来的额数据 + //接到一个字节后单片机将会进入此处,通过在此处读取bluetooth_ch9141_rx_buffer可以取走数据 + + // 读取无线串口的数据 并且置位接收标志 + uart_flag = 1; + uart_data = bluetooth_ch9141_rx_buffer; + } + + } +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块检查OK应答信号 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_check_response(void) +{ + if(4 <= at_mode_num) + { + if(0 == strncmp("OK\r\n", (int8 *)&at_mode_data[at_mode_num-4], 4)) + { + at_mode_cmd_flag = 1; + } + } +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块发送一个没有参数的命令并等待应答信号 +// @param *str 需要发送的命令 完整字符串 +// @return void +// @since v1.0 +// Sample usage: +// @note 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_send_at_command(const int8 *str) +{ + at_mode_num = 0; //接收数量清零 + uart_putstr(BLUETOOTH_CH9141_UART, str); + uart_putstr(BLUETOOTH_CH9141_UART, "\r\n"); + + //等待收到应答信号 + while(!at_mode_cmd_flag); + at_mode_cmd_flag = 0; +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块发送一个带有参数的命令并等待应答信号 +// @param *cmd 需要发送的命令名称 +// @param *data 需要发送的数据 +// @return void +// @since v1.0 +// Sample usage: +// @note 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_send_at_command_parameter(const int8 *cmd, const int8 *data) +{ + at_mode_num = 0; //接收数量清零 + uart_putstr(BLUETOOTH_CH9141_UART, "AT+"); + uart_putstr(BLUETOOTH_CH9141_UART, cmd); + uart_putstr(BLUETOOTH_CH9141_UART, "="); + uart_putstr(BLUETOOTH_CH9141_UART, data); + uart_putstr(BLUETOOTH_CH9141_UART, "\r\n"); + + //等待收到应答信号 + while(!at_mode_cmd_flag); + at_mode_cmd_flag = 0; +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块进入AT模式 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_enter_at_mode(void) +{ + systick_delay_ms(STM0, 550); //发送进入AT模式的命令前需要保证模块在550ms内没有接收过任何数据 + at_mode = 1; //进入AT模式 + bluetooth_ch9141_send_at_command("AT..."); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块退出AT模式 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_exit_at_mode(void) +{ + bluetooth_ch9141_send_at_command("AT+EXIT"); + at_mode = 0; //进入透传模式 + systick_delay_ms(STM0, 300); //等待成功进入AT模式 +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块复位 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_reset(void) +{ + bluetooth_ch9141_send_at_command("AT+RESET"); + at_mode = 2; //进入重启成功检测 + at_mode_num = 0; + while(7 > at_mode_num); //等待蓝牙模块完成复位 + at_mode = 0; //复位之后模块自动进入透传模式 +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块获取本机MAC地址 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note 调用此函数需要先调用bluetooth_ch9141_enter_at_mode或者拉低CMD引脚 进入AT模式 +// 需要特别注意bluetooth_ch9141_enter_at_mode函数内部有500ms的延时 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_get_mac_address(void) +{ + bluetooth_ch9141_send_at_command("AT+MAC?"); + + //mac地址为小段格式,mac_address[0]保存的是mac地址最低位 + memcpy(mac_address, (uint8 *)at_mode_data, 17); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块设置发送功率 +// @param tx_power 设置发送功率,可设置选项查看CH9141_TX_POWEER_enum枚举成员 +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_set_tx_power(CH9141_TX_POWEER_enum tx_power) +{ + int8 tx_power_data; + + tx_power_data = (uint8)tx_power + '0'; + bluetooth_ch9141_send_at_command_parameter("TPL", &tx_power_data); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块设置模式 +// @param mode 模式设置,可设置选项查看CH9141_MODE_enum枚举成员 +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_set_mode(CH9141_MODE_enum mode) +{ + int8 mode_data; + + mode_data = (uint8)mode + '0'; + bluetooth_ch9141_send_at_command_parameter("BLEMODE", &mode_data); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块获取状态 +// @param mode 模式设置,可设置选项查看CH9141_MODE_enum枚举成员 +// @return CH9141_STATUS_enum 返回状态信息 +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +CH9141_STATUS_enum bluetooth_ch9141_get_status(CH9141_MODE_enum mode) +{ + CH9141_STATUS_enum ch9141_status; + int8 mode_data; + + mode_data = (uint8)mode + '0'; + bluetooth_ch9141_send_at_command_parameter("BLEMODE", &mode_data); + + bluetooth_ch9141_send_at_command("AT+BLESTA?"); + + ch9141_status = (at_mode_data[0] - '0') * 10 + (at_mode_data[1] - '0'); + if(SLAVE_MODE == mode) + { + ch9141_status += SLAVE_NO_INIT; + } + + return ch9141_status; +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块设置设备名称 +// @param *str 蓝牙名称 +// @return void +// @since v1.0 +// Sample usage: +// @note 名称长度不能超过18个字符 且只能为英文与数字 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_set_name(const int8 *str) +{ + bluetooth_ch9141_send_at_command_parameter("NAME", str); + bluetooth_ch9141_send_at_command_parameter("PNAME", str); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块密码设置 +// @param enable 使能密码 0:不使用密码,1:使用密码才能连接本设备 +// @param *password 密码的字符串 必须为6个字符 +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_set_password(uint8 enable, const int8 *password) +{ + if(0 == enable) + { + //关闭密码 + bluetooth_ch9141_send_at_command_parameter("PASEN", "OFF"); + } + else + { + //设置密码并使能 + bluetooth_ch9141_send_at_command_parameter("PASEN", "ON"); + bluetooth_ch9141_send_at_command_parameter("PASS", password); + } +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块指定MAC地址并立即进行连接 +// @param *mac_and_password 需要连接的设备mac地址与密码 +// @return void +// @since v1.0 +// Sample usage: +// @note bluetooth_ch9141_connect("58:B7:33:E4:C2:84,000000"); +// 58:B7:33:E4:C2:84为mac地址 ,为分隔符 000000为从机蓝牙密码 +// ===================特别注意================== +// 如果使用手机查看蓝牙的mac地址,则使用本函数连接的时候请将mac倒置一下 +// 例如手机查看到的mac地址为61:62:63:64:65:66,则使用本函数连接的时候应该写 +// bluetooth_ch9141_connect("66:65:64:63:62:61,000000"); +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_connect(const int8 *mac_and_password) +{ + bluetooth_ch9141_send_at_command_parameter("CONN", mac_and_password); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块默认连接参数设置(设置好后,每次开机蓝牙会自动链接这个设备) +// @param *mac_and_password 需要连接的设备mac地址与密码 +// @return void +// @since v1.0 +// Sample usage: +// @note bluetooth_ch9141_default_connect("58:B7:33:E4:C2:84,000000"); +// 58:B7:33:E4:C2:84为mac地址 ,为分隔符 000000为从机蓝牙密码 +// ===================特别注意================== +// 如果使用手机查看CH9141的mac地址,将CH9141设置为从机,使用手机连接 +// 则使用本函数连接的时候请将mac倒置一下 +// 例如手机查看到的mac地址为61:62:63:64:65:67,则使用本函数连接的时候应该写 +// bluetooth_ch9141_default_connect("67:65:64:63:62:61,000000"); +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_default_connect(const int8 *mac_and_password) +{ + bluetooth_ch9141_send_at_command_parameter("CONADD", mac_and_password); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块获取rssi(信号强度) +// @param void +// @return int8 返回信号强度0到-127 +// @since v1.0 +// Sample usage: +// @note 调用此函数需要先调用bluetooth_ch9141_enter_at_mode或者拉低CMD引脚 进入AT模式 +// 需要特别注意bluetooth_ch9141_enter_at_mode函数内部有500ms的延时 +//------------------------------------------------------------------------------------------------------------------- +int16 bluetooth_ch9141_get_rssi(void) +{ + uint8 i; + size_t length; + int16 rssi; + bluetooth_ch9141_send_at_command_parameter("RSSI", "ON,0"); + length = strlen((int8 *)at_mode_data); + length -= 12;//计算RSSI 有多少位 + + rssi = 0; + for(i=0; i30) { - if(gpio_get(RTS_PIN)) - { - return len;//模块忙,如果允许当前程序使用while等待 则可以使用后面注释的while等待语句替换本if语句 - } - //while(gpio_get(RTS_PIN)); //如果RTS为低电平,则继续发送数据 +// if(gpio_get(RTS_PIN)) +// { +// return len;//模块忙,如果允许当前程序使用while等待 则可以使用后面注释的while等待语句替换本if语句 +// } + while(gpio_get(RTS_PIN)); //如果RTS为低电平,则继续发送数据 uart_putbuff(WIRELESS_UART,buff,30); buff += 30; //地址偏移 len -= 30;//数量 } - if(gpio_get(RTS_PIN)) - { - return len;//模块忙,如果允许当前程序使用while等待 则可以使用后面注释的while等待语句替换本if语句 - } - //while(gpio_get(RTS_PIN)); //如果RTS为低电平,则继续发送数据 +// if(gpio_get(RTS_PIN)) +// { +// return len;//模块忙,如果允许当前程序使用while等待 则可以使用后面注释的while等待语句替换本if语句 +// } + while(gpio_get(RTS_PIN)); //如果RTS为低电平,则继续发送数据 uart_putbuff(WIRELESS_UART,buff,len);//发送最后的数据 return 0; diff --git a/Example/PWM_Demo/Libraries/seekfree_peripheral/SEEKFREE_WIRELESS.h b/Example/PWM_Demo/Libraries/seekfree_peripheral/SEEKFREE_WIRELESS.h index 42c0832..d80339d 100644 --- a/Example/PWM_Demo/Libraries/seekfree_peripheral/SEEKFREE_WIRELESS.h +++ b/Example/PWM_Demo/Libraries/seekfree_peripheral/SEEKFREE_WIRELESS.h @@ -38,8 +38,26 @@ #define WIRELESS_UART_RX UART2_RX_P10_6 #define WIRELESS_UART_BAUD 115200 -#define RTS_PIN P10_2 //定义流控位引脚 指示当前模块是否可以接受数据 0可以继续接收 1不可以继续接收 +// ------------------------------------ 自动波特率 ------------------------------------ +// 注意事项1:无线转串口模块版本是V2.0以下的是无法开启自动波特率的。 +// 注意事项2:开启自动波特率务必连接RTS引脚,否则会开启失败。 +// 注意事项3:模块自动波特率失败的话,可以尝试断电重启 +// 开启自动波特率务必阅读上面两条 注意事项 +// 开启自动波特率务必阅读上面两条 注意事项 +// 开启自动波特率务必阅读上面两条 注意事项 + +// 0:关闭自动波特率 +// 1:开启自动波特率 自动波特率的作用是修改WIRELESS_UART_BAUD之后不需要对模块进行配置,模块会自动设置为对应的波特率 + +#define WIRELESS_AUTO_UART_BAUD 0 +// ------------------------------------ 自动波特率 ------------------------------------ + +#define RTS_PIN P10_2 //定义流控位引脚 指示当前模块是否可以接受数据 0可以继续接收 1不可以继续接收 +#define WIRELESS_BUFFER_SIZE 16 + +extern uint8 wireless_send_buffer[WIRELESS_BUFFER_SIZE]; +extern uint32 wireless_rx_index; void wireless_uart_callback(void); void seekfree_wireless_init(void); diff --git a/Example/PWM_Demo/USER/isr.c b/Example/PWM_Demo/USER/isr.c index c55a012..16bff98 100644 --- a/Example/PWM_Demo/USER/isr.c +++ b/Example/PWM_Demo/USER/isr.c @@ -179,7 +179,20 @@ IFX_INTERRUPT(uart2_rx_isr, 0, UART2_RX_INT_PRIO) { enableInterrupts();//开启中断嵌套 IfxAsclin_Asc_isrReceive(&uart2_handle); - wireless_uart_callback(); + switch(wireless_type) + { + case WIRELESS_SI24R1: + { + wireless_uart_callback(); + }break; + + case WIRELESS_CH9141: + { + bluetooth_ch9141_uart_callback(); + }break; + default:break; + } + } IFX_INTERRUPT(uart2_er_isr, 0, UART2_ER_INT_PRIO) { diff --git a/Example/PWM_Demo/鍒犻櫎涓存椂鏂囦欢.bat b/Example/PWM_Demo/鍒犻櫎涓存椂鏂囦欢.bat index 5323dd9..fa499b1 100644 --- a/Example/PWM_Demo/鍒犻櫎涓存椂鏂囦欢.bat +++ b/Example/PWM_Demo/鍒犻櫎涓存椂鏂囦欢.bat @@ -1,9 +1,6 @@ -rmdir .settings /s /q rmdir Debug /s /q del *.launch /s - -pause exit diff --git a/Example/Printf_Demo/.cproject b/Example/Printf_Demo/.cproject index 37fdd5a..8fa9ce2 100644 --- a/Example/Printf_Demo/.cproject +++ b/Example/Printf_Demo/.cproject @@ -3,9 +3,9 @@ - + - + @@ -25,50 +25,76 @@ - + - + - + - + + + + + + @@ -355,9 +371,9 @@ - + - + @@ -377,43 +393,1895 @@ - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -431,13 +2299,37 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + @@ -458,21 +2350,5 @@ - - - - - - - - - - - - - - - - diff --git a/Example/Printf_Demo/.project b/Example/Printf_Demo/.project index 679101d..9e0cf03 100644 --- a/Example/Printf_Demo/.project +++ b/Example/Printf_Demo/.project @@ -5,6 +5,18 @@ + + com.infineon.aurix.buildsystem.builders.booster + full,incremental, + + + + + com.infineon.aurix.buildsystem.builders.autodiscovery + full,incremental, + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder clean,full,incremental, diff --git a/Example/Printf_Demo/.settings/com.infineon.aurix.buildsystem.prefs b/Example/Printf_Demo/.settings/com.infineon.aurix.buildsystem.prefs new file mode 100644 index 0000000..be61bc1 --- /dev/null +++ b/Example/Printf_Demo/.settings/com.infineon.aurix.buildsystem.prefs @@ -0,0 +1,10 @@ +AURIX-LIBRARY-PATH=Libraries/iLLD\#Libraries/Infra\#Libraries/Service +DEVICE-ID=TC26B +DEVICE-ID-FULL=TC26xD_B-Step +ILLD-SET=full +IncludesAutodiscovery=true +LIBRARIES-ROOT-PATH=Libraries +NEVER-EXCLUDE-FROM-BUILD=/Libraries/iLLD/TC26B/Tricore/Cpu/CStart\#/Libraries/iLLD/TC26B/Tricore/Cpu/Trap\#/Configurations\#/Configurations/Debug +PROJECT-VERSION=1.0 +aurixDevice=TC26xD_B-Step +eclipse.preferences.version=1 diff --git a/Example/Printf_Demo/Libraries/doc/version.txt b/Example/Printf_Demo/Libraries/doc/version.txt index ab79909..11ab82e 100644 --- a/Example/Printf_Demo/Libraries/doc/version.txt +++ b/Example/Printf_Demo/Libraries/doc/version.txt @@ -1,3 +1,13 @@ +V1.2.0 + 增加CH9141蓝牙转串口模块的驱动 + 添加无线类型的枚举变量 + 修改 删除临时文件.bat 执行完操作后自动关闭窗口 + 修改 删除临时文件.bat 避免删除新版本所需文件 + 修改工程项目文件,以支持新版本编译 + +V1.1.10 + 修复通过#pragma section all "cpux_dsram"指定变量位置失效的问题 + V1.1.9 将串口的发送buff增加到128字节 diff --git a/Example/Printf_Demo/Libraries/seekfree_libraries/common/common.c b/Example/Printf_Demo/Libraries/seekfree_libraries/common/common.c index 0b9931e..7620ce6 100644 --- a/Example/Printf_Demo/Libraries/seekfree_libraries/common/common.c +++ b/Example/Printf_Demo/Libraries/seekfree_libraries/common/common.c @@ -27,6 +27,8 @@ CAMERA_TYPE_enum camera_type; //摄像头型号 uint8 *camera_buffer_addr; //摄像头数组地址 +WIRELESS_TYPE_enum wireless_type;//无线转串口类型 + IFX_ALIGN(4) IfxCpu_syncEvent g_cpuSyncEvent = 0;//事件同步变量 App_Cpu0 g_AppCpu0; //频率信息变量 diff --git a/Example/Printf_Demo/Libraries/seekfree_libraries/common/common.h b/Example/Printf_Demo/Libraries/seekfree_libraries/common/common.h index 84c43ee..5b741c0 100644 --- a/Example/Printf_Demo/Libraries/seekfree_libraries/common/common.h +++ b/Example/Printf_Demo/Libraries/seekfree_libraries/common/common.h @@ -113,6 +113,12 @@ typedef enum //枚 CAMERA_COLOR, //凌瞳 }CAMERA_TYPE_enum; +typedef enum //无线模块 +{ + WIRELESS_SI24R1 = 1, //无线转串口 + WIRELESS_CH9141, //蓝牙转串口 +}WIRELESS_TYPE_enum; + #include #include #include "IfxCpu.h" @@ -120,6 +126,8 @@ typedef enum //枚 extern CAMERA_TYPE_enum camera_type; //摄像头型号 extern uint8 *camera_buffer_addr; //摄像头数组地址 +extern WIRELESS_TYPE_enum wireless_type; + extern IfxCpu_syncEvent g_cpuSyncEvent; void get_clk(void); diff --git a/Example/Printf_Demo/Libraries/seekfree_libraries/headfile.h b/Example/Printf_Demo/Libraries/seekfree_libraries/headfile.h index 404ee0a..b745302 100644 --- a/Example/Printf_Demo/Libraries/seekfree_libraries/headfile.h +++ b/Example/Printf_Demo/Libraries/seekfree_libraries/headfile.h @@ -65,6 +65,7 @@ #include "SEEKFREE_7725.h" #include "SEEKFREE_RDA5807.h" #include "SEEKFREE_7725_UART.h" +#include "SEEKFREE_BLUETOOTH_CH9141.h" #endif diff --git a/Example/Printf_Demo/Libraries/seekfree_peripheral/SEEKFREE_BLUETOOTH_CH9141.c b/Example/Printf_Demo/Libraries/seekfree_peripheral/SEEKFREE_BLUETOOTH_CH9141.c new file mode 100644 index 0000000..b4ec2df --- /dev/null +++ b/Example/Printf_Demo/Libraries/seekfree_peripheral/SEEKFREE_BLUETOOTH_CH9141.c @@ -0,0 +1,509 @@ +/********************************************************************************************************************* + * COPYRIGHT NOTICE + * Copyright (c) 2021,逐飞科技 + * All rights reserved. + * 技术讨论QQ群:一群:179029047(已满) 二群:244861897 + * + * 以下所有内容版权均属逐飞科技所有,未经允许不得用于商业用途, + * 欢迎各位使用并传播本程序,修改内容时必须保留逐飞科技的版权声明。 + * + * @file 逐飞科技蓝牙转串口模块 + * @company 成都逐飞科技有限公司 + * @author 逐飞科技(QQ3184284598) + * @version 查看doc内version文件 版本说明 + * @Software IAR 8.3 or MDK 5.33 + * @Taobao https://seekfree.taobao.com/ + * @date 2021-08-27 + * @note + 接线定义: + ------------------------------------ + 蓝牙转串口 单片机 + RX 查看SEEKFREE_BLUETOOTH_CH9141.h文件中的BLUETOOTH_CH9141_UART_TX宏定义 + TX 查看SEEKFREE_BLUETOOTH_CH9141.h文件中的BLUETOOTH_CH9141_UART_RX宏定义 + RTS 查看SEEKFREE_BLUETOOTH_CH9141.h文件中的BLUETOOTH_CH9141_RTS_PIN宏定义 + CTS 悬空 + CMD 悬空或者上拉 + ------------------------------------ + ********************************************************************************************************************/ +#include "zf_stm_systick.h" +#include "zf_gpio.h" +#include "zf_uart.h" +#include "zf_assert.h" +#include "SEEKFREE_BLUETOOTH_CH9141.h" + +uint8 uart_flag; +uint8 uart_data; + +vuint8 at_mode = 0; //0:蓝牙透传模式 1:AT模式 2:模块复位中 +vuint8 at_mode_num; //at模式时用于指示数据接收的数量 +vuint8 at_mode_data[30]; //接收at命令的缓存 +vuint8 at_mode_cmd_flag; //OK应答命令接收成功的标志位 + +uint8 mac_address[17]; //本机mac地址 + + +uint8 bluetooth_ch9141_rx_buffer; + + +void bluetooth_ch9141_check_response(void); + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块 串口中断回调函数 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note 该函数在ISR文件 串口8中断程序被调用 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_uart_callback() +{ + while(uart_query(BLUETOOTH_CH9141_UART, &bluetooth_ch9141_rx_buffer)) + { + if(1 == at_mode) + { + //进入AT模式 接收应答信号 此处if语句内代码用户不要改动 + at_mode_data[at_mode_num++] = bluetooth_ch9141_rx_buffer; + bluetooth_ch9141_check_response(); + } + else if(2 == at_mode) + { + //模块正在复位中 此处if语句内代码用户不要改动 + at_mode_num++; + } + else + { + //透传模式 用户在此处接收配对的蓝牙发送过来的额数据 + //接到一个字节后单片机将会进入此处,通过在此处读取bluetooth_ch9141_rx_buffer可以取走数据 + + // 读取无线串口的数据 并且置位接收标志 + uart_flag = 1; + uart_data = bluetooth_ch9141_rx_buffer; + } + + } +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块检查OK应答信号 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_check_response(void) +{ + if(4 <= at_mode_num) + { + if(0 == strncmp("OK\r\n", (int8 *)&at_mode_data[at_mode_num-4], 4)) + { + at_mode_cmd_flag = 1; + } + } +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块发送一个没有参数的命令并等待应答信号 +// @param *str 需要发送的命令 完整字符串 +// @return void +// @since v1.0 +// Sample usage: +// @note 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_send_at_command(const int8 *str) +{ + at_mode_num = 0; //接收数量清零 + uart_putstr(BLUETOOTH_CH9141_UART, str); + uart_putstr(BLUETOOTH_CH9141_UART, "\r\n"); + + //等待收到应答信号 + while(!at_mode_cmd_flag); + at_mode_cmd_flag = 0; +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块发送一个带有参数的命令并等待应答信号 +// @param *cmd 需要发送的命令名称 +// @param *data 需要发送的数据 +// @return void +// @since v1.0 +// Sample usage: +// @note 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_send_at_command_parameter(const int8 *cmd, const int8 *data) +{ + at_mode_num = 0; //接收数量清零 + uart_putstr(BLUETOOTH_CH9141_UART, "AT+"); + uart_putstr(BLUETOOTH_CH9141_UART, cmd); + uart_putstr(BLUETOOTH_CH9141_UART, "="); + uart_putstr(BLUETOOTH_CH9141_UART, data); + uart_putstr(BLUETOOTH_CH9141_UART, "\r\n"); + + //等待收到应答信号 + while(!at_mode_cmd_flag); + at_mode_cmd_flag = 0; +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块进入AT模式 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_enter_at_mode(void) +{ + systick_delay_ms(STM0, 550); //发送进入AT模式的命令前需要保证模块在550ms内没有接收过任何数据 + at_mode = 1; //进入AT模式 + bluetooth_ch9141_send_at_command("AT..."); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块退出AT模式 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_exit_at_mode(void) +{ + bluetooth_ch9141_send_at_command("AT+EXIT"); + at_mode = 0; //进入透传模式 + systick_delay_ms(STM0, 300); //等待成功进入AT模式 +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块复位 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_reset(void) +{ + bluetooth_ch9141_send_at_command("AT+RESET"); + at_mode = 2; //进入重启成功检测 + at_mode_num = 0; + while(7 > at_mode_num); //等待蓝牙模块完成复位 + at_mode = 0; //复位之后模块自动进入透传模式 +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块获取本机MAC地址 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note 调用此函数需要先调用bluetooth_ch9141_enter_at_mode或者拉低CMD引脚 进入AT模式 +// 需要特别注意bluetooth_ch9141_enter_at_mode函数内部有500ms的延时 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_get_mac_address(void) +{ + bluetooth_ch9141_send_at_command("AT+MAC?"); + + //mac地址为小段格式,mac_address[0]保存的是mac地址最低位 + memcpy(mac_address, (uint8 *)at_mode_data, 17); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块设置发送功率 +// @param tx_power 设置发送功率,可设置选项查看CH9141_TX_POWEER_enum枚举成员 +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_set_tx_power(CH9141_TX_POWEER_enum tx_power) +{ + int8 tx_power_data; + + tx_power_data = (uint8)tx_power + '0'; + bluetooth_ch9141_send_at_command_parameter("TPL", &tx_power_data); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块设置模式 +// @param mode 模式设置,可设置选项查看CH9141_MODE_enum枚举成员 +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_set_mode(CH9141_MODE_enum mode) +{ + int8 mode_data; + + mode_data = (uint8)mode + '0'; + bluetooth_ch9141_send_at_command_parameter("BLEMODE", &mode_data); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块获取状态 +// @param mode 模式设置,可设置选项查看CH9141_MODE_enum枚举成员 +// @return CH9141_STATUS_enum 返回状态信息 +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +CH9141_STATUS_enum bluetooth_ch9141_get_status(CH9141_MODE_enum mode) +{ + CH9141_STATUS_enum ch9141_status; + int8 mode_data; + + mode_data = (uint8)mode + '0'; + bluetooth_ch9141_send_at_command_parameter("BLEMODE", &mode_data); + + bluetooth_ch9141_send_at_command("AT+BLESTA?"); + + ch9141_status = (at_mode_data[0] - '0') * 10 + (at_mode_data[1] - '0'); + if(SLAVE_MODE == mode) + { + ch9141_status += SLAVE_NO_INIT; + } + + return ch9141_status; +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块设置设备名称 +// @param *str 蓝牙名称 +// @return void +// @since v1.0 +// Sample usage: +// @note 名称长度不能超过18个字符 且只能为英文与数字 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_set_name(const int8 *str) +{ + bluetooth_ch9141_send_at_command_parameter("NAME", str); + bluetooth_ch9141_send_at_command_parameter("PNAME", str); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块密码设置 +// @param enable 使能密码 0:不使用密码,1:使用密码才能连接本设备 +// @param *password 密码的字符串 必须为6个字符 +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_set_password(uint8 enable, const int8 *password) +{ + if(0 == enable) + { + //关闭密码 + bluetooth_ch9141_send_at_command_parameter("PASEN", "OFF"); + } + else + { + //设置密码并使能 + bluetooth_ch9141_send_at_command_parameter("PASEN", "ON"); + bluetooth_ch9141_send_at_command_parameter("PASS", password); + } +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块指定MAC地址并立即进行连接 +// @param *mac_and_password 需要连接的设备mac地址与密码 +// @return void +// @since v1.0 +// Sample usage: +// @note bluetooth_ch9141_connect("58:B7:33:E4:C2:84,000000"); +// 58:B7:33:E4:C2:84为mac地址 ,为分隔符 000000为从机蓝牙密码 +// ===================特别注意================== +// 如果使用手机查看蓝牙的mac地址,则使用本函数连接的时候请将mac倒置一下 +// 例如手机查看到的mac地址为61:62:63:64:65:66,则使用本函数连接的时候应该写 +// bluetooth_ch9141_connect("66:65:64:63:62:61,000000"); +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_connect(const int8 *mac_and_password) +{ + bluetooth_ch9141_send_at_command_parameter("CONN", mac_and_password); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块默认连接参数设置(设置好后,每次开机蓝牙会自动链接这个设备) +// @param *mac_and_password 需要连接的设备mac地址与密码 +// @return void +// @since v1.0 +// Sample usage: +// @note bluetooth_ch9141_default_connect("58:B7:33:E4:C2:84,000000"); +// 58:B7:33:E4:C2:84为mac地址 ,为分隔符 000000为从机蓝牙密码 +// ===================特别注意================== +// 如果使用手机查看CH9141的mac地址,将CH9141设置为从机,使用手机连接 +// 则使用本函数连接的时候请将mac倒置一下 +// 例如手机查看到的mac地址为61:62:63:64:65:67,则使用本函数连接的时候应该写 +// bluetooth_ch9141_default_connect("67:65:64:63:62:61,000000"); +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_default_connect(const int8 *mac_and_password) +{ + bluetooth_ch9141_send_at_command_parameter("CONADD", mac_and_password); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块获取rssi(信号强度) +// @param void +// @return int8 返回信号强度0到-127 +// @since v1.0 +// Sample usage: +// @note 调用此函数需要先调用bluetooth_ch9141_enter_at_mode或者拉低CMD引脚 进入AT模式 +// 需要特别注意bluetooth_ch9141_enter_at_mode函数内部有500ms的延时 +//------------------------------------------------------------------------------------------------------------------- +int16 bluetooth_ch9141_get_rssi(void) +{ + uint8 i; + size_t length; + int16 rssi; + bluetooth_ch9141_send_at_command_parameter("RSSI", "ON,0"); + length = strlen((int8 *)at_mode_data); + length -= 12;//计算RSSI 有多少位 + + rssi = 0; + for(i=0; i30) { - if(gpio_get(RTS_PIN)) - { - return len;//模块忙,如果允许当前程序使用while等待 则可以使用后面注释的while等待语句替换本if语句 - } - //while(gpio_get(RTS_PIN)); //如果RTS为低电平,则继续发送数据 +// if(gpio_get(RTS_PIN)) +// { +// return len;//模块忙,如果允许当前程序使用while等待 则可以使用后面注释的while等待语句替换本if语句 +// } + while(gpio_get(RTS_PIN)); //如果RTS为低电平,则继续发送数据 uart_putbuff(WIRELESS_UART,buff,30); buff += 30; //地址偏移 len -= 30;//数量 } - if(gpio_get(RTS_PIN)) - { - return len;//模块忙,如果允许当前程序使用while等待 则可以使用后面注释的while等待语句替换本if语句 - } - //while(gpio_get(RTS_PIN)); //如果RTS为低电平,则继续发送数据 +// if(gpio_get(RTS_PIN)) +// { +// return len;//模块忙,如果允许当前程序使用while等待 则可以使用后面注释的while等待语句替换本if语句 +// } + while(gpio_get(RTS_PIN)); //如果RTS为低电平,则继续发送数据 uart_putbuff(WIRELESS_UART,buff,len);//发送最后的数据 return 0; diff --git a/Example/Printf_Demo/Libraries/seekfree_peripheral/SEEKFREE_WIRELESS.h b/Example/Printf_Demo/Libraries/seekfree_peripheral/SEEKFREE_WIRELESS.h index 42c0832..d80339d 100644 --- a/Example/Printf_Demo/Libraries/seekfree_peripheral/SEEKFREE_WIRELESS.h +++ b/Example/Printf_Demo/Libraries/seekfree_peripheral/SEEKFREE_WIRELESS.h @@ -38,8 +38,26 @@ #define WIRELESS_UART_RX UART2_RX_P10_6 #define WIRELESS_UART_BAUD 115200 -#define RTS_PIN P10_2 //定义流控位引脚 指示当前模块是否可以接受数据 0可以继续接收 1不可以继续接收 +// ------------------------------------ 自动波特率 ------------------------------------ +// 注意事项1:无线转串口模块版本是V2.0以下的是无法开启自动波特率的。 +// 注意事项2:开启自动波特率务必连接RTS引脚,否则会开启失败。 +// 注意事项3:模块自动波特率失败的话,可以尝试断电重启 +// 开启自动波特率务必阅读上面两条 注意事项 +// 开启自动波特率务必阅读上面两条 注意事项 +// 开启自动波特率务必阅读上面两条 注意事项 + +// 0:关闭自动波特率 +// 1:开启自动波特率 自动波特率的作用是修改WIRELESS_UART_BAUD之后不需要对模块进行配置,模块会自动设置为对应的波特率 + +#define WIRELESS_AUTO_UART_BAUD 0 +// ------------------------------------ 自动波特率 ------------------------------------ + +#define RTS_PIN P10_2 //定义流控位引脚 指示当前模块是否可以接受数据 0可以继续接收 1不可以继续接收 +#define WIRELESS_BUFFER_SIZE 16 + +extern uint8 wireless_send_buffer[WIRELESS_BUFFER_SIZE]; +extern uint32 wireless_rx_index; void wireless_uart_callback(void); void seekfree_wireless_init(void); diff --git a/Example/Printf_Demo/USER/isr.c b/Example/Printf_Demo/USER/isr.c index c55a012..16bff98 100644 --- a/Example/Printf_Demo/USER/isr.c +++ b/Example/Printf_Demo/USER/isr.c @@ -179,7 +179,20 @@ IFX_INTERRUPT(uart2_rx_isr, 0, UART2_RX_INT_PRIO) { enableInterrupts();//开启中断嵌套 IfxAsclin_Asc_isrReceive(&uart2_handle); - wireless_uart_callback(); + switch(wireless_type) + { + case WIRELESS_SI24R1: + { + wireless_uart_callback(); + }break; + + case WIRELESS_CH9141: + { + bluetooth_ch9141_uart_callback(); + }break; + default:break; + } + } IFX_INTERRUPT(uart2_er_isr, 0, UART2_ER_INT_PRIO) { diff --git a/Example/Printf_Demo/鍒犻櫎涓存椂鏂囦欢.bat b/Example/Printf_Demo/鍒犻櫎涓存椂鏂囦欢.bat index 5323dd9..fa499b1 100644 --- a/Example/Printf_Demo/鍒犻櫎涓存椂鏂囦欢.bat +++ b/Example/Printf_Demo/鍒犻櫎涓存椂鏂囦欢.bat @@ -1,9 +1,6 @@ -rmdir .settings /s /q rmdir Debug /s /q del *.launch /s - -pause exit diff --git a/Example/Specifies_Variable_Or_Code_Location_Demo/.cproject b/Example/Specifies_Variable_Or_Code_Location_Demo/.cproject index b306bed..0355683 100644 --- a/Example/Specifies_Variable_Or_Code_Location_Demo/.cproject +++ b/Example/Specifies_Variable_Or_Code_Location_Demo/.cproject @@ -3,9 +3,9 @@ - + - + @@ -25,50 +25,76 @@ - + - + - + - + + + + + + @@ -355,9 +371,9 @@ - + - + @@ -377,43 +393,1895 @@ - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -431,13 +2299,37 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + @@ -458,21 +2350,5 @@ - - - - - - - - - - - - - - - - diff --git a/Example/Specifies_Variable_Or_Code_Location_Demo/.project b/Example/Specifies_Variable_Or_Code_Location_Demo/.project index 8e1f20d..209ac5c 100644 --- a/Example/Specifies_Variable_Or_Code_Location_Demo/.project +++ b/Example/Specifies_Variable_Or_Code_Location_Demo/.project @@ -5,6 +5,18 @@ + + com.infineon.aurix.buildsystem.builders.booster + full,incremental, + + + + + com.infineon.aurix.buildsystem.builders.autodiscovery + full,incremental, + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder clean,full,incremental, diff --git a/Example/Specifies_Variable_Or_Code_Location_Demo/.settings/com.infineon.aurix.buildsystem.prefs b/Example/Specifies_Variable_Or_Code_Location_Demo/.settings/com.infineon.aurix.buildsystem.prefs new file mode 100644 index 0000000..be61bc1 --- /dev/null +++ b/Example/Specifies_Variable_Or_Code_Location_Demo/.settings/com.infineon.aurix.buildsystem.prefs @@ -0,0 +1,10 @@ +AURIX-LIBRARY-PATH=Libraries/iLLD\#Libraries/Infra\#Libraries/Service +DEVICE-ID=TC26B +DEVICE-ID-FULL=TC26xD_B-Step +ILLD-SET=full +IncludesAutodiscovery=true +LIBRARIES-ROOT-PATH=Libraries +NEVER-EXCLUDE-FROM-BUILD=/Libraries/iLLD/TC26B/Tricore/Cpu/CStart\#/Libraries/iLLD/TC26B/Tricore/Cpu/Trap\#/Configurations\#/Configurations/Debug +PROJECT-VERSION=1.0 +aurixDevice=TC26xD_B-Step +eclipse.preferences.version=1 diff --git a/Example/Specifies_Variable_Or_Code_Location_Demo/Libraries/doc/version.txt b/Example/Specifies_Variable_Or_Code_Location_Demo/Libraries/doc/version.txt index ab79909..11ab82e 100644 --- a/Example/Specifies_Variable_Or_Code_Location_Demo/Libraries/doc/version.txt +++ b/Example/Specifies_Variable_Or_Code_Location_Demo/Libraries/doc/version.txt @@ -1,3 +1,13 @@ +V1.2.0 + 增加CH9141蓝牙转串口模块的驱动 + 添加无线类型的枚举变量 + 修改 删除临时文件.bat 执行完操作后自动关闭窗口 + 修改 删除临时文件.bat 避免删除新版本所需文件 + 修改工程项目文件,以支持新版本编译 + +V1.1.10 + 修复通过#pragma section all "cpux_dsram"指定变量位置失效的问题 + V1.1.9 将串口的发送buff增加到128字节 diff --git a/Example/Specifies_Variable_Or_Code_Location_Demo/Libraries/seekfree_libraries/common/common.c b/Example/Specifies_Variable_Or_Code_Location_Demo/Libraries/seekfree_libraries/common/common.c index 0b9931e..7620ce6 100644 --- a/Example/Specifies_Variable_Or_Code_Location_Demo/Libraries/seekfree_libraries/common/common.c +++ b/Example/Specifies_Variable_Or_Code_Location_Demo/Libraries/seekfree_libraries/common/common.c @@ -27,6 +27,8 @@ CAMERA_TYPE_enum camera_type; //摄像头型号 uint8 *camera_buffer_addr; //摄像头数组地址 +WIRELESS_TYPE_enum wireless_type;//无线转串口类型 + IFX_ALIGN(4) IfxCpu_syncEvent g_cpuSyncEvent = 0;//事件同步变量 App_Cpu0 g_AppCpu0; //频率信息变量 diff --git a/Example/Specifies_Variable_Or_Code_Location_Demo/Libraries/seekfree_libraries/common/common.h b/Example/Specifies_Variable_Or_Code_Location_Demo/Libraries/seekfree_libraries/common/common.h index 84c43ee..5b741c0 100644 --- a/Example/Specifies_Variable_Or_Code_Location_Demo/Libraries/seekfree_libraries/common/common.h +++ b/Example/Specifies_Variable_Or_Code_Location_Demo/Libraries/seekfree_libraries/common/common.h @@ -113,6 +113,12 @@ typedef enum //枚 CAMERA_COLOR, //凌瞳 }CAMERA_TYPE_enum; +typedef enum //无线模块 +{ + WIRELESS_SI24R1 = 1, //无线转串口 + WIRELESS_CH9141, //蓝牙转串口 +}WIRELESS_TYPE_enum; + #include #include #include "IfxCpu.h" @@ -120,6 +126,8 @@ typedef enum //枚 extern CAMERA_TYPE_enum camera_type; //摄像头型号 extern uint8 *camera_buffer_addr; //摄像头数组地址 +extern WIRELESS_TYPE_enum wireless_type; + extern IfxCpu_syncEvent g_cpuSyncEvent; void get_clk(void); diff --git a/Example/Specifies_Variable_Or_Code_Location_Demo/Libraries/seekfree_libraries/headfile.h b/Example/Specifies_Variable_Or_Code_Location_Demo/Libraries/seekfree_libraries/headfile.h index 404ee0a..b745302 100644 --- a/Example/Specifies_Variable_Or_Code_Location_Demo/Libraries/seekfree_libraries/headfile.h +++ b/Example/Specifies_Variable_Or_Code_Location_Demo/Libraries/seekfree_libraries/headfile.h @@ -65,6 +65,7 @@ #include "SEEKFREE_7725.h" #include "SEEKFREE_RDA5807.h" #include "SEEKFREE_7725_UART.h" +#include "SEEKFREE_BLUETOOTH_CH9141.h" #endif diff --git a/Example/Specifies_Variable_Or_Code_Location_Demo/Libraries/seekfree_peripheral/SEEKFREE_BLUETOOTH_CH9141.c b/Example/Specifies_Variable_Or_Code_Location_Demo/Libraries/seekfree_peripheral/SEEKFREE_BLUETOOTH_CH9141.c new file mode 100644 index 0000000..b4ec2df --- /dev/null +++ b/Example/Specifies_Variable_Or_Code_Location_Demo/Libraries/seekfree_peripheral/SEEKFREE_BLUETOOTH_CH9141.c @@ -0,0 +1,509 @@ +/********************************************************************************************************************* + * COPYRIGHT NOTICE + * Copyright (c) 2021,逐飞科技 + * All rights reserved. + * 技术讨论QQ群:一群:179029047(已满) 二群:244861897 + * + * 以下所有内容版权均属逐飞科技所有,未经允许不得用于商业用途, + * 欢迎各位使用并传播本程序,修改内容时必须保留逐飞科技的版权声明。 + * + * @file 逐飞科技蓝牙转串口模块 + * @company 成都逐飞科技有限公司 + * @author 逐飞科技(QQ3184284598) + * @version 查看doc内version文件 版本说明 + * @Software IAR 8.3 or MDK 5.33 + * @Taobao https://seekfree.taobao.com/ + * @date 2021-08-27 + * @note + 接线定义: + ------------------------------------ + 蓝牙转串口 单片机 + RX 查看SEEKFREE_BLUETOOTH_CH9141.h文件中的BLUETOOTH_CH9141_UART_TX宏定义 + TX 查看SEEKFREE_BLUETOOTH_CH9141.h文件中的BLUETOOTH_CH9141_UART_RX宏定义 + RTS 查看SEEKFREE_BLUETOOTH_CH9141.h文件中的BLUETOOTH_CH9141_RTS_PIN宏定义 + CTS 悬空 + CMD 悬空或者上拉 + ------------------------------------ + ********************************************************************************************************************/ +#include "zf_stm_systick.h" +#include "zf_gpio.h" +#include "zf_uart.h" +#include "zf_assert.h" +#include "SEEKFREE_BLUETOOTH_CH9141.h" + +uint8 uart_flag; +uint8 uart_data; + +vuint8 at_mode = 0; //0:蓝牙透传模式 1:AT模式 2:模块复位中 +vuint8 at_mode_num; //at模式时用于指示数据接收的数量 +vuint8 at_mode_data[30]; //接收at命令的缓存 +vuint8 at_mode_cmd_flag; //OK应答命令接收成功的标志位 + +uint8 mac_address[17]; //本机mac地址 + + +uint8 bluetooth_ch9141_rx_buffer; + + +void bluetooth_ch9141_check_response(void); + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块 串口中断回调函数 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note 该函数在ISR文件 串口8中断程序被调用 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_uart_callback() +{ + while(uart_query(BLUETOOTH_CH9141_UART, &bluetooth_ch9141_rx_buffer)) + { + if(1 == at_mode) + { + //进入AT模式 接收应答信号 此处if语句内代码用户不要改动 + at_mode_data[at_mode_num++] = bluetooth_ch9141_rx_buffer; + bluetooth_ch9141_check_response(); + } + else if(2 == at_mode) + { + //模块正在复位中 此处if语句内代码用户不要改动 + at_mode_num++; + } + else + { + //透传模式 用户在此处接收配对的蓝牙发送过来的额数据 + //接到一个字节后单片机将会进入此处,通过在此处读取bluetooth_ch9141_rx_buffer可以取走数据 + + // 读取无线串口的数据 并且置位接收标志 + uart_flag = 1; + uart_data = bluetooth_ch9141_rx_buffer; + } + + } +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块检查OK应答信号 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_check_response(void) +{ + if(4 <= at_mode_num) + { + if(0 == strncmp("OK\r\n", (int8 *)&at_mode_data[at_mode_num-4], 4)) + { + at_mode_cmd_flag = 1; + } + } +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块发送一个没有参数的命令并等待应答信号 +// @param *str 需要发送的命令 完整字符串 +// @return void +// @since v1.0 +// Sample usage: +// @note 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_send_at_command(const int8 *str) +{ + at_mode_num = 0; //接收数量清零 + uart_putstr(BLUETOOTH_CH9141_UART, str); + uart_putstr(BLUETOOTH_CH9141_UART, "\r\n"); + + //等待收到应答信号 + while(!at_mode_cmd_flag); + at_mode_cmd_flag = 0; +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块发送一个带有参数的命令并等待应答信号 +// @param *cmd 需要发送的命令名称 +// @param *data 需要发送的数据 +// @return void +// @since v1.0 +// Sample usage: +// @note 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_send_at_command_parameter(const int8 *cmd, const int8 *data) +{ + at_mode_num = 0; //接收数量清零 + uart_putstr(BLUETOOTH_CH9141_UART, "AT+"); + uart_putstr(BLUETOOTH_CH9141_UART, cmd); + uart_putstr(BLUETOOTH_CH9141_UART, "="); + uart_putstr(BLUETOOTH_CH9141_UART, data); + uart_putstr(BLUETOOTH_CH9141_UART, "\r\n"); + + //等待收到应答信号 + while(!at_mode_cmd_flag); + at_mode_cmd_flag = 0; +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块进入AT模式 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_enter_at_mode(void) +{ + systick_delay_ms(STM0, 550); //发送进入AT模式的命令前需要保证模块在550ms内没有接收过任何数据 + at_mode = 1; //进入AT模式 + bluetooth_ch9141_send_at_command("AT..."); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块退出AT模式 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_exit_at_mode(void) +{ + bluetooth_ch9141_send_at_command("AT+EXIT"); + at_mode = 0; //进入透传模式 + systick_delay_ms(STM0, 300); //等待成功进入AT模式 +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块复位 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_reset(void) +{ + bluetooth_ch9141_send_at_command("AT+RESET"); + at_mode = 2; //进入重启成功检测 + at_mode_num = 0; + while(7 > at_mode_num); //等待蓝牙模块完成复位 + at_mode = 0; //复位之后模块自动进入透传模式 +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块获取本机MAC地址 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note 调用此函数需要先调用bluetooth_ch9141_enter_at_mode或者拉低CMD引脚 进入AT模式 +// 需要特别注意bluetooth_ch9141_enter_at_mode函数内部有500ms的延时 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_get_mac_address(void) +{ + bluetooth_ch9141_send_at_command("AT+MAC?"); + + //mac地址为小段格式,mac_address[0]保存的是mac地址最低位 + memcpy(mac_address, (uint8 *)at_mode_data, 17); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块设置发送功率 +// @param tx_power 设置发送功率,可设置选项查看CH9141_TX_POWEER_enum枚举成员 +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_set_tx_power(CH9141_TX_POWEER_enum tx_power) +{ + int8 tx_power_data; + + tx_power_data = (uint8)tx_power + '0'; + bluetooth_ch9141_send_at_command_parameter("TPL", &tx_power_data); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块设置模式 +// @param mode 模式设置,可设置选项查看CH9141_MODE_enum枚举成员 +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_set_mode(CH9141_MODE_enum mode) +{ + int8 mode_data; + + mode_data = (uint8)mode + '0'; + bluetooth_ch9141_send_at_command_parameter("BLEMODE", &mode_data); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块获取状态 +// @param mode 模式设置,可设置选项查看CH9141_MODE_enum枚举成员 +// @return CH9141_STATUS_enum 返回状态信息 +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +CH9141_STATUS_enum bluetooth_ch9141_get_status(CH9141_MODE_enum mode) +{ + CH9141_STATUS_enum ch9141_status; + int8 mode_data; + + mode_data = (uint8)mode + '0'; + bluetooth_ch9141_send_at_command_parameter("BLEMODE", &mode_data); + + bluetooth_ch9141_send_at_command("AT+BLESTA?"); + + ch9141_status = (at_mode_data[0] - '0') * 10 + (at_mode_data[1] - '0'); + if(SLAVE_MODE == mode) + { + ch9141_status += SLAVE_NO_INIT; + } + + return ch9141_status; +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块设置设备名称 +// @param *str 蓝牙名称 +// @return void +// @since v1.0 +// Sample usage: +// @note 名称长度不能超过18个字符 且只能为英文与数字 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_set_name(const int8 *str) +{ + bluetooth_ch9141_send_at_command_parameter("NAME", str); + bluetooth_ch9141_send_at_command_parameter("PNAME", str); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块密码设置 +// @param enable 使能密码 0:不使用密码,1:使用密码才能连接本设备 +// @param *password 密码的字符串 必须为6个字符 +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_set_password(uint8 enable, const int8 *password) +{ + if(0 == enable) + { + //关闭密码 + bluetooth_ch9141_send_at_command_parameter("PASEN", "OFF"); + } + else + { + //设置密码并使能 + bluetooth_ch9141_send_at_command_parameter("PASEN", "ON"); + bluetooth_ch9141_send_at_command_parameter("PASS", password); + } +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块指定MAC地址并立即进行连接 +// @param *mac_and_password 需要连接的设备mac地址与密码 +// @return void +// @since v1.0 +// Sample usage: +// @note bluetooth_ch9141_connect("58:B7:33:E4:C2:84,000000"); +// 58:B7:33:E4:C2:84为mac地址 ,为分隔符 000000为从机蓝牙密码 +// ===================特别注意================== +// 如果使用手机查看蓝牙的mac地址,则使用本函数连接的时候请将mac倒置一下 +// 例如手机查看到的mac地址为61:62:63:64:65:66,则使用本函数连接的时候应该写 +// bluetooth_ch9141_connect("66:65:64:63:62:61,000000"); +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_connect(const int8 *mac_and_password) +{ + bluetooth_ch9141_send_at_command_parameter("CONN", mac_and_password); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块默认连接参数设置(设置好后,每次开机蓝牙会自动链接这个设备) +// @param *mac_and_password 需要连接的设备mac地址与密码 +// @return void +// @since v1.0 +// Sample usage: +// @note bluetooth_ch9141_default_connect("58:B7:33:E4:C2:84,000000"); +// 58:B7:33:E4:C2:84为mac地址 ,为分隔符 000000为从机蓝牙密码 +// ===================特别注意================== +// 如果使用手机查看CH9141的mac地址,将CH9141设置为从机,使用手机连接 +// 则使用本函数连接的时候请将mac倒置一下 +// 例如手机查看到的mac地址为61:62:63:64:65:67,则使用本函数连接的时候应该写 +// bluetooth_ch9141_default_connect("67:65:64:63:62:61,000000"); +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_default_connect(const int8 *mac_and_password) +{ + bluetooth_ch9141_send_at_command_parameter("CONADD", mac_and_password); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块获取rssi(信号强度) +// @param void +// @return int8 返回信号强度0到-127 +// @since v1.0 +// Sample usage: +// @note 调用此函数需要先调用bluetooth_ch9141_enter_at_mode或者拉低CMD引脚 进入AT模式 +// 需要特别注意bluetooth_ch9141_enter_at_mode函数内部有500ms的延时 +//------------------------------------------------------------------------------------------------------------------- +int16 bluetooth_ch9141_get_rssi(void) +{ + uint8 i; + size_t length; + int16 rssi; + bluetooth_ch9141_send_at_command_parameter("RSSI", "ON,0"); + length = strlen((int8 *)at_mode_data); + length -= 12;//计算RSSI 有多少位 + + rssi = 0; + for(i=0; i30) { - if(gpio_get(RTS_PIN)) - { - return len;//模块忙,如果允许当前程序使用while等待 则可以使用后面注释的while等待语句替换本if语句 - } - //while(gpio_get(RTS_PIN)); //如果RTS为低电平,则继续发送数据 +// if(gpio_get(RTS_PIN)) +// { +// return len;//模块忙,如果允许当前程序使用while等待 则可以使用后面注释的while等待语句替换本if语句 +// } + while(gpio_get(RTS_PIN)); //如果RTS为低电平,则继续发送数据 uart_putbuff(WIRELESS_UART,buff,30); buff += 30; //地址偏移 len -= 30;//数量 } - if(gpio_get(RTS_PIN)) - { - return len;//模块忙,如果允许当前程序使用while等待 则可以使用后面注释的while等待语句替换本if语句 - } - //while(gpio_get(RTS_PIN)); //如果RTS为低电平,则继续发送数据 +// if(gpio_get(RTS_PIN)) +// { +// return len;//模块忙,如果允许当前程序使用while等待 则可以使用后面注释的while等待语句替换本if语句 +// } + while(gpio_get(RTS_PIN)); //如果RTS为低电平,则继续发送数据 uart_putbuff(WIRELESS_UART,buff,len);//发送最后的数据 return 0; diff --git a/Example/Specifies_Variable_Or_Code_Location_Demo/Libraries/seekfree_peripheral/SEEKFREE_WIRELESS.h b/Example/Specifies_Variable_Or_Code_Location_Demo/Libraries/seekfree_peripheral/SEEKFREE_WIRELESS.h index 42c0832..d80339d 100644 --- a/Example/Specifies_Variable_Or_Code_Location_Demo/Libraries/seekfree_peripheral/SEEKFREE_WIRELESS.h +++ b/Example/Specifies_Variable_Or_Code_Location_Demo/Libraries/seekfree_peripheral/SEEKFREE_WIRELESS.h @@ -38,8 +38,26 @@ #define WIRELESS_UART_RX UART2_RX_P10_6 #define WIRELESS_UART_BAUD 115200 -#define RTS_PIN P10_2 //定义流控位引脚 指示当前模块是否可以接受数据 0可以继续接收 1不可以继续接收 +// ------------------------------------ 自动波特率 ------------------------------------ +// 注意事项1:无线转串口模块版本是V2.0以下的是无法开启自动波特率的。 +// 注意事项2:开启自动波特率务必连接RTS引脚,否则会开启失败。 +// 注意事项3:模块自动波特率失败的话,可以尝试断电重启 +// 开启自动波特率务必阅读上面两条 注意事项 +// 开启自动波特率务必阅读上面两条 注意事项 +// 开启自动波特率务必阅读上面两条 注意事项 + +// 0:关闭自动波特率 +// 1:开启自动波特率 自动波特率的作用是修改WIRELESS_UART_BAUD之后不需要对模块进行配置,模块会自动设置为对应的波特率 + +#define WIRELESS_AUTO_UART_BAUD 0 +// ------------------------------------ 自动波特率 ------------------------------------ + +#define RTS_PIN P10_2 //定义流控位引脚 指示当前模块是否可以接受数据 0可以继续接收 1不可以继续接收 +#define WIRELESS_BUFFER_SIZE 16 + +extern uint8 wireless_send_buffer[WIRELESS_BUFFER_SIZE]; +extern uint32 wireless_rx_index; void wireless_uart_callback(void); void seekfree_wireless_init(void); diff --git a/Example/Specifies_Variable_Or_Code_Location_Demo/USER/isr.c b/Example/Specifies_Variable_Or_Code_Location_Demo/USER/isr.c index c55a012..16bff98 100644 --- a/Example/Specifies_Variable_Or_Code_Location_Demo/USER/isr.c +++ b/Example/Specifies_Variable_Or_Code_Location_Demo/USER/isr.c @@ -179,7 +179,20 @@ IFX_INTERRUPT(uart2_rx_isr, 0, UART2_RX_INT_PRIO) { enableInterrupts();//开启中断嵌套 IfxAsclin_Asc_isrReceive(&uart2_handle); - wireless_uart_callback(); + switch(wireless_type) + { + case WIRELESS_SI24R1: + { + wireless_uart_callback(); + }break; + + case WIRELESS_CH9141: + { + bluetooth_ch9141_uart_callback(); + }break; + default:break; + } + } IFX_INTERRUPT(uart2_er_isr, 0, UART2_ER_INT_PRIO) { diff --git a/Example/Specifies_Variable_Or_Code_Location_Demo/鍒犻櫎涓存椂鏂囦欢.bat b/Example/Specifies_Variable_Or_Code_Location_Demo/鍒犻櫎涓存椂鏂囦欢.bat index 5323dd9..fa499b1 100644 --- a/Example/Specifies_Variable_Or_Code_Location_Demo/鍒犻櫎涓存椂鏂囦欢.bat +++ b/Example/Specifies_Variable_Or_Code_Location_Demo/鍒犻櫎涓存椂鏂囦欢.bat @@ -1,9 +1,6 @@ -rmdir .settings /s /q rmdir Debug /s /q del *.launch /s - -pause exit diff --git a/Example/Systick_Demo/.cproject b/Example/Systick_Demo/.cproject index c0a0ab0..cfe5340 100644 --- a/Example/Systick_Demo/.cproject +++ b/Example/Systick_Demo/.cproject @@ -3,9 +3,9 @@ - + - + @@ -25,50 +25,76 @@ - + - + - + - + + + + + + @@ -355,9 +371,9 @@ - + - + @@ -377,43 +393,1895 @@ - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -431,13 +2299,37 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + @@ -458,21 +2350,5 @@ - - - - - - - - - - - - - - - - diff --git a/Example/Systick_Demo/.project b/Example/Systick_Demo/.project index 6d93e1a..3a71be3 100644 --- a/Example/Systick_Demo/.project +++ b/Example/Systick_Demo/.project @@ -5,6 +5,18 @@ + + com.infineon.aurix.buildsystem.builders.booster + full,incremental, + + + + + com.infineon.aurix.buildsystem.builders.autodiscovery + full,incremental, + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder clean,full,incremental, diff --git a/Example/Systick_Demo/.settings/com.infineon.aurix.buildsystem.prefs b/Example/Systick_Demo/.settings/com.infineon.aurix.buildsystem.prefs new file mode 100644 index 0000000..be61bc1 --- /dev/null +++ b/Example/Systick_Demo/.settings/com.infineon.aurix.buildsystem.prefs @@ -0,0 +1,10 @@ +AURIX-LIBRARY-PATH=Libraries/iLLD\#Libraries/Infra\#Libraries/Service +DEVICE-ID=TC26B +DEVICE-ID-FULL=TC26xD_B-Step +ILLD-SET=full +IncludesAutodiscovery=true +LIBRARIES-ROOT-PATH=Libraries +NEVER-EXCLUDE-FROM-BUILD=/Libraries/iLLD/TC26B/Tricore/Cpu/CStart\#/Libraries/iLLD/TC26B/Tricore/Cpu/Trap\#/Configurations\#/Configurations/Debug +PROJECT-VERSION=1.0 +aurixDevice=TC26xD_B-Step +eclipse.preferences.version=1 diff --git a/Example/Systick_Demo/Libraries/doc/version.txt b/Example/Systick_Demo/Libraries/doc/version.txt index ab79909..11ab82e 100644 --- a/Example/Systick_Demo/Libraries/doc/version.txt +++ b/Example/Systick_Demo/Libraries/doc/version.txt @@ -1,3 +1,13 @@ +V1.2.0 + 增加CH9141蓝牙转串口模块的驱动 + 添加无线类型的枚举变量 + 修改 删除临时文件.bat 执行完操作后自动关闭窗口 + 修改 删除临时文件.bat 避免删除新版本所需文件 + 修改工程项目文件,以支持新版本编译 + +V1.1.10 + 修复通过#pragma section all "cpux_dsram"指定变量位置失效的问题 + V1.1.9 将串口的发送buff增加到128字节 diff --git a/Example/Systick_Demo/Libraries/seekfree_libraries/common/common.c b/Example/Systick_Demo/Libraries/seekfree_libraries/common/common.c index 0b9931e..7620ce6 100644 --- a/Example/Systick_Demo/Libraries/seekfree_libraries/common/common.c +++ b/Example/Systick_Demo/Libraries/seekfree_libraries/common/common.c @@ -27,6 +27,8 @@ CAMERA_TYPE_enum camera_type; //摄像头型号 uint8 *camera_buffer_addr; //摄像头数组地址 +WIRELESS_TYPE_enum wireless_type;//无线转串口类型 + IFX_ALIGN(4) IfxCpu_syncEvent g_cpuSyncEvent = 0;//事件同步变量 App_Cpu0 g_AppCpu0; //频率信息变量 diff --git a/Example/Systick_Demo/Libraries/seekfree_libraries/common/common.h b/Example/Systick_Demo/Libraries/seekfree_libraries/common/common.h index 84c43ee..5b741c0 100644 --- a/Example/Systick_Demo/Libraries/seekfree_libraries/common/common.h +++ b/Example/Systick_Demo/Libraries/seekfree_libraries/common/common.h @@ -113,6 +113,12 @@ typedef enum //枚 CAMERA_COLOR, //凌瞳 }CAMERA_TYPE_enum; +typedef enum //无线模块 +{ + WIRELESS_SI24R1 = 1, //无线转串口 + WIRELESS_CH9141, //蓝牙转串口 +}WIRELESS_TYPE_enum; + #include #include #include "IfxCpu.h" @@ -120,6 +126,8 @@ typedef enum //枚 extern CAMERA_TYPE_enum camera_type; //摄像头型号 extern uint8 *camera_buffer_addr; //摄像头数组地址 +extern WIRELESS_TYPE_enum wireless_type; + extern IfxCpu_syncEvent g_cpuSyncEvent; void get_clk(void); diff --git a/Example/Systick_Demo/Libraries/seekfree_libraries/headfile.h b/Example/Systick_Demo/Libraries/seekfree_libraries/headfile.h index 404ee0a..b745302 100644 --- a/Example/Systick_Demo/Libraries/seekfree_libraries/headfile.h +++ b/Example/Systick_Demo/Libraries/seekfree_libraries/headfile.h @@ -65,6 +65,7 @@ #include "SEEKFREE_7725.h" #include "SEEKFREE_RDA5807.h" #include "SEEKFREE_7725_UART.h" +#include "SEEKFREE_BLUETOOTH_CH9141.h" #endif diff --git a/Example/Systick_Demo/Libraries/seekfree_peripheral/SEEKFREE_BLUETOOTH_CH9141.c b/Example/Systick_Demo/Libraries/seekfree_peripheral/SEEKFREE_BLUETOOTH_CH9141.c new file mode 100644 index 0000000..b4ec2df --- /dev/null +++ b/Example/Systick_Demo/Libraries/seekfree_peripheral/SEEKFREE_BLUETOOTH_CH9141.c @@ -0,0 +1,509 @@ +/********************************************************************************************************************* + * COPYRIGHT NOTICE + * Copyright (c) 2021,逐飞科技 + * All rights reserved. + * 技术讨论QQ群:一群:179029047(已满) 二群:244861897 + * + * 以下所有内容版权均属逐飞科技所有,未经允许不得用于商业用途, + * 欢迎各位使用并传播本程序,修改内容时必须保留逐飞科技的版权声明。 + * + * @file 逐飞科技蓝牙转串口模块 + * @company 成都逐飞科技有限公司 + * @author 逐飞科技(QQ3184284598) + * @version 查看doc内version文件 版本说明 + * @Software IAR 8.3 or MDK 5.33 + * @Taobao https://seekfree.taobao.com/ + * @date 2021-08-27 + * @note + 接线定义: + ------------------------------------ + 蓝牙转串口 单片机 + RX 查看SEEKFREE_BLUETOOTH_CH9141.h文件中的BLUETOOTH_CH9141_UART_TX宏定义 + TX 查看SEEKFREE_BLUETOOTH_CH9141.h文件中的BLUETOOTH_CH9141_UART_RX宏定义 + RTS 查看SEEKFREE_BLUETOOTH_CH9141.h文件中的BLUETOOTH_CH9141_RTS_PIN宏定义 + CTS 悬空 + CMD 悬空或者上拉 + ------------------------------------ + ********************************************************************************************************************/ +#include "zf_stm_systick.h" +#include "zf_gpio.h" +#include "zf_uart.h" +#include "zf_assert.h" +#include "SEEKFREE_BLUETOOTH_CH9141.h" + +uint8 uart_flag; +uint8 uart_data; + +vuint8 at_mode = 0; //0:蓝牙透传模式 1:AT模式 2:模块复位中 +vuint8 at_mode_num; //at模式时用于指示数据接收的数量 +vuint8 at_mode_data[30]; //接收at命令的缓存 +vuint8 at_mode_cmd_flag; //OK应答命令接收成功的标志位 + +uint8 mac_address[17]; //本机mac地址 + + +uint8 bluetooth_ch9141_rx_buffer; + + +void bluetooth_ch9141_check_response(void); + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块 串口中断回调函数 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note 该函数在ISR文件 串口8中断程序被调用 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_uart_callback() +{ + while(uart_query(BLUETOOTH_CH9141_UART, &bluetooth_ch9141_rx_buffer)) + { + if(1 == at_mode) + { + //进入AT模式 接收应答信号 此处if语句内代码用户不要改动 + at_mode_data[at_mode_num++] = bluetooth_ch9141_rx_buffer; + bluetooth_ch9141_check_response(); + } + else if(2 == at_mode) + { + //模块正在复位中 此处if语句内代码用户不要改动 + at_mode_num++; + } + else + { + //透传模式 用户在此处接收配对的蓝牙发送过来的额数据 + //接到一个字节后单片机将会进入此处,通过在此处读取bluetooth_ch9141_rx_buffer可以取走数据 + + // 读取无线串口的数据 并且置位接收标志 + uart_flag = 1; + uart_data = bluetooth_ch9141_rx_buffer; + } + + } +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块检查OK应答信号 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_check_response(void) +{ + if(4 <= at_mode_num) + { + if(0 == strncmp("OK\r\n", (int8 *)&at_mode_data[at_mode_num-4], 4)) + { + at_mode_cmd_flag = 1; + } + } +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块发送一个没有参数的命令并等待应答信号 +// @param *str 需要发送的命令 完整字符串 +// @return void +// @since v1.0 +// Sample usage: +// @note 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_send_at_command(const int8 *str) +{ + at_mode_num = 0; //接收数量清零 + uart_putstr(BLUETOOTH_CH9141_UART, str); + uart_putstr(BLUETOOTH_CH9141_UART, "\r\n"); + + //等待收到应答信号 + while(!at_mode_cmd_flag); + at_mode_cmd_flag = 0; +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块发送一个带有参数的命令并等待应答信号 +// @param *cmd 需要发送的命令名称 +// @param *data 需要发送的数据 +// @return void +// @since v1.0 +// Sample usage: +// @note 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_send_at_command_parameter(const int8 *cmd, const int8 *data) +{ + at_mode_num = 0; //接收数量清零 + uart_putstr(BLUETOOTH_CH9141_UART, "AT+"); + uart_putstr(BLUETOOTH_CH9141_UART, cmd); + uart_putstr(BLUETOOTH_CH9141_UART, "="); + uart_putstr(BLUETOOTH_CH9141_UART, data); + uart_putstr(BLUETOOTH_CH9141_UART, "\r\n"); + + //等待收到应答信号 + while(!at_mode_cmd_flag); + at_mode_cmd_flag = 0; +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块进入AT模式 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_enter_at_mode(void) +{ + systick_delay_ms(STM0, 550); //发送进入AT模式的命令前需要保证模块在550ms内没有接收过任何数据 + at_mode = 1; //进入AT模式 + bluetooth_ch9141_send_at_command("AT..."); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块退出AT模式 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_exit_at_mode(void) +{ + bluetooth_ch9141_send_at_command("AT+EXIT"); + at_mode = 0; //进入透传模式 + systick_delay_ms(STM0, 300); //等待成功进入AT模式 +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块复位 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_reset(void) +{ + bluetooth_ch9141_send_at_command("AT+RESET"); + at_mode = 2; //进入重启成功检测 + at_mode_num = 0; + while(7 > at_mode_num); //等待蓝牙模块完成复位 + at_mode = 0; //复位之后模块自动进入透传模式 +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块获取本机MAC地址 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note 调用此函数需要先调用bluetooth_ch9141_enter_at_mode或者拉低CMD引脚 进入AT模式 +// 需要特别注意bluetooth_ch9141_enter_at_mode函数内部有500ms的延时 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_get_mac_address(void) +{ + bluetooth_ch9141_send_at_command("AT+MAC?"); + + //mac地址为小段格式,mac_address[0]保存的是mac地址最低位 + memcpy(mac_address, (uint8 *)at_mode_data, 17); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块设置发送功率 +// @param tx_power 设置发送功率,可设置选项查看CH9141_TX_POWEER_enum枚举成员 +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_set_tx_power(CH9141_TX_POWEER_enum tx_power) +{ + int8 tx_power_data; + + tx_power_data = (uint8)tx_power + '0'; + bluetooth_ch9141_send_at_command_parameter("TPL", &tx_power_data); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块设置模式 +// @param mode 模式设置,可设置选项查看CH9141_MODE_enum枚举成员 +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_set_mode(CH9141_MODE_enum mode) +{ + int8 mode_data; + + mode_data = (uint8)mode + '0'; + bluetooth_ch9141_send_at_command_parameter("BLEMODE", &mode_data); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块获取状态 +// @param mode 模式设置,可设置选项查看CH9141_MODE_enum枚举成员 +// @return CH9141_STATUS_enum 返回状态信息 +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +CH9141_STATUS_enum bluetooth_ch9141_get_status(CH9141_MODE_enum mode) +{ + CH9141_STATUS_enum ch9141_status; + int8 mode_data; + + mode_data = (uint8)mode + '0'; + bluetooth_ch9141_send_at_command_parameter("BLEMODE", &mode_data); + + bluetooth_ch9141_send_at_command("AT+BLESTA?"); + + ch9141_status = (at_mode_data[0] - '0') * 10 + (at_mode_data[1] - '0'); + if(SLAVE_MODE == mode) + { + ch9141_status += SLAVE_NO_INIT; + } + + return ch9141_status; +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块设置设备名称 +// @param *str 蓝牙名称 +// @return void +// @since v1.0 +// Sample usage: +// @note 名称长度不能超过18个字符 且只能为英文与数字 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_set_name(const int8 *str) +{ + bluetooth_ch9141_send_at_command_parameter("NAME", str); + bluetooth_ch9141_send_at_command_parameter("PNAME", str); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块密码设置 +// @param enable 使能密码 0:不使用密码,1:使用密码才能连接本设备 +// @param *password 密码的字符串 必须为6个字符 +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_set_password(uint8 enable, const int8 *password) +{ + if(0 == enable) + { + //关闭密码 + bluetooth_ch9141_send_at_command_parameter("PASEN", "OFF"); + } + else + { + //设置密码并使能 + bluetooth_ch9141_send_at_command_parameter("PASEN", "ON"); + bluetooth_ch9141_send_at_command_parameter("PASS", password); + } +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块指定MAC地址并立即进行连接 +// @param *mac_and_password 需要连接的设备mac地址与密码 +// @return void +// @since v1.0 +// Sample usage: +// @note bluetooth_ch9141_connect("58:B7:33:E4:C2:84,000000"); +// 58:B7:33:E4:C2:84为mac地址 ,为分隔符 000000为从机蓝牙密码 +// ===================特别注意================== +// 如果使用手机查看蓝牙的mac地址,则使用本函数连接的时候请将mac倒置一下 +// 例如手机查看到的mac地址为61:62:63:64:65:66,则使用本函数连接的时候应该写 +// bluetooth_ch9141_connect("66:65:64:63:62:61,000000"); +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_connect(const int8 *mac_and_password) +{ + bluetooth_ch9141_send_at_command_parameter("CONN", mac_and_password); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块默认连接参数设置(设置好后,每次开机蓝牙会自动链接这个设备) +// @param *mac_and_password 需要连接的设备mac地址与密码 +// @return void +// @since v1.0 +// Sample usage: +// @note bluetooth_ch9141_default_connect("58:B7:33:E4:C2:84,000000"); +// 58:B7:33:E4:C2:84为mac地址 ,为分隔符 000000为从机蓝牙密码 +// ===================特别注意================== +// 如果使用手机查看CH9141的mac地址,将CH9141设置为从机,使用手机连接 +// 则使用本函数连接的时候请将mac倒置一下 +// 例如手机查看到的mac地址为61:62:63:64:65:67,则使用本函数连接的时候应该写 +// bluetooth_ch9141_default_connect("67:65:64:63:62:61,000000"); +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_default_connect(const int8 *mac_and_password) +{ + bluetooth_ch9141_send_at_command_parameter("CONADD", mac_and_password); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块获取rssi(信号强度) +// @param void +// @return int8 返回信号强度0到-127 +// @since v1.0 +// Sample usage: +// @note 调用此函数需要先调用bluetooth_ch9141_enter_at_mode或者拉低CMD引脚 进入AT模式 +// 需要特别注意bluetooth_ch9141_enter_at_mode函数内部有500ms的延时 +//------------------------------------------------------------------------------------------------------------------- +int16 bluetooth_ch9141_get_rssi(void) +{ + uint8 i; + size_t length; + int16 rssi; + bluetooth_ch9141_send_at_command_parameter("RSSI", "ON,0"); + length = strlen((int8 *)at_mode_data); + length -= 12;//计算RSSI 有多少位 + + rssi = 0; + for(i=0; i30) { - if(gpio_get(RTS_PIN)) - { - return len;//模块忙,如果允许当前程序使用while等待 则可以使用后面注释的while等待语句替换本if语句 - } - //while(gpio_get(RTS_PIN)); //如果RTS为低电平,则继续发送数据 +// if(gpio_get(RTS_PIN)) +// { +// return len;//模块忙,如果允许当前程序使用while等待 则可以使用后面注释的while等待语句替换本if语句 +// } + while(gpio_get(RTS_PIN)); //如果RTS为低电平,则继续发送数据 uart_putbuff(WIRELESS_UART,buff,30); buff += 30; //地址偏移 len -= 30;//数量 } - if(gpio_get(RTS_PIN)) - { - return len;//模块忙,如果允许当前程序使用while等待 则可以使用后面注释的while等待语句替换本if语句 - } - //while(gpio_get(RTS_PIN)); //如果RTS为低电平,则继续发送数据 +// if(gpio_get(RTS_PIN)) +// { +// return len;//模块忙,如果允许当前程序使用while等待 则可以使用后面注释的while等待语句替换本if语句 +// } + while(gpio_get(RTS_PIN)); //如果RTS为低电平,则继续发送数据 uart_putbuff(WIRELESS_UART,buff,len);//发送最后的数据 return 0; diff --git a/Example/Systick_Demo/Libraries/seekfree_peripheral/SEEKFREE_WIRELESS.h b/Example/Systick_Demo/Libraries/seekfree_peripheral/SEEKFREE_WIRELESS.h index 42c0832..d80339d 100644 --- a/Example/Systick_Demo/Libraries/seekfree_peripheral/SEEKFREE_WIRELESS.h +++ b/Example/Systick_Demo/Libraries/seekfree_peripheral/SEEKFREE_WIRELESS.h @@ -38,8 +38,26 @@ #define WIRELESS_UART_RX UART2_RX_P10_6 #define WIRELESS_UART_BAUD 115200 -#define RTS_PIN P10_2 //定义流控位引脚 指示当前模块是否可以接受数据 0可以继续接收 1不可以继续接收 +// ------------------------------------ 自动波特率 ------------------------------------ +// 注意事项1:无线转串口模块版本是V2.0以下的是无法开启自动波特率的。 +// 注意事项2:开启自动波特率务必连接RTS引脚,否则会开启失败。 +// 注意事项3:模块自动波特率失败的话,可以尝试断电重启 +// 开启自动波特率务必阅读上面两条 注意事项 +// 开启自动波特率务必阅读上面两条 注意事项 +// 开启自动波特率务必阅读上面两条 注意事项 + +// 0:关闭自动波特率 +// 1:开启自动波特率 自动波特率的作用是修改WIRELESS_UART_BAUD之后不需要对模块进行配置,模块会自动设置为对应的波特率 + +#define WIRELESS_AUTO_UART_BAUD 0 +// ------------------------------------ 自动波特率 ------------------------------------ + +#define RTS_PIN P10_2 //定义流控位引脚 指示当前模块是否可以接受数据 0可以继续接收 1不可以继续接收 +#define WIRELESS_BUFFER_SIZE 16 + +extern uint8 wireless_send_buffer[WIRELESS_BUFFER_SIZE]; +extern uint32 wireless_rx_index; void wireless_uart_callback(void); void seekfree_wireless_init(void); diff --git a/Example/Systick_Demo/USER/isr.c b/Example/Systick_Demo/USER/isr.c index c55a012..16bff98 100644 --- a/Example/Systick_Demo/USER/isr.c +++ b/Example/Systick_Demo/USER/isr.c @@ -179,7 +179,20 @@ IFX_INTERRUPT(uart2_rx_isr, 0, UART2_RX_INT_PRIO) { enableInterrupts();//开启中断嵌套 IfxAsclin_Asc_isrReceive(&uart2_handle); - wireless_uart_callback(); + switch(wireless_type) + { + case WIRELESS_SI24R1: + { + wireless_uart_callback(); + }break; + + case WIRELESS_CH9141: + { + bluetooth_ch9141_uart_callback(); + }break; + default:break; + } + } IFX_INTERRUPT(uart2_er_isr, 0, UART2_ER_INT_PRIO) { diff --git a/Example/Systick_Demo/鍒犻櫎涓存椂鏂囦欢.bat b/Example/Systick_Demo/鍒犻櫎涓存椂鏂囦欢.bat index 5323dd9..fa499b1 100644 --- a/Example/Systick_Demo/鍒犻櫎涓存椂鏂囦欢.bat +++ b/Example/Systick_Demo/鍒犻櫎涓存椂鏂囦欢.bat @@ -1,9 +1,6 @@ -rmdir .settings /s /q rmdir Debug /s /q del *.launch /s - -pause exit diff --git a/Example/UART_Demo/.cproject b/Example/UART_Demo/.cproject index b3af179..7d3ced9 100644 --- a/Example/UART_Demo/.cproject +++ b/Example/UART_Demo/.cproject @@ -3,9 +3,9 @@ - + - + @@ -25,50 +25,76 @@ - + - + - + - + + + + + + @@ -355,9 +371,9 @@ - + - + @@ -377,43 +393,1895 @@ - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -431,13 +2299,37 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + @@ -458,21 +2350,5 @@ - - - - - - - - - - - - - - - - diff --git a/Example/UART_Demo/.project b/Example/UART_Demo/.project index 19afa0e..0bb2f85 100644 --- a/Example/UART_Demo/.project +++ b/Example/UART_Demo/.project @@ -5,6 +5,18 @@ + + com.infineon.aurix.buildsystem.builders.booster + full,incremental, + + + + + com.infineon.aurix.buildsystem.builders.autodiscovery + full,incremental, + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder clean,full,incremental, diff --git a/Example/UART_Demo/.settings/com.infineon.aurix.buildsystem.prefs b/Example/UART_Demo/.settings/com.infineon.aurix.buildsystem.prefs new file mode 100644 index 0000000..be61bc1 --- /dev/null +++ b/Example/UART_Demo/.settings/com.infineon.aurix.buildsystem.prefs @@ -0,0 +1,10 @@ +AURIX-LIBRARY-PATH=Libraries/iLLD\#Libraries/Infra\#Libraries/Service +DEVICE-ID=TC26B +DEVICE-ID-FULL=TC26xD_B-Step +ILLD-SET=full +IncludesAutodiscovery=true +LIBRARIES-ROOT-PATH=Libraries +NEVER-EXCLUDE-FROM-BUILD=/Libraries/iLLD/TC26B/Tricore/Cpu/CStart\#/Libraries/iLLD/TC26B/Tricore/Cpu/Trap\#/Configurations\#/Configurations/Debug +PROJECT-VERSION=1.0 +aurixDevice=TC26xD_B-Step +eclipse.preferences.version=1 diff --git a/Example/UART_Demo/Libraries/doc/version.txt b/Example/UART_Demo/Libraries/doc/version.txt index ab79909..11ab82e 100644 --- a/Example/UART_Demo/Libraries/doc/version.txt +++ b/Example/UART_Demo/Libraries/doc/version.txt @@ -1,3 +1,13 @@ +V1.2.0 + 增加CH9141蓝牙转串口模块的驱动 + 添加无线类型的枚举变量 + 修改 删除临时文件.bat 执行完操作后自动关闭窗口 + 修改 删除临时文件.bat 避免删除新版本所需文件 + 修改工程项目文件,以支持新版本编译 + +V1.1.10 + 修复通过#pragma section all "cpux_dsram"指定变量位置失效的问题 + V1.1.9 将串口的发送buff增加到128字节 diff --git a/Example/UART_Demo/Libraries/seekfree_libraries/common/common.c b/Example/UART_Demo/Libraries/seekfree_libraries/common/common.c index 0b9931e..7620ce6 100644 --- a/Example/UART_Demo/Libraries/seekfree_libraries/common/common.c +++ b/Example/UART_Demo/Libraries/seekfree_libraries/common/common.c @@ -27,6 +27,8 @@ CAMERA_TYPE_enum camera_type; //摄像头型号 uint8 *camera_buffer_addr; //摄像头数组地址 +WIRELESS_TYPE_enum wireless_type;//无线转串口类型 + IFX_ALIGN(4) IfxCpu_syncEvent g_cpuSyncEvent = 0;//事件同步变量 App_Cpu0 g_AppCpu0; //频率信息变量 diff --git a/Example/UART_Demo/Libraries/seekfree_libraries/common/common.h b/Example/UART_Demo/Libraries/seekfree_libraries/common/common.h index 84c43ee..5b741c0 100644 --- a/Example/UART_Demo/Libraries/seekfree_libraries/common/common.h +++ b/Example/UART_Demo/Libraries/seekfree_libraries/common/common.h @@ -113,6 +113,12 @@ typedef enum //枚 CAMERA_COLOR, //凌瞳 }CAMERA_TYPE_enum; +typedef enum //无线模块 +{ + WIRELESS_SI24R1 = 1, //无线转串口 + WIRELESS_CH9141, //蓝牙转串口 +}WIRELESS_TYPE_enum; + #include #include #include "IfxCpu.h" @@ -120,6 +126,8 @@ typedef enum //枚 extern CAMERA_TYPE_enum camera_type; //摄像头型号 extern uint8 *camera_buffer_addr; //摄像头数组地址 +extern WIRELESS_TYPE_enum wireless_type; + extern IfxCpu_syncEvent g_cpuSyncEvent; void get_clk(void); diff --git a/Example/UART_Demo/Libraries/seekfree_libraries/headfile.h b/Example/UART_Demo/Libraries/seekfree_libraries/headfile.h index 404ee0a..b745302 100644 --- a/Example/UART_Demo/Libraries/seekfree_libraries/headfile.h +++ b/Example/UART_Demo/Libraries/seekfree_libraries/headfile.h @@ -65,6 +65,7 @@ #include "SEEKFREE_7725.h" #include "SEEKFREE_RDA5807.h" #include "SEEKFREE_7725_UART.h" +#include "SEEKFREE_BLUETOOTH_CH9141.h" #endif diff --git a/Example/UART_Demo/Libraries/seekfree_peripheral/SEEKFREE_BLUETOOTH_CH9141.c b/Example/UART_Demo/Libraries/seekfree_peripheral/SEEKFREE_BLUETOOTH_CH9141.c new file mode 100644 index 0000000..b4ec2df --- /dev/null +++ b/Example/UART_Demo/Libraries/seekfree_peripheral/SEEKFREE_BLUETOOTH_CH9141.c @@ -0,0 +1,509 @@ +/********************************************************************************************************************* + * COPYRIGHT NOTICE + * Copyright (c) 2021,逐飞科技 + * All rights reserved. + * 技术讨论QQ群:一群:179029047(已满) 二群:244861897 + * + * 以下所有内容版权均属逐飞科技所有,未经允许不得用于商业用途, + * 欢迎各位使用并传播本程序,修改内容时必须保留逐飞科技的版权声明。 + * + * @file 逐飞科技蓝牙转串口模块 + * @company 成都逐飞科技有限公司 + * @author 逐飞科技(QQ3184284598) + * @version 查看doc内version文件 版本说明 + * @Software IAR 8.3 or MDK 5.33 + * @Taobao https://seekfree.taobao.com/ + * @date 2021-08-27 + * @note + 接线定义: + ------------------------------------ + 蓝牙转串口 单片机 + RX 查看SEEKFREE_BLUETOOTH_CH9141.h文件中的BLUETOOTH_CH9141_UART_TX宏定义 + TX 查看SEEKFREE_BLUETOOTH_CH9141.h文件中的BLUETOOTH_CH9141_UART_RX宏定义 + RTS 查看SEEKFREE_BLUETOOTH_CH9141.h文件中的BLUETOOTH_CH9141_RTS_PIN宏定义 + CTS 悬空 + CMD 悬空或者上拉 + ------------------------------------ + ********************************************************************************************************************/ +#include "zf_stm_systick.h" +#include "zf_gpio.h" +#include "zf_uart.h" +#include "zf_assert.h" +#include "SEEKFREE_BLUETOOTH_CH9141.h" + +uint8 uart_flag; +uint8 uart_data; + +vuint8 at_mode = 0; //0:蓝牙透传模式 1:AT模式 2:模块复位中 +vuint8 at_mode_num; //at模式时用于指示数据接收的数量 +vuint8 at_mode_data[30]; //接收at命令的缓存 +vuint8 at_mode_cmd_flag; //OK应答命令接收成功的标志位 + +uint8 mac_address[17]; //本机mac地址 + + +uint8 bluetooth_ch9141_rx_buffer; + + +void bluetooth_ch9141_check_response(void); + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块 串口中断回调函数 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note 该函数在ISR文件 串口8中断程序被调用 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_uart_callback() +{ + while(uart_query(BLUETOOTH_CH9141_UART, &bluetooth_ch9141_rx_buffer)) + { + if(1 == at_mode) + { + //进入AT模式 接收应答信号 此处if语句内代码用户不要改动 + at_mode_data[at_mode_num++] = bluetooth_ch9141_rx_buffer; + bluetooth_ch9141_check_response(); + } + else if(2 == at_mode) + { + //模块正在复位中 此处if语句内代码用户不要改动 + at_mode_num++; + } + else + { + //透传模式 用户在此处接收配对的蓝牙发送过来的额数据 + //接到一个字节后单片机将会进入此处,通过在此处读取bluetooth_ch9141_rx_buffer可以取走数据 + + // 读取无线串口的数据 并且置位接收标志 + uart_flag = 1; + uart_data = bluetooth_ch9141_rx_buffer; + } + + } +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块检查OK应答信号 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_check_response(void) +{ + if(4 <= at_mode_num) + { + if(0 == strncmp("OK\r\n", (int8 *)&at_mode_data[at_mode_num-4], 4)) + { + at_mode_cmd_flag = 1; + } + } +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块发送一个没有参数的命令并等待应答信号 +// @param *str 需要发送的命令 完整字符串 +// @return void +// @since v1.0 +// Sample usage: +// @note 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_send_at_command(const int8 *str) +{ + at_mode_num = 0; //接收数量清零 + uart_putstr(BLUETOOTH_CH9141_UART, str); + uart_putstr(BLUETOOTH_CH9141_UART, "\r\n"); + + //等待收到应答信号 + while(!at_mode_cmd_flag); + at_mode_cmd_flag = 0; +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块发送一个带有参数的命令并等待应答信号 +// @param *cmd 需要发送的命令名称 +// @param *data 需要发送的数据 +// @return void +// @since v1.0 +// Sample usage: +// @note 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_send_at_command_parameter(const int8 *cmd, const int8 *data) +{ + at_mode_num = 0; //接收数量清零 + uart_putstr(BLUETOOTH_CH9141_UART, "AT+"); + uart_putstr(BLUETOOTH_CH9141_UART, cmd); + uart_putstr(BLUETOOTH_CH9141_UART, "="); + uart_putstr(BLUETOOTH_CH9141_UART, data); + uart_putstr(BLUETOOTH_CH9141_UART, "\r\n"); + + //等待收到应答信号 + while(!at_mode_cmd_flag); + at_mode_cmd_flag = 0; +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块进入AT模式 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_enter_at_mode(void) +{ + systick_delay_ms(STM0, 550); //发送进入AT模式的命令前需要保证模块在550ms内没有接收过任何数据 + at_mode = 1; //进入AT模式 + bluetooth_ch9141_send_at_command("AT..."); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块退出AT模式 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_exit_at_mode(void) +{ + bluetooth_ch9141_send_at_command("AT+EXIT"); + at_mode = 0; //进入透传模式 + systick_delay_ms(STM0, 300); //等待成功进入AT模式 +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块复位 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_reset(void) +{ + bluetooth_ch9141_send_at_command("AT+RESET"); + at_mode = 2; //进入重启成功检测 + at_mode_num = 0; + while(7 > at_mode_num); //等待蓝牙模块完成复位 + at_mode = 0; //复位之后模块自动进入透传模式 +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块获取本机MAC地址 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note 调用此函数需要先调用bluetooth_ch9141_enter_at_mode或者拉低CMD引脚 进入AT模式 +// 需要特别注意bluetooth_ch9141_enter_at_mode函数内部有500ms的延时 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_get_mac_address(void) +{ + bluetooth_ch9141_send_at_command("AT+MAC?"); + + //mac地址为小段格式,mac_address[0]保存的是mac地址最低位 + memcpy(mac_address, (uint8 *)at_mode_data, 17); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块设置发送功率 +// @param tx_power 设置发送功率,可设置选项查看CH9141_TX_POWEER_enum枚举成员 +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_set_tx_power(CH9141_TX_POWEER_enum tx_power) +{ + int8 tx_power_data; + + tx_power_data = (uint8)tx_power + '0'; + bluetooth_ch9141_send_at_command_parameter("TPL", &tx_power_data); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块设置模式 +// @param mode 模式设置,可设置选项查看CH9141_MODE_enum枚举成员 +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_set_mode(CH9141_MODE_enum mode) +{ + int8 mode_data; + + mode_data = (uint8)mode + '0'; + bluetooth_ch9141_send_at_command_parameter("BLEMODE", &mode_data); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块获取状态 +// @param mode 模式设置,可设置选项查看CH9141_MODE_enum枚举成员 +// @return CH9141_STATUS_enum 返回状态信息 +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +CH9141_STATUS_enum bluetooth_ch9141_get_status(CH9141_MODE_enum mode) +{ + CH9141_STATUS_enum ch9141_status; + int8 mode_data; + + mode_data = (uint8)mode + '0'; + bluetooth_ch9141_send_at_command_parameter("BLEMODE", &mode_data); + + bluetooth_ch9141_send_at_command("AT+BLESTA?"); + + ch9141_status = (at_mode_data[0] - '0') * 10 + (at_mode_data[1] - '0'); + if(SLAVE_MODE == mode) + { + ch9141_status += SLAVE_NO_INIT; + } + + return ch9141_status; +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块设置设备名称 +// @param *str 蓝牙名称 +// @return void +// @since v1.0 +// Sample usage: +// @note 名称长度不能超过18个字符 且只能为英文与数字 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_set_name(const int8 *str) +{ + bluetooth_ch9141_send_at_command_parameter("NAME", str); + bluetooth_ch9141_send_at_command_parameter("PNAME", str); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块密码设置 +// @param enable 使能密码 0:不使用密码,1:使用密码才能连接本设备 +// @param *password 密码的字符串 必须为6个字符 +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_set_password(uint8 enable, const int8 *password) +{ + if(0 == enable) + { + //关闭密码 + bluetooth_ch9141_send_at_command_parameter("PASEN", "OFF"); + } + else + { + //设置密码并使能 + bluetooth_ch9141_send_at_command_parameter("PASEN", "ON"); + bluetooth_ch9141_send_at_command_parameter("PASS", password); + } +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块指定MAC地址并立即进行连接 +// @param *mac_and_password 需要连接的设备mac地址与密码 +// @return void +// @since v1.0 +// Sample usage: +// @note bluetooth_ch9141_connect("58:B7:33:E4:C2:84,000000"); +// 58:B7:33:E4:C2:84为mac地址 ,为分隔符 000000为从机蓝牙密码 +// ===================特别注意================== +// 如果使用手机查看蓝牙的mac地址,则使用本函数连接的时候请将mac倒置一下 +// 例如手机查看到的mac地址为61:62:63:64:65:66,则使用本函数连接的时候应该写 +// bluetooth_ch9141_connect("66:65:64:63:62:61,000000"); +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_connect(const int8 *mac_and_password) +{ + bluetooth_ch9141_send_at_command_parameter("CONN", mac_and_password); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块默认连接参数设置(设置好后,每次开机蓝牙会自动链接这个设备) +// @param *mac_and_password 需要连接的设备mac地址与密码 +// @return void +// @since v1.0 +// Sample usage: +// @note bluetooth_ch9141_default_connect("58:B7:33:E4:C2:84,000000"); +// 58:B7:33:E4:C2:84为mac地址 ,为分隔符 000000为从机蓝牙密码 +// ===================特别注意================== +// 如果使用手机查看CH9141的mac地址,将CH9141设置为从机,使用手机连接 +// 则使用本函数连接的时候请将mac倒置一下 +// 例如手机查看到的mac地址为61:62:63:64:65:67,则使用本函数连接的时候应该写 +// bluetooth_ch9141_default_connect("67:65:64:63:62:61,000000"); +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_default_connect(const int8 *mac_and_password) +{ + bluetooth_ch9141_send_at_command_parameter("CONADD", mac_and_password); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块获取rssi(信号强度) +// @param void +// @return int8 返回信号强度0到-127 +// @since v1.0 +// Sample usage: +// @note 调用此函数需要先调用bluetooth_ch9141_enter_at_mode或者拉低CMD引脚 进入AT模式 +// 需要特别注意bluetooth_ch9141_enter_at_mode函数内部有500ms的延时 +//------------------------------------------------------------------------------------------------------------------- +int16 bluetooth_ch9141_get_rssi(void) +{ + uint8 i; + size_t length; + int16 rssi; + bluetooth_ch9141_send_at_command_parameter("RSSI", "ON,0"); + length = strlen((int8 *)at_mode_data); + length -= 12;//计算RSSI 有多少位 + + rssi = 0; + for(i=0; i30) { - if(gpio_get(RTS_PIN)) - { - return len;//模块忙,如果允许当前程序使用while等待 则可以使用后面注释的while等待语句替换本if语句 - } - //while(gpio_get(RTS_PIN)); //如果RTS为低电平,则继续发送数据 +// if(gpio_get(RTS_PIN)) +// { +// return len;//模块忙,如果允许当前程序使用while等待 则可以使用后面注释的while等待语句替换本if语句 +// } + while(gpio_get(RTS_PIN)); //如果RTS为低电平,则继续发送数据 uart_putbuff(WIRELESS_UART,buff,30); buff += 30; //地址偏移 len -= 30;//数量 } - if(gpio_get(RTS_PIN)) - { - return len;//模块忙,如果允许当前程序使用while等待 则可以使用后面注释的while等待语句替换本if语句 - } - //while(gpio_get(RTS_PIN)); //如果RTS为低电平,则继续发送数据 +// if(gpio_get(RTS_PIN)) +// { +// return len;//模块忙,如果允许当前程序使用while等待 则可以使用后面注释的while等待语句替换本if语句 +// } + while(gpio_get(RTS_PIN)); //如果RTS为低电平,则继续发送数据 uart_putbuff(WIRELESS_UART,buff,len);//发送最后的数据 return 0; diff --git a/Example/UART_Demo/Libraries/seekfree_peripheral/SEEKFREE_WIRELESS.h b/Example/UART_Demo/Libraries/seekfree_peripheral/SEEKFREE_WIRELESS.h index 42c0832..d80339d 100644 --- a/Example/UART_Demo/Libraries/seekfree_peripheral/SEEKFREE_WIRELESS.h +++ b/Example/UART_Demo/Libraries/seekfree_peripheral/SEEKFREE_WIRELESS.h @@ -38,8 +38,26 @@ #define WIRELESS_UART_RX UART2_RX_P10_6 #define WIRELESS_UART_BAUD 115200 -#define RTS_PIN P10_2 //定义流控位引脚 指示当前模块是否可以接受数据 0可以继续接收 1不可以继续接收 +// ------------------------------------ 自动波特率 ------------------------------------ +// 注意事项1:无线转串口模块版本是V2.0以下的是无法开启自动波特率的。 +// 注意事项2:开启自动波特率务必连接RTS引脚,否则会开启失败。 +// 注意事项3:模块自动波特率失败的话,可以尝试断电重启 +// 开启自动波特率务必阅读上面两条 注意事项 +// 开启自动波特率务必阅读上面两条 注意事项 +// 开启自动波特率务必阅读上面两条 注意事项 + +// 0:关闭自动波特率 +// 1:开启自动波特率 自动波特率的作用是修改WIRELESS_UART_BAUD之后不需要对模块进行配置,模块会自动设置为对应的波特率 + +#define WIRELESS_AUTO_UART_BAUD 0 +// ------------------------------------ 自动波特率 ------------------------------------ + +#define RTS_PIN P10_2 //定义流控位引脚 指示当前模块是否可以接受数据 0可以继续接收 1不可以继续接收 +#define WIRELESS_BUFFER_SIZE 16 + +extern uint8 wireless_send_buffer[WIRELESS_BUFFER_SIZE]; +extern uint32 wireless_rx_index; void wireless_uart_callback(void); void seekfree_wireless_init(void); diff --git a/Example/UART_Demo/USER/isr.c b/Example/UART_Demo/USER/isr.c index c55a012..16bff98 100644 --- a/Example/UART_Demo/USER/isr.c +++ b/Example/UART_Demo/USER/isr.c @@ -179,7 +179,20 @@ IFX_INTERRUPT(uart2_rx_isr, 0, UART2_RX_INT_PRIO) { enableInterrupts();//开启中断嵌套 IfxAsclin_Asc_isrReceive(&uart2_handle); - wireless_uart_callback(); + switch(wireless_type) + { + case WIRELESS_SI24R1: + { + wireless_uart_callback(); + }break; + + case WIRELESS_CH9141: + { + bluetooth_ch9141_uart_callback(); + }break; + default:break; + } + } IFX_INTERRUPT(uart2_er_isr, 0, UART2_ER_INT_PRIO) { diff --git a/Example/UART_Demo/鍒犻櫎涓存椂鏂囦欢.bat b/Example/UART_Demo/鍒犻櫎涓存椂鏂囦欢.bat index 5323dd9..fa499b1 100644 --- a/Example/UART_Demo/鍒犻櫎涓存椂鏂囦欢.bat +++ b/Example/UART_Demo/鍒犻櫎涓存椂鏂囦欢.bat @@ -1,9 +1,6 @@ -rmdir .settings /s /q rmdir Debug /s /q del *.launch /s - -pause exit diff --git a/Seekfree_TC264_Opensource_Library/.cproject b/Seekfree_TC264_Opensource_Library/.cproject index 0a032ca..69888ae 100644 --- a/Seekfree_TC264_Opensource_Library/.cproject +++ b/Seekfree_TC264_Opensource_Library/.cproject @@ -3,9 +3,9 @@ - + - + @@ -25,50 +25,76 @@ - + - + - + - @@ -354,12 +362,14 @@ + + - + - + @@ -379,43 +389,1895 @@ - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -433,13 +2295,37 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + @@ -463,6 +2349,18 @@ + + + + + + + + + + + + diff --git a/Seekfree_TC264_Opensource_Library/.project b/Seekfree_TC264_Opensource_Library/.project index 0c7e5a1..fef13df 100644 --- a/Seekfree_TC264_Opensource_Library/.project +++ b/Seekfree_TC264_Opensource_Library/.project @@ -5,6 +5,18 @@ + + com.infineon.aurix.buildsystem.builders.booster + full,incremental, + + + + + com.infineon.aurix.buildsystem.builders.autodiscovery + full,incremental, + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder clean,full,incremental, diff --git a/Seekfree_TC264_Opensource_Library/.settings/com.infineon.aurix.buildsystem.prefs b/Seekfree_TC264_Opensource_Library/.settings/com.infineon.aurix.buildsystem.prefs new file mode 100644 index 0000000..be61bc1 --- /dev/null +++ b/Seekfree_TC264_Opensource_Library/.settings/com.infineon.aurix.buildsystem.prefs @@ -0,0 +1,10 @@ +AURIX-LIBRARY-PATH=Libraries/iLLD\#Libraries/Infra\#Libraries/Service +DEVICE-ID=TC26B +DEVICE-ID-FULL=TC26xD_B-Step +ILLD-SET=full +IncludesAutodiscovery=true +LIBRARIES-ROOT-PATH=Libraries +NEVER-EXCLUDE-FROM-BUILD=/Libraries/iLLD/TC26B/Tricore/Cpu/CStart\#/Libraries/iLLD/TC26B/Tricore/Cpu/Trap\#/Configurations\#/Configurations/Debug +PROJECT-VERSION=1.0 +aurixDevice=TC26xD_B-Step +eclipse.preferences.version=1 diff --git a/Seekfree_TC264_Opensource_Library/Libraries/doc/version.txt b/Seekfree_TC264_Opensource_Library/Libraries/doc/version.txt index 59d6b65..11ab82e 100644 --- a/Seekfree_TC264_Opensource_Library/Libraries/doc/version.txt +++ b/Seekfree_TC264_Opensource_Library/Libraries/doc/version.txt @@ -1,3 +1,10 @@ +V1.2.0 + 增加CH9141蓝牙转串口模块的驱动 + 添加无线类型的枚举变量 + 修改 删除临时文件.bat 执行完操作后自动关闭窗口 + 修改 删除临时文件.bat 避免删除新版本所需文件 + 修改工程项目文件,以支持新版本编译 + V1.1.10 修复通过#pragma section all "cpux_dsram"指定变量位置失效的问题 diff --git a/Seekfree_TC264_Opensource_Library/Libraries/seekfree_libraries/common/common.c b/Seekfree_TC264_Opensource_Library/Libraries/seekfree_libraries/common/common.c index 0b9931e..7620ce6 100644 --- a/Seekfree_TC264_Opensource_Library/Libraries/seekfree_libraries/common/common.c +++ b/Seekfree_TC264_Opensource_Library/Libraries/seekfree_libraries/common/common.c @@ -27,6 +27,8 @@ CAMERA_TYPE_enum camera_type; //摄像头型号 uint8 *camera_buffer_addr; //摄像头数组地址 +WIRELESS_TYPE_enum wireless_type;//无线转串口类型 + IFX_ALIGN(4) IfxCpu_syncEvent g_cpuSyncEvent = 0;//事件同步变量 App_Cpu0 g_AppCpu0; //频率信息变量 diff --git a/Seekfree_TC264_Opensource_Library/Libraries/seekfree_libraries/common/common.h b/Seekfree_TC264_Opensource_Library/Libraries/seekfree_libraries/common/common.h index 84c43ee..5b741c0 100644 --- a/Seekfree_TC264_Opensource_Library/Libraries/seekfree_libraries/common/common.h +++ b/Seekfree_TC264_Opensource_Library/Libraries/seekfree_libraries/common/common.h @@ -113,6 +113,12 @@ typedef enum //枚 CAMERA_COLOR, //凌瞳 }CAMERA_TYPE_enum; +typedef enum //无线模块 +{ + WIRELESS_SI24R1 = 1, //无线转串口 + WIRELESS_CH9141, //蓝牙转串口 +}WIRELESS_TYPE_enum; + #include #include #include "IfxCpu.h" @@ -120,6 +126,8 @@ typedef enum //枚 extern CAMERA_TYPE_enum camera_type; //摄像头型号 extern uint8 *camera_buffer_addr; //摄像头数组地址 +extern WIRELESS_TYPE_enum wireless_type; + extern IfxCpu_syncEvent g_cpuSyncEvent; void get_clk(void); diff --git a/Seekfree_TC264_Opensource_Library/Libraries/seekfree_libraries/headfile.h b/Seekfree_TC264_Opensource_Library/Libraries/seekfree_libraries/headfile.h index 404ee0a..b745302 100644 --- a/Seekfree_TC264_Opensource_Library/Libraries/seekfree_libraries/headfile.h +++ b/Seekfree_TC264_Opensource_Library/Libraries/seekfree_libraries/headfile.h @@ -65,6 +65,7 @@ #include "SEEKFREE_7725.h" #include "SEEKFREE_RDA5807.h" #include "SEEKFREE_7725_UART.h" +#include "SEEKFREE_BLUETOOTH_CH9141.h" #endif diff --git a/Seekfree_TC264_Opensource_Library/Libraries/seekfree_peripheral/SEEKFREE_BLUETOOTH_CH9141.c b/Seekfree_TC264_Opensource_Library/Libraries/seekfree_peripheral/SEEKFREE_BLUETOOTH_CH9141.c new file mode 100644 index 0000000..b4ec2df --- /dev/null +++ b/Seekfree_TC264_Opensource_Library/Libraries/seekfree_peripheral/SEEKFREE_BLUETOOTH_CH9141.c @@ -0,0 +1,509 @@ +/********************************************************************************************************************* + * COPYRIGHT NOTICE + * Copyright (c) 2021,逐飞科技 + * All rights reserved. + * 技术讨论QQ群:一群:179029047(已满) 二群:244861897 + * + * 以下所有内容版权均属逐飞科技所有,未经允许不得用于商业用途, + * 欢迎各位使用并传播本程序,修改内容时必须保留逐飞科技的版权声明。 + * + * @file 逐飞科技蓝牙转串口模块 + * @company 成都逐飞科技有限公司 + * @author 逐飞科技(QQ3184284598) + * @version 查看doc内version文件 版本说明 + * @Software IAR 8.3 or MDK 5.33 + * @Taobao https://seekfree.taobao.com/ + * @date 2021-08-27 + * @note + 接线定义: + ------------------------------------ + 蓝牙转串口 单片机 + RX 查看SEEKFREE_BLUETOOTH_CH9141.h文件中的BLUETOOTH_CH9141_UART_TX宏定义 + TX 查看SEEKFREE_BLUETOOTH_CH9141.h文件中的BLUETOOTH_CH9141_UART_RX宏定义 + RTS 查看SEEKFREE_BLUETOOTH_CH9141.h文件中的BLUETOOTH_CH9141_RTS_PIN宏定义 + CTS 悬空 + CMD 悬空或者上拉 + ------------------------------------ + ********************************************************************************************************************/ +#include "zf_stm_systick.h" +#include "zf_gpio.h" +#include "zf_uart.h" +#include "zf_assert.h" +#include "SEEKFREE_BLUETOOTH_CH9141.h" + +uint8 uart_flag; +uint8 uart_data; + +vuint8 at_mode = 0; //0:蓝牙透传模式 1:AT模式 2:模块复位中 +vuint8 at_mode_num; //at模式时用于指示数据接收的数量 +vuint8 at_mode_data[30]; //接收at命令的缓存 +vuint8 at_mode_cmd_flag; //OK应答命令接收成功的标志位 + +uint8 mac_address[17]; //本机mac地址 + + +uint8 bluetooth_ch9141_rx_buffer; + + +void bluetooth_ch9141_check_response(void); + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块 串口中断回调函数 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note 该函数在ISR文件 串口8中断程序被调用 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_uart_callback() +{ + while(uart_query(BLUETOOTH_CH9141_UART, &bluetooth_ch9141_rx_buffer)) + { + if(1 == at_mode) + { + //进入AT模式 接收应答信号 此处if语句内代码用户不要改动 + at_mode_data[at_mode_num++] = bluetooth_ch9141_rx_buffer; + bluetooth_ch9141_check_response(); + } + else if(2 == at_mode) + { + //模块正在复位中 此处if语句内代码用户不要改动 + at_mode_num++; + } + else + { + //透传模式 用户在此处接收配对的蓝牙发送过来的额数据 + //接到一个字节后单片机将会进入此处,通过在此处读取bluetooth_ch9141_rx_buffer可以取走数据 + + // 读取无线串口的数据 并且置位接收标志 + uart_flag = 1; + uart_data = bluetooth_ch9141_rx_buffer; + } + + } +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块检查OK应答信号 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_check_response(void) +{ + if(4 <= at_mode_num) + { + if(0 == strncmp("OK\r\n", (int8 *)&at_mode_data[at_mode_num-4], 4)) + { + at_mode_cmd_flag = 1; + } + } +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块发送一个没有参数的命令并等待应答信号 +// @param *str 需要发送的命令 完整字符串 +// @return void +// @since v1.0 +// Sample usage: +// @note 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_send_at_command(const int8 *str) +{ + at_mode_num = 0; //接收数量清零 + uart_putstr(BLUETOOTH_CH9141_UART, str); + uart_putstr(BLUETOOTH_CH9141_UART, "\r\n"); + + //等待收到应答信号 + while(!at_mode_cmd_flag); + at_mode_cmd_flag = 0; +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块发送一个带有参数的命令并等待应答信号 +// @param *cmd 需要发送的命令名称 +// @param *data 需要发送的数据 +// @return void +// @since v1.0 +// Sample usage: +// @note 用户无需关心 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_send_at_command_parameter(const int8 *cmd, const int8 *data) +{ + at_mode_num = 0; //接收数量清零 + uart_putstr(BLUETOOTH_CH9141_UART, "AT+"); + uart_putstr(BLUETOOTH_CH9141_UART, cmd); + uart_putstr(BLUETOOTH_CH9141_UART, "="); + uart_putstr(BLUETOOTH_CH9141_UART, data); + uart_putstr(BLUETOOTH_CH9141_UART, "\r\n"); + + //等待收到应答信号 + while(!at_mode_cmd_flag); + at_mode_cmd_flag = 0; +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块进入AT模式 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_enter_at_mode(void) +{ + systick_delay_ms(STM0, 550); //发送进入AT模式的命令前需要保证模块在550ms内没有接收过任何数据 + at_mode = 1; //进入AT模式 + bluetooth_ch9141_send_at_command("AT..."); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块退出AT模式 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_exit_at_mode(void) +{ + bluetooth_ch9141_send_at_command("AT+EXIT"); + at_mode = 0; //进入透传模式 + systick_delay_ms(STM0, 300); //等待成功进入AT模式 +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块复位 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_reset(void) +{ + bluetooth_ch9141_send_at_command("AT+RESET"); + at_mode = 2; //进入重启成功检测 + at_mode_num = 0; + while(7 > at_mode_num); //等待蓝牙模块完成复位 + at_mode = 0; //复位之后模块自动进入透传模式 +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块获取本机MAC地址 +// @param NULL +// @return void +// @since v1.0 +// Sample usage: +// @note 调用此函数需要先调用bluetooth_ch9141_enter_at_mode或者拉低CMD引脚 进入AT模式 +// 需要特别注意bluetooth_ch9141_enter_at_mode函数内部有500ms的延时 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_get_mac_address(void) +{ + bluetooth_ch9141_send_at_command("AT+MAC?"); + + //mac地址为小段格式,mac_address[0]保存的是mac地址最低位 + memcpy(mac_address, (uint8 *)at_mode_data, 17); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块设置发送功率 +// @param tx_power 设置发送功率,可设置选项查看CH9141_TX_POWEER_enum枚举成员 +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_set_tx_power(CH9141_TX_POWEER_enum tx_power) +{ + int8 tx_power_data; + + tx_power_data = (uint8)tx_power + '0'; + bluetooth_ch9141_send_at_command_parameter("TPL", &tx_power_data); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块设置模式 +// @param mode 模式设置,可设置选项查看CH9141_MODE_enum枚举成员 +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_set_mode(CH9141_MODE_enum mode) +{ + int8 mode_data; + + mode_data = (uint8)mode + '0'; + bluetooth_ch9141_send_at_command_parameter("BLEMODE", &mode_data); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块获取状态 +// @param mode 模式设置,可设置选项查看CH9141_MODE_enum枚举成员 +// @return CH9141_STATUS_enum 返回状态信息 +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +CH9141_STATUS_enum bluetooth_ch9141_get_status(CH9141_MODE_enum mode) +{ + CH9141_STATUS_enum ch9141_status; + int8 mode_data; + + mode_data = (uint8)mode + '0'; + bluetooth_ch9141_send_at_command_parameter("BLEMODE", &mode_data); + + bluetooth_ch9141_send_at_command("AT+BLESTA?"); + + ch9141_status = (at_mode_data[0] - '0') * 10 + (at_mode_data[1] - '0'); + if(SLAVE_MODE == mode) + { + ch9141_status += SLAVE_NO_INIT; + } + + return ch9141_status; +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块设置设备名称 +// @param *str 蓝牙名称 +// @return void +// @since v1.0 +// Sample usage: +// @note 名称长度不能超过18个字符 且只能为英文与数字 +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_set_name(const int8 *str) +{ + bluetooth_ch9141_send_at_command_parameter("NAME", str); + bluetooth_ch9141_send_at_command_parameter("PNAME", str); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块密码设置 +// @param enable 使能密码 0:不使用密码,1:使用密码才能连接本设备 +// @param *password 密码的字符串 必须为6个字符 +// @return void +// @since v1.0 +// Sample usage: +// @note +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_set_password(uint8 enable, const int8 *password) +{ + if(0 == enable) + { + //关闭密码 + bluetooth_ch9141_send_at_command_parameter("PASEN", "OFF"); + } + else + { + //设置密码并使能 + bluetooth_ch9141_send_at_command_parameter("PASEN", "ON"); + bluetooth_ch9141_send_at_command_parameter("PASS", password); + } +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块指定MAC地址并立即进行连接 +// @param *mac_and_password 需要连接的设备mac地址与密码 +// @return void +// @since v1.0 +// Sample usage: +// @note bluetooth_ch9141_connect("58:B7:33:E4:C2:84,000000"); +// 58:B7:33:E4:C2:84为mac地址 ,为分隔符 000000为从机蓝牙密码 +// ===================特别注意================== +// 如果使用手机查看蓝牙的mac地址,则使用本函数连接的时候请将mac倒置一下 +// 例如手机查看到的mac地址为61:62:63:64:65:66,则使用本函数连接的时候应该写 +// bluetooth_ch9141_connect("66:65:64:63:62:61,000000"); +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_connect(const int8 *mac_and_password) +{ + bluetooth_ch9141_send_at_command_parameter("CONN", mac_and_password); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块默认连接参数设置(设置好后,每次开机蓝牙会自动链接这个设备) +// @param *mac_and_password 需要连接的设备mac地址与密码 +// @return void +// @since v1.0 +// Sample usage: +// @note bluetooth_ch9141_default_connect("58:B7:33:E4:C2:84,000000"); +// 58:B7:33:E4:C2:84为mac地址 ,为分隔符 000000为从机蓝牙密码 +// ===================特别注意================== +// 如果使用手机查看CH9141的mac地址,将CH9141设置为从机,使用手机连接 +// 则使用本函数连接的时候请将mac倒置一下 +// 例如手机查看到的mac地址为61:62:63:64:65:67,则使用本函数连接的时候应该写 +// bluetooth_ch9141_default_connect("67:65:64:63:62:61,000000"); +//------------------------------------------------------------------------------------------------------------------- +void bluetooth_ch9141_default_connect(const int8 *mac_and_password) +{ + bluetooth_ch9141_send_at_command_parameter("CONADD", mac_and_password); +} + +//------------------------------------------------------------------------------------------------------------------- +// @brief 蓝牙转串口模块获取rssi(信号强度) +// @param void +// @return int8 返回信号强度0到-127 +// @since v1.0 +// Sample usage: +// @note 调用此函数需要先调用bluetooth_ch9141_enter_at_mode或者拉低CMD引脚 进入AT模式 +// 需要特别注意bluetooth_ch9141_enter_at_mode函数内部有500ms的延时 +//------------------------------------------------------------------------------------------------------------------- +int16 bluetooth_ch9141_get_rssi(void) +{ + uint8 i; + size_t length; + int16 rssi; + bluetooth_ch9141_send_at_command_parameter("RSSI", "ON,0"); + length = strlen((int8 *)at_mode_data); + length -= 12;//计算RSSI 有多少位 + + rssi = 0; + for(i=0; i30) { - if(gpio_get(RTS_PIN)) - { - return len;//模块忙,如果允许当前程序使用while等待 则可以使用后面注释的while等待语句替换本if语句 - } - //while(gpio_get(RTS_PIN)); //如果RTS为低电平,则继续发送数据 +// if(gpio_get(RTS_PIN)) +// { +// return len;//模块忙,如果允许当前程序使用while等待 则可以使用后面注释的while等待语句替换本if语句 +// } + while(gpio_get(RTS_PIN)); //如果RTS为低电平,则继续发送数据 uart_putbuff(WIRELESS_UART,buff,30); buff += 30; //地址偏移 len -= 30;//数量 } - if(gpio_get(RTS_PIN)) - { - return len;//模块忙,如果允许当前程序使用while等待 则可以使用后面注释的while等待语句替换本if语句 - } - //while(gpio_get(RTS_PIN)); //如果RTS为低电平,则继续发送数据 +// if(gpio_get(RTS_PIN)) +// { +// return len;//模块忙,如果允许当前程序使用while等待 则可以使用后面注释的while等待语句替换本if语句 +// } + while(gpio_get(RTS_PIN)); //如果RTS为低电平,则继续发送数据 uart_putbuff(WIRELESS_UART,buff,len);//发送最后的数据 return 0; diff --git a/Seekfree_TC264_Opensource_Library/Libraries/seekfree_peripheral/SEEKFREE_WIRELESS.h b/Seekfree_TC264_Opensource_Library/Libraries/seekfree_peripheral/SEEKFREE_WIRELESS.h index 42c0832..d80339d 100644 --- a/Seekfree_TC264_Opensource_Library/Libraries/seekfree_peripheral/SEEKFREE_WIRELESS.h +++ b/Seekfree_TC264_Opensource_Library/Libraries/seekfree_peripheral/SEEKFREE_WIRELESS.h @@ -38,8 +38,26 @@ #define WIRELESS_UART_RX UART2_RX_P10_6 #define WIRELESS_UART_BAUD 115200 -#define RTS_PIN P10_2 //定义流控位引脚 指示当前模块是否可以接受数据 0可以继续接收 1不可以继续接收 +// ------------------------------------ 自动波特率 ------------------------------------ +// 注意事项1:无线转串口模块版本是V2.0以下的是无法开启自动波特率的。 +// 注意事项2:开启自动波特率务必连接RTS引脚,否则会开启失败。 +// 注意事项3:模块自动波特率失败的话,可以尝试断电重启 +// 开启自动波特率务必阅读上面两条 注意事项 +// 开启自动波特率务必阅读上面两条 注意事项 +// 开启自动波特率务必阅读上面两条 注意事项 + +// 0:关闭自动波特率 +// 1:开启自动波特率 自动波特率的作用是修改WIRELESS_UART_BAUD之后不需要对模块进行配置,模块会自动设置为对应的波特率 + +#define WIRELESS_AUTO_UART_BAUD 0 +// ------------------------------------ 自动波特率 ------------------------------------ + +#define RTS_PIN P10_2 //定义流控位引脚 指示当前模块是否可以接受数据 0可以继续接收 1不可以继续接收 +#define WIRELESS_BUFFER_SIZE 16 + +extern uint8 wireless_send_buffer[WIRELESS_BUFFER_SIZE]; +extern uint32 wireless_rx_index; void wireless_uart_callback(void); void seekfree_wireless_init(void); diff --git a/Seekfree_TC264_Opensource_Library/USER/isr.c b/Seekfree_TC264_Opensource_Library/USER/isr.c index c55a012..1dded30 100644 --- a/Seekfree_TC264_Opensource_Library/USER/isr.c +++ b/Seekfree_TC264_Opensource_Library/USER/isr.c @@ -179,7 +179,20 @@ IFX_INTERRUPT(uart2_rx_isr, 0, UART2_RX_INT_PRIO) { enableInterrupts();//开启中断嵌套 IfxAsclin_Asc_isrReceive(&uart2_handle); - wireless_uart_callback(); + switch(wireless_type) + { + case WIRELESS_SI24R1: + { + wireless_uart_callback(); + }break; + + case WIRELESS_CH9141: + { + bluetooth_ch9141_uart_callback(); + }break; + default:break; + } + } IFX_INTERRUPT(uart2_er_isr, 0, UART2_ER_INT_PRIO) { diff --git a/Seekfree_TC264_Opensource_Library/鍒犻櫎涓存椂鏂囦欢.bat b/Seekfree_TC264_Opensource_Library/鍒犻櫎涓存椂鏂囦欢.bat index 5323dd9..fa499b1 100644 --- a/Seekfree_TC264_Opensource_Library/鍒犻櫎涓存椂鏂囦欢.bat +++ b/Seekfree_TC264_Opensource_Library/鍒犻櫎涓存椂鏂囦欢.bat @@ -1,9 +1,6 @@ -rmdir .settings /s /q rmdir Debug /s /q del *.launch /s - -pause exit diff --git a/Seekfree_TC264_Opensource_Library/灏介噺涓嶈浣跨敤鐨勫紩鑴.txt b/Seekfree_TC264_Opensource_Library/灏介噺涓嶈浣跨敤鐨勫紩鑴.txt index ca712ca..e5bde1c 100644 --- a/Seekfree_TC264_Opensource_Library/灏介噺涓嶈浣跨敤鐨勫紩鑴.txt +++ b/Seekfree_TC264_Opensource_Library/灏介噺涓嶈浣跨敤鐨勫紩鑴.txt @@ -7,4 +7,8 @@ P14.4 P14.5 P14.6 P10.5 -P10.6 \ No newline at end of file +P10.6 + +P20.2 这个引脚只能输入不能输出 + +P21.6 在TC264DA芯片中这个引脚无法使用,在TC264D中可以正常使用 \ No newline at end of file