Other Parts Discussed in Thread: MSP430G2553, CC2500, MSP430F2274
Hey everyone,
I'm trying to use the MSP430 on this development board to communicate with another piece of hardware using the I2C bus. I've looked through a variety of old posts and example code and I've come up with the software below; however mine does not work. There seems to be a problem transmitting the START condition to my external device, and the code remains stuck in the while loop waiting for the UCTXSTT bit to be cleared (after confirming the address has been with the external device.
Can anyone offer a suggestion as to why I'm not moving pass the while loop?
Thanks.
#include "msp430x22x4.h"
char count, status, hr_data;
//int blah, test;
int main( void )
{
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
//P1.0 (RED) and P1.1 (GREEN) are LEDs
P1DIR = 0x03; // P1.0 and P1.1 as outputs
P1OUT = 0x00; // All P1 output pins to 0
//I2C Initialization
UCB0CTL1 |= UCSWRST; // Enable SW Reset
P3DIR |= 0x0F;
P3SEL |= 0x06; // Assign I2C pins to USCI_B0
UCB0CTL0 = UCMST+UCMODE_3+UCSYNC; // I2C Master, synchronous mode
UCB0CTL1 = UCSSEL_2+UCSWRST; // Use SMCLK, keep SW reset
UCB0BR0 = 24; // fSCL = SMCLK/24 = ~50kHz
UCB0BR1 = 0;
UCB0I2CSA = 0x7F; // Set Slave Address - 127 (is it 128?)
UCB0I2COA = 0x01; // Set master address (1)
UCB0CTL1 &= ~UCSWRST; // Clear SW reset, resume operation
while(1){
UCB0CTL1 |= UCTR + UCTXSTT; // I2C start condition
while (UCB0CTL1 & UCTXSTT); // Loop until I2C STT is sent
while(UCB0TXIFG == 0); // Wait until data can be written to UCB0TXBUF
UCB0TXBUF = 0x47; // Ask for the heart rate
while(UCB0TXIFG == 0); // Wait until data can be written to UCB0TXBUF
UCB0TXBUF = 0x01; // Ask for one heart rate data
while(UCB0TXIFG == 0); // Wait until the stop bit can be set
UCB0CTL1 |= UCTXSTP; // Generate a STOP Condition