I'm using the sample code that TI has given for the MSP430F149: fet140_uart11_19200_2.c ; I'm porting it to the MSP430F1611 to communicate with an RFID module.
I can see the response from the module on my oscilloscope, so I've gotten the baud rate of 38400 done correctly. The output of the module is put into Pin 3.7 (URXD1).
My problem is, for some reason, the Rx interrupt doesn't become activated! It must have something to do with my watchdog timer, because that's the only thing I really added to the original sample code. If someone could tell me what to do to fix this problem (keep both the watchdog timer and enable the Rx interrupt correctly), I'd really appreciate it.
Here's my code (I apologize for the formatting):
//****************************************************************************** // MSP-FET430P140 Demo - USART1, UART 19200 Echo ISR, XT2 HF XTAL SMCLK // // Description: Echo a received character, RX ISR used. Normal mode is LPM0, // USART1 RX interrupt triggers TX Echo. Though not required, MCLK= XT2. // ACLK =n/a, MCLK = SMCLK = UCLK1 = XT2 = 8MHz // Baud rate divider with 8Mhz XTAL @19200 = 8MHz/19200 = 416.66 ~ 417 (01A0h) // //* An external 8MHz XTAL on X2IN X2OUT is required for XT2CLK *// // //* Min Vcc required varies with MCLK frequency - refer to datasheet *// // // MSP430F149 // ----------------- // /|\| X2IN|- // | | | 8Mhz // --|RST X2OUT|- // | | // | P3.6|------------> // | | 19200 - 8N1 // | P3.7|<------------ // // // M. Buccini // Texas Instruments Inc. // Feb 2005 // Built with CCE Version: 3.2.0 and IAR Embedded Workbench Version: 3.21A //******************************************************************************
#include
<msp430x16x.h>
unsigned
int
count;
volatile
unsigned char
RxBuffer[50] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
unsigned
short index;
//index in RxBuffer
unsigned
short
recieved;
void
main(void
)
{
volatile unsigned int
i;
count = 1; index = 0; recieved = 0; WDTCTL = WDT_ADLY_1000;
// Interval timer
IE1 |= WDTIE;
// Enable WDT interrupt
P3SEL |= 0xC0;
// P3.6,7 = USART1 option select
BCSCTL1 &= ~XT2OFF;
// XT2on
do
{ IFG1 &= ~OFIFG;
// Clear OSCFault flag
for (i = 0xFF; i > 0; i--);
// Time for flag to set
}
while ((IFG1 & OFIFG));
// OSCFault flag still set?
BCSCTL2 |= SELM_2 + SELS;
// MCLK= SMCLK= XT2 (safe)
ME2 |= UTXE1 + URXE1;
// Enable USART1 TXD/RXD
UCTL1 |= CHAR;
// 8-bit character
UTCTL1 |= SSEL1;
// UCLK = SMCLK
UBR01 = 0xD0;
// 8Mhz/38400 ~ 208
UBR11 = 0x00;
UMCTL1 = 0x00;
// no modulation
UCTL1 &= ~SWRST;
// Initialize USART state machine
IE2 |= URXIE1;
// Enable USART1 RX interrupt
while (1)
{
//Send the Command
TXBUF1 = 0x02;
while (!(IFG2 & UTXIFG1)); // USART1 TX buffer ready?
TXBUF1 = 0x00;
while (!(IFG2 & UTXIFG1)); // USART1 TX buffer ready?
TXBUF1 = 0x08;
while (!(IFG2 & UTXIFG1)); // USART1 TX buffer ready?
TXBUF1 = 0x00;
while (!(IFG2 & UTXIFG1)); // USART1 TX buffer ready?
TXBUF1 = 0x22;
while (!(IFG2 & UTXIFG1)); // USART1 TX buffer ready?
TXBUF1 = 0x01;
while (!(IFG2 & UTXIFG1)); // USART1 TX buffer ready?
TXBUF1 = 0x01;
while (!(IFG2 & UTXIFG1)); // USART1 TX buffer ready?
TXBUF1 = 0x00;
while (!(IFG2 & UTXIFG1)); // USART1 TX buffer ready?TXBUF1 = 0x00;
TXBUF1 = 0xEE;
while (!(IFG2 & UTXIFG1)); // USART1 TX buffer ready?TXBUF1 = 0x92;
_BIS_SR(LPM0_bits + GIE);
// Enter LPM0
}
}
#pragma
vector=USART1RX_VECTOR
__interrupt
void usart1_rx (void
)
{
while (!(IFG2 & UTXIFG1));
// USART1 TX buffer ready?
recieved = 1;
RxBuffer[index] = RXBUF1;
if
(index>48)
{ index = index;
//not circular buffer
}
else
{
index++; } }
#pragma
vector=WDT_VECTOR
__interrupt
void watchdog_timer (void
)
{ count++; _BIC_SR_IRQ(LPM0_bits); //Leave LMP0 to run for loop again
}