-
Notifications
You must be signed in to change notification settings - Fork 0
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
Ht09 fall david #5
base: main
Are you sure you want to change the base?
Conversation
…to execute write and read functions. Need to add MessageInterface
…into ht09-fall-david
/** | ||
* Transfers bytes (uint8_t) of arbritrary length on to the SPI line | ||
* @param data input buffer of size length | ||
* @param length length of buffer, number of bytes | ||
*/ | ||
template <size_t data_size> | ||
void _transfer_SPI_data(const std::array<uint8_t, data_size> &data); | ||
|
||
/** | ||
* Receives SPI data | ||
* @param length length of data we expect to receive | ||
* @return data we are receiving instantaneously | ||
*/ | ||
template <size_t data_size> | ||
std::array<uint8_t, data_size> _receive_SPI_data(); | ||
|
||
/** | ||
* Writes a LOW on one of the chip selects, then delays | ||
* @param cs the chip select we are writing to | ||
* @param delay time in microseconds | ||
*/ | ||
void _write_and_delay_LOW(int cs, int delay_microSeconds); | ||
|
||
/** | ||
* Writes a HIGH on one of the chip selects, then delay | ||
* @param cs the chip select we are writing to | ||
* @param delay time in microseconds | ||
*/ | ||
void _write_and_delay_HIGH(int cs, int delay_microSeconds); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to declare the leading underscore "private" functions here. for these functions that you dont want to have others use for this interface (leading underscore, private visibility), you dont have to declare them in the header file here if you only use them in the associated cpp file and can just make forward declarations in the cpp file itself to use them in the "visible" interface spi functions
uint16_t _pec15Table[256]; | ||
|
||
/** | ||
* We will need this for both models of the IC | ||
* This determines where we get our signals from on the Arduino | ||
* It can only be 9 or 10 | ||
* NOTE: needs to be initialized | ||
*/ | ||
std::array<int, num_chip_selects> _chip_select; | ||
|
||
/** | ||
* We will need this for both models of the IC | ||
* This determines where we get our signals from on the Arduino | ||
* It can only be 9 or 10 | ||
* NOTE: needs to be initialized | ||
*/ | ||
std::array<int, num_chips> _chip_select_per_chip; | ||
|
||
/** | ||
* We will only end up using the address if this is a LTC6811-2 | ||
* NOTE: But if we are, we need to call a setup function to instatiate each with the correct addresses | ||
* BMS Segments 1, 4, and 5 are on chip select 9 | ||
* BMS Segments 2, 3, and 6 are on chip select 10 | ||
* Those segments correspond to 2 ICs each, so the instance with chip_select 9 | ||
* Will have IC addresses: 0,1,6,7,8,9 | The rest are for chip_select 10 | ||
*/ | ||
std::array<int, num_chips> _address; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make these const if they are not going to change during runtime
if (_chip_type == LTC6811_Type_e::LTC6811_1) | ||
{ | ||
return _read_data_through_broadcast(); | ||
} | ||
else | ||
{ | ||
return _read_data_through_address(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use if constexpr
here instead instead and make the type const
.
cmd[0] = (adc_cmd >> 8) & 0xFF; | ||
cmd[1] = adc_cmd & 0xFF; | ||
|
||
if (_chip_type == LTC6811_Type_e::LTC6811_1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if constexpr
updated for loop for read_data and added a package cell voltage/auxillaries so there's no switch statement.
I also used the logic analyzer for the broadcast signal, and for some reason the 2 second delay time threw the enable / SCK off, so I increased it to 5 and that fixed it. Not once have I been able to get a MISO signal from the new board, so I'm still trying to figure that out.