OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 4347|回复: 2

STM32F103RBT6 串口发送问题

[复制链接]

1

主题

1

帖子

0

精华

新手入门

积分
25
金钱
25
注册时间
2014-9-15
在线时间
0 小时
发表于 2014-9-15 16:13:02 | 显示全部楼层 |阅读模式
5金钱
为什么我的串口给PC发送0x01,不成功,接收都是00.
void RCC_Configuration(void);
void GPIO_Configuration(void);
void NVIC_Configuration(void);

void Delay(__IO uint32_t nCount);

void USART_Config(USART_TypeDef* USARTx);

GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStruct;
USART_ClockInitTypeDef USART_ClockInitStruct;


/****************************************************************************
* ??    ????
* ??    ??
* ??????????
* ????????????
* ??    ?÷??
****************************************************************************/
void USART_Config(USART_TypeDef* USARTx){
  USART_InitStructure.USART_BaudRate = 115200; //????115200bps
  USART_InitStructure.USART_WordLength = USART_WordLength_8b; //??????8??
  USART_InitStructure.USART_StopBits = USART_StopBits_1; //??????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; //??·?????
  

  /* Configure USART1 */
  USART_Init(USARTx, &USART_InitStructure); //?????®??????????
  USART1->SR&=~(1<<7);
  
  /* Enable USART1 Receive and Transmit interrupts */
  USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);                    //????????????
  USART_ITConfig(USART1, USART_IT_TXE, ENABLE); //????·?????????????   

  /* Enable the USART1 */
  USART_Cmd(USART1, ENABLE);
}
/****************************************************************************
* ??    ????int main(void)
* ??    ?????÷????
* ????????????
* ????????????
* ??    ?÷??
* ?÷??·?·¨???? 
****************************************************************************/
int main(void)
{

  

  RCC_Configuration();  //?????±???è??

  NVIC_Configuration();  //??????????

 
  GPIO_Configuration();  //??????????

  USART_Config(USART1);  //?®??1??????

  USART_SendData(USART1,0x01); 
  while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);
  while (1);



}
/****************************************************************************
* ??    ????void Delay(__IO uint32_t nCount)
* ??    ???????±????
* ????????????
* ????????????
* ??    ?÷??
* ?÷??·?·¨???? 
****************************************************************************/
void Delay(__IO uint32_t nCount)
{
  for(; nCount != 0; nCount--);
}

/****************************************************************************
* ??    ????void RCC_Configuration(void)
* ??    ?????????±????????72MHZ?? ???è?±??????
* ????????????
* ????????????
* ??    ?÷??
* ?÷??·?·¨???? 
****************************************************************************/ 
void RCC_Configuration(void)
{
   SystemInit(); 
   RCC_APB2PeriphClockCmd( RCC_APB2Periph_USART1|RCC_APB2Periph_GPIOC |RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |RCC_APB2Periph_AFIO  , ENABLE);  
}

/****************************************************************************
* ??    ????void GPIO_Configuration(void)
* ??    ?????¨??IO??????
* ????????????
* ????????????
* ??    ?÷??
* ?÷??·?·¨??
****************************************************************************/  
void GPIO_Configuration(void)
{

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;     //LED3????--PB2
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //???ì????
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIOB, &GPIO_InitStructure);  

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;         //USART1 TX
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;     //???????ì????
  GPIO_Init(GPIOA, &GPIO_InitStructure);     //A???? 



}


/****************************************************************************
* ??    ????void NVIC_Configuration(void)
* ??    ??????????????
* ????????????
* ????????????
* ??    ?÷??
* ?÷??·?·¨???? 
****************************************************************************/
void NVIC_Configuration(void)
{
  /*  ?á???ù?÷*/
  NVIC_InitTypeDef NVIC_InitStructure;

  /* Configure the NVIC Preemption Priority Bits */  
  /* Configure one bit for preemption priority */
  /* ??????×é ???÷?????????????ù????????????×????????ù????????   ????????1?? 7 */    
  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);  
  

  NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;     //?è???®??1????
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;     //?????????? 0
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //×?????????0
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //????
  NVIC_Init(&NVIC_InitStructure);
}

最佳答案

查看完整内容[请看2#楼]

你的GPIO初始化一塌糊涂。。。 仔细看看去。。。 完全是胡乱写的。。。 void GPIO_Configuration(void) {   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;      //LED3????--PB2   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;  //???ì????   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;   GPIO_Init(G ...
正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

19

主题

122

帖子

0

精华

中级会员

Rank: 3Rank: 3

积分
218
金钱
218
注册时间
2014-8-20
在线时间
0 小时
发表于 2014-9-15 16:13:03 | 显示全部楼层
你的GPIO初始化一塌糊涂。。。
仔细看看去。。。
完全是胡乱写的。。。

void GPIO_Configuration(void)
{

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;      //LED3????--PB2
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;  //???ì????
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIOB, &GPIO_InitStructure);   

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;          //USART1 TX
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;      //???????ì????
  GPIO_Init(GPIOA, &GPIO_InitStructure);       //A???? 



}
回复

使用道具 举报

17

主题

342

帖子

0

精华

高级会员

Rank: 4

积分
544
金钱
544
注册时间
2014-4-24
在线时间
20 小时
发表于 2014-9-15 19:38:21 | 显示全部楼层
里面很多初始化都是瞎搞啊。先学好理论知识吧。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-7-5 19:56

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表