Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
aareyes
Smart-Battery-Module-Info_For_Arduino
Commits
72a44477
Commit
72a44477
authored
Dec 31, 2018
by
Armin
Browse files
Serial wait for Leonardo boards
parent
b2d8daf8
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
52 additions
and
44 deletions
+52
-44
.cproject
.cproject
+3
-0
README.md
README.md
+1
-3
src/.gitignore
src/.gitignore
+1
-0
src/SBMInfo/SBMInfo.ino
src/SBMInfo/SBMInfo.ino
+47
-41
No files found.
.cproject
View file @
72a44477
...
@@ -76,6 +76,9 @@
...
@@ -76,6 +76,9 @@
<tool
id=
"de.innot.avreclipse.tool.avrdude.app.release.440173151"
name=
"AVRDude"
superClass=
"de.innot.avreclipse.tool.avrdude.app.release"
/>
<tool
id=
"de.innot.avreclipse.tool.avrdude.app.release.440173151"
name=
"AVRDude"
superClass=
"de.innot.avreclipse.tool.avrdude.app.release"
/>
</toolChain>
</toolChain>
</folderInfo>
</folderInfo>
<sourceEntries>
<entry
excluding=
"src/SBMInfo.cpp|src/lib/SoftwareWire.cpp"
flags=
"VALUE_WORKSPACE_PATH|RESOLVED"
kind=
"sourcePath"
name=
""
/>
</sourceEntries>
</configuration>
</configuration>
</storageModule>
</storageModule>
<storageModule
moduleId=
"org.eclipse.cdt.core.externalSettings"
/>
<storageModule
moduleId=
"org.eclipse.cdt.core.externalSettings"
/>
...
...
README.md
View file @
72a44477
...
@@ -7,9 +7,7 @@ Prints SBM controller info
...
@@ -7,9 +7,7 @@ Prints SBM controller info
Based on https://github.com/PowerCartel/PackProbe from Power Cartel http://powercartel.com/projects/packprobe/.
Based on https://github.com/PowerCartel/PackProbe from Power Cartel http://powercartel.com/projects/packprobe/.
## Compile with the Arduino IDE
## Compile with the Arduino IDE
First you need to install "SoftwareWire" library with Sketch -> Include Library -> Manage Librarys.... Use "SoftwareWire" as filter string.
Download and extract the repository. In the Arduino IDE open the sketch with File -> Open... and select the src/SBMInfo folder.
Then download and extract the repository. In the Arduino IDE open the sketch with File -> Open... and select the src/SBMInfo folder.
## Identifying the right connection
## Identifying the right connection
After startup, the program scans for a connected I2C device.
After startup, the program scans for a connected I2C device.
...
...
src/.gitignore
View file @
72a44477
/lib/
/lib/
/SBMInfo.cpp
src/SBMInfo/SBMInfo.ino
View file @
72a44477
...
@@ -18,20 +18,18 @@
...
@@ -18,20 +18,18 @@
#include <Arduino.h>
#include <Arduino.h>
#include "SBMInfo.h"
#include "SBMInfo.h"
#include <
Software
Wire.h>
#include <Wire.h>
#include <LiquidCrystal.h>
#include <LiquidCrystal.h>
#define LCD_COLUMNS 20
#define LCD_COLUMNS 20
#define LCD_ROWS 4
#define LCD_ROWS 4
#define VERSION "3.
0
"
#define VERSION "3.
1
"
//#define DEBUG
/*
/*
*
Corresponds to
A4/A5 - the hardware I2C pins on Arduino
*
Uses
A4/A5 - the hardware I2C pins on Arduino
*/
*/
#define SDA_PIN A4
#define SCL_PIN A5
SoftwareWire
SBMConnection
(
SDA_PIN
,
SCL_PIN
);
#define DATA_BUFFER_LENGTH 32
#define DATA_BUFFER_LENGTH 32
uint8_t
sI2CDataBuffer
[
DATA_BUFFER_LENGTH
];
uint8_t
sI2CDataBuffer
[
DATA_BUFFER_LENGTH
];
...
@@ -137,7 +135,6 @@ const char Cell_3_Voltage[] PROGMEM = "Cell 3 Voltage: ";
...
@@ -137,7 +135,6 @@ const char Cell_3_Voltage[] PROGMEM = "Cell 3 Voltage: ";
const
char
Cell_4_Voltage
[]
PROGMEM
=
"Cell 4 Voltage: "
;
const
char
Cell_4_Voltage
[]
PROGMEM
=
"Cell 4 Voltage: "
;
const
char
State_of_Health
[]
PROGMEM
=
"State of Health: "
;
const
char
State_of_Health
[]
PROGMEM
=
"State of Health: "
;
int
nonStandardInfoSupportedByPack
=
0
;
// 0 not initialized, 1 supported, > 1 not supported
int
nonStandardInfoSupportedByPack
=
0
;
// 0 not initialized, 1 supported, > 1 not supported
struct
SBMFunctionDescriptionStruct
sSBMNonStandardFunctionDescriptionArray
[]
=
{
{
struct
SBMFunctionDescriptionStruct
sSBMNonStandardFunctionDescriptionArray
[]
=
{
{
CELL1_VOLTAGE
,
Cell_1_Voltage
,
&
printVoltage
},
{
CELL1_VOLTAGE
,
Cell_1_Voltage
,
&
printVoltage
},
{
...
@@ -177,8 +174,8 @@ void setup() {
...
@@ -177,8 +174,8 @@ void setup() {
// initialize the digital pin as an output.
// initialize the digital pin as an output.
pinMode
(
LED_PIN
,
OUTPUT
);
pinMode
(
LED_PIN
,
OUTPUT
);
// Shutdown SPI
and TWI
, timers, and ADC
// Shutdown SPI, timers, and ADC
PRR
=
(
1
<<
PRSPI
)
|
(
1
<<
PRTWI
)
|
(
1
<<
PRTIM1
)
|
(
1
<<
PRTIM2
)
|
(
1
<<
PRADC
);
PRR
=
(
1
<<
PRSPI
)
|
(
1
<<
PRTIM1
)
|
(
1
<<
PRTIM2
)
|
(
1
<<
PRADC
);
// Disable digital input on all unused ADC channel pins to reduce power consumption
// Disable digital input on all unused ADC channel pins to reduce power consumption
DIDR0
=
ADC0D
|
ADC1D
|
ADC2D
|
ADC3D
;
DIDR0
=
ADC0D
|
ADC1D
|
ADC2D
|
ADC3D
;
...
@@ -197,8 +194,8 @@ void setup() {
...
@@ -197,8 +194,8 @@ void setup() {
* The workaround to set __FILE__ with #line __LINE__ "LightToServo.cpp" disables source output including in .lss file (-S option)
* The workaround to set __FILE__ with #line __LINE__ "LightToServo.cpp" disables source output including in .lss file (-S option)
*/
*/
SBMConnection
.
begin
();
Wire
.
begin
();
SBMConnection
.
setClock
(
2
5
000
);
Wire
.
setClock
(
3
2000
);
// lowest rate available is 31000
/*
/*
* Check for I2C device and blink until device attached
* Check for I2C device and blink until device attached
...
@@ -260,11 +257,12 @@ void TogglePin(uint8_t aPinNr) {
...
@@ -260,11 +257,12 @@ void TogglePin(uint8_t aPinNr) {
}
}
bool
checkForAttachedI2CDevice
(
uint8_t
aStandardDeviceAddress
)
{
bool
checkForAttachedI2CDevice
(
uint8_t
aStandardDeviceAddress
)
{
SBMConnection
.
beginTransmission
(
aStandardDeviceAddress
);
Wire
.
beginTransmission
(
aStandardDeviceAddress
);
uint8_t
tOK
=
SBMConnection
.
endTransmission
();
uint8_t
tOK
=
Wire
.
endTransmission
();
if
(
tOK
==
SOFTWAREWIRE_NO_ERROR
)
{
if
(
tOK
==
0
)
{
Serial
.
print
(
F
(
"Found attached I2C device at 0x"
));
Serial
.
print
(
F
(
"Found attached I2C device at 0x"
));
Serial
.
println
(
aStandardDeviceAddress
,
HEX
);
Serial
.
println
(
aStandardDeviceAddress
,
HEX
);
Serial
.
flush
();
sI2CDeviceAddress
=
SBM_DEVICE_ADDRESS
;
sI2CDeviceAddress
=
SBM_DEVICE_ADDRESS
;
return
true
;
return
true
;
}
else
{
}
else
{
...
@@ -278,9 +276,9 @@ int sScanCount = 0;
...
@@ -278,9 +276,9 @@ int sScanCount = 0;
int
scanForAttachedI2CDevice
(
void
)
{
int
scanForAttachedI2CDevice
(
void
)
{
int
tFoundAdress
=
-
1
;
int
tFoundAdress
=
-
1
;
for
(
uint8_t
i
=
0
;
i
<
127
;
i
++
)
{
for
(
uint8_t
i
=
0
;
i
<
127
;
i
++
)
{
SBMConnection
.
beginTransmission
(
i
);
Wire
.
beginTransmission
(
i
);
uint8_t
tOK
=
SBMConnection
.
endTransmission
(
true
);
uint8_t
tOK
=
Wire
.
endTransmission
(
true
);
if
(
tOK
==
SOFTWAREWIRE_NO_ERROR
)
{
if
(
tOK
==
0
)
{
Serial
.
print
(
F
(
"Found I2C device attached at address: 0x"
));
Serial
.
print
(
F
(
"Found I2C device attached at address: 0x"
));
Serial
.
println
(
i
,
HEX
);
Serial
.
println
(
i
,
HEX
);
tFoundAdress
=
i
;
tFoundAdress
=
i
;
...
@@ -304,24 +302,21 @@ int scanForAttachedI2CDevice(void) {
...
@@ -304,24 +302,21 @@ int scanForAttachedI2CDevice(void) {
}
}
int
readWord
(
uint8_t
aFunction
)
{
int
readWord
(
uint8_t
aFunction
)
{
cli
();
Wire
.
beginTransmission
(
sI2CDeviceAddress
);
SBMConnection
.
beginTransmission
(
sI2CDeviceAddress
);
Wire
.
write
(
aFunction
);
SBMConnection
.
write
(
aFunction
);
Wire
.
endTransmission
();
SBMConnection
.
requestFrom
(
sI2CDeviceAddress
,
(
uint8_t
)
2
);
Wire
.
requestFrom
(
sI2CDeviceAddress
,
(
uint8_t
)
2
);
sei
();
uint8_t
tLSB
=
Wire
.
read
();
uint8_t
tLSB
=
SBMConnection
.
read
();
uint8_t
tMSB
=
Wire
.
read
();
uint8_t
tMSB
=
SBMConnection
.
read
();
return
(
int
)
tLSB
|
(((
int
)
tMSB
)
<<
8
);
return
(
int
)
tLSB
|
(((
int
)
tMSB
)
<<
8
);
}
}
void
writeWord
(
uint8_t
aFunction
,
uint16_t
aValue
)
{
void
writeWord
(
uint8_t
aFunction
,
uint16_t
aValue
)
{
cli
();
Wire
.
beginTransmission
(
sI2CDeviceAddress
);
SBMConnection
.
beginTransmission
(
sI2CDeviceAddress
);
Wire
.
write
(
aFunction
);
SBMConnection
.
write
(
aFunction
);
Wire
.
write
(
aValue
&
0xFF
);
SBMConnection
.
write
(
aValue
&
0xFF
);
Wire
.
write
((
aValue
>>
8
)
&
0xFF
);
SBMConnection
.
write
((
aValue
>>
8
)
&
0xFF
);
Wire
.
endTransmission
();
SBMConnection
.
endTransmission
();
sei
();
}
}
int
readWordFromManufacturerAccess
(
uint16_t
aCommand
)
{
int
readWordFromManufacturerAccess
(
uint16_t
aCommand
)
{
...
@@ -330,24 +325,35 @@ int readWordFromManufacturerAccess(uint16_t aCommand) {
...
@@ -330,24 +325,35 @@ int readWordFromManufacturerAccess(uint16_t aCommand) {
}
}
uint8_t
readBlock
(
uint8_t
aCommand
,
uint8_t
*
aDataBufferPtr
,
uint8_t
aDataBufferLength
)
{
uint8_t
readBlock
(
uint8_t
aCommand
,
uint8_t
*
aDataBufferPtr
,
uint8_t
aDataBufferLength
)
{
cli
();
Wire
.
beginTransmission
(
sI2CDeviceAddress
);
SBMConnection
.
beginTransmission
(
sI2CDeviceAddress
);
Wire
.
write
(
aCommand
);
SBMConnection
.
write
(
aCommand
);
Wire
.
endTransmission
();
SBMConnection
.
requestFrom
(
sI2CDeviceAddress
,
(
uint8_t
)
1
);
Wire
.
requestFrom
(
sI2CDeviceAddress
,
(
uint8_t
)
1
);
// First read length of data
// First read length of data
uint8_t
tLengthOfData
=
SBMConnection
.
read
();
uint8_t
tLengthOfData
=
Wire
.
read
();
#ifdef DEBUG
Serial
.
print
(
F
(
"
\n
tLengthOfData="
));
Serial
.
println
(
tLengthOfData
);
#endif
tLengthOfData
++
;
// since the length is read again
tLengthOfData
++
;
// since the length is read again
if
(
tLengthOfData
>
aDataBufferLength
)
{
if
(
tLengthOfData
>
aDataBufferLength
)
{
tLengthOfData
=
aDataBufferLength
;
tLengthOfData
=
aDataBufferLength
;
}
}
SBMConnection
.
requestFrom
(
sI2CDeviceAddress
,
tLengthOfData
,
false
);
SBMConnection
.
read
();
#ifdef DEBUG
tLengthOfData
--
;
// since the length must be skipped
uint8_t
tNumberOfDataReceived
=
Wire
.
requestFrom
(
sI2CDeviceAddress
,
tLengthOfData
);
SBMConnection
.
readBytes
(
aDataBufferPtr
,
tLengthOfData
);
Serial
.
print
(
F
(
"tNumberOfDataReceived="
));
Serial
.
println
(
tNumberOfDataReceived
);
#else
Wire
.
requestFrom
(
sI2CDeviceAddress
,
tLengthOfData
);
#endif
sei
();
Wire
.
read
();
tLengthOfData
--
;
// since the length must be skipped
Wire
.
readBytes
(
aDataBufferPtr
,
tLengthOfData
);
return
tLengthOfData
;
return
tLengthOfData
;
}
}
...
...
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