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.

CC430F5135 hardware I2C, problem to communicate with DS1803

Other Parts Discussed in Thread: MSP430WARE

Hello,

I have problem with communication to DS1803 using hardware I2C of msp430 .

My code is

#include  "cc430x513x.h"

void I2C_init(void)
{
PMAPPWD = 0x02D52;                        // Get write-access to port mapping regs
PMAPCTL |= PMAPRECFG;                       //Allow reconfiguration of port mapping
P1MAP1 = PM_UCB0SCL;                      // Map PM_UCB0SCL output to P1.1
P1MAP0 = PM_UCB0SDA;                      // Map PM_UCB0SDA output to P1.0
PMAPPWD = 0;
 
UCB0CTL1 |= UCSWRST;                      // Enable SW reset     
UCB0CTL0 = UCMST + UCMODE_3 + UCSYNC;     // I2C Master, synchronous mode
UCB0CTL1 |= UCSSEL_3 + UCSWRST;           // Use SMCLK, keep SW reset
UCB0BR0 = 12;                             // fSCL = SMCLK/12 = ~100kHz
UCB0BR1 = 0;
UCB0I2CSA = 0x28;                         // Set slave address

P1SEL |= BIT0+ BIT1;
P1DIR |= BIT0+ BIT1;

UCB0CTL1 &= ~UCSWRST;                     // Clear SW reset, resume operation
}

void I2C_send(void)
{
__disable_interrupt();                // Global interrupt disable
UCB0CTL1 |= UCTR+UCTXSTT;             // Switch to I2C transmit mode, send START condition
UCB0TXBUF = 0xAF;                     // Send control byte 10101111 -setting both wipers
UCB0TXBUF = 0xFF;                     // Send wipers position on FULL(VCC)
UCB0CTL1 |= UCTXSTP;                // STOP condition send
__enable_interrupt();                //global interrupt enable
}

and when I call up the I2C-send function it goes through whole code without hunging, but on the scope I can see that were send only start condition, adress, write mode, and control bite marked by yellow. Next in the row should be sent data bate, but as you can see below on the picture it is not. My ask have someone had similar problem and can help me? Is there any very simple example how to use hardware I2C?



  • The UCBxTXBUF register is only supposed to be written to when the UCBxTXBUF is ready for new data (UCTXIFG is set). See the Universal Serial Communication Interface – I2C Mode chapter of the CC430 Family User's Guide for details.

    The following code attempts two back-to-back writes to the UCBxTXBUF, and so the second write will be discarded (which ties up with scope capture): 

    UCB0TXBUF = 0xAF; // Send control byte 10101111 -setting both wipers

    UCB0TXBUF = 0xFF; // Send wipers position on FULL(VCC)

    See the MSP430ware examples\devices\cc430\CC430x513x Code Examples\C\cc430x513x_uscib0_i2c_08.c file for how use an interrupt routine to pace the transmit of multiple bytes from a I2C master.

  • I am reding I2C Mode chapter of the CC430 family all the time and my problem can try to do it without interrupt. Can I do it in the following way without use of interrupt:

    -sent START condition,

    -load first data byte to UCBxTXBUF

    -wait till UCTXIFG will be set

    -load second data byte to UCBxTXBUF

    -wait again till UCTXIFG will be set

    -sent STOP condition.

  • Marcin Gajewski said:
    Can I do it in the following way without use of interrupt:

    Yes.

    However, it would be better to do some additional checking:

    - wait until UCSTP is clear (previous transfer ended)
    - check UCBUSY (just in case there is more than one master)
    - send START condition
    - write first byte to TXBUF
    - wait until UCTXSTT is clear again
    - check UCNACKIFG bit
    - if set, send STOP and exit (slave didn't answer, byte written to TXBUF is discarded)
    - if clear, wait for UCTXIFG (should be set already at this point)
    - load next data byte to TXBUF
    - wait for UCTXIFG
    - send STOP.

**Attention** This is a public forum