打印

【求助】串口中断打开,接受数据,为何进不去定时器中断呢?

[复制链接]
2635|19
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
lqfy|  楼主 | 2013-7-5 11:04 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
沙发
ayb_ice| | 2013-7-5 11:28 | 只看该作者
串口中断程序有问题吧

使用特权

评论回复
板凳
ayb_ice| | 2013-7-5 16:23 | 只看该作者
这种问题肯定是软件问题了,
都说了,可能是你的串口程序有问题,影响了T0的工作,

使用特权

评论回复
地板
qingqiu647| | 2013-7-5 16:49 | 只看该作者
51中,UART不仅仅接收会产生中断,发送也产生,查查看是不是这个问题

使用特权

评论回复
5
qingqiu647| | 2013-7-5 16:50 | 只看该作者
51中,UART不仅仅接收会产生中断,发送也产生,查查看是不是这个问题

使用特权

评论回复
6
ningling_21| | 2013-7-5 20:18 | 只看该作者
肯定是程序有问题...

使用特权

评论回复
7
xyz549040622| | 2013-7-6 07:15 | 只看该作者
贴程序。。。

使用特权

评论回复
8
soso| | 2013-7-6 21:07 | 只看该作者
了能是中断优先级的问题

使用特权

评论回复
9
huangxz| | 2013-7-6 21:45 | 只看该作者
有可能在中断里面根本就没退出来。

使用特权

评论回复
10
lqfy|  楼主 | 2013-7-8 10:26 | 只看该作者
串口通信的接受程序。@qingqiu647 @ningling_21  

串口通信.jpg (23.03 KB )

串口通信.jpg

使用特权

评论回复
11
qingqiu647| | 2013-7-8 15:40 | 只看该作者
中断程序中,加入TI=0;再试试。

使用特权

评论回复
12
ayb_ice| | 2013-7-8 15:46 | 只看该作者
先去掉using 3试试

使用特权

评论回复
13
xvezhe| | 2013-11-12 15:44 | 只看该作者
ayb_ice 发表于 2013-7-8 15:46
先去掉using 3试试

我现在也遇到这种问题。。。单一工作就没问题,合并就有问问题了。。。。是那里出现问题了呢

使用特权

评论回复
14
cjseng| | 2013-11-12 16:13 | 只看该作者
用KEIL的仿真调试,用虚拟串口对程序发送数据,看看程序死在哪里了。

使用特权

评论回复
15
ayb_ice| | 2013-11-13 07:58 | 只看该作者
你这串口基本程序应该有问题,一般是这样的
void isr_uart(void) interrupt 4
{
    if(RI){
        RI = 0;
...
    }
    if(TI){
        TI = 0;
...
    }



}

使用特权

评论回复
16
CZ_Liang| | 2013-11-13 09:51 | 只看该作者
我的理解是:你串口的优先级高于定时器,你串口中断服务程序里又没用清中断,导致一直进入串口中断

使用特权

评论回复
17
探索者_wyg| | 2013-11-30 11:59 | 只看该作者
请问 楼主的 这个问题 怎么解决呢,是什么原因造成的呢?我现在也遇到这个问题了,求 指点。

使用特权

评论回复
18
yangfan19641964| | 2013-12-2 16:49 | 只看该作者
你的程序未按照设想的运行,后面一段等效于:

if ( (counter_i % 2) == 0 )
{
        speed = 256*speed_H + speed_L;
        speed_ii++;
}


speed_l = speed;



1   if ( (counter_i % 2) == 2 ) 永远为假
2   我不喜欢去背优先级,而是用括号。看起来也直观。

使用特权

评论回复
19
dong_abc| | 2013-12-4 04:24 | 只看该作者

/*----------------------------------------------------------------------------
* Name:    Usart.c
* Purpose: USART usage for STM32
* Version: V1.00
*----------------------------------------------------------------------------
* This file is part of the uVision/ARM development tools.
* This software may only be used under the terms of a valid, current,
* end user licence from KEIL for a compatible version of KEIL software
* development tools. Nothing else gives you the right to use this software.
*
* Copyright (c) 2005-2007 Keil Software. All rights reserved.
*----------------------------------------------------------------------------*/
#include <stm32f10x_lib.h>                        // STM32F10x Library Definitions
#include <stdio.h>
#include "STM32_Init.h"                           // STM32 Initialization

/*----------------------------------------------------------------------------
  Notes:
  The length of the receive and transmit buffers must be a power of 2.
  Each buffer has a next_in and a next_out index.
  If next_in = next_out, the buffer is empty.
  (next_in - next_out) % buffer_size = the number of characters in the buffer.
*----------------------------------------------------------------------------*/
#define TBUF_SIZE   256      /*** Must be a power of 2 (2,4,8,16,32,64,128,256,512,...) ***/
#define RBUF_SIZE   256      /*** Must be a power of 2 (2,4,8,16,32,64,128,256,512,...) ***/
/*----------------------------------------------------------------------------
*----------------------------------------------------------------------------*/
#if TBUF_SIZE < 2
#error TBUF_SIZE is too small.  It must be larger than 1.
#elif ((TBUF_SIZE & (TBUF_SIZE-1)) != 0)
#error TBUF_SIZE must be a power of 2.
#endif
#if RBUF_SIZE < 2
#error RBUF_SIZE is too small.  It must be larger than 1.
#elif ((RBUF_SIZE & (RBUF_SIZE-1)) != 0)
#error RBUF_SIZE must be a power of 2.
#endif
/*----------------------------------------------------------------------------
*----------------------------------------------------------------------------*/
struct buf_st {
  unsigned int in;                                // Next In Index
  unsigned int out;                               // Next Out Index
  char buf [RBUF_SIZE];                           // Buffer
};
static struct buf_st rbuf = { 0, 0, };
#define SIO_RBUFLEN ((unsigned short)(rbuf.in - rbuf.out))
static struct buf_st tbuf = { 0, 0, };
#define SIO_TBUFLEN ((unsigned short)(tbuf.in - tbuf.out))
static unsigned int tx_restart = 1;               // NZ if TX restart is required
/*----------------------------------------------------------------------------
  USART1_IRQHandler
  Handles USART1 global interrupt request.
*----------------------------------------------------------------------------*/
void USART1_IRQHandler (void) {
  volatile unsigned int IIR;
  struct buf_st *p;
    IIR = USART1->SR;
    if (IIR & USART_FLAG_RXNE) {                  // read interrupt
      USART1->SR &= ~USART_FLAG_RXNE;           // clear interrupt
      p = &rbuf;
      if (((p->in - p->out) & ~(RBUF_SIZE-1)) == 0) {
        p->buf [p->in & (RBUF_SIZE-1)] = (USART1->DR & 0x1FF);
        p->in++;
      }
    }
    if (IIR & USART_FLAG_TXE) {
      USART1->SR &= ~USART_FLAG_TXE;           // clear interrupt
      p = &tbuf;
      if (p->in != p->out) {
        USART1->DR = (p->buf [p->out & (TBUF_SIZE-1)] & 0x1FF);
        p->out++;
        tx_restart = 0;
      }
      else {
        tx_restart = 1;
  USART1->CR1 &= ~USART_FLAG_TXE;        // disable TX interrupt if nothing to send
      }
    }
}
/*------------------------------------------------------------------------------
  buffer_Init
  initialize the buffers
*------------------------------------------------------------------------------*/
void buffer_Init (void) {
  tbuf.in = 0;                                    // Clear com buffer indexes
  tbuf.out = 0;
  tx_restart = 1;
  rbuf.in = 0;
  rbuf.out = 0;
}
/*------------------------------------------------------------------------------
  SenChar
  transmit a character
*------------------------------------------------------------------------------*/
int SendChar (int c) {
  struct buf_st *p = &tbuf;
                                                  // If the buffer is full, return an error value
  if (SIO_TBUFLEN >= TBUF_SIZE)
    return (-1);
                                                  
  p->buf [p->in & (TBUF_SIZE - 1)] = c;           // Add data to the transmit buffer.
  p->in++;
  if (tx_restart) {                               // If transmit interrupt is disabled, enable it
    tx_restart = 0;
USART1->CR1 |= USART_FLAG_TXE;            // enable TX interrupt
  }
  return (0);
}
/*------------------------------------------------------------------------------
  GetKey
  receive a character
*------------------------------------------------------------------------------*/
int GetKey (void) {
  struct buf_st *p = &rbuf;
  if (SIO_RBUFLEN == 0)
    return (-1);
  return (p->buf [(p->out++) & (RBUF_SIZE - 1)]);
}

/*----------------------------------------------------------------------------
  MAIN function
*----------------------------------------------------------------------------*/
int main (void) {
  buffer_Init();                                  // init RX / TX buffers
  stm32_Init ();                                  // STM32 setup
  printf ("Interrupt driven Serial I/O Example\r\n\r\n");
  while (1) {                                     // Loop forever
    unsigned char c;
    printf ("Press a key. ");
    c = getchar ();
    printf ("\r\n");
    printf ("You pressed '%c'.\r\n\r\n", c);
  } // end while
} // end main

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

8

主题

99

帖子

1

粉丝