Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
labrobotica
firmware
avr8_smbus_battery_monitor
Commits
041f7ee6
Commit
041f7ee6
authored
Jul 18, 2012
by
Sergi Hernandez
Browse files
Removed the hardcoded I2C address. Now it is using the value read from the EEPROM at startup.
parent
a637366b
Changes
1
Hide whitespace changes
Inline
Side-by-side
fuel_gauge.c
View file @
041f7ee6
...
...
@@ -11,7 +11,7 @@ float output_current;
// battery I2C slave address
unsigned
char
battery_id
;
unsigned
char
EEMEM
ee_battery_id
=
0x
31
;
unsigned
char
EEMEM
ee_battery_id
=
0x
60
;
// remaining_capacity
volatile
unsigned
short
int
remaining_capacity
;
...
...
@@ -102,9 +102,9 @@ void get_voltage(unsigned char *voltage)
// read the voltage registers of the battery
// send the read request
read_cmd
=
0x30
;
if
(
i2cMasterSendNI
(
0x62
,
1
,
&
read_cmd
)
==
I2C_OK
)
if
(
i2cMasterSendNI
(
battery_id
,
1
,
&
read_cmd
)
==
I2C_OK
)
{
if
(
i2cMasterReceiveNI
(
0x62
,
18
,
voltage_data
)
==
I2C_OK
)
if
(
i2cMasterReceiveNI
(
battery_id
,
18
,
voltage_data
)
==
I2C_OK
)
{
for
(
i
=
0
;
i
<
16
;
i
++
)
voltage
[
i
]
=
voltage_data
[
i
+
2
];
...
...
@@ -118,9 +118,9 @@ void get_temperature(unsigned char *temp1, unsigned char *temp2)
unsigned
char
read_cmd
;
read_cmd
=
0x4A
;
// device start read address
if
(
i2cMasterSendNI
(
0x62
,
1
,
&
read_cmd
)
==
I2C_OK
)
if
(
i2cMasterSendNI
(
battery_id
,
1
,
&
read_cmd
)
==
I2C_OK
)
{
if
(
i2cMasterReceiveNI
(
0x62
,
6
,
temp_data
)
==
I2C_OK
)
if
(
i2cMasterReceiveNI
(
battery_id
,
6
,
temp_data
)
==
I2C_OK
)
{
temp1
[
0
]
=
temp_data
[
2
];
temp1
[
1
]
=
temp_data
[
3
];
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment