This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TIVA129 I2C problem

Hi Amit,

I'm writing this new post as my old post is probably lost. I'm back after few days.

I researched lot regarding the I2C_MASTER_CMD_BURST_SEND_START and other similar commands and came to know about many things. 

I understood that we have to issue start and stop condition only once. In between that, you can write various registers. I modified my code accordingly. One more thing is that, TMP100 doesnt have alert pin. Temp high and temp low register are specially used for alert function. Since we have TMP100 on board, do I really need to set the high and low temperature limit? I dont think so. But please confirm it. 

Another thing is that, on what edge I2C captures data? I read the datasheet and it doesnt say anything. I tried looking the waveforms in oscilloscope and it looks like data is captured in falling edge. Please clarify this thing.

It looks like my code is not reliable, in the sense that sometimes it gives me correct reading and sometimes it shows me constant value 1B. I live in toronto and right now its under 10C. Please take a look at the code and any suggestions are welcomed.

#include <stdbool.h>
#include <stdint.h>
#include "inc/hw_i2c.h"
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/gpio.h"
#include "driverlib/i2c.h"
#include "driverlib/interrupt.h"
#include "driverlib/pin_map.h"
#include "driverlib/sysctl.h"

#define SLAVE_ADDRESS 0x4A //should send 94?

void main()
{
	uint8_t data_low, data_high;
	uint16_t data;
	uint32_t sys_clock;
	int i;
	sys_clock = SysCtlClockFreqSet(SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_25MHZ, 25000000);

	SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C6);
	while(!(SysCtlPeripheralReady(SYSCTL_PERIPH_I2C6)));
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
	while(!(SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOB)));

	GPIOPinConfigure(GPIO_PB6_I2C6SCL);
	GPIOPinConfigure(GPIO_PB7_I2C6SDA);

	GPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_6);
	GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_7);

	I2CMasterInitExpClk(I2C6_BASE, sys_clock, false);
	I2CMasterSlaveAddrSet(I2C6_BASE, SLAVE_ADDRESS, false);

	/*  Configuration Register */
	I2CMasterDataPut(I2C6_BASE, 0x01);
	I2CMasterControl(I2C6_BASE, I2C_MASTER_CMD_BURST_SEND_START);
	while(I2CMasterBusy(I2C6_BASE));

	I2CMasterDataPut(I2C6_BASE, 0xA1);
	I2CMasterControl(I2C6_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);
	while(I2CMasterBusy(I2C6_BASE));


	/* T High Register
	I2CMasterSlaveAddrSet(I2C6_BASE, SLAVE_ADDRESS, false);
	I2CMasterDataPut(I2C6_BASE, 0x02);
	I2CMasterControl(I2C6_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
	while(I2CMasterBusy(I2C6_BASE));

	I2CMasterDataPut(I2C6_BASE, 0x28);
	I2CMasterControl(I2C6_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
	while(I2CMasterBusy(I2C6_BASE));

	/*  T Low Register
	I2CMasterSlaveAddrSet(I2C6_BASE, SLAVE_ADDRESS, false);
	I2CMasterDataPut(I2C6_BASE, 0x03);
	I2CMasterControl(I2C6_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
	while(I2CMasterBusy(I2C6_BASE));
	
	I2CMasterDataPut(I2C6_BASE, 0x28);
	I2CMasterControl(I2C6_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);
	while(I2CMasterBusy(I2C6_BASE));  */

	for (i=100; i>=0; i--)
	{
		;
	}

	while(1)
	{
		I2CMasterSlaveAddrSet(I2C6_BASE, SLAVE_ADDRESS, false);
		I2CMasterDataPut(I2C6_BASE, 0x00);	// selects temp register
		I2CMasterControl(I2C6_BASE, I2C_MASTER_CMD_BURST_SEND_START);
		while(I2CMasterBusy(I2C6_BASE));

		I2CMasterSlaveAddrSet(I2C6_BASE, SLAVE_ADDRESS, true);  // true indicates that master is initiating the receive.
	    I2CMasterControl(I2C6_BASE, I2C_MASTER_CMD_BURST_RECEIVE_START);
		while(I2CMasterBusy(I2C6_BASE));
		data_high = I2CMasterDataGet(I2C6_BASE);
		while(I2CMasterBusy(I2C6_BASE));
		I2CMasterControl(I2C6_BASE, I2C_MASTER_CMD_BURST_RECEIVE_FINISH);
		data_low = I2CMasterDataGet(I2C6_BASE);

		data = (data_high << 8) | data_low;

	}

}

I tried running your code also and it shows me 0. The board behavior is very random.