本帖最后由 RUnewhand 于 2010-3-10 16:40 编辑
单片机实验板和蓝牙适配器(清华紫光25元一个)连接,用的是两头都是母口接口。如图:
基于HCI层协议,通过UART0向蓝牙发送reset指令:即 01 03 0C 00 按道理来说应该返回:040E0401030C00(指令完成)。但蓝牙模块没有任何反应。部分程序如下(串口初始化已经完成):我设置的串口通讯速率为9600bps,8位数据位,1位停止。
void main (void) {
PCA0MD &= ~0x40; // Disable Watchdog timer
SYSTEMCLOCK_Init (); // initialize oscillator
PORT_Init (); // initialize crossbar and GPIO
TH1 = -(SYSCLK/BAUDRATE0/2/12);
CKCON &= ~0x0B;
SCON= 0x30;
TL1 = TH1; // init Timer1
TMOD &= ~0xf0; // TMOD: timer 1 in 8-bit autoreload
TMOD |= 0x20;
TR1 = 1; // START Timer1
IP |= 0x10; // Make UART high priority
TI0 = 0;
ES0 = 1; // Enable UART0 interrupts
SBUF0 = 0x01;
while(!TI0);
TI0 = 0;
SBUF0 = 0x03;
while(!TI0);
TI0 = 0;
SBUF0 = 0x0c;
while(!TI0);
TI0 = 0;
SBUF0 = 0x00;
while(!TI0);
TI0 = 0;
EA = 1;
ES0 = 1;
while (1);//等待返回命令
}
void SYSTEMCLOCK_Init (void)
{
OSCICN |= 0x03; // Configure internal oscillator for
// its maximum frequency and enable
// missing clock detector
CLKMUL = 0x00; // Select internal oscillator as
// input to clock multiplier
CLKMUL |= 0x80; // Enable clock multiplier
Delay(); // Delay for clock multiplier to begin
CLKMUL |= 0xC0; // Initialize the clock multiplier
Delay(); // Delay for clock multiplier to begin
while(!(CLKMUL & 0x20)); // Wait for multiplier to lock
CLKSEL = 0x03; // Select system clock
}
void PORT_Init (void)
{
XBR0 = 0x01; // route UART 0 to crossbar
XBR2 = 0x01; // route UART 1 to crossbar
XBR1 = 0x40; // enable crossbar
P0MDOUT |= 0x11; // set P0.4 to push-pull output
P0MDOUT |= 0x0f;
P2MDOUT |= 0x04; // set LED to push-pull
P2MDIN |= 0x0F; // Lower four pins on P2 are digital
P2MDOUT = 0x0C; // enable LEDs as push-pull outputs
// enable Switches as open-drain
P2 |= 0x03; // Set port latches for P2.0
// and P2.1 to '1'
}
请问是哪里出了问题? |