Hi,
I have Tiva4C129x development kit. It has TMP100 temperature sensor which has I2C.
My purpose is to learn I2C and read the temperature from the sensor.
I have wrote a dummy code which explains the procedure in which one should configure I2C and start the communication.
SCL and SDA is located on PB6 and PB7 on TIVA. Also it uses I2C6 module which is connected to TMP100.
I have read the datasheet of both device and from that what I have understood I wrote the code.
Please note that I'm just focusing on the procedure and dont worry about debugging the code right now. I'm using 25MHz crystal.
I'm bit confused in configuring the TMP100 registers. It has 5 registers in total. Pointer Reg, Configuration Reg, Temperate High and Low Reg, Temperature Register. The last one stores the conversion result.
Also I'm not sure if I'm waiting for acknowledgement correctly or not. Please correct me if I'm wrong.
Here is the code.
#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
void main()
{
SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
SYSCTL_XTAL_25MHZ);
SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C6);
SysCtlPeripheralEnable(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, SysCtlClockGet(), false); //initialization of master module
I2CMasterSlaveAddrSet(I2C6_BASE, SLAVE_ADDRESS, true); //sets the slave address and indicate that the master is reading from slave
I2CMasterDataPut(I2C6_BASE, 0x01); //P1 P0 = 01 = configuration reg. Byte goes to PR
while(I2CMasterBusy(I2C6_BASE)); //is it correct?
I2CMasterDataPut(I2C6_BASE, 0xA1); //sets the bits of configuration reg. A1 = 10 bit, shutdown, OS=1 start conv. Byte goes to Config Reg
while(I2CMasterBusy(I2C6_BASE));
I2CMasterSlaveAddrSet(I2C6_BASE, SLAVE_ADDRESS, true); //selects the pointer reg
while(I2CMasterBusy(I2C6_BASE));
I2CMasterDataPut(I2C6_BASE, 0x03); //P1P0= 11 = Temp high reg. Byte goes to PR
while(I2CMasterBusy(I2C6_BASE));
I2CMasterDataPut(I2C6_BASE, 0x640); //sets the Thigh reg = 100C. Byte goes to Thigh
I2CMasterSlaveAddrSet(I2C6_BASE, SLAVE_ADDRESS, true); //selects the pointer reg
while(I2CMasterBusy(I2C6_BASE));
I2CMasterDataPut(I2C6_BASE, 0x02); //P1P0= 10 = Temp low reg. Byte goes to PR
while(I2CMasterBusy(I2C6_BASE));
I2CMasterDataPut(I2C6_BASE, 0x640); //sets the Tlow reg = -25C. Byte goes to Tlow
while(I2CMasterBusy(I2C6_BASE));
I2CMasterSlaveAddrSet(I2C6_BASE, SLAVE_ADDRESS, true); //selects the pointer reg
while(I2CMasterBusy(I2C6_BASE));
I2CMasterDataPut(I2C6_BASE, 0x00); //P1P0= 00 = Temp high reg. Byte goes to PR
while(I2CMasterBusy(I2C6_BASE));
data_low = I2CMasterDataGet(I2C6_BASE); //receives the bytes from slave
data_high = I2CMasterDataGet(I2C6_BASE);
while(I2CMasterBusy(I2C6_BASE));
}
I hope the I have given enough information, if not please let me know.
Again I'm more interested to know about the procedure rather than worrying about the code itself.
Any help is much appreciated. thanks