rs232 communication with msp430f247

Thread Starter

sweetbasi

Joined Jan 27, 2012
8
Rich (BB code):
#include "msp430x24x.h"

void main(void)
{
  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
  if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ == 0xFF)                                     
  {  
    while(1);                               // If calibration constants erased
                                            // do not load, trap CPU!!
  }   
  BCSCTL1 = CALBC1_1MHZ;                    // Set DCO
  DCOCTL = CALDCO_1MHZ;
  P3SEL |= 0x0C0;                           // P3.6,7 = USCI_A1 TXD/RXD
  UCA1CTL1 |= UCSSEL_2;                     // SMCLK
  UCA1BR0 = 8;                              // 1MHz 115200
  UCA1BR1 = 0;                              // 1MHz 115200
  UCA1MCTL = UCBRS2 + UCBRS0;               // Modulation UCBRSx = 5 ucbrs0
  UCA1CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**
  UC1IE |= UCA1RXIE;                        // Enable USCI_A1 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 USCIAB0RX_ISR(void){
  while (!(UC1IFG & UCA1TXIFG));            // USCI_A1 TX buffer ready?
  UCA1TXBUF = UCA1RXBUF;                    // TX -> RXed character
}
This is code i've written to test msp430f247 uart communication. But there is no reply from the processor. What is the mistake in this?

Thanks in advance
 
Last edited by a moderator:

JMac3108

Joined Aug 16, 2010
348
Couple comments...

You didn't say exactly 'how' it didn't work.

One approach I often take when debugging is to remove everything that is unecessary to make sure that its not causing the problem. There are two things you can eliminate immediately by simply commenting them out without affecting your program. These are probably not the issue, but try anyway because its fast and easy.

(1) Comment out the part that checks the calibration constants.
(2) Comment out the low power mode setting

I discovered the following issue recently with an MSP430 and you might check it out. If you change the DCO frequency before the power supply voltage has reached the level required for that particular frequency, the system will lock. This happens sometimes because the MSP430 comes out of reset and boots at a low voltage, and you change the DCO almost first thing in your program. I had to add a software delay before changing the DCO.

Have you looked at the sample TI code? They have samples that you chould be able to compare or even paste into your code.

Then of course there is always the possibility that you connected the hardware wrong.

By the way, how are you testing that the program works?
 

Thread Starter

sweetbasi

Joined Jan 27, 2012
8
Iam using 3.6,3.7 (RS232-A1). There is no sample code for this directly to copy paste. But I don't know if there are any specified conditions for usig A1 RS-232...? And I don't know how this simple code doesn't work...It's not AB0...it's AB1 in the last part...And the problem is...no response from MSP430f247 and is there any particular software other than teraterm...etc.; to send data through rs-232 to msp430f247
 
Last edited:

JMac3108

Joined Aug 16, 2010
348
OK, lets step back and check the basics ...

Are you connecting the MSP430 serial port to a PC serial port and using TeraTerm to test it?

Are you aware that you need a level shifter to convert the digital RX and TX signals from the MSP430 to RS-232 levels for your PC serial port? The usual way to do this is with some version of the MAX232 chip.
 

Thread Starter

sweetbasi

Joined Jan 27, 2012
8
it's working now...der was a problem in the board.now i've got a weird problem now...i want to convert adc data from A1 and transfer it through rs232 to the pc...here is my code...
Rich (BB code):
#include <msp430F247.h>
#include "Global_Variables.h"
#define   Num_of_Results   8

volatile unsigned int results[Num_of_Results];  // Needs to be global in this
                                              // example. Otherwise, the
                                              // compiler removes it because it
                                              // is not used for anything.


void main(void)
{
      WDTCTL = WDTPW + WDTHOLD;                     // Stop WDT
      _DINT();                                  //Disable Interrupt
      _NOP();
      
     if (CALBC1_8MHZ ==0xFF || CALDCO_8MHZ == 0xFF)      // If calibration constants erased, do not load, trap CPU!! 
        {
        while(1);                               
        }

      BCSCTL1 = CALBC1_8MHZ;                    // Set DCO to 8MHz
      DCOCTL = CALDCO_8MHZ;
      
     //SVSCTL = 0x60 + PORON; 
         // SVS POR enabled @ 2.5V 
    Init_ADC12();     
     
     

      _EINT();                                 //Enable Global Interrupt
       
 }        

void Init_ADC12(void)
{
 ADC12CTL0 &= ~ENC;
  P6SEL |= 0x02;  
  P6DIR &=~0x02;                         // Enable A/D channel A1

  ADC12CTL0 = ADC12ON+SHT0_8+MSC;           // Turn on ADC12, set sampling time
  ADC12CTL1 = SHP+CONSEQ_2+ADC12SSEL_3+ADC12DIV_1; // Use sampling timer, set mode
     ADC12MCTL1= INCH_1;                             //A1                
  ADC12IE = 0x01;                                 // Enable ADC12IFG.0

  ADC12CTL0 |= ENC;                         // Enable conversions
  
   while(1)
  {
  ADC12CTL0 |= ADC12SC;                     // Start convn - software trigger
  _BIS_SR(LPM0_bits + GIE);                 // Enter LPM0, Enable interrupts
  }
  
  /*ADC12CTL0 |= ADC12SC;                     // Start conversion
   _BIS_SR(LPM0_bits + GIE);                 // Enter LPM0, Enable interrupts*/
  
}




void Init_Module_UART_115200(void)
{
  UCA1CTL1 |= UCSWRST;
  P3SEL |= 0xC0;                                // P3.6,7 = USCI_A1 TXD/RXD
  UCA1CTL1 |= UCSSEL_2;                         // SMCLK
  UCA1BR0 = 69;                                    // 1MHz 115200; (104)decimal = 0x068h
  UCA1BR1 = 0;                                  // 1MHz 115200
  UCA1MCTL = UCBRS2+ UCBRS1;                              // Modulation UCBRSx = 6
  UCA1CTL1 &= ~UCSWRST;                         // **Initialize USCI state machine**
  //UC1IE |= UCA1RXIE;
  
}



#pragma vector=ADC12_VECTOR
__interrupt void ADC12ISR (void)
{    
 //static unsigned int index = 0;
 //ADC12MEM0=0;
 while(ADC12MEM0==0)
{
} 
Init_Module_UART_115200();     
            
  UCA1TXBUF= ADC12MEM0;               // Move results
  //index = (index+1)%Num_of_Results;         // Increment results index, modulo; Set Breakpoint1 here
  //if (index == 0)
  //  _NOP();                                 // Set Breakpoint2 here
  

 
}



but i get some random junk data with and even without giving input...anything wrong with the code?
 
Last edited by a moderator:
Top