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

I2c problem

Hello,
I'd like to ask a little bit help.
I downloaded the mcb517_i2c aplication note.
I try to read the LM75 tempereture sensor with the bit_bang i2c routines.
The problem is...
There is a 16 bit temperature register and I can read only the high byte .
I use the following program
.
.
unsigned char data_in;
i2c_start();
i2c_write(0x91);
data_in=i2c_read();
i2c_stop();

I try to use the unsigned int instead unsigned char and modified the i2c_read routin to read 16 bit but no succes.

Any advice?
Cheer George



Parents
  • Hi George!

    My LM75 library code looks like this:

    #include "i2c.h"
    
    #define uchar unsigned char
    
    #define LM75_SLA       0x49
    #define LM75_TEMPADR   0x00
    #define LM75_CONFADR   0x01
    #define LM75_THYSTADR  0x02
    #define LM75_TOSADR    0x03
    
    uchar get_temp( int *halfdegree ) {
      uchar sendbyte;
      uchar rbuf[2];
      sendbyte = LM75_TEMPADR;
      
      if (i2c_xceive( LM75_SLA, &sendbyte, 1, rbuf, 2 )){
        *halfdegree = -1;
        return -1;
      }
      else {
        *halfdegree = ((((int)rbuf[0]) << 8) + rbuf[1]) / 128;
        return 0;
      }
    }
    

    i2c_xceive is from my ic2 library (not bit banged) and is defined as following:

    /*-------------------------------------------------------------------------
       Transmit data then receive data on I2C-Bus:
       sla  : Slave Adress
       xbuf : data buffer  (transmit )
       xmit_count: Number of bytes. Has to be <= 16!!! 
       rbuf : data buffer  ( receive )
       recv_count: Number of bytes. Has to be <= 16!!! 
       returns -1 if error
      -------------------------------------------------------------------------*/
    
    extern int i2c_xceive( uchar sla, uchar xbuf[], uchar xmit_count,
                                      uchar rbuf[], uchar recv_count );
    

    So you need to receive two bytes in a row. Maybe you have to modify your bit banged routine for that. I think, it is a problem with the ack bits.

Reply
  • Hi George!

    My LM75 library code looks like this:

    #include "i2c.h"
    
    #define uchar unsigned char
    
    #define LM75_SLA       0x49
    #define LM75_TEMPADR   0x00
    #define LM75_CONFADR   0x01
    #define LM75_THYSTADR  0x02
    #define LM75_TOSADR    0x03
    
    uchar get_temp( int *halfdegree ) {
      uchar sendbyte;
      uchar rbuf[2];
      sendbyte = LM75_TEMPADR;
      
      if (i2c_xceive( LM75_SLA, &sendbyte, 1, rbuf, 2 )){
        *halfdegree = -1;
        return -1;
      }
      else {
        *halfdegree = ((((int)rbuf[0]) << 8) + rbuf[1]) / 128;
        return 0;
      }
    }
    

    i2c_xceive is from my ic2 library (not bit banged) and is defined as following:

    /*-------------------------------------------------------------------------
       Transmit data then receive data on I2C-Bus:
       sla  : Slave Adress
       xbuf : data buffer  (transmit )
       xmit_count: Number of bytes. Has to be <= 16!!! 
       rbuf : data buffer  ( receive )
       recv_count: Number of bytes. Has to be <= 16!!! 
       returns -1 if error
      -------------------------------------------------------------------------*/
    
    extern int i2c_xceive( uchar sla, uchar xbuf[], uchar xmit_count,
                                      uchar rbuf[], uchar recv_count );
    

    So you need to receive two bytes in a row. Maybe you have to modify your bit banged routine for that. I think, it is a problem with the ack bits.

Children