单片机是STM32F103RBT6,调试GPRS,USART2接SIM900A模块,UASRT1用来向电脑发送信息。
一直没有标准的库函数版本,就参考了一下程序,自己写了下,能够正常和模块通信,但是程序printf结束之后总会打印出8,然后就硬件错误。经验不足,特来向大家
请教。
上代码:
主函数:简单的测试程序
[mw_shl_code=c,true]int main(void)
{
USART1_Config();
SIM900A_Config();
printf("\r\nWF-SIM900A model Test!\r\n");
while(sim900a_cmd("AT\r","OK",10) != SIM900A_TRUE)
{
printf("\r\nSIM900A module error!\r\n");
}
sim900a_cmd("AT+CGATT=1\r","",10) ;
printf("\r\n SIM900A test access!\r\n");
}[/mw_shl_code]
程序运行截图如下:
在printf("\r\n SIM900A test access!\r\n");执行结束之后,就又跳回了printf中。。。
一些中断函数:
串口2的:
[mw_shl_code=c,true]void bsp_USART2_IRQHandler(void)
{
if(Receive_Length<UART_BUFF_SIZE )
{
// if this is the first data to receive ,enable the TIM2
if (Receive_Length == 0) TIM_Cmd(TIM2, ENABLE);
if(USART_GetITStatus(USART2, USART_IT_RXNE) != RESET)
{
/*-----------the second method to update the TIM2*************/
TIM2->CNT=0;
uart_buff[Receive_Length] = USART_ReceiveData(USART2);
Receive_Length++;
}
}
else
{
Receive_Length|=1<<15; //terminating symbol
}
}[/mw_shl_code]
TIM2中断:
[mw_shl_code=c,true]void My_TIM2_IRQHandler(void)
{
if (TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET)
{
TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
Receive_Length|=1<<15;
uart_buff[Receive_Length&0x7fff] ='\0';//the end of the received string ('\0')
printf("Have received all the data this time!Wait next time!\n");
TIM_Cmd(TIM2,DISABLE);//close the TIM2
// clean_rebuff();
}
}[/mw_shl_code]
另附工程,感谢各位的指导!
|