Hi,
I am new to MSP. I cannot find a sample code for 6438, but I do find in the product page, there are sample codes for 663x.
I tried the receive and Echo code of 663x on 6438. It does not work.
Anybody help me have a look ? Thanks!
#include <msp430.h>
void Port_Mapping(void);
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
while(BAKCTL & LOCKBAK) // Unlock XT1 pins for operation
BAKCTL &= ~(LOCKBAK);
UCSCTL6 &= ~(XT1OFF); // XT1 On
UCSCTL6 |= XCAP_3; // Internal load cap
// Loop until XT1 fault flag is cleared
do
{
UCSCTL7 &= ~(XT2OFFG + XT1LFOFFG + DCOFFG);
// Clear XT2,XT1,DCO fault flags
SFRIFG1 &= ~OFIFG; // Clear fault flags
}while (SFRIFG1&OFIFG); // Test oscillator fault flag
Port_Mapping();
P2SEL |= 0x03; // Assign P2.0 to UCA0TXD and...
P2DIR |= 0x03; // P2.1 to UCA0RXD
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
}
// 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?
UCA0TXBUF = UCA0RXBUF; // TX -> RXed character
break;
case 4:break; // Vector 4 - TXIFG
default: break;
}
}
void Port_Mapping(void)
{
// Disable Interrupts before altering Port Mapping registers
__disable_interrupt();
// Enable Write-access to modify port mapping registers
PMAPPWD = 0x02D52;
#ifdef PORT_MAP_RECFG
// Allow reconfiguration during runtime
PMAPCTL = PMAPRECFG;
#endif
P2MAP0 = PM_UCA0TXD;
P2MAP1 = PM_UCA0RXD;
// Disable Write-Access to modify port mapping registers
PMAPPWD = 0;
#ifdef PORT_MAP_EINT
__enable_interrupt(); // Re-enable all interrupts
#endif
}
Several more questions. What does the Port_Mapping function exactly do?
Why need XT1 in this case?
Thanks!