Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements to read_68() for LTC681x libraries #47

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 19 additions & 15 deletions LTSketchbook/libraries/LTC6810/LTC6810.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,7 @@ void LTC6810_rds_reg(uint8_t reg, //Determines which S voltage register is read
uint8_t *data //An array of the unparsed cell codes
)
{
const uint8_t REG_LEN = 8; //Number of bytes in each ICs register + 2 bytes for the PEC
uint8_t cmd[4];
uint16_t cmd_pec;
uint8_t cmd[2];

if (reg == 1) // RDSA
{
Expand Down Expand Up @@ -582,11 +580,11 @@ void LTC6810_stcomm(uint8_t len) //Length of data to be transmitted
}

/* Reads Serial ID registers group. */
uint8_t LTC6810_rdsid(uint8_t total_ic, // The number of ICs in the system
int8_t LTC6810_rdsid(uint8_t total_ic, // The number of ICs in the system
cell_asic *ic //A two dimensional array that the function stores the read data.
)
{
uint8_t cmd[4];
uint8_t cmd[2];
uint8_t read_buffer[256];
int8_t pec_error = 0;
uint16_t data_pec;
Expand All @@ -597,23 +595,29 @@ uint8_t LTC6810_rdsid(uint8_t total_ic, // The number of ICs in the system
cmd[0] = 0x00;
cmd[1] = 0x2C;

pec_error = read_68(total_ic, cmd, read_buffer);
read_68(total_ic, cmd, read_buffer);

for(uint8_t current_ic =0; current_ic<total_ic; current_ic++)
{
if (temp== false)
{
c_ic = current_ic;
}
else
{
c_ic = total_ic - current_ic - 1;
}
if (temp== false)
{
c_ic = current_ic;
}
else
{
c_ic = total_ic - current_ic - 1;
}

for(int byte=0; byte<8;byte++)
for(int byte = 0; byte < 6; byte++)
{
ic[c_ic].sid[byte] = read_buffer[byte+(8*current_ic)];
}

calc_pec = pec15_calc(6,&read_buffer[8*current_ic]);
data_pec = read_buffer[7+(8*current_ic)] | (read_buffer[6+(8*current_ic)]<<8);
if(calc_pec != data_pec ){
pec_error = -1;
}
}
return(pec_error);
}
Expand Down
2 changes: 1 addition & 1 deletion LTSketchbook/libraries/LTC6810/LTC6810.h
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ void LTC6810_stcomm(uint8_t len //!< Length of data to be transmitted
0: Data read back has matching PEC
-1: Data read back has incorrect PEC
*/
uint8_t LTC6810_rdsid(uint8_t total_ic, //!< The number of ICs in the system
int8_t LTC6810_rdsid(uint8_t total_ic, //!< The number of ICs in the system
cell_asic *ic //!< A two dimensional array that will store the read data
);

Expand Down
13 changes: 6 additions & 7 deletions LTSketchbook/libraries/LTC6812/LTC6812.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -527,19 +527,17 @@ int8_t LTC6812_rdpsb(uint8_t total_ic, //Number of ICs in the daisy chain
cell_asic *ic //A two dimensional array that the function stores the read data
)
{
uint8_t cmd[4];
uint8_t cmd[2];
uint8_t read_buffer[256];
int8_t pec_error = 0;
uint16_t data_pec;
uint16_t calc_pec;
uint8_t c_ic = 0;

cmd[0] = 0x00;
cmd[1] = 0x1E;


cmd[0] = 0x00;
cmd[1] = 0x1E;


pec_error = read_68(total_ic, cmd, read_buffer);
read_68(total_ic, cmd, read_buffer);

for(uint8_t current_ic =0; current_ic<total_ic; current_ic++)
{
Expand All @@ -564,6 +562,7 @@ int8_t LTC6812_rdpsb(uint8_t total_ic, //Number of ICs in the daisy chain
data_pec = read_buffer[7+(8*current_ic)] | (read_buffer[6+(8*current_ic)]<<8);
if(calc_pec != data_pec )
{
pec_error = -1;
ic[c_ic].pwmb.rx_pec_match = 1;
ic[c_ic].sctrlb.rx_pec_match = 1;
}
Expand Down
9 changes: 4 additions & 5 deletions LTSketchbook/libraries/LTC6813/LTC6813.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -530,19 +530,19 @@ void LTC6813_wrpsb(uint8_t total_ic, // Number of ICs in the system
}

/* Reading the 6813 PWM/Sctrl Register B */
uint8_t LTC6813_rdpsb(uint8_t total_ic, //< number of ICs in the daisy chain
int8_t LTC6813_rdpsb(uint8_t total_ic, //< number of ICs in the daisy chain
cell_asic *ic //< a two dimensional array that the function stores the read data
)
{
uint8_t cmd[4];
uint8_t cmd[2];
uint8_t read_buffer[256];
int8_t pec_error = 0;
uint16_t data_pec;
uint16_t calc_pec;
uint8_t c_ic = 0;
cmd[0] = 0x00;
cmd[1] = 0x1E;
pec_error = read_68(total_ic, cmd, read_buffer);
read_68(total_ic, cmd, read_buffer);

for(uint8_t current_ic =0; current_ic<total_ic; current_ic++)
{
Expand All @@ -568,15 +568,14 @@ uint8_t LTC6813_rdpsb(uint8_t total_ic, //< number of ICs in the daisy chain
data_pec = read_buffer[7+(8*current_ic)] | (read_buffer[6+(8*current_ic)]<<8);
if(calc_pec != data_pec )
{
pec_error = -1;
ic[c_ic].pwmb.rx_pec_match = 1;
ic[c_ic].sctrlb.rx_pec_match = 1;

}
else
{
ic[c_ic].pwmb.rx_pec_match = 0;
ic[c_ic].sctrlb.rx_pec_match = 0;

}
}
return(pec_error);
Expand Down
2 changes: 1 addition & 1 deletion LTSketchbook/libraries/LTC6813/LTC6813.h
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ void LTC6813_wrpsb(uint8_t total_ic, //!< Number of ICs in the system
0: Data read back has matching PEC
-1: Data read back has incorrect PEC
*/
uint8_t LTC6813_rdpsb(uint8_t total_ic, //!< Number of ICs in the daisy chain
int8_t LTC6813_rdpsb(uint8_t total_ic, //!< Number of ICs in the daisy chain
cell_asic *ic //!< A two dimensional array that the function stores the read data
);

Expand Down
Loading