req
Dependents: BMS_BMUCore_Max_DummyData BMS_BMUCore_Max
Fork of LTC6804 by
SPI_Parser.h@9:1c94bbb97eaa, 2017-09-16 (annotated)
- Committer:
- DasSidG
- Date:
- Sat Sep 16 01:04:41 2017 +0000
- Revision:
- 9:1c94bbb97eaa
- Parent:
- 7:1448777cbc34
Removed some couts which were generating warnings as they were placed after a break
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
DasSidG | 5:324a19dcfdec | 1 | #ifndef SPI_Parser_H |
DasSidG | 5:324a19dcfdec | 2 | #define SPI_Parser_H |
DasSidG | 5:324a19dcfdec | 3 | |
DasSidG | 5:324a19dcfdec | 4 | #include "mbed.h" |
DasSidG | 5:324a19dcfdec | 5 | #include "CAN_Data.h" |
DasSidG | 5:324a19dcfdec | 6 | #include "CAN_IDs.h" |
DasSidG | 5:324a19dcfdec | 7 | #include <stdlib.h> |
DasSidG | 5:324a19dcfdec | 8 | #include <iostream> |
DasSidG | 5:324a19dcfdec | 9 | |
DasSidG | 7:1448777cbc34 | 10 | #define DEBUG 1 |
DasSidG | 6:47ffbe9ee110 | 11 | |
DasSidG | 5:324a19dcfdec | 12 | const int socAddress = 0x64 << 1; //refer to slave address for LTC2943 on pg 16 of datasheet. mbed API uses 8 bit addresses, therefore left shift by 1 needed before passing. |
DasSidG | 5:324a19dcfdec | 13 | |
DasSidG | 5:324a19dcfdec | 14 | |
DasSidG | 5:324a19dcfdec | 15 | const int spiBitrate=250000; |
DasSidG | 5:324a19dcfdec | 16 | |
DasSidG | 5:324a19dcfdec | 17 | /*! |
DasSidG | 5:324a19dcfdec | 18 | |
DasSidG | 5:324a19dcfdec | 19 | |MD| Dec | ADC Conversion Model| |
DasSidG | 5:324a19dcfdec | 20 | |--|------|---------------------| |
DasSidG | 5:324a19dcfdec | 21 | |01| 1 | Fast | |
DasSidG | 5:324a19dcfdec | 22 | |10| 2 | Normal | |
DasSidG | 5:324a19dcfdec | 23 | |11| 3 | Filtered | |
DasSidG | 5:324a19dcfdec | 24 | */ |
DasSidG | 5:324a19dcfdec | 25 | #define MD_FAST 1 |
DasSidG | 5:324a19dcfdec | 26 | #define MD_NORMAL 2 |
DasSidG | 5:324a19dcfdec | 27 | #define MD_FILTERED 3 |
DasSidG | 5:324a19dcfdec | 28 | |
DasSidG | 5:324a19dcfdec | 29 | |
DasSidG | 5:324a19dcfdec | 30 | /*! |
DasSidG | 5:324a19dcfdec | 31 | |CH | Dec | Channels to convert | |
DasSidG | 5:324a19dcfdec | 32 | |---|------|---------------------| |
DasSidG | 5:324a19dcfdec | 33 | |000| 0 | All Cells | |
DasSidG | 5:324a19dcfdec | 34 | |001| 1 | Cell 1 and Cell 7 | |
DasSidG | 5:324a19dcfdec | 35 | |010| 2 | Cell 2 and Cell 8 | |
DasSidG | 5:324a19dcfdec | 36 | |011| 3 | Cell 3 and Cell 9 | |
DasSidG | 5:324a19dcfdec | 37 | |100| 4 | Cell 4 and Cell 10 | |
DasSidG | 5:324a19dcfdec | 38 | |101| 5 | Cell 5 and Cell 11 | |
DasSidG | 5:324a19dcfdec | 39 | |110| 6 | Cell 6 and Cell 12 | |
DasSidG | 5:324a19dcfdec | 40 | */ |
DasSidG | 5:324a19dcfdec | 41 | |
DasSidG | 5:324a19dcfdec | 42 | #define CELL_CH_ALL 0 |
DasSidG | 5:324a19dcfdec | 43 | #define CELL_CH_1and7 1 |
DasSidG | 5:324a19dcfdec | 44 | #define CELL_CH_2and8 2 |
DasSidG | 5:324a19dcfdec | 45 | #define CELL_CH_3and9 3 |
DasSidG | 5:324a19dcfdec | 46 | #define CELL_CH_4and10 4 |
DasSidG | 5:324a19dcfdec | 47 | #define CELL_CH_5and11 5 |
DasSidG | 5:324a19dcfdec | 48 | #define CELL_CH_6and12 6 |
DasSidG | 5:324a19dcfdec | 49 | |
DasSidG | 5:324a19dcfdec | 50 | |
DasSidG | 5:324a19dcfdec | 51 | /*! |
DasSidG | 5:324a19dcfdec | 52 | |
DasSidG | 5:324a19dcfdec | 53 | |CHG | Dec |Channels to convert | |
DasSidG | 5:324a19dcfdec | 54 | |----|------|----------------------| |
DasSidG | 5:324a19dcfdec | 55 | |000 | 0 | All GPIOS and 2nd Ref| |
DasSidG | 5:324a19dcfdec | 56 | |001 | 1 | GPIO 1 | |
DasSidG | 5:324a19dcfdec | 57 | |010 | 2 | GPIO 2 | |
DasSidG | 5:324a19dcfdec | 58 | |011 | 3 | GPIO 3 | |
DasSidG | 5:324a19dcfdec | 59 | |100 | 4 | GPIO 4 | |
DasSidG | 5:324a19dcfdec | 60 | |101 | 5 | GPIO 5 | |
DasSidG | 5:324a19dcfdec | 61 | |110 | 6 | Vref2 | |
DasSidG | 5:324a19dcfdec | 62 | */ |
DasSidG | 5:324a19dcfdec | 63 | |
DasSidG | 5:324a19dcfdec | 64 | #define AUX_CH_ALL 0 |
DasSidG | 5:324a19dcfdec | 65 | #define AUX_CH_GPIO1 1 |
DasSidG | 5:324a19dcfdec | 66 | #define AUX_CH_GPIO2 2 |
DasSidG | 5:324a19dcfdec | 67 | #define AUX_CH_GPIO3 3 |
DasSidG | 5:324a19dcfdec | 68 | #define AUX_CH_GPIO4 4 |
DasSidG | 5:324a19dcfdec | 69 | #define AUX_CH_GPIO5 5 |
DasSidG | 5:324a19dcfdec | 70 | #define AUX_CH_VREF2 6 |
DasSidG | 5:324a19dcfdec | 71 | |
DasSidG | 5:324a19dcfdec | 72 | //uint8_t CHG = 0; //!< aux channels to be converted |
DasSidG | 5:324a19dcfdec | 73 | /*!**************************************************** |
DasSidG | 5:324a19dcfdec | 74 | \brief Controls if Discharging transitors are enabled |
DasSidG | 5:324a19dcfdec | 75 | or disabled during Cell conversions. |
DasSidG | 5:324a19dcfdec | 76 | |
DasSidG | 5:324a19dcfdec | 77 | |DCP | Discharge Permitted During conversion | |
DasSidG | 5:324a19dcfdec | 78 | |----|----------------------------------------| |
DasSidG | 5:324a19dcfdec | 79 | |0 | No - discharge is not permitted | |
DasSidG | 5:324a19dcfdec | 80 | |1 | Yes - discharge is permitted | |
DasSidG | 5:324a19dcfdec | 81 | |
DasSidG | 5:324a19dcfdec | 82 | ********************************************************/ |
DasSidG | 5:324a19dcfdec | 83 | #define DCP_DISABLED 0 |
DasSidG | 5:324a19dcfdec | 84 | #define DCP_ENABLED 1 |
DasSidG | 5:324a19dcfdec | 85 | |
DasSidG | 5:324a19dcfdec | 86 | |
DasSidG | 5:324a19dcfdec | 87 | |
DasSidG | 5:324a19dcfdec | 88 | |
DasSidG | 5:324a19dcfdec | 89 | static const unsigned int crc15Table[256] = {0x0,0xc599, 0xceab, 0xb32, 0xd8cf, 0x1d56, 0x1664, 0xd3fd, 0xf407, 0x319e, 0x3aac, //!<precomputed CRC15 Table |
DasSidG | 5:324a19dcfdec | 90 | 0xff35, 0x2cc8, 0xe951, 0xe263, 0x27fa, 0xad97, 0x680e, 0x633c, 0xa6a5, 0x7558, 0xb0c1, |
DasSidG | 5:324a19dcfdec | 91 | 0xbbf3, 0x7e6a, 0x5990, 0x9c09, 0x973b, 0x52a2, 0x815f, 0x44c6, 0x4ff4, 0x8a6d, 0x5b2e, |
DasSidG | 5:324a19dcfdec | 92 | 0x9eb7, 0x9585, 0x501c, 0x83e1, 0x4678, 0x4d4a, 0x88d3, 0xaf29, 0x6ab0, 0x6182, 0xa41b, |
DasSidG | 5:324a19dcfdec | 93 | 0x77e6, 0xb27f, 0xb94d, 0x7cd4, 0xf6b9, 0x3320, 0x3812, 0xfd8b, 0x2e76, 0xebef, 0xe0dd, |
DasSidG | 5:324a19dcfdec | 94 | 0x2544, 0x2be, 0xc727, 0xcc15, 0x98c, 0xda71, 0x1fe8, 0x14da, 0xd143, 0xf3c5, 0x365c, |
DasSidG | 5:324a19dcfdec | 95 | 0x3d6e, 0xf8f7,0x2b0a, 0xee93, 0xe5a1, 0x2038, 0x7c2, 0xc25b, 0xc969, 0xcf0, 0xdf0d, |
DasSidG | 5:324a19dcfdec | 96 | 0x1a94, 0x11a6, 0xd43f, 0x5e52, 0x9bcb, 0x90f9, 0x5560, 0x869d, 0x4304, 0x4836, 0x8daf, |
DasSidG | 5:324a19dcfdec | 97 | 0xaa55, 0x6fcc, 0x64fe, 0xa167, 0x729a, 0xb703, 0xbc31, 0x79a8, 0xa8eb, 0x6d72, 0x6640, |
DasSidG | 5:324a19dcfdec | 98 | 0xa3d9, 0x7024, 0xb5bd, 0xbe8f, 0x7b16, 0x5cec, 0x9975, 0x9247, 0x57de, 0x8423, 0x41ba, |
DasSidG | 5:324a19dcfdec | 99 | 0x4a88, 0x8f11, 0x57c, 0xc0e5, 0xcbd7, 0xe4e, 0xddb3, 0x182a, 0x1318, 0xd681, 0xf17b, |
DasSidG | 5:324a19dcfdec | 100 | 0x34e2, 0x3fd0, 0xfa49, 0x29b4, 0xec2d, 0xe71f, 0x2286, 0xa213, 0x678a, 0x6cb8, 0xa921, |
DasSidG | 5:324a19dcfdec | 101 | 0x7adc, 0xbf45, 0xb477, 0x71ee, 0x5614, 0x938d, 0x98bf, 0x5d26, 0x8edb, 0x4b42, 0x4070, |
DasSidG | 5:324a19dcfdec | 102 | 0x85e9, 0xf84, 0xca1d, 0xc12f, 0x4b6, 0xd74b, 0x12d2, 0x19e0, 0xdc79, 0xfb83, 0x3e1a, 0x3528, |
DasSidG | 5:324a19dcfdec | 103 | 0xf0b1, 0x234c, 0xe6d5, 0xede7, 0x287e, 0xf93d, 0x3ca4, 0x3796, 0xf20f, 0x21f2, 0xe46b, 0xef59, |
DasSidG | 5:324a19dcfdec | 104 | 0x2ac0, 0xd3a, 0xc8a3, 0xc391, 0x608, 0xd5f5, 0x106c, 0x1b5e, 0xdec7, 0x54aa, 0x9133, 0x9a01, |
DasSidG | 5:324a19dcfdec | 105 | 0x5f98, 0x8c65, 0x49fc, 0x42ce, 0x8757, 0xa0ad, 0x6534, 0x6e06, 0xab9f, 0x7862, 0xbdfb, 0xb6c9, |
DasSidG | 5:324a19dcfdec | 106 | 0x7350, 0x51d6, 0x944f, 0x9f7d, 0x5ae4, 0x8919, 0x4c80, 0x47b2, 0x822b, 0xa5d1, 0x6048, 0x6b7a, |
DasSidG | 5:324a19dcfdec | 107 | 0xaee3, 0x7d1e, 0xb887, 0xb3b5, 0x762c, 0xfc41, 0x39d8, 0x32ea, 0xf773, 0x248e, 0xe117, 0xea25, |
DasSidG | 5:324a19dcfdec | 108 | 0x2fbc, 0x846, 0xcddf, 0xc6ed, 0x374, 0xd089, 0x1510, 0x1e22, 0xdbbb, 0xaf8, 0xcf61, 0xc453, |
DasSidG | 5:324a19dcfdec | 109 | 0x1ca, 0xd237, 0x17ae, 0x1c9c, 0xd905, 0xfeff, 0x3b66, 0x3054, 0xf5cd, 0x2630, 0xe3a9, 0xe89b, |
DasSidG | 5:324a19dcfdec | 110 | 0x2d02, 0xa76f, 0x62f6, 0x69c4, 0xac5d, 0x7fa0, 0xba39, 0xb10b, 0x7492, 0x5368, 0x96f1, 0x9dc3, |
DasSidG | 5:324a19dcfdec | 111 | 0x585a, 0x8ba7, 0x4e3e, 0x450c, 0x8095}; |
DasSidG | 5:324a19dcfdec | 112 | |
DasSidG | 5:324a19dcfdec | 113 | |
DasSidG | 5:324a19dcfdec | 114 | void wake_LTC6804(); |
DasSidG | 5:324a19dcfdec | 115 | void wake_SPI(); |
DasSidG | 5:324a19dcfdec | 116 | void LTC6804_init(uint8_t mode, uint8_t balancingEn, uint8_t cellCh, uint8_t gpioCh); |
DasSidG | 5:324a19dcfdec | 117 | void LTC6804_acquireVoltageTx(); |
DasSidG | 5:324a19dcfdec | 118 | uint8_t LTC6804_acquireAllVoltageRegRx(uint8_t reg, uint8_t cmuCount, uint16_t cell_codes[][12]); |
DasSidG | 5:324a19dcfdec | 119 | void LTC6804_acquireSingleVoltageRegRx(uint8_t reg, uint8_t cmuCount, uint8_t *data); |
DasSidG | 5:324a19dcfdec | 120 | void LTC6804_setConfigReg(uint8_t cmuCount, uint8_t config[][6]); |
DasSidG | 5:324a19dcfdec | 121 | uint16_t pec15_calc(uint8_t len, uint8_t *data); |
DasSidG | 5:324a19dcfdec | 122 | void spi_write_array(uint8_t len, uint8_t data[]); |
DasSidG | 5:324a19dcfdec | 123 | void spi_write_read(uint8_t tx_Data[], uint8_t tx_len, uint8_t *rx_data, uint8_t rx_len); |
DasSidG | 5:324a19dcfdec | 124 | int8_t LTC6804_rdcfg(uint8_t total_ic, uint8_t r_config[][8]); |
DasSidG | 5:324a19dcfdec | 125 | int8_t LTC6804_rdstat(uint8_t total_ic, uint8_t r_config[][8]); |
DasSidG | 5:324a19dcfdec | 126 | void LTC6804_wrcfg(uint8_t total_ic,uint8_t config[][6]); |
DasSidG | 5:324a19dcfdec | 127 | void LTC6804_balance(uint8_t total_ic, uint8_t ic, uint8_t states[12]); |
DasSidG | 5:324a19dcfdec | 128 | |
DasSidG | 5:324a19dcfdec | 129 | #endif |