专家
公告
财富商城
电子网
旗下网站
首页
问题库
专栏
标签库
话题
专家
NEW
门户
发布
提问题
发文章
STM32
求大神帮助~~stm32f103c8t6的串口调试~~~~~~~~~~~
2019-08-14 03:23
发布
×
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
站内问答
/
STM32/STM8
5809
12
1655
最基础的就有点不会,想要发数据到串口三的,我把原子的源码包里的实验四串口实验的USART1全部改成了3,发现没反应,这是为什么~~~~~~连printf函数的内容都不显示~~~请问配置串口还需要做什么~~~~
usart.c已经被我改的面目全非。。。。。。5555555~~~~
主要改动如下:
友情提示:
此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
12条回答
明夕何夕君已陌路
2019-08-15 01:28
回复【3楼】正点原子:
---------------------------------
各种折腾还是不行%>_<%就是串口没有一点东西显示,
usrt.c:
void uart_init(u32 bound){
//GPIO?????è??
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
//NVIC_InitTypeDef NVIC_InitStructure;
//USART_ClockInitTypeDef USART_ClockInitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_AFIO,ENABLE); //????USART3??GPIOB?±??
//USART3_TX  
B.10
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; //PB.10
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //???????ì????
GPIO_Init(GPIOB, &GPIO_InitStructure);
//USART3_RX  
B.11
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;//????????
GPIO_Init(GPIOB, &GPIO_InitStructure);
//Usart3 NVIC ????
/* NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3 ;//??????????3
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //×???????3
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ?¨??????
NVIC_Init(&NVIC_InitStructure); //?ù?????¨????????????VIC?????÷
*/
//USART ???????è??
/*
USART_ClockInitStructure.USART_Clock = USART_Clock_Disable; // ?±????????????
USART_ClockInitStructure.USART_CPOL = USART_CPOL_Low; // ?±????????
USART_ClockInitStructure.USART_CPHA = USART_CPHA_2Edge; //?±????????±???????????????
USART_ClockInitStructure.USART_LastBit = USART_LastBit_Disable; // ×??ó???????????±??±???????SCLK??
Configure the USART3 synchronous paramters */
//USART_ClockInit(USART3, &USART_ClockInitStructure); // ?±?????????????è??
USART_InitStructure.USART_BaudRate = bound;//??°??è????9600;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;//×??¤??8??????????
USART_InitStructure.USART_StopBits = USART_StopBits_1;//??????????
USART_InitStructure.USART_Parity = USART_Parity_No;//?????????é??
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//???????????÷????
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //??·?????
USART_Init(USART3, &USART_InitStructure); //??????????
// USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);//????????
USART_Cmd(USART3, ENABLE); //????????
//USART_ClearFlag(USART3, USART_FLAG_TC);
//USART_ClearFlag(USART3, USART_FLAG_TXE);
}
void USART3_IRQHandler(void) //????3????·??????ò
{
u8 Res;
#ifdef OS_TICKS_PER_SEC //?????±?????????¨????,???÷??????ucosII??.
OSIntEnter();
#endif
if(USART_GetITStatus(USART3, USART_IT_RXNE) != RESET) //????????(????????????±?????0x0d 0x0a?á??)
{
Res =USART_ReceiveData(USART3);//(USART1->DR); //????????????????
if((USART_RX_STA&0x8000)==0)//???????ê??
{
if(USART_RX_STA&0x4000)//????????0x0d
{
if(Res!=0x0a)USART_RX_STA=0;//?????í?ó,????????
else USART_RX_STA|=0x8000; //?????ê????
}
else //????????0X0D
{
if(Res==0x0d)USART_RX_STA|=0x4000;
else
{
USART_RX_BUF[USART_RX_STA&0X3FFF]=Res ;
USART_RX_STA++;
if(USART_RX_STA>(USART_REC_LEN-1))USART_RX_STA=0;//?????????í?ó,????????????
}
}
}
}
我直接在main.c开头加了一句USART_SendData(USART3, 0x01);
如下:
while(1)
{//printf(" ????STM32??·?°? ???????é ")??????
USART_SendData(USART3, 0x01);
if(USART_RX_STA&0x8000) //???????ê??
{
len=USART_RX_STA&0x3f;//?????????????????????¤??
printf(" ?ú·???????????: ");
for(t=0;t<len;t++)
{
USART_SendData(USART3, USART_RX_BUF[t]);//?ò????3·???????
while(USART_GetFlagStatus(USART3,USART_FLAG_TC)!=SET);//????·????á??
if(times%30==0)
LED0=!LED0;
}
printf(" ");//????????
USART_RX_STA=0;
}
else
{
times++;
if(times%5000==0)
{
printf(" ????STM32??·?°? ???????é ");
printf("??????×?@ALIENTEK ");
}
if(times%200==0)
printf("??????????,???????ü?á?? ");
//if(times%30==0)
//LED0=!LED0;//????LED,?á??????????????.
delay_ms(10);
}
}
}
还是没有任何的显示任何的反应,单步调试在主函数每次都是跳到执行else time++这是为什么%>_<%%>_<%%>_<%
求站长大大帮我看看~~~
加载中...
查看其它12个回答
一周热门
更多
>
相关问题
STM32F4上I2C(在PROTEUS中模拟)调试不通的问题
6 个回答
芯片供应紧张,准备换个MCU,MM32L系列替换STM32L系列的怎么样?
7 个回答
STM32同时使用两个串口进行数据收发时数据丢包的问题
5 个回答
STM32F103串口通信死机问题
4 个回答
STM32WLE5CC连接SX1268在LoRa模式下能与 SX1278互通吗?
2 个回答
相关文章
ST公司第一款无线低功耗单片机模块有效提高物联网设计生产效率
0个评论
如何实现对单片机寄存器的访问
0个评论
通过USB用STM32片内自带Bootloader下载程序及注意事项
0个评论
欲练此功必先自宫之STM32汇编启动,放慢是为了更好的前行
0个评论
×
关闭
采纳回答
向帮助了您的知道网友说句感谢的话吧!
非常感谢!
确 认
×
关闭
编辑标签
最多设置5个标签!
STM32
保存
关闭
×
关闭
举报内容
检举类型
检举内容
检举用户
检举原因
广告推广
恶意灌水
回答内容与提问无关
抄袭答案
其他
检举说明(必填)
提交
关闭
×
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
×
付费偷看金额在0.1-10元之间
确定
×
关闭
您已邀请
0
人回答
查看邀请
擅长该话题的人
回答过该话题的人
我关注的人
---------------------------------
各种折腾还是不行%>_<%就是串口没有一点东西显示,
usrt.c:
void uart_init(u32 bound){
//GPIO?????è??
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
//NVIC_InitTypeDef NVIC_InitStructure;
//USART_ClockInitTypeDef USART_ClockInitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_AFIO,ENABLE); //????USART3??GPIOB?±??
//USART3_TX  B.10
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; //PB.10
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //???????ì????
GPIO_Init(GPIOB, &GPIO_InitStructure);
//USART3_RX  B.11
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;//????????
GPIO_Init(GPIOB, &GPIO_InitStructure);
//Usart3 NVIC ????
/* NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3 ;//??????????3
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //×???????3
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ?¨??????
NVIC_Init(&NVIC_InitStructure); //?ù?????¨????????????VIC?????÷
*/
//USART ???????è??
/*
USART_ClockInitStructure.USART_Clock = USART_Clock_Disable; // ?±????????????
USART_ClockInitStructure.USART_CPOL = USART_CPOL_Low; // ?±????????
USART_ClockInitStructure.USART_CPHA = USART_CPHA_2Edge; //?±????????±???????????????
USART_ClockInitStructure.USART_LastBit = USART_LastBit_Disable; // ×??ó???????????±??±???????SCLK??
Configure the USART3 synchronous paramters */
//USART_ClockInit(USART3, &USART_ClockInitStructure); // ?±?????????????è??
USART_InitStructure.USART_BaudRate = bound;//??°??è????9600;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;//×??¤??8??????????
USART_InitStructure.USART_StopBits = USART_StopBits_1;//??????????
USART_InitStructure.USART_Parity = USART_Parity_No;//?????????é??
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//???????????÷????
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //??·?????
USART_Init(USART3, &USART_InitStructure); //??????????
// USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);//????????
USART_Cmd(USART3, ENABLE); //????????
//USART_ClearFlag(USART3, USART_FLAG_TC);
//USART_ClearFlag(USART3, USART_FLAG_TXE);
}
void USART3_IRQHandler(void) //????3????·??????ò
{
u8 Res;
#ifdef OS_TICKS_PER_SEC //?????±?????????¨????,???÷??????ucosII??.
OSIntEnter();
#endif
if(USART_GetITStatus(USART3, USART_IT_RXNE) != RESET) //????????(????????????±?????0x0d 0x0a?á??)
{
Res =USART_ReceiveData(USART3);//(USART1->DR); //????????????????
if((USART_RX_STA&0x8000)==0)//???????ê??
{
if(USART_RX_STA&0x4000)//????????0x0d
{
if(Res!=0x0a)USART_RX_STA=0;//?????í?ó,????????
else USART_RX_STA|=0x8000; //?????ê????
}
else //????????0X0D
{
if(Res==0x0d)USART_RX_STA|=0x4000;
else
{
USART_RX_BUF[USART_RX_STA&0X3FFF]=Res ;
USART_RX_STA++;
if(USART_RX_STA>(USART_REC_LEN-1))USART_RX_STA=0;//?????????í?ó,????????????
}
}
}
}
我直接在main.c开头加了一句USART_SendData(USART3, 0x01);
如下:
while(1)
{//printf(" ????STM32??·?°? ???????é ")??????
USART_SendData(USART3, 0x01);
if(USART_RX_STA&0x8000) //???????ê??
{
len=USART_RX_STA&0x3f;//?????????????????????¤??
printf(" ?ú·???????????: ");
for(t=0;t<len;t++)
{
USART_SendData(USART3, USART_RX_BUF[t]);//?ò????3·???????
while(USART_GetFlagStatus(USART3,USART_FLAG_TC)!=SET);//????·????á??
if(times%30==0)
LED0=!LED0;
}
printf(" ");//????????
USART_RX_STA=0;
}
else
{
times++;
if(times%5000==0)
{
printf(" ????STM32??·?°? ???????é ");
printf("??????×?@ALIENTEK ");
}
if(times%200==0)
printf("??????????,???????ü?á?? ");
//if(times%30==0)
//LED0=!LED0;//????LED,?á??????????????.
delay_ms(10);
}
}
}
还是没有任何的显示任何的反应,单步调试在主函数每次都是跳到执行else time++这是为什么%>_<%%>_<%%>_<%
求站长大大帮我看看~~~
一周热门 更多>