你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

紧急求助:请帮忙解决STM32usart通信问题

[复制链接]
tree0429 提问时间:2011-7-24 13:31 /
程序主要内容如下:
int main(void)
{
#ifdef DEBUG
  debug();
#endif
  int Tx_Data,Led_Seq;
  int i;
   /* System Clocks Configuration */
  RCC_Configuration();
  /* NVIC configuration */
  NVIC_Configuration(); 
 
  /* Configure the GPIO ports */
  GPIO_Configuration(); 
 
    /* Enable USART1 */
  USART_Cmd(USART1, ENABLE);
 
    /* Enable USART2 */
  USART_Cmd(USART2, ENABLE); 
/* USART1 configuration ------------------------------------------------------*/
  USART_InitStructure.USART_BaudRate = 9600;
  USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  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_InitStructure.USART_Clock = USART_Clock_Disable;
  USART_InitStructure.USART_CPOL = USART_CPOL_Low;
  USART_InitStructure.USART_CPHA = USART_CPHA_2Edge; 
  USART_InitStructure.USART_LastBit = USART_LastBit_Disable;
 
  /* Configure the USART1 */
  USART_Init(USART1, &USART_InitStructure);
  /* Configure the USART2 */
  USART_Init(USART2, &USART_InitStructure); 
 
 /* Enable the USART Transmoit interrupt: this interrupt is generated when the
     USART1 transmit data register is empty */
  //USART_ITConfig(USART1, USART_IT_RXNE, DISABLE);
   /* Enable the USART Receive interrupt: this interrupt is generated when the
   USART1 receive data register is not empty */
  USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
 
  /* Enable the USART Receive interrupt: this interrupt is generated when the
   USART1 receive data register is not empty */
  USART_ITConfig(USART2, USART_IT_RXNE, ENABLE); 
 
  /* Enable USART1 */
 // USART_Cmd(USART1, ENABLE);
  Tx_Data=0x30;
  
  
  while(1)
  {
    RxBuffer2[5] = 0xFF;

    USART_SendData(USART1, Tx_Data);

    //while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);
    RxBuffer2[5] = USART_ReceiveData(USART1);
  }
}
 
 
void USART_SendData(USART_TypeDef* USARTx, u16 Data)
{
  /* Check the parameters */
  assert(IS_USART_DATA(Data)); 
    
  USART_ITConfig(USART1, USART_IT_TXE, ENABLE);   
  USART_Cmd(USART1, ENABLE);
  /* Transmit Data */
  USARTx->DR = (Data & (u16)0x01FF);
  Data ++;
}
编译后执行到“USART_SendData(USART1, Tx_Data);
发生异常错误,程序跳转到程序最后。
请大家帮我看看是什么问题
收藏 评论4 发布时间:2011-7-24 13:31

举报

4个回答
hui235 回答时间:2011-7-24 23:09:25

RE:紧急求助:请帮忙解决STM32usart通信问题

发生什么异常?请把出错信息贴出来,
hui235 回答时间:2011-7-24 23:21:09

RE:紧急求助:请帮忙解决STM32usart通信问题

首先你的函数USART_SendData()里面的Data++用法是错误的,如果你想让传进来的值自加,要用指针,否则下次调用的时候实参的值是不会变的。
废鱼 回答时间:2011-7-25 08:44:16

RE:紧急求助:请帮忙解决STM32usart通信问题

void USART_SendData(USART_TypeDef* USARTx, u16 Data)
{
  /* Check the parameters */
  assert(IS_USART_DATA(Data));     
  //USART_ITConfig(USART1, USART_IT_TXE, ENABLE); 已经开启了中断,这里可以不用处理  
  //USART_Cmd(USART1, ENABLE);前面已经开启了,这个也可以不处理
  /* Transmit Data */
  USARTx->DR = (Data & (u16)0x01FF);
  Data ++;
}
tree0429 回答时间:2011-7-26 15:35:19

RE:紧急求助:请帮忙解决STM32usart通信问题

出错信息:
单步执行到USART_SendData(USART1, Tx_Data);时程序跳到0xfffffffe

所属标签

相似问题

关于意法半导体
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
招聘信息
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
关注我们
st-img 微信公众号
st-img 手机版