我在我的8051单片机上用硅实验室IDE写了一个代码。
在我的代码中,我试图与HC-06模块通信,并从带有UART连接到我的微控制器板的android应用程序中发送和接收数据。
但我无法接收从微控制器发送到android应用程序的数据,我也无法在微控制器上接收从android应用程序接收到的数据。
当我检查我的UART的Rx & Tx时,数据被正确地发送了。所以问题在HC-06模块中。
这是我的UART中断代码(在Silicon中):
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;
}
}
},这是我的init_devide代码:
#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();
}我的波特率设置为9600。
BT 06连接到UART0.
你能告诉我我做错了什么吗?为什么我的BT-HC-06不起作用?
非常感谢雷瑟夫
发布于 2018-10-02 21:46:00
确保满足以下基本条件,
连接
码校验
https://stackoverflow.com/questions/51028541
复制相似问题