This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Receive and Echo code for MSP430f6438 not working

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!

  • xianzhen zhu said:
    What does the Port_Mapping function exactly do

    Some MSPs have a port mapping controller. It allows to map any module signal (or a subset of them) to a number of port pins. Which module signals can be mapped and which por tpins have mapping capabilities depends on the individual MSP.
    In this specific case, the TX and RX signals of USCI A0 are mapped to P2.0 and P2.1, which have UCA0CLK/UCB0STE and UCB0SIMO by default.

    The 6438 and the 663x are compatible here, as far as I can tell. Other MSP may have other modules to be mapped, or no mapping controller at all.

    Howeve,r the demo code assumes a watch crystal on XT1. If the crystal isn't there, ther eis a default fallback to internal REFO, but the code will loop eternally until the crystal is running. So if you don't have a crystal attached, it will stall in the do/while(SFRIFG&OFIFG) loop.

    If you remove this loop, it should work, but on internal REFO clock (lower precision and stability). And with a crystal fault condition flagged.

**Attention** This is a public forum