|
|
本帖最后由 southwolf 于 2013-10-3 03:27 编辑
事情的起因是这样的……
我在调试Microduino蓝牙模块的时候,本来是要设成115200 的,一不小心设置了它的波特率为鬼畜的1382400(不知道为啥是这个数字,模块的datasheet里支持的最高速度)
然后这个蓝牙模块竟然没有硬件的恢复出厂方法……只能通过串口发指令……问题是这个鬼畜的波特率我怎么可能连得上啊……
看了一下AVR的手册,貌似16Mhz的时候是可以支持到1mbps的,但仍然不能支持1382400
试了一下windows里以前用过的设置波特率 貌似不起作用……
[pre lang="C" line="1"]// SerialPort.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
HANDLE hCom;
DCB dcb;
BOOL bSuccess;
COMMTIMEOUTS CommTimeouts;
char* msg="AT+DEFAULT";
DWORD count = 0;
hCom = CreateFile(L"COM2",
GENERIC_READ|GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
0,
NULL
);
if(hCom==INVALID_HANDLE_VALUE)
{
printf("Com port open failed\n");
return 1;
}
memset(&dcb,0,sizeof(DCB));
bSuccess=GetCommState(hCom,&dcb);
if(!bSuccess)
{
printf("Com port info error!\n");
return 1;
}
GetCommTimeouts(hCom,&CommTimeouts);
CommTimeouts.ReadTotalTimeoutConstant=10;
CommTimeouts.WriteTotalTimeoutConstant=10;
if(!SetCommTimeouts(hCom,&CommTimeouts))
{
printf("Timeout set error!\n");
return 1;
}
bSuccess=SetCommState(hCom,&dcb);
dcb.BaudRate = 1382400;
if(!SetCommState(hCom, &dcb))
{
printf("Com state set error!\n");
return 1;
}
if(WriteFile(hCom, msg, 11, &count, NULL)==0)
{
printf("Write error!\n");
return 1;
}
CloseHandle(hCom);
return 0;
}
[/code] |
|