Quantcast
Channel: MSP low-power microcontroller forum - Recent Threads
Viewing all articles
Browse latest Browse all 22185

MSP430FR6047: UART interrupt not responding while running example code FR6047_USSSWLib_template_example

$
0
0
Part Number: MSP430FR6047

Hi

I am working on to receiving a data through UART to toggle LED1 while running the code FR6047_USSSWLib_template_example, I am using eUSCI_A1 Registers, for that I modified the the system_pre_init.c as following.


#include <intrinsics.h>
#include <stdint.h>
#include "msp430.h"
#include "main.h"

#ifdef __TI_COMPILER_VERSION__
int _system_pre_init(void)
#elif __IAR_SYSTEMS_ICC__
int __low_level_init(void)
#elif __GNUC__
extern int system_pre_init(void) __attribute__((constructor));
int system_pre_init(void)
#else
#error Compiler not supported!
#endif
{
    /* Insert your low-level initializations here */

    /* Disable Watchdog timer to prevent reset during */
    /* int32_t variable initialization sequences. */
    // Stop WDT
    WDTCTL = WDTPW + WDTHOLD;

    /*
     * Configure CS module
     * MCLK  = 16 MHz from DCOCLK
     * SMCLK = 8MHz from DCOCLK
     * ACLK  = LFXTCLK expected to have a 32.768 KHz
     */
	// Unlock CS registers
	CSCTL0_H = CSKEY >> 8;
#if (USS_PULSE_MODE == 2)
    // Set DCO to 16MHz
    CSCTL1 = DCORSEL | DCOFSEL_4;
    // Configure wait states to be able to use 16 MHz MCLK
    FRCTL0 = (FRCTLPW | NWAITS_2);
    // Configure clock dividers all dividers
    CSCTL3 = (DIVA__1 | DIVS__2 | DIVM__1);
#else
    // Set DCO to 8MHz
    CSCTL1 = DCORSEL | DCOFSEL_3;
    // Configure clock dividers all dividers
    CSCTL3 = (DIVA__1 | DIVS__1 | DIVM__1);
#endif
    // Set SMCLK = MCLK = DCO, ACLK = LFXTCLK
    CSCTL2 = SELA__LFXTCLK | SELS__DCOCLK | SELM__DCOCLK;
	CSCTL4 |= (LFXTDRIVE_3);
	CSCTL4 &= ~(LFXTOFF);
	CSCTL0_H = 0;

	// GPIO Configuration
	PAOUT = 0;
	PADIR = 0xFFFF;

	PBOUT = 0;
	PBDIR = 0xFFFF;

	PCOUT = 0;
	PCDIR = 0xFFFF;

	PDOUT = 0;
	PDDIR = 0xFFFF;

    PEOUT = 0;
    PEDIR = 0xFFFF;

#if APPLICATION_ENABLE_UART_DEBUG
	// GPIO Configuration for UART mode
    P1SEL0 |= (BIT2 | BIT3);
    P1SEL1 &= ~(BIT2 | BIT3);

    P1OUT &= ~BIT0;                         // Clear P1.0 output latch
    P1DIR |= BIT0;                          // For LED on P1.0


    // Configure USCI_A0 for UART mode, 8-bit data, 1 stop bit
    UCA1CTLW0 = UCSWRST;                    // Put eUSCI in reset
    UCA1CTLW0 |= UCSSEL__SMCLK;             // CLK = SMCLK

    // For BRCLK = SMCLK = 8MHz, and Baud rate = 115200 (See UG)
    UCA1BRW = 4;
    // UCBRSx (bits 7-4) = 0x55, UCBRFx (bits 3-1) = 5, UCOS16 (bit 0) = 1
    UCA1MCTLW = 0x5551;

    UCA1CTLW0 &= ~UCSWRST;                 // release from reset


    //--SETUP IRQ A1 RXIFG
           UCA1IE |= UCRXIE;                       // Enable USCI_A0 RX interrupt
           __enable_interrupt();

#endif

    /*
     * Configure LFXT GPIO pins and start
     */
	PJSEL0 |= BIT4 | BIT5;

	// Disable the GPIO power-on default high-impedance mode to activate
	// previously configured port settings
	PM5CTL0 &= ~LOCKLPM5;


    /*==================================*/
    /* Choose if segment initialization */
    /* should be done or not.           */
    /* Return: 0 to omit initialization */
    /* 1 to run initialization          */
    /*==================================*/
    return(1);
}

//--------------ISR-------------------

#pragma vector=EUSCI_A1_VECTOR
__interrupt void USCI_A1_ISR(void)
{
    if(UCA1RXBUF == 't')
    {
      P1OUT ^= BIT0;  // TOGGLE LED
    }

}

In the line 88 I enabled USCI_A1 RX interrupt and at line no 115 I have added ISR.

However when I try to send data via UART I don't get any response. But when I run a separate code as shown below the LED1 toggles, con some one tell me what I am doing wrong.

#include <msp430.h>


/**
 * main.c
 */
int main(void)
{
	WDTCTL = WDTPW | WDTHOLD;	// stop watchdog timer
	
	//Setup UART A1

	UCA1CTLW0 |= UCSWRST; //Put A1 into SW Reset

	UCA1CTLW0 |= UCSSEL__SMCLK; //BRCLK = SMCLK (115200 BAUD)
	UCA1BRW = 8;               // prescalar=8
	UCA1MCTLW = 0xD600;        //set modulation & low freq

	// -- setup ports
    P1SEL0 |= (BIT2 | BIT3);      // P1 set functions to UART A1 Rx ()
    P1SEL1 &= ~(BIT2 | BIT3);

    P1OUT &= ~BIT0;                         // Clear P1.0 output latch
    P1DIR |= BIT0;                          // For LED on P1.0


    // Disable the GPIO power-on default high-impedance mode to activate
      // previously configured port settings
      PM5CTL0 &= ~LOCKLPM5;

      UCA1CTLW0 &= ~UCSWRST;                  // release from reset



      //--SETUP IRQ A1 RXIFG
      UCA1IE |= UCRXIE;                       // Enable USCI_A0 RX interrupt
      __enable_interrupt();

      //main loop
      while(1){}   //do nothing


	return 0;
}

//--ISRs

#pragma vector=EUSCI_A1_VECTOR
__interrupt void USCI_A1_ISR(void)
    {
        if(UCA1RXBUF == 't')
        {
          P1OUT ^= BIT0;  // TOGGLE LED
        }

    }

Thanks in advance
Antony


Viewing all articles
Browse latest Browse all 22185

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>