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.
Dear Sir,
I am new to I2C.
I have a custom board TMS570LS3137-EP. In the board I have a external Temperature IC (TMP117).
I am attaching the custom board schematic of micro controller and TMP117
at R67 ---> SCL
at R68 ---> SDA
I am capturing the sclk and data in oscilloscope and attaching the snap shots also
while I am reading the temperature data in my GUI it is coming wrong.
In GUI temperature value*0.0625 = my actual temperature (as per data sheet)
I am attaching the code also
where i am wrong please help me
/* Include Files */
#include "stdio.h"
#include "sys_common.h"
#include "system.h"
#include "gio.h"
#include "sci.h"
#include "reg_het.h"
#include "reg_sci.h"
#include "reg_gio.h"
#include "sys_vim.h"
#include "system.h"
#include <string.h>
#include "adc.h"
#include "reg_adc.h"
#include "stdlib.h"
#include "mibspi.h"
#include "sys_vim.h"
#include "reg_mibspi.h"
#include "reg_gio.h"
#include "i2c.h"
#define TSIZE1 12
uint8 TEXT1[TSIZE1]= {'\r','\n','|','\t','C','H','.','I','D','=','0','x'};
#define TSIZE2 9
uint8 TEXT2[TSIZE2]= {'\t','V','A','L','U','E','=','0','x'};
#define DATA_COUNT 2
#define Master_Address 0x26
#define Slave_Address 0x8
#define Slave_Word_address 0x00
#define Receive_data_setup 0x1 // 1 Word address
uint8_t TX_Data_Master[DATA_COUNT] = {0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19};
uint8 RX_Data_Master[DATA_COUNT] = { 0 };
uint8_t TX_Data_Slave[10] = { 0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29};
uint8_t RX_Data_Slave[10] = { 0 };
#define TMP117_ADDRESS 0x48 // All A0,A1,A2 are tied to 3.3V in PCF8570
/* USER CODE BEGIN (1) */
/* USER CODE END */
/** @fn void main(void)
* @brief Application main function
* @note This function is empty by default.
*
* This function is called after startup.
* The user can use this function to implement the application.
*/
static unsigned char command;
/* USER CODE BEGIN (2) */
/* USER CODE END */
uint8 emacAddress[6U] = {0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU};
uint32 emacPhyAddress = 0U;
adcData_t adc_data[2];
void sciDisplayText(sciBASE_t *sci, uint8 *text, uint32 length);
void sciDisplayData(sciBASE_t *sci, uint8 *text,uint32 length);
void wait(uint32 time);
#define ADC_DATA_LENGTH 1
void main(void)
{
_enable_IRQ();
sciInit();
// adcInit();
gioInit();
hetInit();
mibspiInit();
// i2cInit();
i2cInit();
sciSend(scilinREG, 5, (unsigned char *)"ENTC\n\r");
sciReceive(scilinREG, 1,(unsigned char *)&command);
//adcStartConversion(adcREG1,adcGROUP1);
//*****************************iic************************************************************* iic
int repeat = 0; int delay =0;
/* I2C Init as per GUI
* Mode = Master - Transmitter
* baud rate = 100KHz
* Count = 10
* Bit Count = 8bit
*/
// i2cInit();
// Master Transfer Functionality //
/* Configure address of Slave to talk to */
i2cSetSlaveAdd(i2cREG1, TMP117_ADDRESS);
/* Set direction to Transmitter */
/* Note: Optional - It is done in Init */
i2cSetDirection(i2cREG1, I2C_TRANSMITTER);
// // Set direction to receiver
// i2cSetDirection(i2cREG1, I2C_RECEIVER);
/* Configure Data count */
/* Data Count + 1 ( Word Address) */
i2cSetCount(i2cREG1,1);
/* Set mode as Master */
i2cSetMode(i2cREG1, I2C_MASTER);
/* Set Stop after programmed Count */
i2cSetStop(i2cREG1);
/* Transmit Start Condition */
i2cSetStart(i2cREG1);
/* Send the Word Address */
i2cSendByte(i2cREG1, 0x00);
/* Tranmit DATA_COUNT number of data in Polling mode */
// i2cSend(i2cREG1, 1, 0x00);
/* Wait until Bus Busy is cleared */
while(i2cIsBusBusy(i2cREG1) == true);
/* Wait until Stop is detected */
while(i2cIsStopDetected(i2cREG1) == 0);
/* Clear the Stop condition */
i2cClearSCD(i2cREG1);
/* Simple Dealya before starting Next Block */
/* Depends on how quick the Slave gets ready */
for(delay=0;delay<1000;delay++);
// Master Receive Functionality //
/*****************************************/
/*****************************************/
/* wait until MST bit gets cleared, this takes
* few cycles after Bus Busy is cleared */
/* while(i2cIsMasterReady(i2cREG1) != true);
/* Configure address of Slave to talk to */
// i2cSetSlaveAdd(i2cREG1, TMP117_ADDRESS);
//
// /* Set direction to Transmitter */
// /* Note: Optional - It is done in Init */
// i2cSetDirection(i2cREG1, I2C_TRANSMITTER);
//
// /* Configure Data count */
// /* Slave address + Word address write operation before reading */
// i2cSetCount(i2cREG1, 0x91);
//
// /* Set mode as Master */
// i2cSetMode(i2cREG1, I2C_MASTER);
//
// /* Set Stop after programmed Count */
// i2cSetStop(i2cREG1);
//
// /* Transmit Start Condition */
// i2cSetStart(i2cREG1);
//
// /* Send the Word Address */
// i2cSendByte(i2cREG1, Slave_Word_address);
//
// /* Wait until Bus Busy is cleared */
// while(i2cIsBusBusy(i2cREG1) == true);
//
// /* Wait until Stop is detected */
// while(i2cIsStopDetected(i2cREG1) == 0);
//
// /* Clear the Stop condition */
// i2cClearSCD(i2cREG1);
//
// /*****************************************/
// /*****************************************/
//
// /* wait until MST bit gets cleared, this takes
// * few cycles after Bus Busy is cleared */
// while(i2cIsMasterReady(i2cREG1) != true);
/* Configure address of Slave to talk to */
i2cSetSlaveAdd(i2cREG1, TMP117_ADDRESS);
/* Set direction to receiver */
i2cSetDirection(i2cREG1, I2C_RECEIVER);
/* Configure Data count */
/* Note: Optional - It is done in Init, unless user want to change */
i2cSetCount(i2cREG1, 3);
/* Set mode as Master */
i2cSetMode(i2cREG1, I2C_MASTER);
/* Set Stop after programmed Count */
i2cSetStop(i2cREG1);
/* Transmit Start Condition */
i2cSetStart(i2cREG1);
// uint32_t u[2];
/* Tranmit DATA_COUNT number of data in Polling mode */
i2cReceive(i2cREG1, 2, RX_Data_Master);
// uint16_t temperatureData;
// i2cReceive(i2cREG1, 3, (uint8_t*)&temperatureData);
uint32_t k;
// j=((RX_Data_Master[1]<<8) + RX_Data_Master[0]);
for (k = 0; k < 2; k++)
{
// Convert the ADC value to a decimal string representation
char adcValueStrr[4]; // Assuming the maximum ADC value fits in 5 digits plus a null-terminator
// j =j>>4 ;
//j=j;
// Convert adcValueStr to an integer
// int adcValue = (int)strtol(adcValueStrr, NULL, 10);
sprintf(adcValueStrr, "%x", RX_Data_Master[k]);
// sprintf(adcValueStrr1, "%x", u[k]);
// Send the ADC value over SCI to the GUI
sciSend(scilinREG, strlen(adcValueStrr), (uint8_t*)adcValueStrr);
// sciSend(scilinREG, strlen(adcValueStrr1), (uint8_t*)adcValueStrr1);
sciSend(scilinREG, 2, "\r\n");
}
/* Wait until Bus Busy is cleared */
while(i2cIsBusBusy(i2cREG1) == true);
/* Wait until Stop is detected */
while(i2cIsStopDetected(i2cREG1) == 0);
/* Clear the Stop condition */
i2cClearSCD(i2cREG1);
// asm(" nop");
// asm(" nop");
// asm(" nop");
while(1);
{
}
// /* USER CODE BEGIN (13) */
// /* USER CODE END */
}
Hi Balu,
In GUI temperature value*0.0625 = my actual temperature (as per data sheet)
The temperature resolution for TMP117 is 0.0078125 not 0.0625.
May be this gives you wrong result.
If i multiply with correct resolution then your value of 0x0D9B is 27.21C.
--
Thanks & regards,
Jagadish.