写了一个串口
通信实验,接的蓝牙,发送指令后,正确的话应该能收到OK,但是现在就是没有返回。
void USART_Config(void)
{
GPIO_Init(GPIOC,GPIO_Pin_6,GPIO_Mode_In_PU_No_IT);
GPIO_Init(GPIOC,GPIO_Pin_5,GPIO_Mode_Out_PP_Low_Fast);
CLK_PeripheralClockConfig(CLK_Peripheral_USART1,
ENABLE);
USART_DeInit(USART1);
USART_Init(USART1,
(u32)9600,
USART_WordLength_8b,
USART_StopBits_1,
USART_Parity_No,
(USART_Mode_TypeDef)(USART_Mode_Tx |USART_Mode_Rx ));
USART_Cmd(USART1,ENABLE);
}
PUTCHAR_PROTOTYPE
{
if(ch =='n')
{
while(!(USART1->SR USART_FLAG_TC ));
USART_SendData8(USART1,'r');
while(!(USART1->SR USART_FLAG_TC ));
}
while(!(USART1->SR USART_FLAG_TXE ));
USART_SendData8(USART1,ch);
while(!(USART1->SR USART_FLAG_TXE ));
return (ch);
}
//主函数
void main(void)
{
char zsh[]="AT+CBn";
// disableInterrupts();
// enableInterrupts();
CLK_Config();
USART_Config();
/*
GPIO_Init(GPIOB,
GPIO_Pin_0,
(GPIO_Mode_TypeDef)GPIO_Mode_Out_PP_High_Slow);//BT_RESET/
*/
while(1){
// scan_key();
/*
GPIOB ->ODR =~GPIOB ->ODR;
DelayMS(1000);
GPIOB ->ODR =~GPIOB ->ODR;
*/
cnt = 0;
printf("AT+CArn");
while(temp !=' n'){
while(!(USART_FLAG_RXNE USART1_SR) );
temp = USART_ReceiveData8(USART1);
buf[cnt++]=temp;
}
DelayMS(100);
}
}