Quantcast
Channel: MSP430 Technical Forums
Viewing all articles
Browse latest Browse all 2077

I2C Repeat start

$
0
0

Hi All,

 

Using the MSP430FR5739 UCSI_B in i2c mode.

 

Just checking ive got this right, as I've never used it before.
I neod to do the following, Ive left out the ack's
 
S= start
E= stop
 
[S][Address+write][Register][S][Address+read][Read 6 bytes][E]
 
Setup at beginning of program:


UCB0CTL1 = UCSWRST; // put eUSCI_B in reset state


UCB0CTLW0 = UCMODE_3 | UCMST | UCSSEL__SMCLK; //I2C master mode
UCB0BRW = 0x0008; //clock scaler


UCB0CTL1 &= !UCSWRST; // eUSCI_B in operational state
UCB0IE |= UCTXIE; // Enable interrupts

Program calls the following to get things going:


UCB0CTL1 |= UCSWRST; // put eUSCI_B in reset state


UCB0CTLW1 |= UCASTP_2; // stop after bytes sent
UCB0TBCNT = 6; // automatic stop after bytes

UCB0CTL1 &= !UCSWRST; // eUSCI_B in operational state

UCB0I2CSA = 0x3A; // address of slave
UCB0CTLW0 |= UCTR; //transmitter mode
UCB0CTLW0 |= UCTXSTT; // generate start condition,
Transmit interrupt (should 1 byte and then get ready to send a repeat start once that byte has finished)
case 0x18: // Vector 24: TXIFG0 Ok to accept data into buffer

UCB0TXBUF = 0x32; // send register of first byte of data
//I2C will start sending this data
//Get i2c ready for next bit
UCB0CTLW0 &= !UCTR; //receive mode
UCB0CTLW0 |= UCTXSTT; // generate start condition.
break;
Receive interrupt (accel[] is a char array where I want to store the data, should receive 6 bytes into this array then stop.
The auto stop was setup at the beginning.
case 0x16: // Vector 22: RXIFG0 Ready to take data from buffer

accel[UCB0TBCNT] = UCB0RXBUF; //Get data from buffer
break;

Thanks in advance!


Viewing all articles
Browse latest Browse all 2077

Trending Articles