Bluetooth BT HC-06未从8051接收数据
我正在硅实验室IDE上的8051微控制器上写代码 在我的代码中,我试图与HC-06模块通信,并通过UART连接到我的微控制器板,从android应用程序发送和接收数据 但是我无法接收从微控制器发送到android应用程序的数据,也无法接收从微控制器上的android应用程序接收的数据 当我检查UART的接收和发送时,数据发送正确。所以问题出在HC-06模块上 这是我的UART中断代码(在Silicon Labs IDE中):Bluetooth BT HC-06未从8051接收数据,bluetooth,arduino,microcontroller,android-bluetooth,8051,Bluetooth,Arduino,Microcontroller,Android Bluetooth,8051,我正在硅实验室IDE上的8051微控制器上写代码 在我的代码中,我试图与HC-06模块通信,并通过UART连接到我的微控制器板,从android应用程序发送和接收数据 但是我无法接收从微控制器发送到android应用程序的数据,也无法接收从微控制器上的android应用程序接收的数据 当我检查UART的接收和发送时,数据发送正确。所以问题出在HC-06模块上 这是我的UART中断代码(在Silicon Labs IDE中): void UART0_BT_ISR(void) interrupt 4
void UART0_BT_ISR(void) interrupt 4
{
if(TI0==1)
{
TI0=0;
while(TI0 == 0);
TI0=0;
}
if(RI0==1)
{
UART0_Buffer[BTi]=SBUF0;
BTi++;
RI0 = 0;
}
}
void SendUARTData(char* FunkKey)
{
i=0;
while(1)
{
if(TI0==0)
{
SBUF0=FunkKey[i];
i++;
TI0=1;
}
if(i>16)
{
return;
i=0;
}
}
}
#include "compiler_defs.h"
#include "C8051F020_defs.h"
// Peripheral specific initialization functions,
// Called from the Init_Device() function
void Reset_Sources_Init()
{
WDTCN = 0xDE;
WDTCN = 0xAD;
}
void Timer_Init()
{
CKCON = 0x30;
TCON = 0x40;
TMOD = 0x20;
TH1 = 0xB8;
T2CON = 0x34;
RCAP2L = 0xB8;
RCAP2H = 0xFF;
}
void UART_Init()
{
SCON0 = 0x50;
SCON1 = 0x40;
}
void Port_IO_Init()
{
// P0.0 - TX0 (UART0), Push-Pull, Digital
// P0.1 - RX0 (UART0), Open-Drain, Digital
// P0.2 - TX1 (UART1), Push-Pull, Digital
// P0.3 - RX1 (UART1), Open-Drain, Digital
// P0.4 - Unassigned, Open-Drain, Digital
// P0.5 - Unassigned, Open-Drain, Digital
// P0.6 - Unassigned, Open-Drain, Digital
// P0.7 - Unassigned, Open-Drain, Digital
// P1.0 - Unassigned, Push-Pull, Digital
// P1.1 - Unassigned, Push-Pull, Digital
// P1.2 - Unassigned, Push-Pull, Digital
// P1.3 - Unassigned, Open-Drain, Digital
// P1.4 - Unassigned, Open-Drain, Digital
// P1.5 - Unassigned, Push-Pull, Digital
// P1.6 - Unassigned, Push-Pull, Digital
// P1.7 - Unassigned, Push-Pull, Digital
// P2.0 - Unassigned, Open-Drain, Digital
// P2.1 - Unassigned, Open-Drain, Digital
// P2.2 - Unassigned, Open-Drain, Digital
// P2.3 - Unassigned, Open-Drain, Digital
// P2.4 - Unassigned, Open-Drain, Digital
// P2.5 - Unassigned, Open-Drain, Digital
// P2.6 - Unassigned, Open-Drain, Digital
// P2.7 - Unassigned, Open-Drain, Digital
// P3.0 - Unassigned, Open-Drain, Digital
// P3.1 - Unassigned, Open-Drain, Digital
// P3.2 - Unassigned, Open-Drain, Digital
// P3.3 - Unassigned, Open-Drain, Digital
// P3.4 - Unassigned, Push-Pull, Digital
// P3.5 - Unassigned, Push-Pull, Digital
// P3.6 - Unassigned, Push-Pull, Digital
// P3.7 - Unassigned, Push-Pull, Digital
P0MDOUT = 0x05;
P1MDOUT = 0xE7;
P3MDOUT = 0xF0;
XBR0 = 0x04;
XBR2 = 0x44;
}
void Oscillator_Init()
{
int i = 0;
OSCXCN = 0x67;
for (i = 0; i < 3000; i++); // Wait 1ms for initialization
while ((OSCXCN & 0x80) == 0);
OSCICN = 0x0C;
}
void Interrupts_Init()
{
IE = 0x90;
IP = 0x10;
}
// Initialization function for device,
// Call Init_Device() from your main program
void Init_Device(void)
{
Reset_Sources_Init();
Timer_Init();
UART_Init();
Port_IO_Init();
Oscillator_Init();
Interrupts_Init();
}
这是我的初始设备代码:
void UART0_BT_ISR(void) interrupt 4
{
if(TI0==1)
{
TI0=0;
while(TI0 == 0);
TI0=0;
}
if(RI0==1)
{
UART0_Buffer[BTi]=SBUF0;
BTi++;
RI0 = 0;
}
}
void SendUARTData(char* FunkKey)
{
i=0;
while(1)
{
if(TI0==0)
{
SBUF0=FunkKey[i];
i++;
TI0=1;
}
if(i>16)
{
return;
i=0;
}
}
}
#include "compiler_defs.h"
#include "C8051F020_defs.h"
// Peripheral specific initialization functions,
// Called from the Init_Device() function
void Reset_Sources_Init()
{
WDTCN = 0xDE;
WDTCN = 0xAD;
}
void Timer_Init()
{
CKCON = 0x30;
TCON = 0x40;
TMOD = 0x20;
TH1 = 0xB8;
T2CON = 0x34;
RCAP2L = 0xB8;
RCAP2H = 0xFF;
}
void UART_Init()
{
SCON0 = 0x50;
SCON1 = 0x40;
}
void Port_IO_Init()
{
// P0.0 - TX0 (UART0), Push-Pull, Digital
// P0.1 - RX0 (UART0), Open-Drain, Digital
// P0.2 - TX1 (UART1), Push-Pull, Digital
// P0.3 - RX1 (UART1), Open-Drain, Digital
// P0.4 - Unassigned, Open-Drain, Digital
// P0.5 - Unassigned, Open-Drain, Digital
// P0.6 - Unassigned, Open-Drain, Digital
// P0.7 - Unassigned, Open-Drain, Digital
// P1.0 - Unassigned, Push-Pull, Digital
// P1.1 - Unassigned, Push-Pull, Digital
// P1.2 - Unassigned, Push-Pull, Digital
// P1.3 - Unassigned, Open-Drain, Digital
// P1.4 - Unassigned, Open-Drain, Digital
// P1.5 - Unassigned, Push-Pull, Digital
// P1.6 - Unassigned, Push-Pull, Digital
// P1.7 - Unassigned, Push-Pull, Digital
// P2.0 - Unassigned, Open-Drain, Digital
// P2.1 - Unassigned, Open-Drain, Digital
// P2.2 - Unassigned, Open-Drain, Digital
// P2.3 - Unassigned, Open-Drain, Digital
// P2.4 - Unassigned, Open-Drain, Digital
// P2.5 - Unassigned, Open-Drain, Digital
// P2.6 - Unassigned, Open-Drain, Digital
// P2.7 - Unassigned, Open-Drain, Digital
// P3.0 - Unassigned, Open-Drain, Digital
// P3.1 - Unassigned, Open-Drain, Digital
// P3.2 - Unassigned, Open-Drain, Digital
// P3.3 - Unassigned, Open-Drain, Digital
// P3.4 - Unassigned, Push-Pull, Digital
// P3.5 - Unassigned, Push-Pull, Digital
// P3.6 - Unassigned, Push-Pull, Digital
// P3.7 - Unassigned, Push-Pull, Digital
P0MDOUT = 0x05;
P1MDOUT = 0xE7;
P3MDOUT = 0xF0;
XBR0 = 0x04;
XBR2 = 0x44;
}
void Oscillator_Init()
{
int i = 0;
OSCXCN = 0x67;
for (i = 0; i < 3000; i++); // Wait 1ms for initialization
while ((OSCXCN & 0x80) == 0);
OSCICN = 0x0C;
}
void Interrupts_Init()
{
IE = 0x90;
IP = 0x10;
}
// Initialization function for device,
// Call Init_Device() from your main program
void Init_Device(void)
{
Reset_Sources_Init();
Timer_Init();
UART_Init();
Port_IO_Init();
Oscillator_Init();
Interrupts_Init();
}
#包括“compiler_defs.h”
#包括“C8051F020_defs.h”
//特定于外围设备的初始化功能,
//从Init_Device()函数调用
void Reset_Sources_Init()
{
WDTCN=0xDE;
WDTCN=0xAD;
}
void Timer_Init()
{
CKCON=0x30;
TCON=0x40;
TMOD=0x20;
TH1=0xB8;
T2CON=0x34;
RCAP2L=0xB8;
RCAP2H=0xFF;
}
void UART_Init()
{
SCON0=0x50;
SCON1=0x40;
}
无效端口IO初始化()
{
//P0.0-TX0(UART0),推拉式,数字
//P0.1-RX0(UART0),明沟,数字
//P0.2-TX1(UART1),推挽式,数字
//P0.3-RX1(UART1),开漏,数字
//P0.4-未分配、明渠、数字
//P0.5-未分配、明渠、数字
//P0.6-未分配、明渠、数字
//P0.7-未分配、明渠、数字
//P1.0-未分配、推拉、数字
//P1.1-未分配、推拉、数字
//P1.2-未分配、推拉、数字
//P1.3-未分配、明渠、数字
//P1.4-未分配、明渠、数字
//P1.5-未分配、推拉、数字
//P1.6-未分配、推拉、数字
//P1.7-未分配、推拉、数字
//P2.0-未分配、明渠、数字
//P2.1-未分配、明渠、数字
//P2.2-未分配、明渠、数字
//P2.3-未分配、明渠、数字
//P2.4-未分配、明渠、数字
//P2.5-未分配、明渠、数字
//P2.6-未分配、明渠、数字
//P2.7-未分配、明渠、数字
//P3.0-未分配、明渠、数字
//P3.1-未分配、明渠、数字
//P3.2-未分配、明渠、数字
//P3.3-未分配、明渠、数字
//P3.4-未分配、推拉、数字
//P3.5-未分配、推拉、数字
//P3.6-未分配、推拉、数字
//P3.7-未分配、推拉、数字
P0MDOUT=0x05;
P1MDOUT=0xE7;
P3MDOUT=0xF0;
XBR0=0x04;
XBR2=0x44;
}
void振荡器_Init()
{
int i=0;
OSCXCN=0x67;
for(i=0;i<3000;i++);//等待1ms进行初始化
而((OSCXCN&0x80)==0);
OSCICN=0x0C;
}
void中断_Init()
{
IE=0x90;
IP=0x10;
}
//设备的初始化功能,
//从主程序调用Init_Device()
void Init_设备(void)
{
重置_源_Init();
计时器_Init();
UART_Init();
端口IO初始化();
振荡器_Init();
中断_Init();
}
我的波特率设置为9600
BT HC-06连接到UART0
你能告诉我我做错了什么,为什么我的BT HC-06不能工作
多谢各位
Reshef确保满足以下基本条件 连接