MSP430接收UART的数据,但是一直没有接收到,可是sscom又显示已经发送了数据。不知道是没有进中断还是什么问题。能否帮忙看看是不是代码哪里错了。
下面是代码
void UARTinit()
{
/* GPIO_setAsPeripheralModuleFunctionInputPin(
GPIO_PORT_P9,
GPIO_PIN5
);
GPIO_setAsPeripheralModuleFunctionOutputPin(
GPIO_PORT_P9,
GPIO_PIN4
); */
GPIO_setAsPeripheralModuleFunctionInputPin(
GPIO_PORT_P5,
GPIO_PIN7
);
//Initialize USCI UART module
//Baudrate = 9600, clock freq =8M // 1.048MHz
//UCBRx = 6, UCBRFx = 13, UCBRSx = 0, UCOS16 = 1
USCI_A_UART_initParam param = {0};
param.selectClockSource = USCI_A_UART_CLOCKSOURCE_ACLK;
param.clockPrescalar =3 /*52*/;
param.firstModReg = 0/*1*/;
param.secondModReg = 3/*0*/;
param.parity = USCI_A_UART_NO_PARITY;
param.msborLsbFirst = USCI_A_UART_LSB_FIRST;
param.numberofStopBits = USCI_A_UART_ONE_STOP_BIT;
param.uartMode = USCI_A_UART_IDLE_LINE_MULTI_PROCESSOR_MODE;
param.overSampling = USCI_A_UART_LOW_FREQUENCY_BAUDRATE_GENERATION/*USCI_A_UART_OVERSAMPLING_BAUDRATE_GENERATION*/;
if(STATUS_FAIL == USCI_A_UART_init(USCI_A1_BASE, ¶m))
{
return;
}
//Enable UART module for operation
USCI_A_UART_enable(USCI_A1_BASE);
//Set USCI UART in dormant/sleep mode
//USCI_A_UART_setDormant(USCI_A1_BASE);
//Enable Receive Interrupt
USCI_A_UART_clearInterrupt(USCI_A1_BASE,
USCI_A_UART_RECEIVE_INTERRUPT
);
USCI_A_UART_enableInterrupt(USCI_A1_BASE,
USCI_A_UART_RECEIVE_INTERRUPT
);
}
//******************************************************************************
//
//This is the USCI_A1 interrupt vector service routine.
//
//******************************************************************************
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=USCI_A1_VECTOR
__interrupt
#elif defined(__GNUC__)
__attribute__((interrupt(USCI_A1_VECTOR)))
#endif
void USCI_A1_ISR(void)
{
switch(__even_in_range(UCA1IV,4))
{
//Vector 2 - RXIFG
case 2:
//USCI_A1 TX buffer ready?
while(!USCI_A_UART_getInterruptStatus(USCI_A1_BASE,
USCI_A_UART_TRANSMIT_INTERRUPT_FLAG)
)
{
;
}
// USCI_A_UART_resetDormant(USCI_A1_BASE);
//Receive the data
receivedData = USCI_A_UART_receiveData(USCI_A1_BASE);
/* if(receivedData!=0x00) bspLedSet(BSP_LED_1);
else bspLedSet(BSP_LED_2);*/
// Send data back "echo"
USCI_A_UART_transmitData(USCI_A1_BASE,
receivedData
);
// USCI_A_UART_setDormant(USCI_A1_BASE);
break;
default: break;
}
} |