msp430f247 rs232 and i2c communication

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

  1. sweetbasi

    Thread Starter New Member

    Jan 27, 2012
    8
    0
    I want to send some instruction through rs232 to msp430f247 which inturn communicates with a battery through i2c...(infact smbus and there is a level shifter between battery and msp430f247...) Iam not able to get the output. I want to confirm if my code is correct.
    This is my code.

    Code ( (Unknown Language)):
    1.  
    2. #include <msp430F247.h>
    3. #include "Global_Variables.h"
    4. void main(void)
    5. {
    6.    
    7.  WDTCTL = WDTPW + WDTHOLD;                     // Stop WDT
    8.       _DINT();                                  //Disable Interrupt
    9.       _NOP();
    10.      
    11.      if (CALBC1_8MHZ ==0xFF || CALDCO_8MHZ == 0xFF)      // If calibration constants erased, do not load, trap CPU!!
    12.         {
    13.         while(1);                              
    14.         }
    15.  
    16.       BCSCTL1 = CALBC1_8MHZ;                    // Set DCO to 8MHz
    17.       DCOCTL = CALDCO_8MHZ;
    18.  
    19. Init_Module_UART_115200();                  
    20.  
    21. Init_I2c();
    22. _EINT(); // Enable interrupts
    23. }
    24.  
    25.  
    26. void DeInitI2c(void)
    27. {
    28. UCB1CTL0 &= ~(ENC+UCSYNC); ///// 1) Clear I2C, SYNC, and I2CEN (CLR.B &U0CTL)
    29. UCB1CTL1 |= UCSWRST; ///////2) Set SWRST (MOV.B #SWRST,&U0CTL)
    30.  
    31.  
    32. }
    33. void Init_I2c(void)
    34. {
    35. P5SEL |= BIT1+BIT2;                                // P5.1,P5.2
    36. UCB1CTL0 |= (UCMST + UCMODE_3  + UCSYNC);           // Master, I2C mode, Synchronous.
    37. UCB1CTL1 &= ~UCSWRST;                     // Clear SW reset, resume operation
    38.   IE2 |= UCB1RXIE;                          // Enable RX interrupt
    39. UCB1CTL1 |= (UCSSEL_2 + UCSWRST);                // SMCLK, Transmitter, Software reset.
    40.                        
    41. UCB1I2CSA = 0x16;                         //battery slave
    42. UCB1CTL0 |= USISWRST;
    43. }
    44. void Init_Module_UART_115200(void)
    45. {
    46.   UCA1CTL1 |= UCSWRST;
    47.   P3SEL |= 0xC0;                                // P3.6,7 = USCI_A1 TXD/RXD
    48.   UCA1CTL1 |= UCSSEL_2;                         // SMCLK
    49.   UCA1BR0 = 69;                                    // 1MHz 115200; (104)decimal = 0x068h
    50.   UCA1BR1 = 0;                                  // 1MHz 115200
    51.   UCA1MCTL = UCBRS2+ UCBRS1;                              // Modulation UCBRSx =6
    52.   UCA1CTL1 &= ~UCSWRST;                         // **Initialize USCI state machine**
    53.   UC1IE |= UCA1RXIE;
    54.  
    55. }
    56.  
    57. #pragma vector=USCIAB1RX_VECTOR
    58. __interrupt void USCIAB1RX_ISR(void){
    59.      
    60.   //while (!(UC1IFG & UCB1TXIFG));            // USCI_B1 TX buffer ready?
    61.    
    62.   while( UCA1RXBUF== 0)  
    63.   {
    64.   }                
    65.  UCB1TXBUF = UCA1RXBUF;
    66.  while( UCB1TXBUF== 0)  
    67.   {
    68.   }  
    69.   UCA1RXBUF = UCB1TXBUF;// RX -> TXed character
    70.   DeInitI2c();
    71. }
    72.  
    73. /*#pragma vector = USCIAB1TX_VECTOR
    74. __interrupt void USCIAB1TX_ISR(void)
    75. {
    76.   RXData = UCB0RXBUF;                       // Get RX data
    77.   __bic_SR_register_on_exit(CPUOFF);        // Exit LPM0
    78. }
    79. */
    80.  
     
    Last edited by a moderator: Jul 31, 2012
  2. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    I2C will run at any speed down to zero... meaning you can troubleshoot it with a dc meter or a LED if that is all you have.

    Look for the ACK bit first. If the address you send first is not ACKed then nothing else is possible.

    Sorry I will not read all that code.
     
  3. sweetbasi

    Thread Starter New Member

    Jan 27, 2012
    8
    0
    In msp430f247 both uart and i2c have the same USCIAB1RX_VECTOR or USCIAB0RX_VECTOR...So how do I manage?
     
Loading...