chnmartins 0 Posted August 26, 2016 Share Posted August 26, 2016 Hey MSPGuys! Im working with MSP430G2553 in my own board. In ports P1.6 and P1.7 i have i2c to connect with m24lr and TMP102 ( Temperature sensor) . I`m finishing to code the TMP102 and i detect something strange and i didnt find no explanation until now. After I start the I2C bus I send the configuration word to TMP102. The TMP102 answer correct with ACK. As shown below After it I send the command to read the temperature of sensor, the sensor answer with correct ACK. When I send the read command to get the bytes in this moment i detect the problems. The temperature indicated by sensor is right. but in first burst the msp send on clock train extra. ( I didnt find in code the problem to it happen) and the data bus receive the correct information. like shown below ok, now i send a new command to read and in this moment the msp didnt include the extra clock train and the sensor didnt answer the last ACK. and this mode the data is not transfered to buffer like shown in figure below. Im working in polling mode, to my application I dont need requirements of Interrupt mode. Some one can help me discovery what is happenning . My code is below: COnfig temperature sensor //************************************************************************************************************ //************************************************************************************************************ void TMP102_config (unsigned int Config_TMP) { // Protocol Base >>[sTART BIT][ADDR+R/W][REGISTER][DATA1][DATA2][sTOP BIT] i2c_tx(Conf_Reg); // this function transmit the I2C address 0x48 ( TMP102) + register. i2c_txx(Config_TMP>>8); // this function transmit the MSB of register control. i2c_txx(Config_TMP&0x00FF); // this function transmit the LSB of register control. i2c_stop(); // generate de stop bit. } //************************************************************************************************************ I2C init //************************************************************************************************************ //************************************************************************************************************ // I2C configuration ( set pins / speed) void I2C_Init(void) { P1SEL |= BIT6 + BIT7; // Assign I2C pins to USCI_B0, P1.6 for SCL and P1.7 for SDA P1SEL2|= BIT6 + BIT7; // Assign I2C pins to USCI_B0, P1.6 for SCL and P1.7 for SDA UCB0CTL1 |= UCSWRST; // PUT I2C control in logic reset (register = 0x01) UCB0CTL0 |= UCMST + UCMODE_3 + UCSYNC; UCB0CTL1 |= UCSSEL_2 + UCSWRST; UCB0BR0 = 10; UCB0BR1 = 0; UCB0I2CSA = 0x48; //UCB0I2CIE = 0; //IE2 &= ~(UCB0TXIE + UCB0RXIE); //disable interrupts //UCB0I2CIE |= UCNACKIE; // Interrupt on slave Nack //UCB0CTL1 |= UCSSEL_2; UCB0CTL1 &= ~UCSWRST; } //************************************************************************************************************ I2c write //----------SEND DATA WITH A START BIT------ void i2c_tx(unsigned char data) { while((UCB0STAT & BUSY)!= 0); // free bus while (UCB0CTL1 & UCTXSTP); // stop UCB0CTL1 |= UCTR; // UCTR=1 => Transmit Mode (R/W bit = 0) UCB0CTL1 |= UCTXSTT; UCB0TXBUF = data;// start condition generation while((IFG2 & UCB0TXIFG ) ==0); //__delay_cycles(200); } //************************************************************************************************************ int Read_TMP102(unsigned char TMPaddr) { // Protocol Base >>[sTART BIT][ADDR+R/W][REGISTER][DATA1][DATA2][sTOP BIT] //I2C description document TI SLAU144J - page 461 (http://www.ti.com/lit/ug/slau144j/slau144j.pdf) while((UCB0STAT & BUSY)!= 0); // free bus while (UCB0CTL1 & UCTXSTP); // Ensure stop condition to sent // this part of code send the command to set the register that will be read. // command format = [start_bit][address + r/w][command to read][stop bit] i2c_tx(TMPaddr); // this function transmit the I2C address 0x48 ( TMP102) + register. i2c_stop(); // generate de stop bit. while((UCB0STAT & BUSY)!= 0); // verify if bus is free //start the read command UCB0CTL1 &= ~UCTR; // change I2C controller to receive mode, in this point address is loaded ( UCBxI2CCSA = slave address) UCB0CTL1 |= UCTXSTT; while((IFG2 & UCB0RXIFG )==0); // send start condiction to transceiver RX_INH = UCB0RXBUF; while((IFG2 & UCB0RXIFG )==0); // wait to receive a new byte. RX_INL = UCB0RXBUF; //GENERATE STOP BIT //while((UCB0STAT & BUSY)!= 0); // generate the stop condiction UCB0CTL1 |= UCTXSTP; while(UCB0CTL1 & UCTXSTP); Data_out = (int)RX_INH<<8; Data_out +=(int)RX_INL; __delay_cycles(10); return Data_out; } //************************************************************************************************************ void i2c_txx(unsigned char data1) { UCB0TXBUF = data1; while((IFG2 & UCB0TXIFG ) ==0); // buffer is filled //__delay_cycles(200); } Quote Link to post Share on other sites
chicken 630 Posted August 27, 2016 Share Posted August 27, 2016 I seem to remember that the stop condition needs to be indicated to the I2C peripheral before the last byte is received.. You may want to check out the I2C code in Energia. tripwire 1 Quote Link to post Share on other sites
Clavier 34 Posted August 27, 2016 Share Posted August 27, 2016 Already answered on E2E. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.