打印

cc430串口接收中断问题

[复制链接]
1589|9
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
inboyg|  楼主 | 2013-11-23 15:32 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
#include "cc430x613x.h"
#include "stdint.h"

uint8_t data[4]={0x00};

void main(void){
  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT

  PMAPPWD = 0x02D52;                        // Get write-access to port mapping regs  
  P2MAP6 = PM_UCA0RXD;                      // Map UCA0RXD output to P2.6
  P2MAP7 = PM_UCA0TXD;                      // Map UCA0TXD output to P2.7
  PMAPPWD = 0;                              // Lock port mapping registers

  P1DIR |= BIT6;                            // Set P2.7 as TX output
  P1SEL |= BIT5 + BIT6;                     // Select P2.6 & P2.7 to UART function

  UCA0CTL1 |= UCSWRST;                      // **Put state machine in reset**
  UCA0CTL1 |= UCSSEL_1;                     // CLK = ACLK
  UCA0BR0 = 0x03;                           // 32kHz/9600=3.41 (see User's Guide)
  UCA0BR1 = 0x00;                           //
  UCA0MCTL = UCBRS_3+UCBRF_0;               // Modulation UCBRSx=3, UCBRFx=0
  UCA0CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**
  UCA0IE |= UCRXIE;                         // Enable USCI_A0 RX interrupt

  __bis_SR_register(LPM3_bits + GIE);       // Enter LPM3, interrupts enabled
  __no_operation();                         // For debugger


    __no_operation();
}

// Echo back RXed character, confirm TX buffer is ready first
#pragma vector=USCI_A0_VECTOR
__interrupt void USCI_A0_ISR(void)
{
  switch(__even_in_range(UCA0IV,4))
  {
  case 0:break;                             // Vector 0 - no interrupt
  case 2:                                   // Vector 2 - RXIFG
  //  while (!(UCA0IFG&UCTXIFG));             // USCI_A0 TX buffer ready?

     data[0]= UCA0RXBUF;                  // TX -> RXed character
      UCA0IE= 0x00;     
    break;
  case 4:break;                             // Vector 4 - TXIFG
  default: break;  
  }
    __bic_SR_register(LPM3_bits);       // Enter LPM3, interrupts enabled
}

我使用这段程序可以顺利进入中断,在串口调试助手发过来数也能进入数组,但是似乎无法跳出中断执行到断点处,如图

求大虾指点我程序中的问题

相关帖子

沙发
inboyg|  楼主 | 2013-11-23 20:07 | 只看该作者
#include "cc430x613x.h"
#include "stdint.h"

uint8_t data[4]={0x00};

void main(void)
{
  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
  
  PMAPPWD = 0x02D52;                        // Get write-access to port mapping regs  
  P1MAP5 = PM_UCA0RXD;                      // Map UCA0RXD output to P2.6
  P1MAP6 = PM_UCA0TXD;                      // Map UCA0TXD output to P2.7
  PMAPPWD = 0;                              // Lock port mapping registers
  
  P1DIR |= BIT6;                            // Set P2.7 as TX output
  P1SEL |= BIT5 + BIT6;                     // Select P2.6 & P2.7 to UART function
  
  UCA0CTL1 |= UCSWRST;                      // **Put state machine in reset**
  UCA0CTL1 |= UCSSEL_1;                     // CLK = ACLK
  UCA0BR0 = 0x03;                           // 32kHz/9600=3.41 (see User's Guide)
  UCA0BR1 = 0x00;                           //
  UCA0MCTL = UCBRS_3+UCBRF_0;               // Modulation UCBRSx=3, UCBRFx=0
  UCA0CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**
  UCA0IE |= UCRXIE;                         // Enable USCI_A0 RX interrupt

  __bis_SR_register(LPM0_bits+GIE);       // Enter LPM3, interrupts enabled
  __no_operation();                         // For debugger
  

    __no_operation();
}

// Echo back RXed character, confirm TX buffer is ready first
#pragma vector=USCI_A0_VECTOR
__interrupt void USCI_A0_ISR(void)
{
  switch(__even_in_range(UCA0IV,4))
  {
  case 0:break;                             // Vector 0 - no interrupt
  case 2:                                   // Vector 2 - RXIFG
  //  while (!(UCA0IFG&UCTXIFG));             // USCI_A0 TX buffer ready?
   
     data[0]= UCA0RXBUF;                  // TX -> RXed character
      UCA0IE &= ~ UCRXIE;      
    break;
  case 4:break;                             // Vector 4 - TXIFG
  default: break;  
  }
    __bic_SR_register(LPM0_bits);       // Enter LPM3, interrupts enabled
}
更正一下,前面的程序是有问题但居然能跑,这个程序现象也一样,求指导

使用特权

评论回复
板凳
inboyg|  楼主 | 2013-11-24 09:17 | 只看该作者
希望有高手可以看一下,是我中断服务程序有问题还是中断开的有问题

使用特权

评论回复
地板
dirtwillfly| | 2013-11-24 16:16 | 只看该作者
程序永远执行不到那个位置,因为执行完中断服务程序后,又进入低功耗模式了

使用特权

评论回复
5
inboyg|  楼主 | 2013-11-25 16:31 | 只看该作者
dirtwillfly 发表于 2013-11-24 16:16
程序永远执行不到那个位置,因为执行完中断服务程序后,又进入低功耗模式了 ...

谢谢,我昨天已经把这个问题解决了

使用特权

评论回复
6
dirtwillfly| | 2013-11-25 19:10 | 只看该作者
inboyg 发表于 2013-11-25 16:31
谢谢,我昨天已经把这个问题解决了

恭喜,能者自答。

使用特权

评论回复
7
yufanjoy| | 2014-11-10 11:55 | 只看该作者
dirtwillfly 发表于 2013-11-25 19:10
恭喜,能者自答。

版主你好:

最近刚学CC430,发现这款芯片和stm32一样有管脚映射功能,看英文文档看的头脑有点模糊了,按照自己的理解,好像cc430的port mapping可以将一根io口任意的映射为其他的功能,不知道我这样理解对不对啊?

使用特权

评论回复
8
dirtwillfly| | 2014-11-11 09:12 | 只看该作者
yufanjoy 发表于 2014-11-10 11:55
版主你好:

最近刚学CC430,发现这款芯片和stm32一样有管脚映射功能,看英文文档看的头脑有点模糊了,按 ...

不对,也是有限制的。具体可以看数据手册

使用特权

评论回复
9
yufanjoy| | 2014-11-14 14:04 | 只看该作者
dirtwillfly 发表于 2014-11-11 09:12
不对,也是有限制的。具体可以看数据手册

现在已经基本清楚了。另外我在调试串口的时候发现个问题,把我求助的帖子发出来看看,麻烦帮我参谋参谋:

我也遇到了同样的问题,我是用串口自收自发:收到什么就发什么,用的是中断处理的,具体程序如下:
#pragma vector=USCI_A0_VECTOR
__interrupt void USCI_A0_ISR(void)
{
  switch(__even_in_range(UCA0IV,4))
  {
  case 0:break;                             // Vector 0 - no interrupt
  case 2:                                   // Vector 2 - RXIFG
    while (!(UCA0IFG&UCTXIFG));             // USCI_A1 TX buffer ready?
    UCA0TXBUF = UCA0RXBUF;                  // TX -> RXed character
    break;
  case 4:break;                             // Vector 4 - TXIFG
  default: break;
  }  
}

主函数就是对串口初始化而已,并未有其他关于数组和指针的操作,程序的主要是要实现串口接收和发送,所以就简单写了下串口初始化和上面贴出来的串口数据处理代码,用串口调试助手每隔80ms发送数据,程序在收到数据后就自动发到串口调试助手。
程序刚开始运行的半个多小时时间内,跑的很正常,但是要是时间再跑长点,程序就进入?reset_vector段里面去了,调试log里面显示的溢出了,但是我没有涉及数组和指针的操作,怎么会溢出啊,百思不得其解啊,烦请各位大侠帮我参谋参谋啊!!!

使用特权

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

本版积分规则

3

主题

15

帖子

0

粉丝