This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

LPC4088 with LM75 temperature sensor

Hello all,

I'm using LPC4088 experiment bundle, in which a temperature sensor (LM75) is connected to the LPC4088 controller using IC2 connection.
I'm using this code to test the temperature sensor. However, the program is getting stuck at temperature_enable(); The code changes an RGB LED color based on the temperature value.

This is the main code
#include <stdint.h>
#include <stdio.h>
#include "leds.h"
#include "temperature.h"

const int threshold[] = {29, 28, 27, 26, 25, 24};
const int colors[][3] = { { 1, 1, 1}, // White { 1, 0, 1}, // Magenta { 1, 0, 0}, // Red { 1, 1, 0}, // Yellow { 0, 0, 1}, // Blue { 0, 1, 0} // Green
};

void pick_leds(float measured) { int i; for (i = 0; i < sizeof(threshold) / sizeof(int); i++) { if (measured >= threshold[i]) { break; } } leds_set(colors[i][0], colors[i][1], colors[i][2]);
}

int main(void) { leds_init();
temperature_init();
temperature_enable(); __enable_irq();

while (1) {
pick_leds(temperature_read()); //pick_leds(29); }
}

// *******************************ARM University Program Copyright © ARM Ltd 2014*************************************

This is the temperature.c
#include "temperature.h"
#include "i2c.h"

#define SLAVE_ADDRESS 0x90
#define READ 0x1
#define WRITE 0x0
#define START_CONVERT_T 0x51
#define READ_TEMPERATURE 0xAA

void temperature_init(void) { i2c_init();
}

void temperature_enable(void) { uint8_t buff[1]; buff[0] = START_CONVERT_T; i2c_write(SLAVE_ADDRESS, buff, 1);
}

float temperature_read(void) { short temp; uint8_t buff[2]; buff[0] = READ_TEMPERATURE; i2c_write(SLAVE_ADDRESS, buff, 1); i2c_read(SLAVE_ADDRESS, buff, 2); temp = (buff[0] << 8) | buff[1];

// Sign extend from 16-bit to 12-bit. temp >>= 4;

// Convert from fixed point to floating point. return temp / (float)16;
}

// *******************************ARM University Program Copyright © ARM Ltd 2014*************************************

Parents
  • Hello Lilas,

    What part of temperature_enable() does the code stop executing?

    When it gets stuck, does it stay on a particular line?
    If you enter debug mode, and go to Peripherals => Core Peripherals => Fault Reports, does any checkmark appear in this dialog when the function executes?

    In the future, try placing source code between:

     < pre > and < /pre >
    

    tags. See: http://www.keil.com/forum/tips.asp

    Thanks,
    Zack

Reply
  • Hello Lilas,

    What part of temperature_enable() does the code stop executing?

    When it gets stuck, does it stay on a particular line?
    If you enter debug mode, and go to Peripherals => Core Peripherals => Fault Reports, does any checkmark appear in this dialog when the function executes?

    In the future, try placing source code between:

     < pre > and < /pre >
    

    tags. See: http://www.keil.com/forum/tips.asp

    Thanks,
    Zack

Children