SMBUS 100KHz, repeated start, Arduino Uno

  1. Attached is the SMBUS protocol which i need to implement with master(arduino), sending command code & then receive 2 bytes from slave(device).

  2. It also has repeated start in between.

  3. i have implement it with code attached, but I think it will not work since it don't have repeated start option.

  4. Is there any other smbus library with timeout option.

  5. I have found one here: Arduino Playground - SoftwareI2CLibrary
    Is it safe to use as SMBUS library as it is not in standard examples & which timer it uses for timeout ?

  6. i am using arduino 1.6.5 with UNO R3.

pic.png

smbus.ino (1023 Bytes)

Vindhyachal_Takniki:

  1. Attached is the SMBUS protocol which i need to implement with master(arduino), sending command code & then receive 2 bytes from slave(device).

  2. It also has repeated start in between.

  3. i have implement it with code attached, but I think it will not work since it don't have repeated start option.

  4. Is there any other smbus library with timeout option.

  5. I have found one here: Arduino Playground - HomePage
    Is it safe to use as SMBUS library as it is not in standard examples & which timer it uses for timeout ?

  6. i am using arduino 1.6.5 with UNO R3.

Vindhyachal,
The repeated Start function is implemented by changing Wire.endTransmission(false); the boolean value passed to endTransmission() controls STOP signal generation.

Here is your code with the change inserted.

#include <Wire.h>

/* you do not need to do this modification to the address, the wire library
 * appends the Read/Write bit to the address internally. 
 * if the 7bit device address is 0x0B, just pass this to the Wire Library. 
 */

#define DEVICE_ADD   0x0b  // << 1  /* 7 bit -> 0001011 */ unnecessary, handled by Wire

int reading = 0;


void setup() 
{
    Wire.begin();      /* join i2c bus (address optional for master) */
    Serial.begin(9600); 

}

void loop()
{
    Wire.beginTransmission(byte(DEVICE_ADD));   /* start address */
    Wire.write(byte(0x00));                     /* command address */
    Wire.endTransmission(false);                     /* stop transmitting, do not Send STOP signal */

    Wire.requestFrom(byte(DEVICE_ADD) , 2);     /* 2 bytes send back */

    if (2 <= Wire.available())                  /* if two bytes were received */
    {
        reading = Wire.read();                  /* receive high byte (overwrites previous reading) */
        reading = reading << 8;                 /* shift high byte to be high 8 bits */
        reading |= Wire.read();                 /* receive low byte as lower 8 bits */
        Serial.println(reading);                /* print the reading */
    }

    delay(250);                                 /* wait a bit */
  
}

Chuck.

Thanx.

  1. Yes it helped to solve reeated start problem.

  2. Now one problem left is 10ms timeout in case of smbus protocol which I am using.
    I think there is no such functionality in wire library for timeout. Right?

  3. I am using this library for timeout functionality:
    Arduino Playground - SoftwareI2CLibrary

However it has some warnings:

SoftI2CMaster.h:269:7: warning: unused parameter 'addr' [-Wunused-parameter]
 bool  i2c_start(uint8_t addr)
       ^
SoftI2CMaster.h:287:7: warning: unused parameter 'addr' [-Wunused-parameter]
 bool  i2c_rep_start(uint8_t addr)
       ^
SoftI2CMaster.h:312:7: warning: unused parameter 'addr' [-Wunused-parameter]
 void  i2c_start_wait(uint8_t addr)
       ^
SoftI2CMaster.h:359:6: warning: unused parameter 'value' [-Wunused-parameter]
 bool i2c_write(uint8_t value)
      ^
SoftI2CMaster.h:436:9: warning: unused parameter 'last' [-Wunused-parameter]
 uint8_t i2c_read(bool last)
  1. I think to remove these warning, since these are warning of unused varaibles in function so
    writing this, will remove the warning.I am not sure if this is right way to do.
    if(unused_var){}

Attached is original file & updated file.

SoftI2CMaster.h (20.4 KB)

SoftI2CMaster_updated.h (20.6 KB)

Vindhyachal_Takniki:
Thanx.

  1. I am using this library for timeout functionality:
    Arduino Playground - HomePage

However it has some warnings:

Sorry I cannot help you, I have no experience with that library.

chuck.

Ok,

  1. Do wire library in arduino have timeout function in case of SMBUS.

Vindhyachal_Takniki:
Ok,

  1. Do wire library in arduino have timeout function in case of SMBUS.

No, it does not. I have attached a modified Wire library that has one second timeouts. If you need to change it to 100ms you can change the timeout counstant TIMEOUTMS in utility\twi.c

chuck.

Wire.zip (16 KB)

thanx for lib.

I think one problem in it , after getting timeout it sets err flag, but immediately returns back, without sending stop condition.
Although Wire.endTransmission(); can be send in main code also or that's not an issue.

Vindhyachal_Takniki:
thanx for lib.

I think one problem in it , after getting timeout it sets err flag, but immediately returns back, without sending stop condition.
Although Wire.endTransmission(); can be send in main code also or that's not an issue.

You might be right, I'll check that error path.

chuck.