首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >BT HC-06没有从8051接收数据

BT HC-06没有从8051接收数据
EN

Stack Overflow用户
提问于 2018-06-25 17:03:17
回答 1查看 286关注 0票数 0

我在我的8051单片机上用硅实验室IDE写了一个代码。

在我的代码中,我试图与HC-06模块通信,并从带有UART连接到我的微控制器板的android应用程序中发送和接收数据。

但我无法接收从微控制器发送到android应用程序的数据,我也无法在微控制器上接收从android应用程序接收到的数据。

当我检查我的UART的Rx & Tx时,数据被正确地发送了。所以问题在HC-06模块中。

这是我的UART中断代码(在Silicon中):

代码语言:javascript
复制
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代码:

代码语言:javascript
复制
#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不起作用?

非常感谢雷瑟夫

EN

回答 1

Stack Overflow用户

发布于 2018-10-02 21:46:00

确保满足以下基本条件,

连接

  1. 检查地是常见的。模块和芯片都接通了电源。
  2. 确保8051_TX->Module_Rx和Module_Tx->8051_Rx连接。
  3. 检查两者是否使用3.3V进行通信(使用电阻电平移位器)。

码校验

  1. 试着做空你的芯片Rx到Tx,看看你是否能够接收回波。
  2. 如果您有USB到UART转换器,请尝试直接连接模块(检查电压)并检查数据传输。
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51028541

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档