Has base BMU code but sends dummy temperature and voltage readings to test CAN
Dependencies: CUER_CAN DS1820 LTC2943 LTC6804 mbed
Fork of BMS_BMUCore_Max by
EEPROM_I2C.cpp@15:e901aff1f5b3, 2017-07-02 (annotated)
- Committer:
- DasSidG
- Date:
- Sun Jul 02 11:25:37 2017 +0000
- Revision:
- 15:e901aff1f5b3
- Parent:
- 1:51477fe4851b
Added temperature probe initialization
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lcockerton62 | 0:0a5f554d2a16 | 1 | #include "EEPROM_I2C.h" |
lcockerton62 | 1:51477fe4851b | 2 | |
lcockerton62 | 0:0a5f554d2a16 | 3 | I2C i2c(I2C_DATA, I2C_CLOCK); |
lcockerton62 | 1:51477fe4851b | 4 | |
lcockerton62 | 1:51477fe4851b | 5 | /* Dont think this will be used |
lcockerton62 | 0:0a5f554d2a16 | 6 | // Write individual byte |
lcockerton62 | 0:0a5f554d2a16 | 7 | void i2c_write(int start_address,char data_out){ |
lcockerton62 | 1:51477fe4851b | 8 | |
lcockerton62 | 0:0a5f554d2a16 | 9 | char data[3]; |
lcockerton62 | 0:0a5f554d2a16 | 10 | data[0] = start_address; |
lcockerton62 | 0:0a5f554d2a16 | 11 | data[1] = start_address; |
lcockerton62 | 0:0a5f554d2a16 | 12 | data[2] = data_out; |
lcockerton62 | 0:0a5f554d2a16 | 13 | i2c.write(ADDRESS_1, data, 3, false); |
lcockerton62 | 0:0a5f554d2a16 | 14 | } |
lcockerton62 | 1:51477fe4851b | 15 | */ |
lcockerton62 | 1:51477fe4851b | 16 | // Read individual byte |
lcockerton62 | 1:51477fe4851b | 17 | /* Dont think this will be used |
lcockerton62 | 0:0a5f554d2a16 | 18 | char i2c_read(int start_address){ |
lcockerton62 | 0:0a5f554d2a16 | 19 | char cmd[3]; |
lcockerton62 | 0:0a5f554d2a16 | 20 | cmd[0] = start_address; |
lcockerton62 | 0:0a5f554d2a16 | 21 | cmd[1] = start_address; |
lcockerton62 | 0:0a5f554d2a16 | 22 | i2c.write(ADDRESS_1, cmd, 2, true); |
lcockerton62 | 1:51477fe4851b | 23 | |
lcockerton62 | 0:0a5f554d2a16 | 24 | char data_out; |
lcockerton62 | 1:51477fe4851b | 25 | i2c.read(ADDRESS_1, &data_out, 1, false); |
lcockerton62 | 0:0a5f554d2a16 | 26 | return data_out; |
lcockerton62 | 0:0a5f554d2a16 | 27 | } |
lcockerton62 | 1:51477fe4851b | 28 | */ |
lcockerton62 | 0:0a5f554d2a16 | 29 | // Page write |
lcockerton62 | 1:51477fe4851b | 30 | void i2c_page_write(uint16_t start_address,int length, char data_out[] ) |
lcockerton62 | 1:51477fe4851b | 31 | { |
lcockerton62 | 1:51477fe4851b | 32 | char cmd[2+length]; |
lcockerton62 | 1:51477fe4851b | 33 | cmd[0] = start_address >> 8; |
lcockerton62 | 1:51477fe4851b | 34 | cmd[1] = start_address && 0x00FF; |
lcockerton62 | 1:51477fe4851b | 35 | for(int i = 0; i< length ; i++) { |
lcockerton62 | 1:51477fe4851b | 36 | cmd[i+2] = data_out[i]; |
lcockerton62 | 1:51477fe4851b | 37 | } |
lcockerton62 | 0:0a5f554d2a16 | 38 | |
lcockerton62 | 1:51477fe4851b | 39 | i2c.write(ADDRESS_1, cmd, length, false); |
lcockerton62 | 0:0a5f554d2a16 | 40 | } |
lcockerton62 | 0:0a5f554d2a16 | 41 | // Page read |
lcockerton62 | 1:51477fe4851b | 42 | void i2c_page_read(uint16_t start_address, int length, char data_in[]) |
lcockerton62 | 1:51477fe4851b | 43 | { |
lcockerton62 | 0:0a5f554d2a16 | 44 | char cmd[2]; |
lcockerton62 | 1:51477fe4851b | 45 | cmd[0] = start_address >> 8; |
lcockerton62 | 1:51477fe4851b | 46 | cmd[1] = start_address && 0x00FF; |
lcockerton62 | 1:51477fe4851b | 47 | i2c.write(ADDRESS_1, cmd, 2, true); |
lcockerton62 | 0:0a5f554d2a16 | 48 | |
lcockerton62 | 0:0a5f554d2a16 | 49 | i2c.read(ADDRESS_1, data_in, length, false); |
lcockerton62 | 0:0a5f554d2a16 | 50 | } |