TI中文支持网
TI专业的中文技术问题搜集分享网站

求大神帮忙看下串口中断啊 总是进不去中断是个什么情况 单步运行总停在__bis_SR_register(LPM0_bits+GIE);万分感谢!

Other Parts Discussed in Thread:DAC8831

#include <msp430.h>void chuankou();
void ***();
unsigned char chuan;
volatile unsigned int j;
volatile unsigned int i;
void main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
P4DIR |= BIT7;
//anjian();
chuankou();
***();
chuan = 0x3fd;
__bis_SR_register(LPM0_bits+GIE);
while(1);
}

void chuankou()

{
P3SEL |=BIT3+BIT4;
UCA0CTL1 |=UCSWRST;
UCA0CTL1 |=UCSSEL_2;
UCA0BR0 = 6;
UCA0BR1 = 0;
UCA0MCTL =UCBRS_0 + UCBRF_13 + UCOS16;
UCA0CTL1 &= ~UCSWRST;
UCA0IE |= UCTXIE;
}

void ***()
{
P2DIR |=BIT2;
P2SEL |=BIT2;
UCSCTL4 |= SELA_2;
}
#pragma vector=USIC_A0_VECTOR
__interrupt void USCI_A0_ISR()
{
switch(__even_in_range(UCA0IV,4))
{
case 0:break;
case 2:break;
case 4:
while(!(UCA0IFG&UCTXIFG));
UCA0TXBUF = 0x3fd;
P4OUT |= BIT7;
break;
default:break;
}
UCA0IV = 0;
return;
}

灰小子:

楼主你好。你用的哪一款msp430?

430是跟电脑通讯么? 

建议先运行一下code example 试试

,

Weiming Qiu:

您好!

我用的是f5529的单片机

想把数据发送给外部dac  

但是在debug里面一直调不对 不进入串口中断

不用中断直接写数据到UCA0TXBUF也没效果T_T 

,

灰小子:

dac用的哪个ic呢?

,

Weiming Qiu:

dac用的8831

,

灰小子:

dac8831是spi接口的ic。我手里没有这个ic。

你参考官网的例程吧

/* --COPYRIGHT--,BSD_EX* Copyright (c) 2012, Texas Instruments Incorporated* All rights reserved.** Redistribution and use in source and binary forms, with or without* modification, are permitted provided that the following conditions* are met:** *Redistributions of source code must retain the above copyright*notice, this list of conditions and the following disclaimer.** *Redistributions in binary form must reproduce the above copyright*notice, this list of conditions and the following disclaimer in the*documentation and/or other materials provided with the distribution.** *Neither the name of Texas Instruments Incorporated nor the names of*its contributors may be used to endorse or promote products derived*from this software without specific prior written permission.** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.**********************************************************************************MSP430 CODE EXAMPLE DISCLAIMER** MSP430 code examples are self-contained low-level programs that typically* demonstrate a single peripheral function or device feature in a highly* concise manner. For this the code may rely on the device's power-on default* register values and settings such as the clock configuration and care must* be taken when combining code from several examples to avoid potential side* effects. Also see www.ti.com/grace for a GUI- and www.ti.com/msp430ware* for an API functional library-approach to peripheral configuration.** --/COPYRIGHT--*/
//******************************************************************************
//MSP430F552x Demo - USCI_A0, SPI 3-Wire Master Incremented Data
//
//Description: SPI master talks to SPI slave using 3-wire mode. Incrementing
//data is sent by the master starting at 0x01. Received data is expected to
//be same as the previous transmission.USCI RX ISR is used to handle
//communication with the CPU, normally in LPM0. If high, P1.0 indicates
//valid data reception.Because all execution after LPM0 is in ISRs,
//initialization waits for DCO to stabilize against ACLK.
//ACLK = ~32.768kHz, MCLK = SMCLK = DCO ~ 1048kHz.BRCLK = SMCLK/2
//
//Use with SPI Slave Data Echo code example.If slave is in debug mode, P1.1
//slave reset signal conflicts with slave's JTAG; to work around, use IAR's
//"Release JTAG on Go" on slave device.If breakpoints are set in
//slave RX ISR, master must stopped also to avoid overrunning slave
//RXBUF.
//
//MSP430F552x
//-----------------
///|\||
//| ||
//--|RSTP1.0|-> LED
//||
//|P3.3|-> Data Out (UCA0SIMO)
//||
//|P3.4|<- Data In (UCA0SOMI)
//||
//Slave reset <-|P1.1P2.7|-> Serial Clock Out (UCA0CLK)
//
//
//Bhargavi Nisarga
//Texas Instruments Inc.
//April 2009
//Built with CCSv4 and IAR Embedded Workbench Version: 4.21
//******************************************************************************#include <msp430.h>unsigned char MST_Data,SLV_Data;
unsigned char temp;int main(void)
{volatile unsigned int i;WDTCTL = WDTPW+WDTHOLD;// Stop watchdog timerP1OUT |= 0x02;// Set P1.0 for LED// Set P1.1 for slave resetP1DIR |= 0x03;// Set P1.0-2 to output directionP3SEL |= BIT3+BIT4;// P3.3,4 option selectP2SEL |= BIT7;// P2.7 option selectUCA0CTL1 |= UCSWRST;// **Put state machine in reset**UCA0CTL0 |= UCMST+UCSYNC+UCCKPL+UCMSB;// 3-pin, 8-bit SPI master// Clock polarity high, MSBUCA0CTL1 |= UCSSEL_2;// SMCLKUCA0BR0 = 0x02;// /2UCA0BR1 = 0;//UCA0MCTL = 0;// No modulationUCA0CTL1 &= ~UCSWRST;// **Initialize USCI state machine**UCA0IE |= UCRXIE;// Enable USCI_A0 RX interruptP1OUT &= ~0x02;// Now with SPI signals initialized,P1OUT |= 0x02;// reset slavefor(i=50;i>0;i--);// Wait for slave to initializeMST_Data = 0x01;// Initialize data valuesSLV_Data = 0x00;//while (!(UCA0IFG&UCTXIFG));// USCI_A0 TX buffer ready?UCA0TXBUF = MST_Data;// Transmit first character__bis_SR_register(LPM0_bits + GIE);// CPU off, enable interrupts
}#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=USCI_A0_VECTOR
__interrupt void USCI_A0_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(USCI_A0_VECTOR))) USCI_A0_ISR (void)
#else
#error Compiler not supported!
#endif
{volatile unsigned int i;switch(__even_in_range(UCA0IV,4)){case 0: break;// Vector 0 - no interruptcase 2:// Vector 2 - RXIFGwhile (!(UCA0IFG&UCTXIFG));// USCI_A0 TX buffer ready?if (UCA0RXBUF==SLV_Data)// Test for correct character RX'dP1OUT |= 0x01;// If correct, light LEDelseP1OUT &= ~0x01;// If incorrect, clear LEDMST_Data++;// Increment dataSLV_Data++;UCA0TXBUF = MST_Data;// Send next valuefor(i = 20; i>0; i--);// Add time between transmissions to// make sure slave can process informationbreak;case 4: break;// Vector 4 - TXIFGdefault: break;}
}

,

Weiming Qiu:

好的  感谢您

,

stark fairy:

已经过去这么久了,IAR的话,如果要进入中断,建议在中断函数里设置断点,再全速运行到断点就可以进入中断函数,单步的话是进不去的。

,

ansibob:

例程中是要

__bis_SR_register(LPM0_bits + GIE); // CPU off, enable interrupts有测试如果改为

__bis_SR_register(GIE);// CPU off, enable interrupts不进入LPM0模式,则通讯中断还是不正常。有什么办法可以避免启用LPM0,也能正常进入中断,正常通讯?

赞(0)
未经允许不得转载:TI中文支持网 » 求大神帮忙看下串口中断啊 总是进不去中断是个什么情况 单步运行总停在__bis_SR_register(LPM0_bits+GIE);万分感谢!
分享到: 更多 (0)