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.

MSP430FR5739 I2C repeated start issue

Hey everyone,

for some reason when i send a repeated start i cant put it in reciever mode therefore setting the R/W bit high. After watching debug mode and trying to run to line (UCB0CTLW0 &= ~UCTR)  it skips over it and keeps it high there causing the R/W bit to stay low. why won't it execute this command. See below for a picture of my waveforms i can make. Also see below for the waveform (figure 8) im trying to make. please help.

I2c sequence:

transmit start in write mode

send command

send repeated start in read mode

#include <msp430.h>

#define SLAVE_ADDRESS 0x5A

int Temperature;

void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P4DIR |= BIT0;
P4OUT |= BIT0;
P1SEL1 |= BIT6 + BIT7;
UCB0CTL1 |= UCSWRST;
UCB0CTLW0 |= UCSYNC + UCMODE_3 + UCSSEL_2+ UCMST;
UCB0TBCNT |= 0x0002;
UCB0BR0 = 0x001F;
UCB0BR1 = 0;
UCB0CTLW1 = 0;
UCB0CTLW0 &= ~UCTR;
//UCB0CTLW0 |= UCSLA10;
UCB0I2CSA = SLAVE_ADDRESS;
// UCB0CTLW0 = UCSSEL_2 //+ UCSWRST;
UCB0CTL1 &= ~UCSWRST;
// UCB0IE |= UCTXIE + UCRXIE + UCNACKIFG;
P1OUT &= ~BIT7;
// __delay_cycles(100000);

for (;;) {

P1OUT &= ~BIT7;
__delay_cycles(100000);
P1OUT |= BIT7;
P1SEL1 |= BIT7;
UCB0CTLW0 |= UCTR;
UCB0CTLW0 |= UCTXSTT;

while ((UCB0CTLW0 & UCTXSTT) != 0)
//{}

UCB0TXBUF = 0x0007;

while ((UCB0IFG & UCTXIFG) != 0)

UCB0CTLW0 &= ~UCTR;

UCB0CTLW0 |= UCTXSTT;

}
}

  • According to figure 20-12 of the User's Guide, you should write TXBUF before waiting for UCTXSTT to clear.

    This code doesn't do anything after the repeated start. Don't you want to read something?
  • ahhh i see. I didn't realize that. Yes i want to read a command after the repeated start slave address. i know my code is super basic and sloppy. This is my 4th or 5th program so i'm still new to programming, but have learned so much. My approach is to keep a scope on it and get one thing working then write the next lines and see if they work etc. I believe getting the UCTR in receive mode will keep the clock running, so after the repeated start slave address is sent the clock will still be running so my device would then pull down the SDA lines and i could read the recieved data with scope then implement my code to store it so i know its accurate (maybe my logic is flawwed lol) . i could use the byte counter register to determine when to send the appropriate PEC and stop signals etc. all help and experience is welcome. ALSO i had to add the delay cycles line because the sensor requires the SCL to be held low to wake it up.

**Attention** This is a public forum