Other Parts Discussed in Thread: TM4C123GH6PM
Hello,
I am having trouble getting my micro-controller (TM4C123GH6PM) to get receive data from my D6T Thermal Sensor through I2C. The micro-controller is the master and the D6T thermal sensor is the slave. I have attached my code. The company who created the D6T thermal sensor gave a sample code, but this code will not work for this micro-controller. So I am trying to translate the sample code to a code that will work on the TM4C123GH6PM. I would really appreciate the help.
2630.D6T thermal sensor example code.pdf
/*
* Thermal Sensor.c
*
* Created on: Apr 25, 2014
* Author: ghadley
* ghadley is the ECE computer
* Actual Author: Uma Sambasivam
*/
#define PART_TM4C123GH6PM
#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "inc/hw_ints.h"
#include "inc/hw_gpio.h"
#include "driverlib/debug.h"
#include "driverlib/gpio.h"
#include "driverlib/i2c.h"
#include "driverlib/interrupt.h"
#include <driverlib/pin_map.h>
#include "driverlib/rom.h"
#include "driverlib/rom_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/uart.h"
#include "utils/uartstdio.h"
int main (void)
{
//uint32_t ui32SysClock; //will be for the SCL in I2C
//uint32_t ui32Base = I2C1_BASE; // output data is 35 bytes 0x35; I am setting this value to 35 for temperature recordings...is this right?
//uint32_t ui32I2CClk;
//bool bFast = 1; // set up for fast data transfers
//bool bReceive = 1; // flag indicating the type of communication with the slave
//uint8_t ui8SlaveAddr = 0x3B; // 7 bit address
//uint8_t ui8Data = 'Q'; //ui8Data data to be transmitted from the I2C Master.
//uint8_t ui32Cmd = I2C_MASTER_CMD_SINGLE_RECEIVE; // command to be issued to the I2C Master.
// Configure the system frequency. //
SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
SYSCTL_OSC_MAIN | SYSCTL_USE_PLL |
SYSCTL_CFG_VCO_480), 120000000);
//Configure the device pins in this board.
// The I2C1 peripheral must be enabled before use.
SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C1);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
//GPIOPadConfigSet(GPIO_PORTA_BASE, GPIO_PIN_1,GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD_WPU);
//GPIOPadConfigSet(uint32_t ui32Port, uint8_t ui8Pins,GPIO_STRENGTH_8MA, uint32_t ui32PinType);
// Select the I2C function for these pins. This function will also
// configure the GPIO pins pins for I2C operation, setting them to
// open-drain operation with weak pull-ups. Consult the data sheet
// to see which functions are allocated per pin.
//Configure the pin muxing for I2C1 functions on port A6 and A7.
GPIOPinConfigure(GPIO_PA7_I2C1SDA);
GPIOPinConfigure(GPIO_PA6_I2C1SCL);
GPIOPinTypeI2CSCL(GPIO_PORTA_BASE, GPIO_PIN_6);
GPIOPinTypeI2C(GPIO_PORTA_BASE, GPIO_PIN_7);
I2CMasterInitExpClk(I2C1_BASE,SysCtlClockGet(),1); // Initializes the I2C Master block.
/* This function initializes operation of the I2C Master block by configuring the bus speed for the
* master and enabling the I2C Master block. If the parameter bFast is true, then the master block is
* set up to transfer data at 400 Kbps; otherwise, it is set up to transfer data at 100 Kbps.
*/
I2CMasterSlaveAddrSet(I2C1_BASE,0x23,1); //Sets the address that the I2C Master places on the bus.
/* Sets the address that the I2C Master places on the bus. This function configures the address
* that the I2C Master places on the bus when initiating a transaction. When the bReceive parameter
* is set to true, the address indicates that the I2C Master is initiating a read from the slave.
*/
//I2CMasterBusy(ui32Base); // Indicates whether or not the I2C Master is busy.
/* This function returns an indication of whether or not the I2C Master is busy transmitting or
* receiving data. Returns true if the I2C Master is busy; otherwise, returns false.
*/
I2CMasterControl(I2C1_BASE,I2C_MASTER_CMD_SINGLE_RECEIVE); //Controls the state of the I2C Master.
/* This function is used to control the state of the Master send and receive operations. The
* ui8Cmd parameter used for this code is I2C_MASTER_CMD_SINGLE_RECEIVE. The master will be receiving
* data from the Thermal sensor.
*/
I2CMasterDataPut(I2C1_BASE,'Q' ); // This function places the supplied data into I2C Master Data Register.
while(I2CMasterBusBusy(I2C1_BASE))
{
}
I2CMasterDisable(I2C1_BASE); //Disables the I2C master block.
// while(1) {};
//return(0);
}
