Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] TMP117 > Can not read temperature on LCD

Eric_O

Advanced Member level 4
Full Member level 1
Joined
May 31, 2020
Messages
109
Helped
0
Reputation
0
Reaction score
0
Trophy points
16
Activity points
1,042
I can not read and display temperature with TMP117 i2C temp sensor.

Here attached file with my code.

I have no idea why.

Can somebody enlighted me ?

Thanks.
 

Attachments

  • Thermometer_with_TMP117_and_LCD_v3_callertable.txt
    1 KB · Views: 34
What language is that code written in? What is this code running on?
Have you made sure that you can write a simple constant string to the LCD?
Have you tried to format a floating point value to a string and display that?
Similarly have you made sure that the I2C read of the temperature sensor is working?
Susan
 
I'm also lost when it comes to that code. It is a list of function calls, not the program itself and I have no idea what language or PIC it uses. We need the actual program and a schematic to debug it for you.

Brian.
 
Sorry for my mistake.

PIC is 16F887 and code is MikroC.

Code doesn't run properly. LCD display allways - 0,00 °C while temperature room is 21°C.

Here attached the source code file.

PS :
After testing the various analogue temperature sensors, LM35CZ, LM135 and MCP9701A, I found the latest one as the most reliable. Indeed, the DS18B20 digital temperature sensor that I tested, obviously works very well and precisely. Now, with the TMP117, I want to start the chapter of the I2C function of the PIC.
 

Attachments

  • Thermometer_with_TMP117_and_LCD_v3.txt
    28.6 KB · Views: 17
Last edited:
I take it from the above post that you have the LCD working, but the I2C is not.
Firstly, why are you not using the I2C library functions in the MikroC compiler? I see that you have commented out what looks like using those functions and have tried to bit-bang your own. (In my opinion that is a bad move.)
Also you seem to have written your own floating to ASCII function. Are you sue that it is working correctly? And why not use the 'sprintf()' function that the MikroC library provides? (I know that it takes up a lot of memory and your MCU does not have much to start with but....)
More basically - why use floating point at all. You are far better off to use scaled integers. You are only using 2 decimal places (so I assume 2 degree digits, a decimal point and 2 fraction of a degree digits) which means that you really want numbers in the range (say) -4000 to +7000 which would fit into a 'signed 16-bit integer'.

So we know that you can write to the LCD but does your 'float2ascii_v4()' function work reliably? If not then that is the next thing to get right.
If it does then, having gone down the bit-bang I2C route, either use the MikroC library functions (my recommendation) or you really need a logic analyser (or at least a good scope) to examine the SCL and SDA signals. I think you may get your code to work but you really need to think about the clock stretching and other timing issues with bit-banging.

Finally (and I've just seen this in your code) in your I2C functions, you seem to be toggling the TRIS register bits a lot where I think you should be manipulating the PORT bits. (IMHO this is one of the BIG problems with hiding these things behind macros - but in this case I think you have simply used the wrong macros that you have defined.)
Be very careful with these old MCUs that don't have LAT registers or you may encounter RMW issues.

Susan
 
Some questions: Isn't it possible to use I2C hardware interface (at different pins)? Mikro-C compiler has also soft I2C library, why are you using homemade I2C driver?

Possible reasons: 1. Hardware, e.g. missing I2C pull-ups. 2. Error in I2C driver code 3. Error in TMP117 access 4. Error in temperature measurement processing

We'd expect some debugging on your side, starting with check for I2C ACK.
 
Correction to the last paragraph on my post #5 above - ignore the last paragraph. (Unfortunately it is too late for me to edit it.)
I realised (at about 3AM!) that I2C is active low but passive high with the pull-up resistors doing that job. Therefore tri-stating the output to generate a 'high' is correct.
HOWEVER, unless you KNOW that there will never be another device on the I2C lines, you need to check that allowing as line to float high is being allowed by other devices and you are not getting bus contention.
Again - use the hardware module.
Susan
 

LaTeX Commands Quick-Menu:

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top