回复【2楼】正点原子:
---------------------------------
原子哥:还是不行啊。今天试了一天的。即使当作透明串口使用也不行啊。STM32压根收不到来自手机通过蓝牙模块发送过来的指令啊?麻烦您帮帮忙
我用的蓝牙是HC06模块
#include "led.h"
#include "delay.h"
#include "sys.h"
#include "usart.h"
#include "lcd.h"
#include "hc05.h"
#include "usart2.h"
#include "string.h"
#include "key.h"
// //????ATK-HC05???é???÷??×???
// void HC05_Role_Show(void)
// {
// if(HC05_Get_Role()==1)LCD_ShowString(30,140,200,16,16,"ROLE:Master"); //?÷?ú
// else LCD_ShowString(30,140,200,16,16,"ROLE:Slave "); //???ú
// }
//// ????ATK-HC05???é??????×???
// void HC05_Sta_Show(void)
// {
// f(HC05_LED)LCD_ShowString(120,140,120,16,16,"STA:Connected "); //????????
// else LCD_ShowString(120,140,120,16,16,"STAisconnect"); //??????
// }
int main(void)
{
u8 t;
u8 key;
u8 sendmask=0;
u8 sendcnt=0;
u8 sendbuf[20];
u8 reclen=0;
delay_init(); //???±??????????
NVIC_Configuration(); //?è??NVIC????·?×é2:2??????????????2???ì????????
uart_init(9600); //?®??????????9600
LED_Init(); //????????LED??????????????
KEY_Init(); //??????°??ü
LCD_Init(); //??????LCD
POINT_COLOR=RED;
LCD_ShowString(30,30,200,16,16,"ALIENTEK STM32 ^_^");
LCD_ShowString(30,50,200,16,16,"HC05 BLUETOOTH COM TEST");
LCD_ShowString(30,70,200,16,16,"ATOM@ALIENTEK");
HC05_Init();
// while(HC05_Init()) //??????ATK-HC05???é
// {
// LCD_ShowString(30,90,200,16,16,"ATK-HC05 Error!");
// delay_ms(500);
// LCD_ShowString(30,90,200,16,16,"Please Check!!!");
// delay_ms(100);
// }
LCD_ShowString(30,90,200,16,16,"WK_UP:ROLE KEY0:SEND/STOP");
LCD_ShowString(30,110,200,16,16,"ATK-HC05 Standby!");
LCD_ShowString(30,160,200,16,16,"Send:");
LCD_ShowString(30,180,200,16,16,"Receive:");
POINT_COLOR=BLUE;
// HC05_Role_Show();
while(1)
{
for(t=0;t<10;t++) //×??¤????50ms,??????HC05???é??????
{
if(USART2_RX_STA&0X8000)break;
delay_ms(5);
}
if(USART2_RX_STA&0X8000) //????????????????
{
reclen=USART2_RX_STA&0X7FFF; //?????????¤??
USART2_RX_BUF[reclen]=0; //?????á??·?
// if(reclen==9||reclen==8) //????DS1?ì??
// {
if(strcmp((const char*)USART2_RX_BUF,"ON")==0)LED0=0; //?ò??LED1
if(strcmp((const char*)USART2_RX_BUF,"OFF")==0)LED0=1;//??±?LED1
// }
LCD_ShowString(30,200,209,119,16,USART2_RX_BUF);//????????????????
}
USART2_RX_STA=0;
}
// while(1)
// {
// key=KEY_Scan(0);
// if(key==WKUP_PRES) //???????é?÷???è??
// {
// key=HC05_Get_Role(); //·?????:0,???ú;1,?÷?ú;0XFF,?????§°?.
// if(key!=0XFF)
// {
// key=!key; //×?????·?
// if(key==0)
// HC05_Set_Cmd("AT+ROLE=0"); //ATK-HC05?è???ü??,·?????:0,?è??????;????,?è???§°?.
// else HC05_Set_Cmd("AT+ROLE=1");
// HC05_Role_Show();
// HC05_Set_Cmd("AT+RESET"); //????ATK-HC05???é
// }
// }
// else if(key==KEY0_PRES)
// {
// sendmask=!sendmask; //·???/????·???
// if(sendmask==0)LCD_Fill(30+40,160,240,160+16,WHITE);//????????
// }
// else delay_ms(10);
// if(t==50)
// {
// if(sendmask) //?¨?±·???
// {
// sprintf((char*)sendbuf,"ALIENTEK HC05 %d\r\n",sendcnt);
// LCD_ShowString(30+40,160,200,16,16,sendbuf); //????·???????
// u2_printf("ALIENTEK HC05 %d\r\n",sendcnt); //·????????????é
// sendcnt++;
// if(sendcnt>99)sendcnt=0;
// }
// HC05_Sta_Show();
// t=0;
// LED0=!LED0;
// }
// if(USART2_RX_STA&0X8000) //????????????????
// {
// LCD_Fill(30,200,240,320,WHITE); //????????
// reclen=USART2_RX_STA&0X7FFF; //?????????¤??
// USART2_RX_BUF[reclen]=0; //?????á??·?
// if(reclen==9||reclen==8) //????DS1?ì??
// {
// if(strcmp((const char*)USART2_RX_BUF,"ON")==0)LED1=0; //?ò??LED1
// if(strcmp((const char*)USART2_RX_BUF,"OFF")==0)LED1=1;//??±?LED1
// }
// LCD_ShowString(30,200,209,119,16,USART2_RX_BUF);//????????????????
// USART2_RX_STA=0;
// }
// t++;
// }
}
|