OpenEdv-开源电子网

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

STM32 USATR 中断发送 如何定义 以下定义看下有没有问题

[复制链接]

2

主题

7

帖子

0

精华

新手上路

积分
39
金钱
39
注册时间
2013-8-30
在线时间
1 小时
发表于 2013-9-2 17:08:09 | 显示全部楼层 |阅读模式

USART_InitTypeDef USART_InitStructure;
  /* USART1 configured as follow:
        - BaudRate = 115200 baud 
        - Word Length = 8 Bits
        - One Stop Bit
        - No parity
        - Hardware flow control disabled (RTS and CTS signals)
        - Receive and transmit enabled
  */
  USART_InitStructure.USART_BaudRate = 115200;       //波特率:   115200
  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;   //Open RX接收和TX发送功能
 
  /* Configure the USART1*/
  USART_Init(USART1, &USART_InitStructure);

  /* Enable USART2 Receive and Transmit interrupts */
  USART_ITConfig(USART1, USART_IT_RXNE |USART_IT_TXE, ENABLE); //接收中断模式允许   发送中断模式允许
 
  /* Enable the USART1 */
  USART_Cmd(USART1, ENABLE);   //启动串口1

正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

530

主题

11万

帖子

34

精华

管理员

Rank: 12Rank: 12Rank: 12

积分
165540
金钱
165540
注册时间
2010-12-1
在线时间
2117 小时
发表于 2013-9-2 20:46:42 | 显示全部楼层
我是开源电子网www.openedv.com站长,有关站务问题请与我联系。
正点原子STM32开发板购买店铺http://openedv.taobao.com
正点原子官方微信公众平台,点击这里关注“正点原子”
回复 支持 反对

使用道具 举报

2

主题

7

帖子

0

精华

新手上路

积分
39
金钱
39
注册时间
2013-8-30
在线时间
1 小时
 楼主| 发表于 2013-9-3 11:17:06 | 显示全部楼层
有试  串口初始化  中有这个
USART_ITConfig(USART1, USART_IT_TXE, ENABLE);

程序就不运行   去掉这句又正常 
高手指点下哦
回复 支持 反对

使用道具 举报

530

主题

11万

帖子

34

精华

管理员

Rank: 12Rank: 12Rank: 12

积分
165540
金钱
165540
注册时间
2010-12-1
在线时间
2117 小时
发表于 2013-9-3 15:49:04 | 显示全部楼层
你这是开启了发送完成中断,那你的中断服务函数要有,否则就死机了。
我是开源电子网www.openedv.com站长,有关站务问题请与我联系。
正点原子STM32开发板购买店铺http://openedv.taobao.com
正点原子官方微信公众平台,点击这里关注“正点原子”
回复 支持 反对

使用道具 举报

2

主题

7

帖子

0

精华

新手上路

积分
39
金钱
39
注册时间
2013-8-30
在线时间
1 小时
 楼主| 发表于 2013-9-3 17:06:36 | 显示全部楼层
这个是中断函数
/*******************************************************************************
* Function Name: USART1_IRQHandler
* Description : This function handles USART1 global interrupt request.
* Input       : None
* Output      : None
* Return      : None
*******************************************************************************/
void USART1_IRQHandler(void)
{

unsigned char i;
    unsigned int  Len;
//================================================================================================
if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)//接收中断
{
/* Clear the USART1 Receive interrupt */
USART_ClearITPendingBit(USART1, USART_IT_RXNE);
{
UART_0 . RxBuf[UART_0 . RxWriteShift ++] = USART_ReceiveData(USART1);  // 接收数据
         UART_0 . RxNum  ++;
         if(UART_0 . RxWriteShift >= UART0_RxFifo)
         {
             UART_0 . RxWriteShift = 0;
         }
        }
//================================================================================================
        isr_evt_set(UART0_RxNotEmpty , tid_uart0_rx); //发送串口接收缓冲区非空标志  
        if(UART_0 . RxNum >= UART_0 . RxMax) 
            isr_sem_send (UART_0 . RxSem); 
//================================================================================================            
    }

//================================================================================================
if(USART_GetITStatus(USART1, USART_IT_TXE) != RESET)//发送中断
{
/* Clear the USART1 transmit interrupt */
     USART_ClearITPendingBit(USART1, USART_IT_TXE); 

if(UART_0 . TxNum) //串口发送缓冲区中有待发送
{  
Len = UART_0 . TxNum;
for(i = 0 ; i < Len ; i++)
{
    Uart_SendChar(USART1_BASE, * (UART_0 . TxPointer ++));

UART_0 . TxNum -= Len;
  }
else
{
              isr_sem_send(UART_0 . TxSem);
}
    }

}

串口初始化
     USART_InitTypeDef USART_InitStructure;
     /* USART1 and USARTx configuration ------------------------------------------------------*/
        /* USART and USARTx configured as follow:
        - BaudRate = baudrate  
        - Word Length = 8 Bits
        - One Stop Bit
        - No parity
        - Hardware flow control disabled (RTS and CTS signals)
        - Receive and transmit enabled
        - USART Clock disabled
        - USART CPOL: Clock is active low
        - USART CPHA: Data is captured on the second edge 
        - USART LastBit: The clock pulse of the last data bit is not output to 
                         the SCLK pin
   */
   USART_InitStructure.USART_BaudRate = baudrate;
   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);

            /* 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);   //启动串口1
回复 支持 反对

使用道具 举报

530

主题

11万

帖子

34

精华

管理员

Rank: 12Rank: 12Rank: 12

积分
165540
金钱
165540
注册时间
2010-12-1
在线时间
2117 小时
发表于 2013-9-3 21:14:15 | 显示全部楼层
那你看看死在哪里?
我是开源电子网www.openedv.com站长,有关站务问题请与我联系。
正点原子STM32开发板购买店铺http://openedv.taobao.com
正点原子官方微信公众平台,点击这里关注“正点原子”
回复 支持 反对

使用道具 举报

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

本版积分规则



关闭

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

正点原子公众号

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

GMT+8, 2025-7-14 01:50

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

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