Hey guys and gals,
I have been searching and reading all posts about MSP430 and TMP112 I2C setup. I for the life of me cannot read any information from the TMP112. The TMP112 ADD0 pin is connected to ground so therefore, I am addressing it as 0x48. I've been oscoping this and I am getting a clock and data on the SCL and SDA lines respectfully. Below is my code, and I removed a lot from it that I was using to troubleshoot it.
When I am debugging I am only getting 0xFF from the RXBUF. Also, are my sequence and notes accurate? What am I missing from code? Please help. Thank you.
#include <msp430x26x.h>
#include <stdlib.h> //Processor specific definitions
#include <stdio.h>
unsigned char SADDR = 0x48; //Slave address for TMP112 WRITE TO 0b01001000
unsigned char RADDR = 0x00; //Slave register address for TMP112
unsigned char temp= 0x00; //assign temperature variable
void I2C_Setup_B1(); // Define Initialization of Systems
void init_setup();
void readI2C();
void init_clock();
int main( void )
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
init_clock();
init_setup();
while(1)
{
readI2C();
}
}
void init_clock()
{
// Turning on XTAL2
BCSCTL3 |= XT2S1; // Allow external 3-16 MHz crystal
BCSCTL1 &= ~XT2OFF; // Turn on XT2
// SMCLK (from XTAL2)
BCSCTL2 |= SELS; // Source SMCLK from XT2 = 16MHz
BCSCTL2 |= DIVS0; // Divide SMCLK by 2 = 8MHz
}
void init_setup()
{
P5SEL |= 0x06; //Assign P5.1,2 as UCB1_SDA,SCL
I2C_Setup_B1(); //Call Function Setup UCBI for I2C
}
void I2C_Setup_B1()
{
UCB1CTL1 |= UCSWRST; // Enable SoftWare reset
UCB1CTL0 = UCMST + UCMODE_3 + UCSYNC; // Mode: Master, I2C, synchronous
UCB1CTL1 = UCSSEL_2 + UCSWRST; // Use SMCLK, keep SW reset
UCB1BR0 = 80; // fSCL = SMCLK/80 = ~100kHz
UCB1BR1 = 0;
UCB1CSA = SADDR; //Set Slave address 0x48
UCB1CTL1 &= ~UCSWRST; // Clear SW reset, resume operation
}
void readI2C()
{
UCB1CTL0 &= ~UCSLA10; // Enable 7 bit slave address option
UCB1CTL1 |= UCTR; // Master is a transmitter
UCB1CTL1 |= UCTXSTT; // Staart : TXIFG flag is raised
unsigned char hold = 0x00;
while (hold == 0x00){
hold = UC1IFG & UCB1TXIFG; //wait until slave address is sent completely
}
UCB1TXBUF = RADDR; // input register addr into TXBUF, TXIFG flag cleared
hold = 0x00; //clear hold variable for next wait cycle
//TMP112 is now setup with it being addressed and its register when temp data is now address
//Now starting the Master Receiver mode where the TMP112 will be outputting temperature data to MSP430
//Master Receiver Mode
UCB1CTL1 &= ~UCTR; // Master is a receiver
UCB1CTL1 |= UCTXSTT; // Repeated Staart
while (hold == 0x00){
hold = (UC1IFG & UCB1RXIFG); // Wait for RX Interrupt flag
}
temp = UCB1RXBUF;
hold = 0x00;
while (hold == 0x00){
hold = (UC1IFG & UCB1RXIFG); // Wait for RX Interrupt flag
}
temp = UCB1RXBUF;
hold = 0x00;
UCB1CTL1 |= UCTXSTP; // I2C stop condition
}