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/MSP430F5438A: Send multiple bytes in a given time

Part Number: MSP430F5438A


Tool/software: Code Composer Studio

Hi,

I am trying to create an easy program which sends 3 byte ('A', 'B' and 'C') every second. But the problem is that I just can obtain de first byte ('A'), the othe two do not appear. How can I solve this? 

This is my code:

#include <msp430.h>

unsigned char data [3]={'A','B','C'};


void uartSend (unsigned char *pucData, unsigned char ucLength)
{
  while(ucLength !=0)
  {
    // Wait for TX buffer to be ready for new data
    while(!(UCA1IFG & UCTXIFG));

    // Push data to TX buffer
    UCA0TXBUF = *pucData;

    // Update variables
    ucLength--;
    pucData++;
  }

  // Wait until the last byte is completely sent
  while(UCA0STAT & UCBUSY);

}


int main(void)
{
  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
  P1DIR |= 0x01;                            // P1.0 output
  TA1CCTL0 = CCIE;                          // CCR0 interrupt enabled
  TA1CCR0 = 32768-1;
  TA1CTL = TASSEL_1 + MC_1 + TACLR;         // ACLK, upmode, clear TAR


  //Configuración UART
     UCA0CTL1 |= UCSWRST;                      // **Put state machine in reset**
     UCA0CTL1 |= UCSSEL_2;                     // SMCLK
     UCA0BR0 = 6;                              // 1MHz 9600 (see User's Guide)
     UCA0BR1 = 0;                              // 1MHz 9600
     UCA0MCTL = UCBRS_0 + UCBRF_13 + UCOS16;   // Modln UCBRSx=0, UCBRFx=0,
                                               // over sampling
 	P3SEL = 0x30;                             // P3.4,5 = USCI_A0 TXD/RXD
     UCA0CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**

  __bis_SR_register(LPM3_bits + GIE);       // Enter LPM3, enable interrupts
  __no_operation();                         // For debugger
}

// Timer A0 interrupt service routine
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=TIMER1_A0_VECTOR
__interrupt void TIMER1_A0_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(TIMER1_A0_VECTOR))) TIMER1_A0_ISR (void)
#else
#error Compiler not supported!
#endif
{
	 while (!(UCA0IFG&UCTXIFG)); // USCI_A0 TX buffer ready?
	  uartSend(data,3);

}

In the picture the data received through UART is shown.

Thanks in advance,

Regards

  • Hi Miguel,

    Start by changing UCA1IFG to UCA0IFG in line 11 and see if that fixes the issue.

    Regards,
    Ryan
  • Hi Ryan,

    thanks for your quick answer. The problem is fix with your solution.

    Now, I have change the uart send function in order to send a separator between bytes, but this produce this warning:

    #515-D a value of type "char *" cannot be assigned to an entity of type "unsigned char" ABC.c /msp430x54xA_ta3_05.c line 20 C/C++ Problem

     

    How can I solve it? I do not understand this warning because i just send a new byte with the separator "*".

    Code below show this:

    unsigned int data1 [3]={10,20,30};
    unsigned int data2 [3]={100,200,300};
    
    void uartSend (unsigned int *pucData, unsigned char ucLength)
    {
      while(ucLength !=0)
      {
        // Wait for TX buffer to be ready for new data
        while(!(UCA0IFG & UCTXIFG));
    
        // Push data to TX buffer
        UCA0TXBUF = *pucData;
        UCA0TXBUF = "*";
        // Update variables
        ucLength--;
        pucData++;
      }
    
      // Wait until the last byte is completely sent
      while(UCA0STAT & UCBUSY);
    
    }

    Thanks in advance another time

    Regards

  • Hello Miguel,

    Try single quotation marks instead: '*'

    Or the ASCII representation: 0x2A

    Regards,
    Ryan

  • Hello Ryan,

    Thanks for all and I am so sorry for the stupid question.

    Is it normal that uart sends data in ASCII? Because when I send for example:

    Uca0txbuf=125;

    The terminal receives "{" and not the decimal number.

    I would like receive the same same number, is it posible? Changing the way of send data?

    Regards,

    Miguel

  • Miguel,

    Your PC terminal interprets bytes sent through UART as ASCII characters, please see the ASCII table to better understand what you are sending or receiving: http://www.asciitable.com/

    If you want to send the decimal number 125 then you will have to split it into 3 separate bytes to send: '1' (0x31), '2' (0x32), and '5' (0x35).

    Regards,
    Ryan

**Attention** This is a public forum