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.

CCS/MSP-EXP430F5529LP: Receiving a UART signal in MSP430 microcontroller

Part Number: MSP-EXP430F5529LP
Other Parts Discussed in Thread: BOOSTXL-PGA460, PGA460, MSP430WARE, MSP430F5529, MSP430F5438A

Tool/software: Code Composer Studio

Hello

 

I am working in a project in an enterprise and I have the TI launchPad Kit with MSP430 MCU and an analog evaluation module - BOOSTXL-PGA460.

I communicate with the PGA460 with a program made in code compose studio.

To develop a program fastly I used a program in Software MSP430ware in the  driver library and adapt it to my case.

The microcontroller in use is the MSP430F5529.

 

Here is the code I used for my program:

//******************************************************************************
//! This example shows how to configure the UART module as the loopback to
//! verify that received data is sent data.
//!
//!               MSP430F5438A
//!             -----------------
//!       RST -|     P3.4/UCA0TXD|----|
//!            |                 |    |
//!            |                 |    |
//!            |     P3.5/UCA0RXD|----|
//!            |                 |
//!
//!
//! This example uses the following peripherals and I/O signals.  You must
//! review these and change as needed for your own board:
//! - UART peripheral
//! - GPIO Port peripheral (for UART pins)
//! - UCA0TXD
//! - UCA0RXD
//!
//! This example uses the following interrupt handlers.  To use this example
//! in your own application you must add these interrupt handlers to your
//! vector table.
//! - USCI_A0_VECTOR.
//******************************************************************************
#include "driverlib.h"

//*****************************************************************************
//
//Select Baud rate
//
//*****************************************************************************
#define BAUD_RATE                               9600 //JS--

//#define BAUD_RATE                               2400 //JS++ // nota: se eu alterar esta variável
// o débito binário observado no osciloscópio é sempre 9600 bps - para já vou deixar como está
//*****************************************************************************
//
//Initialize received data
//
//*****************************************************************************
uint8_t receivedData = 0x00;
//*****************************************************************************
//
//Initialize trasnmit data
//
//*****************************************************************************
uint8_t transmitData = 0x00;

uint8_t check = 0;

uint8_t i1 = 0 ; //JS++
uint8_t i2 = 0 ; //JS++
uint8_t i3 = 0 ; //JS++

void main (void)
{
    //Stop WDT
    WDT_A_hold(WDT_A_BASE);



      GPIO_setAsOutputPin (GPIO_PORT_P2, GPIO_PIN2); //\ PD como saída

      GPIO_setAsOutputPin (GPIO_PORT_P7, GPIO_PIN4); //porto SEL como saída

      GPIO_setOutputLowOnPin (GPIO_PORT_P2, GPIO_PIN2 ); //coloca pino a zero

      GPIO_setOutputLowOnPin (GPIO_PORT_P7, GPIO_PIN4 ); //coloca pino a zero

      // Fim JS++


      //JS--
      GPIO_setAsPeripheralModuleFunctionInputPin(
          GPIO_PORT_P3,
          GPIO_PIN3 + GPIO_PIN4
          );

      //Fim JS++


      //Fim JS++


      // Pull-up resistor in P3.4  //JS++
      GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P3, GPIO_PIN4); //JS++

    USCI_A_UART_initParam param = {0};
    param.selectClockSource = USCI_A_UART_CLOCKSOURCE_SMCLK;
    param.clockPrescalar = 109;
    param.firstModReg = 0;
    param.secondModReg = 2;
    param.parity = USCI_A_UART_NO_PARITY;
    param.msborLsbFirst = USCI_A_UART_LSB_FIRST;
//    param.numberofStopBits = USCI_A_UART_ONE_STOP_BIT; //JS--
    param.numberofStopBits = USCI_A_UART_TWO_STOP_BITS; //JS--

    param.uartMode = USCI_A_UART_MODE;
    param.overSampling = USCI_A_UART_LOW_FREQUENCY_BAUDRATE_GENERATION;

    if (STATUS_FAIL == USCI_A_UART_init(USCI_A0_BASE, &param)){
        return;
    }

    //Enable UART module for operation
    USCI_A_UART_enable(USCI_A0_BASE);

    //Enable Receive Interrupt
      USCI_A_UART_clearInterrupt(USCI_A0_BASE,
        USCI_A_UART_RECEIVE_INTERRUPT);
    USCI_A_UART_enableInterrupt(USCI_A0_BASE,
        USCI_A_UART_RECEIVE_INTERRUPT);

    __enable_interrupt(); //JS--


    transmitData = 0x55;
    // Load data onto buffer
    USCI_A_UART_transmitData(USCI_A0_BASE,
            transmitData);

    transmitData = 0x0A;
    // Load data onto buffer
    USCI_A_UART_transmitData(USCI_A0_BASE,
            transmitData);

    transmitData = 0x68;
    // Load data onto buffer
    USCI_A_UART_transmitData(USCI_A0_BASE,
            transmitData);

    transmitData = 0x42;
    // Load data onto buffer
    USCI_A_UART_transmitData(USCI_A0_BASE,
            transmitData);

    transmitData = 0x4B;
    // Load data onto buffer
    USCI_A_UART_transmitData(USCI_A0_BASE,
            transmitData);

for(i2=0; i2<20;i2++)
{
//            for(i3=0;i3<255;i3++)
//            {
   for (i1=0; i1<255;i1++); //JS++
//            }
}

transmitData = 0x55;
// Load data onto buffer
USCI_A_UART_transmitData(USCI_A0_BASE,
        transmitData);

transmitData = 0x09;
// Load data onto buffer
USCI_A_UART_transmitData(USCI_A0_BASE,
        transmitData);

transmitData = 0x68;
// Load data onto buffer
USCI_A_UART_transmitData(USCI_A0_BASE,
        transmitData);

transmitData = 0x8E;
// Load data onto buffer
USCI_A_UART_transmitData(USCI_A0_BASE,
        transmitData);

USCI_A_UART_clearInterrupt(USCI_A0_BASE,
          USCI_A_UART_RECEIVE_INTERRUPT_FLAG);




    while (1)
    {

    transmitData = 0x55;
    // Load data onto buffer
    USCI_A_UART_transmitData(USCI_A0_BASE,
            transmitData);

    transmitData = 0x09;
    // Load data onto buffer
    USCI_A_UART_transmitData(USCI_A0_BASE,
            transmitData);

    transmitData = 0x68;
    // Load data onto buffer
    USCI_A_UART_transmitData(USCI_A0_BASE,
            transmitData);

    transmitData = 0x8E;
    // Load data onto buffer
    USCI_A_UART_transmitData(USCI_A0_BASE,
            transmitData);

    for(i2=0; i2<20;i2++)
    {
//                for(i3=0;i3<255;i3++)
//                {
           for (i1=0; i1<255;i1++); //JS++
//                }
    }


    }
}


#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=USCI_A0_VECTOR
__interrupt void USCI_A0_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(USCI_A0_VECTOR))) USCI_A0_ISR (void)
#else
#error Compiler not supported!
#endif



{
    i3=0;

    switch (__even_in_range(UCA0IV,4)){
        //Vector 2 - RXIFG
        case 2:
            receivedData = USCI_A_UART_receiveData(USCI_A0_BASE);
//            if(!(receivedData == transmitData))                   // Check value //JS--
//            {                                 //JS--
//              while(1);                       //JS--
//            }                                 //JS--
            check =1;
            break;
        default: break;
    }
}

 

// -------End of my program

I put a breakpoint inside the __interrupt void USCI_A0_ISR(void) rotine (in the instruction i3=0), in debug mode, and the program never stops here.

I send the signal that I see in RXD and TXD (on the PGA460) respectively:

 

 

 

 

 

 

The last signal is the signal sent by the UART of the PGA to the MSP430, composed of 3 bytes that I never detect in my microcontroller. Why?

 

Please Help me,

 

Jose Simoes

  • Hello,

    I send again the fotos of the signal in the oscilloscope (because they did not appear in the last post):

     

    Thanks

    Jose Simoes

  • You need to make receiveddata volatile so the compiler knows it might change at any time. If you don't make it volatile, the compiler just assumes that it stays constant in main().

  • Hello,

    I put the variable volatile before main and ran the program. The program don't  stop in a breakpoint in the interruption where i3=0:

    volatile  uint8_t receivedData;
    //*****************************************************************************
    //
    //Initialize trasnmit data
    //
    //*****************************************************************************
    uint8_t transmitData = 0x00;

    uint8_t check = 0;

    uint8_t i1 = 0 ; //JS++
    uint8_t i2 = 0 ; //JS++
    uint8_t i3 = 0 ; //JS++

    void main (void)
    {

    .....

    code in the interrupt


    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
    #pragma vector=USCI_A0_VECTOR
    __interrupt void USCI_A0_ISR(void)
    #elif defined(__GNUC__)
    void __attribute__ ((interrupt(USCI_A0_VECTOR))) USCI_A0_ISR (void)
    #else
    #error Compiler not supported!
    #endif



    {
        i3=0;

        switch (__even_in_range(UCA0IV,4)){
            //Vector 2 - RXIFG
            case 2:
                receivedData = USCI_A_UART_receiveData(USCI_A0_BASE);
    //            if(!(receivedData == transmitData))                   // Check value //JS--
    //            {                                 //JS--
    //              while(1);                       //JS--
    //            }                                 //JS--
                check =1;
                break;
            default: break;
        }
    }

    I ask again for help please.

    Jose Simoes

  • I tried also to put only volatile variables inside the interrupt and it doesn't work (the program don't stop in the instruction i4=0 in the interrupt - see changes)


    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
    #pragma vector=USCI_A0_VECTOR
    __interrupt void USCI_A0_ISR(void)
    #elif defined(__GNUC__)
    void __attribute__ ((interrupt(USCI_A0_VECTOR))) USCI_A0_ISR (void)
    #else
    #error Compiler not supported!
    #endif



    {

        volatile  uint8_t receivedData;

        volatile uint8_t i4;

        i4=0;
        //    i3=0;

        switch (__even_in_range(UCA0IV,4)){
            //Vector 2 - RXIFG
            case 2:
                receivedData = USCI_A_UART_receiveData(USCI_A0_BASE);
    //            if(!(receivedData == transmitData))                   // Check value //JS--
    //            {                                 //JS--
    //              while(1);                       //JS--
    //            }                                 //JS--
                check =1;
                break;
            default: break;
        }
    }

    Jose Simoes

  • Take a step back and try the loopback example from TiRex.

  • Hi Jose,

    Through the situation you describe,  it did not enter the interrupt service function. You can refer to the following code, also using the P3.3 and P3.4 ports.

    http://dev.ti.com/tirex/explore/node?node=AO.y3PbPXQlPwKTmMax5Sw__IOGqZri__LATEST

    Best Regards

    Johnson

  • Thank you, this suggestion solved my question.

  • Thank you for your advice. I solved my question with another example:

    http://dev.ti.com/tirex/explore/node?node=AO.y3PbPXQlPwKTmMax5Sw__IOGqZri__LATEST

    José Simões

  • Hi Jose,

           Congratulations! I am glad to meet you on E2E,  and please ask directly on E2E if you have any problems later.

    Best Regards

    Johnson

**Attention** This is a public forum