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.

msp430f2618 UART

Other Parts Discussed in Thread: MSP430F2618

Hi,

I want to transfer a text file that contain few characters. i am using hyper-terminal to send this file to UART in receive mode. The below is the code:

#include <msp430f2618.h>
/*
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
if (CALBC1_1MHZ==0xFF) // If calibration constant erased
{
while(1); // do not load, trap CPU!!
}
DCOCTL = 0; // Select lowest DCOx and MODx settings
BCSCTL1 = CALBC1_1MHZ; // Set DCO
DCOCTL = CALDCO_1MHZ;
P3SEL = 0x30; // P3.4,5 = USCI_A0 TXD/RXD
P3OUT &= ~(BIT4+BIT5);
UCA0CTL1 |= UCSSEL_2; // SMCLK
UCA0BR0 = 68; // 1MHz 115200
UCA0BR1 = 0; // 1MHz 115200
UCA0MCTL = UCBRS_1 + UCBRF_0; // Modulation UCBRSx = 5
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
IE2 |= UCA0RXIE; // Enable USCI_A0 RX interrupt

__bis_SR_register(LPM0_bits + GIE); // Enter LPM0, interrupts enabled
}

// Echo back RXed character, confirm TX buffer is ready first
#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)
{
while (!(IFG2&UCA0TXIFG)); // USCI_A0 TX buffer ready?
UCA0TXBUF = UCA0RXBUF; // TX -> RXed character
__bic_SR_register_on_exit(LPM0_bits);
}


*/
//unsigned char *msg = "hello";
static unsigned char recv_file_data[17];
static unsigned int k=0;

int main(void)
{
unsigned int i;
WDTCTL = WDTPW + WDTHOLD;

if (CALBC1_1MHZ ==0xFF || CALBC1_1MHZ == 0xFF)
{
while(1); // If calibration constants erased
// do not load, trap CPU!!
}
BCSCTL1 = CALBC1_1MHZ; // Set DCO to 8MHz
DCOCTL = CALBC1_1MHZ;

// Stop WDT
P3OUT &= ~(BIT4+BIT5);
P3SEL = 0x30; // P3.4,5 = USCI_A0 TXD/RXD
UCA0CTL1 |= UCSSEL_2; // CLK = ACLK
UCA0BR0 = 0x08; // 1MHz/115200
UCA0BR1 = 0x00; //
UCA0MCTL = UCBRS_5 + UCBRF_0; // Modulation UCBRSx = 3
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
IE2 |= UCA0RXIE; // Enable USCI_A0 RX interrupt

__bis_SR_register(LPM3_bits + GIE);
__no_operation();
__no_operation();

for(i = 0;i<17;i++)
{
UCA0TXBUF = recv_file_data[i];
while (!(IFG2&UCA0TXIFG));

}

}

// Echo back RXed character, confirm TX buffer is ready first
#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)
{
while (!(IFG2&UCA0TXIFG)); // USCI_A0 TX buffer ready?
 recv_file_data[k++] = UCA0RXBUF;
//UCA0TXBUF = UCA0RXBUF;
__bic_SR_register_on_exit(LPM3_bits);
}

But i am not getting recv_file_data[] with the file content.

How can i check this it is hanging just after "__bis_SR_register(LPM3_bits + GIE);" line.

regards.

  • hello one more time,

    I wrote you solution

    http://e2e.ti.com/support/microcontrollers/msp430/f/166/p/344965/1206053.aspx#1206053

    what is wrong ?

  • Hi Lukasz,

    I am able to receive only one character but i want to receive multiple characters from the file how can we implement it?

    Please help considering my previous post for receiving multiple character from a file.

     

  • ok I wrote code for you,

    MSP430 recived data until end sign (in this example CR-0x0d)

    or until data amout will be equal 90 (you can modyfied this code)

    #include <msp430.h>
    
    #define  MAX_REC_DATA_SIZE  (unsigned char)    100
    
    #define  MAX_FILE_SIZE      (unsigned char)     90  
    #define  END_FILE_SIGN      (unsigend char)    0x0d
    
    
    volatile unsigned char index = 0;
    unsigned char     recv_file_data[MAX_REC_DATA_SIZE];
    
    int main(void)
    {
      WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
      if (CALBC1_1MHZ==0xFF)                    // If calibration constant erased
      {                                        
        while(1);                               // do not load, trap CPU!! 
      }
      DCOCTL = 0;                               // Select lowest DCOx and MODx settings
      BCSCTL1 = CALBC1_1MHZ;                    // Set DCO
      DCOCTL = CALDCO_1MHZ;
      P3SEL = 0x30;                             // P3.4,5 = USCI_A0 TXD/RXD
      UCA0CTL1 |= UCSSEL_2;                     // SMCLK
      UCA0BR0 = 6;                              // 1MHz 9600
      UCA0BR1 = 0;                              // 1MHz 9600
      UCA0MCTL = UCBRF3 + UCOS16;               // Modln UCBRSx=1, over sampling
      UCA0CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**
      IE2 |= UCA0RXIE;                          // Enable USCI_A0 RX interrupt
    
     while(1)
     {
          __bis_SR_register(LPM0_bits + GIE);   // Enter LPM0, interrupts enabled
          
          __no_operation();                     // <- set breakpoint here
          index = 0;                            // clear index
                                                // work with recived data
    
      }
    
    }
    #pragma vector=USCIAB0RX_VECTOR
    __interrupt void USCI0RX_ISR(void)
    {
      unsigned char sign;
      
      sign = UCA0RXBUF;
      
       if(index < MAX_REC_DATA_SIZE)	
                      recv_file_data[index ] = sign;
    
       
       if(sign == END_FILE_SIGN || index == MAX_FILE_SIZE)
                    __bic_sr_register_on_exit(LPM0_bits);
    
    index += 1; }

  • HI Lukasz,

    I am getting this error:

    Warning[Pe223]: function "__bic_sr_register_on_exit" declared implicitly E:\MSP430F2618\MSP430F2618_flash_SPI\UART_multi_RX.c 53
    Linking
    Error[e46]: Undefined external "__bic_sr_register_on_exit" referred in UART_multi_RX ( E:\MSP430F2618\MSP430F2618_flash_SPI\Debug\Obj\UART_multi_RX.r43 )
    Error while running Linker

    Total number of errors: 1
    Total number of warnings: 1

  • sorry I wrote code in notepad :)

    __bic_SR_register_on_exit(LPM0_bits)

     

    will be ok,

     

  • Hi Lukasz,

    I am really happy that i am able to receive the data.

    I have few things to know from this example:

    1. can we use it without a wile(1) if we know size of the file?

    2. can we implement this without ISR vector means using polling?

    3. i have file with hexa file, each byte is separated by a comma does this work?

    regards.

  • 3 times YES, code is below,

    you can set breakpoint (look in code)

    and you can check all data in recived buffor,

    #include <msp430.h>
    #define  MAX_REC_DATA_SIZE  (unsigned int)    100
    
    
    unsigned int 	  index = 0;
    unsigned char     recv_file_data[MAX_REC_DATA_SIZE];
    
    int main(void)
    {
      WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
      if (CALBC1_1MHZ==0xFF)                    // If calibration constant erased
      {                                       
        while(1);                               // do not load, trap CPU!!
      }
      DCOCTL = 0;                               // Select lowest DCOx and MODx settings
      BCSCTL1 = CALBC1_1MHZ;                    // Set DCO
      DCOCTL = CALDCO_1MHZ;
      P3SEL = 0x30;                             // P3.4,5 = USCI_A0 TXD/RXD
      UCA0CTL1 |= UCSSEL_2;                     // SMCLK
      UCA0BR0 = 6;                              // 1MHz 9600
      UCA0BR1 = 0;                              // 1MHz 9600
      UCA0MCTL = UCBRF3 + UCOS16;               // Modln UCBRSx=1, over sampling
      UCA0CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**
    
    //
      while(index < MAX_REC_DATA_SIZE )	
      {
    	while (!(IFG2&UCA0RXIFG)); 
    	recv_file_data[index ] = UCA0RXBUF;
    	index += 1;
       }
    
    
      // your data are recived
      __no_operation();                     // <- set breakpoint here
     
      while(1){};
    }

  • Hi Lukasz,

    Thank you very much for help. Every thing is working fine.

    Regards.

  • Hey Uma , will u close the thread by checking Verify answer in any of lukazas posts pleazse.

**Attention** This is a public forum