Other Parts Discussed in Thread: TMP100
i have problem with using the msp430 with tmp100, my tmp100 has add0=add1=gnd so its address is 0x48 base on the datasheet, i have search some topic related in this forum but i still so confused. I got stuck for several days and really need some help, here is my work
this is function i2c start and stop
void i2c_start(void)
{
UCB0CTL1 |= UCTXSTT; // I2C start condition
while (UCB0CTL1 & UCTXSTT); // Loop until I2C STT is sent
}
void i2c_stop(void)
{
UCB0CTL1 |= UCTXSTP; // Generate I2C stop condition
while (UCB0CTL1 & UCTXSTP); // Ensure stop condition got sent
this is how i init the i2c
void i2c_init(int slave_add)
{
UCB0CTL1 |= UCSWRST;
P1DIR |= BIT6 + BIT7 ; // Set SCL, SDA as Output
//P1REN |= BIT6 + BIT7; // enable Pull-Ups or down on SCL and SDA
//P1OUT |= BIT6 + BIT7; // Set Pull-Ups on SCL and SDA
P1SEL |= BIT6 + BIT7; // Assign I2C pins to USCI_B0
P1SEL2|= BIT6 + BIT7; // Assign I2C pins to USCI_B0
UCB0CTL0 = UCMST + UCMODE_3 + UCSYNC;
UCB0CTL1 = UCSSEL_2 + UCSWRST; // Use SMCLK, keep SW reset
UCB0BR0 = 12; // fSCL = SMCLK/12 = ~100kHz
UCB0BR1 = 0;
UCB0I2CSA = slave_add; // Set slave address
UCB0CTL1 ^= UCSWRST; // Clear SW reset, resume operation
}
this is how i config and read the temperature
void i2c_config_tmp100(void)
{
UCB0CTL1 |= UCTR; // I2C Transmitter
i2c_start();
UCB0TXBUF = 0x01; // POINT REGISTER = 01 => CONFIGURATION
while(UCB0TXIFG==0);
UCB0TXBUF = 0x60; // SET THE RESOLUTION TO 12 BIT (0.0625 CELCIUS DEGREE)
i2c_stop();
UCB0CTL1 |= UCTR;
i2c_start();
UCB0TXBUF = 0x00; // POINT REGISTER = 00 => TEMPERATURE REGISTER
i2c_stop();
UCB0CTL1 ^= UCTR; // receiver mode
}
void i2c_tempread_tmp100(void)
{
i2c_start();
data_tmp100[1]=UCB0RXBUF;//
while(UCB0RXIFG==0);
data_tmp100[0]=UCB0RXBUF;//
i2c_stop();
}
void i2c_lcd_tmp100(void) => this function is used to put the raw temperature on the lcd
{
lcd_gotoxy(0,1);
data_tmp100[2]=( (data_tmp100[1]<<4) | (data_tmp100[0]>>4) );
lcd_putnumber(data_tmp100[2]);
}
in the main.c, after init the lcd, the i2c module, i call the function i2c_tempread_tmp100 after every 2s
this is my first post in this forum, if i did something wrong, please tell me :P