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.

Switching From RS232 to I2C and back

Other Parts Discussed in Thread: MSP430F169

My code doesn't seem to be working. Using MSP430F169 trying to get a 1 one I Press 'd'  after switching from I2C Back to RS232

 

void main(void)
{
   WDTCTL = WDTPW + WDTHOLD;  // Stop watchdog timer
   InitUSART0();              // Initialize Serial UART Port 0
  
   
   _EINT();                   // Enable interrupts
}

// UART0 RX ISR
#pragma vector=USART0RX_VECTOR
__interrupt void usart0_rx (void)
{
   
 
  int flg_a = 0;
 
   if (RXBUF0 == 'd')                        // 'u' received?
  {
        InitI2C();
       flg_a = 1;
  
        DeInitI2c();
    InitUSART0();
     UART_transmit ('1');
 

  }
 if (flg_a == 0)
  {
        UART_transmit (RXBUF0);
  }
}

void DeInitI2c(void)
{
        U0CTL &= ~(I2C + SYNC);         ///// 1) Clear I2C, SYNC, and I2CEN (CLR.B &U0CTL)
        U0CTL &= ~I2CEN;
        UCTL0 |= SWRST;                ///////2) Set SWRST (MOV.B #SWRST,&U0CTL)
     
 
}
void InitI2C(void)
{
    P3SEL |= 0x0A;                            // P3.1,P3.3
    UCTL0  |= SWRST;
      U0CTL |= (I2C + SYNC);                    // Switch USART0 to I2C mode
      U0CTL &= ~I2CEN;                        // Recommended init procedure - Disable I2C
        U0CTL |= I2CEN;                         // Enable I2C, 7 bit addr,
}
void InitUSART0(void)
{
    P3SEL |= 0x30;                             // P3.4,3.5 = USART0 TXD/RXD
     UCTL0  |= SWRST;
      ME1 |= UTXE0 + URXE0;                     // Enabled USART0 TXD/RXD
      UCTL0 |= CHAR;                            // 8-bit character, SWRST=1
      UTCTL0 |= SSEL0;                          // UCLK = ACLK
      UBR00 = 0x03;                             // 9600 from 1Mhz
      UBR10 = 0x00;                             //
      UMCTL0 = 0x4A;                            // Modulation
      UCTL0 &= ~SWRST;                          // Initialize USART state machine
      IE1 |= URXIE0 + UTXIE0;                   // Enable USART0 RX/TX interrupt
      IFG1 &= ~UTXIFG0;
     
     
    
}

void UART_transmit (unsigned char Transmit_Data)              //UART1 Transmit Subroutine
{
     TXBUF0 = Transmit_Data;                   //send data
}  

**Attention** This is a public forum