环境:
主机:WIN7
开发环境:MDK4.23
功能:
打开Android手机或者平台的蓝牙,通过蓝牙连接蓝牙转串口板,通过蓝牙转串口板的串口与需要调试的串口设备相连
说明:
1.PCB为我同学hunter绘制,他同时是stm32的高手,感谢他提供的支持.
2.制作了一个蓝牙转串口的板子,Android设备连接上这个板子,就相当于增加了一个串口.
3.单片机选用的是STM32F101C8,蓝牙模块选用的是HC05.HC05本身就是一个蓝牙转串口模块,再增加一个单片机的作用是可以通过单片机来配置波特率等参数.
4.蓝牙转串口板可以用MINI USB来供电,或者用3.7V锂电池来供电,板子上带有充电管理芯片,由于没锂电池,充电这块还没有测试.
5.上位机程序(Android上的串口助手)暂时没有时间写,可以在安卓市场上搜索"蓝牙串口"下一个串口助手.
实物图:
电路图:
第1部分:
图片较大,部分没有显示.可以在新窗口打开图片来看到全部内容
第2部分:
下位机程序:
public.h
- #ifndef _PUBLIC_H_
- #define _PUBLIC_H_
-
-
- #include "main.h"
- #include "string.h"
- #include "stdlib.h"
- #include "stm32f10x_tim.h"
-
-
- #define U8 unsigned char
- #define U16 unsigned short
- #define U32 unsigned long
-
-
- #define LEN_BT_STACK 10
-
-
- #define BT_BAUD_4800 "AT+UART=4800,0,0"
- #define BT_BAUD_9600 "AT+UART=9600,0,0"
- #define BT_BAUD_19200 "AT+UART=19200,0,0"
- #define BT_BAUD_38400 "AT+UART=38400,0,0"
- #define BT_BAUD_57600 "AT+UART=57600,0,0"
- #define BT_BAUD_115200 "AT+UART=115200,0,0"
- #define DEFAULT_BAUD 9600
-
-
- #if defined (STM32F10X_HD) || defined (STM32F10X_HD_VL) || (STM32F10X_CL) || defined (STM32F10X_XL)
- #define FLASH_PAGE_SIZE ((uint16_t)0x800)
- #define FLASH_PAGES_TO_BE_PROTECTED (FLASH_WRProt_Pages12to13 | FLASH_WRProt_Pages14to15)
- #else
- #define FLASH_PAGE_SIZE ((uint16_t)0x400)
-
- #define FLASH_PAGES_TO_BE_PROTECTED (FLASH_WRProt_Pages60to63)
- #endif
-
-
- #define BANK1_WRITE_START_ADDR ((uint32_t)0x0800FC00)
- #define BANK1_WRITE_END_ADDR ((uint32_t)0x08010000)
-
-
-
-
-
- #define LEN_BUF 512
- struct _FIFO_Stack
- {
- unsigned char buf[LEN_BUF];
- short ptr_r;
- short ptr_w;
- };
-
-
- #define LEN_MATCH_STRING_HEADER 9
- struct _match_string_header
- {
- char match[LEN_MATCH_STRING_HEADER];
- int state;
- };
-
-
- #define LEN_MATCH_STRING_TAIL 3
- struct _match_string_tail
- {
- char match[LEN_MATCH_STRING_TAIL];
- int state;
- int value;
- int max_len;
- char capture_string[10];
- int capture_index;
- struct _match_string_header match_string_header;
- int flag;
- };
-
-
- struct _edit_flash
- {
- unsigned short buf[512];
- int flag;
- int baud;
- };
-
-
-
- extern USART_InitTypeDef USART_InitStructure;
-
-
- extern struct _FIFO_Stack fifo_uart2;
-
-
- extern struct _FIFO_Stack fifo_uart1;
-
-
- extern struct _edit_flash edit_flash;
-
-
-
- void send_bt_cmd(char *str);
-
-
-
- void init_fifo_stack(struct _FIFO_Stack *stack);
-
-
- short read_all_fifo_stack(struct _FIFO_Stack *stack,unsigned char *buf);
-
-
- int write_byte_fifo_stack(struct _FIFO_Stack *stack,unsigned char byte);
-
-
-
-
- int init_match_string_header(struct _match_string_header *m_str,char *buf);
-
- int match_string_header_state(struct _match_string_header *m_str,char ch);
-
-
-
-
- int init_match_string_tail(struct _match_string_tail *m_str,char *buf,int max_len);
-
- int match_string_tail_state(struct _match_string_tail *m_str,char ch);
-
-
-
- void open_write_lock();
-
-
- int write_flash(unsigned short *buf);
-
-
- int read_flash(unsigned short *buf);
-
-
-
- int read_baud(struct _edit_flash *edit);
-
-
- int write_baud(struct _edit_flash *edit,int baud);
-
- #endif