Reading battery data from SMBus/i2c

Status
Not open for further replies.

SteveH

Member
First off, I am not very adept with C, but do have a PHP background and have been coding in various languages for over 35 years. I did take Borland C++ back in 1990 for college, but haven't visited it since. I also worked in electronic assembly for 15 years and understand basic concepts, etc. I can mostly hack together what I need from other similar projects found on the net.

That being said, my goal is to read the battery data off it's SMBus and display it on an LCD. I have the LCD working. My understanding is this can be accomplished over i2c. I've researched "arduino smbus" and have found several sketches, but they both use this library: http://playground.arduino.cc/Main/SoftwareI2CLibrary

The 2 projects:
https://github.com/PowerCartel/PackProbe/blob/master/PackProbe/PackProbe.ino
http://linuxehacking.blogspot.it/2014/03/recharging-and-reusing-acer-laptop.html

I just can't get that library (SoftwareI2CLibrary) to compile in even the most simple sketch that does nothing. This library (just a .h file) requires a few defines to be in place before importing the library.

Code:
#define SCL_PIN 19 
#define SCL_PORT PORTD 
#define SDA_PIN 18 
#define SDA_PORT PORTC 
#include <SoftI2CMaster.h>

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}

Arduino: 1.6.5 (Windows 8.1), TD: 1.25, Board: "Teensy 3.2 / 3.1, Serial, 96 MHz optimized (overclock), US English"

In file included from SMBus.ino:7:0:
C:\Users\Steve\Documents\Arduino\libraries\SoftI2C/SoftI2CMaster.h: In function 'void i2c_wait_scl_high()':
C:\Users\Steve\Documents\Arduino\libraries\SoftI2C/SoftI2CMaster.h:171:39: error: '_SFR_IO_ADDR' was not declared in this scope
#define SCL_IN (_SFR_IO_ADDR(SCL_PORT) - 2)
^
C:\Users\Steve\Documents\Arduino\libraries\SoftI2C/SoftI2CMaster.h:209:23: note: in expansion of macro 'SCL_IN'
: : [SCLIN] "I" (SCL_IN), [SCLPIN] "I" (SCL_PIN));
^
C:\Users\Steve\Documents\Arduino\libraries\SoftI2C/SoftI2CMaster.h: In function 'boolean i2c_init()':
C:\Users\Steve\Documents\Arduino\libraries\SoftI2C/SoftI2CMaster.h:167:46: error: '_SFR_IO_ADDR' was not declared in this scope
#define SCL_DDR (_SFR_IO_ADDR(SCL_PORT) - 1)
^
C:\Users\Steve\Documents\Arduino\libraries\SoftI2C/SoftI2CMaster.h:263:23: note: in expansion of macro 'SCL_DDR'
[SCLDDR] "I" (SCL_DDR), [SCLPIN] "I" (SCL_PIN),
^
C:\Users\Steve\Documents\Arduino\libraries\SoftI2C/SoftI2CMaster.h: In function 'bool i2c_start(uint8_t)':
C:\Users\Steve\Documents\Arduino\libraries\SoftI2C/SoftI2CMaster.h:166:46: error: '_SFR_IO_ADDR' was not declared in this scope
#define SDA_DDR (_SFR_IO_ADDR(SDA_PORT) - 1)
^
C:\Users\Steve\Documents\Arduino\libraries\SoftI2C/SoftI2CMaster.h:283:25: note: in expansion of macro 'SDA_DDR'
: : [SDADDR] "I" (SDA_DDR), [SDAPIN] "I" (SDA_PIN),
^
C:\Users\Steve\Documents\Arduino\libraries\SoftI2C/SoftI2CMaster.h: In function 'bool i2c_rep_start(uint8_t)':
C:\Users\Steve\Documents\Arduino\libraries\SoftI2C/SoftI2CMaster.h:167:46: error: '_SFR_IO_ADDR' was not declared in this scope
#define SCL_DDR (_SFR_IO_ADDR(SCL_PORT) - 1)
^
C:\Users\Steve\Documents\Arduino\libraries\SoftI2C/SoftI2CMaster.h:308:25: note: in expansion of macro 'SCL_DDR'
: : [SCLDDR] "I" (SCL_DDR), [SCLPIN] "I" (SCL_PIN),[SCLIN] "I" (SCL_IN),
^
C:\Users\Steve\Documents\Arduino\libraries\SoftI2C/SoftI2CMaster.h: In function 'void i2c_start_wait(uint8_t)':
C:\Users\Steve\Documents\Arduino\libraries\SoftI2C/SoftI2CMaster.h:166:46: error: '_SFR_IO_ADDR' was not declared in this scope
#define SDA_DDR (_SFR_IO_ADDR(SDA_PORT) - 1)
^
C:\Users\Steve\Documents\Arduino\libraries\SoftI2C/SoftI2CMaster.h:336:24: note: in expansion of macro 'SDA_DDR'
: : [SDADDR] "I" (SDA_DDR), [SDAPIN] "I" (SDA_PIN),
^
C:\Users\Steve\Documents\Arduino\libraries\SoftI2C/SoftI2CMaster.h: In function 'void i2c_stop()':
C:\Users\Steve\Documents\Arduino\libraries\SoftI2C/SoftI2CMaster.h:167:46: error: '_SFR_IO_ADDR' was not declared in this scope
#define SCL_DDR (_SFR_IO_ADDR(SCL_PORT) - 1)
^
C:\Users\Steve\Documents\Arduino\libraries\SoftI2C/SoftI2CMaster.h:356:25: note: in expansion of macro 'SCL_DDR'
: : [SCLDDR] "I" (SCL_DDR), [SCLPIN] "I" (SCL_PIN), [SCLIN] "I" (SCL_IN),
^
C:\Users\Steve\Documents\Arduino\libraries\SoftI2C/SoftI2CMaster.h: In function 'bool i2c_write(uint8_t)':
C:\Users\Steve\Documents\Arduino\libraries\SoftI2C/SoftI2CMaster.h:167:46: error: '_SFR_IO_ADDR' was not declared in this scope
#define SCL_DDR (_SFR_IO_ADDR(SCL_PORT) - 1)
^
C:\Users\Steve\Documents\Arduino\libraries\SoftI2C/SoftI2CMaster.h:432:22: note: in expansion of macro 'SCL_DDR'
[SCLDDR] "I" (SCL_DDR), [SCLPIN] "I" (SCL_PIN), [SCLIN] "I" (SCL_IN),
^
C:\Users\Steve\Documents\Arduino\libraries\SoftI2C/SoftI2CMaster.h: In function 'uint8_t i2c_read(bool)':
C:\Users\Steve\Documents\Arduino\libraries\SoftI2C/SoftI2CMaster.h:167:46: error: '_SFR_IO_ADDR' was not declared in this scope
#define SCL_DDR (_SFR_IO_ADDR(SCL_PORT) - 1)
^
C:\Users\Steve\Documents\Arduino\libraries\SoftI2C/SoftI2CMaster.h:501:22: note: in expansion of macro 'SCL_DDR'
[SCLDDR] "I" (SCL_DDR), [SCLPIN] "I" (SCL_PIN), [SCLIN] "I" (SCL_IN),
^
Error compiling.

This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.

Ultimate, this is the battery I'm trying to interface with: http://dev.3dr.com/hardware-battery-charging.html
Here is the SMBus code that the copter is using, which is open source: https://github.com/diydrones/PX4Firmware/blob/master/src/drivers/batt_smbus/batt_smbus.cpp

I'm just not sure why the above won't compile since I'm not doing anything other than including the library. Is it teensy related vs arduino, which the library was created for?
 
Status
Not open for further replies.
Back
Top