![]() | ![]() | ![]() |
| |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
![]() |
| | Tools |
| | #1 |
|
need some help ![]() i got a LM75(BD) and can only get so far.. its I2C and so far i can read from it i think heh Im using the below code to split the 2 byte data (temperature) into 1 byte then into 3 bytes... Code: temp3 = ReadLM75BD(); //get 2 bytes (int)
temp4 = temp3 >> 8; // erase the LSByte (the LSBit is not important i assume)
tH = (temp4 / 100) + 0x30; // divide by 100 to get hundreds #
tT = ((temp4 % 100) / 10) + 0x30; // divide by 100 and use remainder to divide by 10 to get tens #
tO = (((temp4 % 100) % 10) % 10) + 0x30; //use remainder on of temp4/100 then divide that byt 10 and with that remainder divide it by ten and use last remainder as ones...
Code: unsigned int ReadLM75BD(void){
unsigned int tmp;
char result;
i2c_start(); //Send Start
i2c_write(RAdd); //Send our Device Address with the Write BIT
result = i2c_ack2(); //Test for ACK
tmp = i2c_read(); //Read 1 Byte from device and save in tmp
result = i2c_ack2(); //Test for ACK
tmp = tmp << 8;
tmp |= i2c_read(); //Read 1 Byte from device and save in tmp
result = i2c_ack(); //Test for NACK
i2c_stop(); //Send Stop
return tmp;
}
I assume it the way i convert the stuff or something or read the bytes in.. EDIT: Here is some valuable info which i dont understand much: " "
__________________ AtomSofts eBay Store AtomSoftTech: C18 TIPS & TRICKS v9 PDF Nokia 6100 Driver/Software My Name: Jason Lopez http://atomsofttech.info/ | My YouTube Videos! My Favorite Store: dipmicro Electronics Last edited by AtomSoft; 12th October 2009 at 11:16 PM. | |
| |
| | #2 |
|
I get a steady reading of 0x01 or 0x00 and it increases with my finger on it. It says the default register is TEMP so i assume thats what im reading. Im reading D15 to D8 as my temperature but heh its unlikely the temperature is 0-1C here heh... I must be doing something wrong... when i first start the program i get a reading of about 25C
__________________ AtomSofts eBay Store AtomSoftTech: C18 TIPS & TRICKS v9 PDF Nokia 6100 Driver/Software My Name: Jason Lopez http://atomsofttech.info/ | My YouTube Videos! My Favorite Store: dipmicro Electronics | |
| |
| | #3 |
|
decided to use the built in i2c stuff: Code: unsigned char ReadLM(void){
unsigned char tmpC;
unsigned char result;
StartI2C();
WriteI2C(WAdd);
AckI2C();
WriteI2C(0x00);
AckI2C();
RestartI2C();
WriteI2C(RAdd);
AckI2C();
tmpC = ReadI2C();
//AckI2C();
//result = getcI2C();
NotAckI2C();
StopI2C();
return tmpC;
}
__________________ AtomSofts eBay Store AtomSoftTech: C18 TIPS & TRICKS v9 PDF Nokia 6100 Driver/Software My Name: Jason Lopez http://atomsofttech.info/ | My YouTube Videos! My Favorite Store: dipmicro Electronics Last edited by AtomSoft; 13th October 2009 at 01:52 AM. | |
| |
| | #4 |
|
Jason, You need to make your variables signed. Code: signed int ReadLM75BD(void){
signed int tmp;
char result;
i2c_start(); //Send Start
i2c_write(RAdd); //Send our Device Address with the Write BIT
result = i2c_ack2(); //Test for ACK
tmp = i2c_read(); //Read 1 Byte from device and save in tmp
result = i2c_ack2(); //Test for ACK
tmp = tmp << 8;
tmp |= i2c_read(); //Read 1 Byte from device and save in tmp
result = i2c_ack(); //Test for NACK
i2c_stop(); //Send Stop
return (tmp>>7);
}
Code: signed int temp; //must be signed
temp=ReadLM75BD(); //get temperature
if(temp<0){ //if negative
PutLCD('-'); //put minus sign
temp=-temp; //and negate temperature
}
else{ //else
PutLCD(' '); //put a space
}
PutNumber(temp/2); //put the 3 digit number
PutLCD('.') //put decimal point
if(temp&1) //if there was a half degree
PutLCD('5'); //display it
else
PutLCD('0'); //or dont
Mike. | |
| |
| | #5 |
|
If you have read a single byte as in your last code you may have hung the I2C bus. Power your circuit down and try again. Mike. | |
| |
| | #6 |
|
thanks guys BUT.... no luck... after a power off (complete no power) then power on and code alterations i have this code Code:
while(1){
LCD_LINE(2);
LCD_STR((unsigned rom char*)"Temp: ");
temp=ReadLM75BD(); //get temperature
if(temp<0){ //if negative
LCD_DATA('-',1); //put minus sign
temp=-temp; //and negate temperature
} else { //else
LCD_DATA(' ',1); //put a space
}
tH = ((temp/2) / 100) + 0x30;
tT = (((temp/2) % 100) / 10) + 0x30;
tO = ((temp/2) % 10) + 0x30;
LCD_DATA(tH,1);
LCD_DATA(tT,1);
LCD_DATA(tO,1);
LCD_DATA('.',1); //put decimal point
if(temp&1) //if there was a half degree
LCD_DATA('5',1); //display it
else
LCD_DATA('0',1); //or dont
}
__________________ AtomSofts eBay Store AtomSoftTech: C18 TIPS & TRICKS v9 PDF Nokia 6100 Driver/Software My Name: Jason Lopez http://atomsofttech.info/ | My YouTube Videos! My Favorite Store: dipmicro Electronics | |
| |
| | #7 |
|
The LM75 is returning 0x00ff and so I guess it's not working. Can you go back to the code that returned 25C? Mike. | |
| |
| | #8 |
|
right now it shows 127c only and dosnt chang but im using c18 i2c maybe i should return to my bit bang method
__________________ AtomSofts eBay Store AtomSoftTech: C18 TIPS & TRICKS v9 PDF Nokia 6100 Driver/Software My Name: Jason Lopez http://atomsofttech.info/ | My YouTube Videos! My Favorite Store: dipmicro Electronics | |
| |
| | #9 |
|
hey guys funny stuff. Im using SOIC to DIP and when i disconnect the ground i get 27.5C
__________________ AtomSofts eBay Store AtomSoftTech: C18 TIPS & TRICKS v9 PDF Nokia 6100 Driver/Software My Name: Jason Lopez http://atomsofttech.info/ | My YouTube Videos! My Favorite Store: dipmicro Electronics | |
| |
| | #10 |
| Code: while(1){
LCD_LINE(2);
LCD_STR((unsigned rom char*)"Temp: ");
temp = 0;
temp=ReadLM75BD(); //get temperature
if(temp<0){ //if negative
LCD_DATA('-',1); //put minus sign
temp=-temp; //and negate temperature
} else { //else
LCD_DATA(' ',1); //put a space
}
temp = 1.8*temp+32;
tH = ((temp/2) / 100) + 0x30;
tT = (((temp/2) % 100) / 10) + 0x30;
tO = ((temp/2) % 10) + 0x30;
LCD_DATA(tH,1);
LCD_DATA(tT,1);
LCD_DATA(tO,1);
LCD_DATA('.',1); //put decimal point
if(temp&1) //if there was a half degree
LCD_DATA('5',1); //display it
else
LCD_DATA('0',1); //or dont
LCD_DATA('F',1); //or dont
DelayMS(250);
DelayMS(250);
DelayMS(250);
DelayMS(250);
}
__________________ AtomSofts eBay Store AtomSoftTech: C18 TIPS & TRICKS v9 PDF Nokia 6100 Driver/Software My Name: Jason Lopez http://atomsofttech.info/ | My YouTube Videos! My Favorite Store: dipmicro Electronics | |
| |
| | #11 |
|
I can't really follow what you are doing. I have to assume the I2C functions are doing more than just a basic write and read. This is my function for returning the temp bytes from the LM75 using bit banged code on the MSP430. I'll just post the read function and maybe you can figure out what it's doing differently. Code: unsigned int get_temp( void)
{
unsigned char buf[2];
volatile unsigned int temp;
i2cm_start( );
if( i2cm_out( 0x90 | device ) ) //send write control byte
return 9999;
else if( i2cm_out( 0x00 ) )//send config command byte
return 9999;
i2cm_start( );//device wants start again to read
if( i2cm_out( 0x91 | device ) ) //send read control byte
return 9999;
i2cm_in( buf, 2 ); //input the config byte to 'buf'
i2cm_stop( );
//device was not busy or failed...
//set sucsess flag if needed before return
temp = buf[0] << 8 | buf[1];
temp >>= 5;
return temp;
}
__________________ Mark Higgins | |
| |
| | #12 |
|
I guess I sat on my message too long. Is it possibly the device address? If you have the address select pins grounded, that might be affected by taking away ground. EDIT: Are you sure its correct? 27.5 Celsius is really pretty hot for indoors.
__________________ Mark Higgins Last edited by DirtyLude; 13th October 2009 at 04:24 AM. | |
| |
| | #13 |
|
64.5F in my room it says right now. I guess i need a digital temp sensor to compare with heh
__________________ AtomSofts eBay Store AtomSoftTech: C18 TIPS & TRICKS v9 PDF Nokia 6100 Driver/Software My Name: Jason Lopez http://atomsofttech.info/ | My YouTube Videos! My Favorite Store: dipmicro Electronics | |
| |
| | #14 |
|
This line, Code: temp = 1.8*temp+32; Code: temp = 1.8*temp+64; so I suspect something is still wrong.A better way would be, Code: temp*=9;
temp/=5;
temp+=64;
Mike. | |
| |
| | #15 |
|
__________________ AtomSofts eBay Store AtomSoftTech: C18 TIPS & TRICKS v9 PDF Nokia 6100 Driver/Software My Name: Jason Lopez http://atomsofttech.info/ | My YouTube Videos! My Favorite Store: dipmicro Electronics | |
| |
|
| Tags |
| lm75 |
| Thread Tools | |
| Display Modes | |
| |
Similar | ||||
| Title | Starter | Forum | Replies | Latest |
| interfacing Atmel Microcontroller AT89C51 with LM75 | umar abdul sattar | Micro Controllers | 0 | 28th June 2003 06:27 AM |