STM32F103VET6 串口 初试
1.实验环境
1.野火STM32指南者(STM32F103VET6)
2.keil5
3.野火多功能调试助手.exe
参考:零死角玩转STM32F103—霸道_V2 开发板(20、21章)
2.修改源码
请下载野火相应章节源码进行修改
main.c
#include "stm32f10x.h"
#include "bsp_usart.h"
//延时
void delay(int i)
{
while(i)
{
i--;
};
}
int main(void)
{
USART_Config();
while(1)
{
//向上位机发送数据
delay(10000000);
printf( "hello windows!\n" );
}
}
/*********************************************END OF FILE**********************/
修改串口中断服务函数DEBUG_USART_IRQHandler,使得上位机发送‘stop’命令后,STM32停止数据发送。
该函数在stm32f10x_it.c文件中。
int i = 0;
uint8_t ucTemp[4];
void DEBUG_USART_IRQHandler(void)
{
if(i == 4)
{
i = 0;
}
if(USART_GetITStatus(DEBUG_USARTx,USART_IT_RXNE)!=RESET)
{
ucTemp[i] = USART_ReceiveData(DEBUG_USARTx);
// USART_SendData(DEBUG_USARTx,ucTemp[i]);
}
if(i == 3)
{
if(ucTemp[0] == 's' && ucTemp[1] == 't' && ucTemp[2] == 'o' && ucTemp[3] == 'p')
{
printf("Stop send!!!");
while(1){};
}
else
{
printf("Enter 'stop*' to stop\n");
i = -1;
}
}
i++;
}
3.效果