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

查看: 2710|回复: 4

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

[复制链接]

1

主题

12

回帖

0

蝴蝶豆

新手上路

最后登录
1970-1-1
发表于 2011-7-24 13:31:56 | 显示全部楼层 |阅读模式
程序主要内容如下:
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);
发生异常错误,程序跳转到程序最后。
请大家帮我看看是什么问题
<
回复

使用道具 举报

11

主题

57

回帖

0

蝴蝶豆

中级会员

最后登录
1970-1-1
发表于 2011-7-24 23:09:25 | 显示全部楼层

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

发生什么异常?请把出错信息贴出来,
回复 支持 反对

使用道具 举报

11

主题

57

回帖

0

蝴蝶豆

中级会员

最后登录
1970-1-1
发表于 2011-7-24 23:21:09 | 显示全部楼层

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

首先你的函数USART_SendData()里面的Data++用法是错误的,如果你想让传进来的值自加,要用指针,否则下次调用的时候实参的值是不会变的。
回复 支持 反对

使用道具 举报

134

主题

4489

回帖

239

蝴蝶豆

版主

最后登录
2020-12-9
发表于 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-&gt;DR = (Data &amp; (u16)0x01FF);
  Data ++;
}
回复 支持 反对

使用道具 举报

1

主题

12

回帖

0

蝴蝶豆

新手上路

最后登录
1970-1-1
 楼主| 发表于 2011-7-26 15:35:19 | 显示全部楼层

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

出错信息:
单步执行到USART_SendData(USART1, Tx_Data);时程序跳到0xfffffffe
回复 支持 反对

使用道具 举报

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32N6 AI生态系统
STM32MCU,MPU高性能GUI
ST ACEPACK电源模块
意法半导体生物传感器
STM32Cube扩展软件包
关注我们
st-img 微信公众号
st-img 手机版