rs232 communication with msp430f247

Discussion in 'Embedded Systems and Microcontrollers' started by sweetbasi, Jul 11, 2012.

  1. sweetbasi

    Thread Starter New Member

    Jan 27, 2012
    8
    0
    Code ( (Unknown Language)):
    1.  
    2. #include "msp430x24x.h"
    3.  
    4. void main(void)
    5. {
    6.   WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
    7.   if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ == 0xFF)                                    
    8.   {  
    9.     while(1);                               // If calibration constants erased
    10.                                             // do not load, trap CPU!!
    11.   }  
    12.   BCSCTL1 = CALBC1_1MHZ;                    // Set DCO
    13.   DCOCTL = CALDCO_1MHZ;
    14.   P3SEL |= 0x0C0;                           // P3.6,7 = USCI_A1 TXD/RXD
    15.   UCA1CTL1 |= UCSSEL_2;                     // SMCLK
    16.   UCA1BR0 = 8;                              // 1MHz 115200
    17.   UCA1BR1 = 0;                              // 1MHz 115200
    18.   UCA1MCTL = UCBRS2 + UCBRS0;               // Modulation UCBRSx = 5 ucbrs0
    19.   UCA1CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**
    20.   UC1IE |= UCA1RXIE;                        // Enable USCI_A1 RX interrupt
    21.  
    22.   __bis_SR_register(LPM0_bits + GIE);       // Enter LPM0, interrupts enabled
    23. }
    24.  
    25. // Echo back RXed character, confirm TX buffer is ready first
    26. #pragma vector=USCIAB0RX_VECTOR
    27. __interrupt void USCIAB0RX_ISR(void){
    28.   while (!(UC1IFG & UCA1TXIFG));            // USCI_A1 TX buffer ready?
    29.   UCA1TXBUF = UCA1RXBUF;                    // TX -> RXed character
    30. }
    31.  
    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: Jul 27, 2012
  2. JMac3108

    Active Member

    Aug 16, 2010
    349
    66
    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?
     
  3. sweetbasi

    Thread Starter New Member

    Jan 27, 2012
    8
    0
    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: Jul 14, 2012
  4. JMac3108

    Active Member

    Aug 16, 2010
    349
    66
    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.
     
  5. sweetbasi

    Thread Starter New Member

    Jan 27, 2012
    8
    0
    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...
    Code ( (Unknown Language)):
    1.  
    2. #include <msp430F247.h>
    3. #include "Global_Variables.h"
    4. #define   Num_of_Results   8
    5.  
    6. volatile unsigned int results[Num_of_Results];  // Needs to be global in this
    7.                                               // example. Otherwise, the
    8.                                               // compiler removes it because it
    9.                                               // is not used for anything.
    10.  
    11.  
    12. void main(void)
    13. {
    14.       WDTCTL = WDTPW + WDTHOLD;                     // Stop WDT
    15.       _DINT();                                  //Disable Interrupt
    16.       _NOP();
    17.      
    18.      if (CALBC1_8MHZ ==0xFF || CALDCO_8MHZ == 0xFF)      // If calibration constants erased, do not load, trap CPU!!
    19.         {
    20.         while(1);                              
    21.         }
    22.  
    23.       BCSCTL1 = CALBC1_8MHZ;                    // Set DCO to 8MHz
    24.       DCOCTL = CALDCO_8MHZ;
    25.      
    26.      //SVSCTL = 0x60 + PORON;
    27.          // SVS POR enabled @ 2.5V
    28.     Init_ADC12();    
    29.      
    30.      
    31.  
    32.       _EINT();                                 //Enable Global Interrupt
    33.        
    34.  }        
    35.  
    36. void Init_ADC12(void)
    37. {
    38.  ADC12CTL0 &= ~ENC;
    39.   P6SEL |= 0x02;  
    40.   P6DIR &=~0x02;                         // Enable A/D channel A1
    41.  
    42.   ADC12CTL0 = ADC12ON+SHT0_8+MSC;           // Turn on ADC12, set sampling time
    43.   ADC12CTL1 = SHP+CONSEQ_2+ADC12SSEL_3+ADC12DIV_1; // Use sampling timer, set mode
    44.      ADC12MCTL1= INCH_1;                             //A1                
    45.   ADC12IE = 0x01;                                 // Enable ADC12IFG.0
    46.  
    47.   ADC12CTL0 |= ENC;                         // Enable conversions
    48.  
    49.    while(1)
    50.   {
    51.   ADC12CTL0 |= ADC12SC;                     // Start convn - software trigger
    52.   _BIS_SR(LPM0_bits + GIE);                 // Enter LPM0, Enable interrupts
    53.   }
    54.  
    55.   /*ADC12CTL0 |= ADC12SC;                     // Start conversion
    56.    _BIS_SR(LPM0_bits + GIE);                 // Enter LPM0, Enable interrupts*/
    57.  
    58. }
    59.  
    60.  
    61.  
    62.  
    63. void Init_Module_UART_115200(void)
    64. {
    65.   UCA1CTL1 |= UCSWRST;
    66.   P3SEL |= 0xC0;                                // P3.6,7 = USCI_A1 TXD/RXD
    67.   UCA1CTL1 |= UCSSEL_2;                         // SMCLK
    68.   UCA1BR0 = 69;                                    // 1MHz 115200; (104)decimal = 0x068h
    69.   UCA1BR1 = 0;                                  // 1MHz 115200
    70.   UCA1MCTL = UCBRS2+ UCBRS1;                              // Modulation UCBRSx = 6
    71.   UCA1CTL1 &= ~UCSWRST;                         // **Initialize USCI state machine**
    72.   //UC1IE |= UCA1RXIE;
    73.  
    74. }
    75.  
    76.  
    77.  
    78. #pragma vector=ADC12_VECTOR
    79. __interrupt void ADC12ISR (void)
    80. {    
    81.  //static unsigned int index = 0;
    82.  //ADC12MEM0=0;
    83.  while(ADC12MEM0==0)
    84. {
    85. }
    86. Init_Module_UART_115200();    
    87.            
    88.   UCA1TXBUF= ADC12MEM0;               // Move results
    89.   //index = (index+1)%Num_of_Results;         // Increment results index, modulo; Set Breakpoint1 here
    90.   //if (index == 0)
    91.   //  _NOP();                                 // Set Breakpoint2 here
    92.  
    93.  
    94.  
    95. }
    96.  



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