zigbee CC2530 series of 14 tutorials Bluetooth control experiment

Seeing all links courses:

zigbee CC2530 series of tutorials 0 Courses

 

4.14 Bluetooth control experiment

4.14.1 Purpose 

Learn to use Bluetooth module, and by FY serial control assistant.

4.14.2 Introductory Lecture

Determining first connection pin and a Bluetooth module according CC2530 chip development board hardware schematic diagram, shown in Figure 4-17.

Figure 4-17 Bluetooth module interface map

This section may refer to section 4.6, and serial data transceiver experiment Now Bluetooth module specification learning situation.

Bluetooth module Bluetooth module using the situation, pin definitions:

Bluetooth module TXD: Bluetooth module transmitting end, the communication must be connected properly RXD another device.

Bluetooth module RXD: Bluetooth module receiving end, normal communication must be connected to another device TXD.

Bluetooth module STATE: the state of the pin Bluetooth module, Bluetooth consistent state represented by the led (this pin is not used).

Bluetooth module EN: Enable Bluetooth module (This pin is not used).

Bluetooth module 5V: power pin Bluetooth module.

Bluetooth module GND: Ground pin of the Bluetooth module

Note: usually only TXD, RXD, 5V, GND can communicate

The main function of the program is as follows:

#include <iocc2530.h>

//LED灯IO定义

#define LED1   P1_0

#define LED2   P1_1

unsigned char temp;

void initUART0(void);

/****************************************************************

串口(UART0)初始化函数:

****************************************************************/

void initUART0(void)

{

    CLKCONCMD &= ~0x40;      //设置系统时钟源为32MHZ晶振

    while(CLKCONSTA & 0x40);   //等待晶振稳定

    CLKCONCMD &= ~0x47;     //设置系统主时钟频率为32MHZ

    PERCFG = 0x00;             //位置1 P0口

    P0SEL = 0x3c;            //P0用作串口

    P2DIR &= ~0XC0;           //P0优先作为UART0    

    U0CSR |= 0x80;            //串口设置为UART方式

    U0GCR |= 8;

    U0BAUD |= 59;              //波特率设为9600

    UTX0IF = 1;              //UART0 TX中断标志初始置位1    

    U0CSR |= 0X40;      //允许接收

    IEN0 |= 0x84;            //开总中断,接收中断

}

/****************************************************************

主函数

****************************************************************/

void main(void)

{

    /******LED P1_0,P1_1方向初始化******/

    P1DIR |= 0x03;     //P1_0,P1_1设置为输出模式    

    LED1 = 1;         //熄灭LED1

    LED2 = 1;         //熄灭LED2

    initUART0();

    while(1)

    {

        if(temp == 0x01)

        {

            LED1 = 0;         //点亮LED1

        }

        if(temp == 0x02)

        {

            LED2 = 0;         //点亮LED2

        }

        if(temp == 0x11)

        {

            LED1 = 1;         //熄灭LED1

        }

        if(temp == 0x22)

        {

            LED2 = 1;         //熄灭LED2

        }

    }

}

/****************************************************************

一旦有数据从串口传至CC2530,则进入中断,将接收到的数据赋值给变量temp.

****************************************************************/

#pragma vector = URX0_VECTOR

 __interrupt void UART0_ISR(void)

{

    URX0IF = 0; //清中断标志

    temp = U0DBUF;

}

4.14.3 experimental results

The situation Bluetooth module development board patch into place, pay attention to the direction of the patch, follow the instructions correctly plug into, and then download the program, install to install phone assistant FY Bluetooth serial port, shown in Figure 4-18, connect a Bluetooth phone module, transmission command as follows:

0x01 transmission instruction, development board D3 (LED1) lights, send commands 0x11, development board D3 (LED1) is off;

0x02 transmission instruction boards D4 (LED2) lights, send commands 0x22, boards D4 (LED2) is off.

Published 133 original articles · won praise 51 · Views 200,000 +

Guess you like

Origin blog.csdn.net/aa120515692/article/details/104007216