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 between resources



I have to switch between I2C and SPI in MS430F2254 on UCB0, they share the data pin, and I am not using DIN in SPI mode. SPI works fine but I2C doesn't work after reinitializing the UCB0 for I2C. Sometimes there is no clock and other times there is negative acknowledge from the slave. In both SPI and I2c, uC is the master.

I wanted to know if switching between resources has been tried by anyone? Can it be done? if so; is there a special reinitialization sequence? or the same initialization should work?

Please advise

  • Are you making sure to switch the port pins appropriately between modes?

    Are you resetting the USCI when you switch modes?

  • I set the reset bit in CTL1 as follows:

    void InitI2C()
    {
        // I2C
        UCB0CTL1 = UCSWRST;                        // reset the uart
        UCB0CTL0 = UCMST+UCMODE_3+UCSYNC;        // I2C master, 7 bit address
        UCB0CTL1 = UCSSEL_2 + UCSWRST;            // clock source SMCLK
        UCB0BR0 = 12;                            // 100k
        UCB0BR1 = 0;
        UCB0STAT = 0;
        UCB0I2COA = 0;
        UCB0I2CSA = 0xC0;
        UCB0I2CIE = 0x0;
        //UCNACKIE:    Bit 3 Not-acknowledge interrupt enable
        //UCSTPIE:    Bit 2 Stop condition interrupt enable
        //UCSTTIE:    Bit 1 Start condition interrupt enable
        //UCALIE:    Bit 0 Arbitration lost interrupt enable

        P3SEL = 0;
        P3DIR = 0xDD;                            // set unused pins as output
        P3SEL = 0x3E;

        IFG2 &= ~UCB0TXIFG;
        IFG2 &= ~UCB0RXIFG;
        UCB0CTL1 &= ~UCSWRST;                    // remove the reset
        // enable interrupts
        //UCB0I2CIE = UCALIE+UCSTTIE+UCSTPIE+UCNACKIE;
        IE2 |= UCB0RXIE + UCB0TXIE;
    }

    void InitSPI()
    {
        // SPI
          UCB0CTL1 = UCSWRST;                        // reset the uart
        UCB0CTL0 = UCMSB+UCMST+UCMODE_0+UCSYNC+UCCKPH;    // master, 8 bit, MSB first,
        UCB0CTL1 = UCSSEL_2 + UCSWRST;            // clock source SMCLK
        UCB0BR0 = 4;                            // 250k
        UCB0BR1 = 0;
        UCB0STAT = 0;

        P3SEL = 0;
        P3DIR = 0xDD;                            // set unused pins as output
        P3SEL = 0x3E;

        IFG2 &= ~UCB0TXIFG;
        IFG2 &= ~UCB0RXIFG;
        UCB0CTL1 &= ~UCSWRST;                    // remove the reset
        // enable interrupts
        IE2 |= UCB0RXIE + UCB0TXIE;
    }

  • While an SPI slave will ignore all bus activities while not being selected (separate CS signal), the I2C slaves woN't be deaf when you push the SPI data over the line. YOu might accidentally address a slave, or jsut confuse them by apparent start conditions or such.

    At least you should do a dummy transfer (start with an unused slave address, then stop) before trying an I2C transfer after an SPI transfer.

    Also, keep in mind that the mandatory pullups for I2C have an impact on the signal in SPI mode. I wouldn't try to go with maximum speed.

**Attention** This is a public forum