Hi Sarathkumar,
Here is our code to read out up to eight LM75 temperature sensors:
static void initI2C()
{
// Set the mode for PB11 an PB12 to open drain
uint32_t *pportbmode = (uint32_t*)0x4000602c;
uint32_t temp = *pportbmode;
temp |= 0x00088000;
*pportbmode = temp;
// Initialize I2C channel 1
I2C_drvInit(I2C_CHANNEL_1, 1<<8);
// make additional GND at pin E2
GPIO_handleInfo_t gnd;
gnd.port = gpioPortE;
gnd.bitIndex = 2;
gnd.magicWord = GPIO_HANDLE_MAGIC_WORD;
GPIO_init(&gnd, GPIO_DIRECTION_OUTPUT, GPIO_STATE_OFF);
}
static int readTemperatures(char *str)
{
int count = 0;
for (int i = 0; i < NUM_ADDRESS; i++)
{
unsigned char address = addresses[i];
int8_t buffer[2];
if (i == 0) str[0] = '\0';
else strcat(str, ";");
if (I2C_busReadChannel1(address, 0, (unsigned char*)&buffer, 2) == 0)
{
char s[7];
if (buffer[1] & 0x80) sprintf(s, "%d.5", buffer[0]);
else sprintf(s, "%d", buffer[0]);
strcat(str, s);
count++;
}
}
return count;
}
I hope it helps you!
Greetings,
Jürgen