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@0:0a5f554d2a16, 2016-12-22 (annotated)
- Committer:
- lcockerton62
- Date:
- Thu Dec 22 15:11:29 2016 +0000
- Revision:
- 0:0a5f554d2a16
- Child:
- 1:51477fe4851b
Initial commit: Added a basic overview of the code in main, added CANParserBMU and defined some data structures
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lcockerton62 | 0:0a5f554d2a16 | 1 | #include "EEPROM_I2C.h" |
lcockerton62 | 0:0a5f554d2a16 | 2 | |
lcockerton62 | 0:0a5f554d2a16 | 3 | I2C i2c(I2C_DATA, I2C_CLOCK); |
lcockerton62 | 0:0a5f554d2a16 | 4 | |
lcockerton62 | 0:0a5f554d2a16 | 5 | // Write individual byte |
lcockerton62 | 0:0a5f554d2a16 | 6 | void i2c_write(int start_address,char data_out){ |
lcockerton62 | 0:0a5f554d2a16 | 7 | |
lcockerton62 | 0:0a5f554d2a16 | 8 | char data[3]; |
lcockerton62 | 0:0a5f554d2a16 | 9 | data[0] = start_address; |
lcockerton62 | 0:0a5f554d2a16 | 10 | data[1] = start_address; |
lcockerton62 | 0:0a5f554d2a16 | 11 | data[2] = data_out; |
lcockerton62 | 0:0a5f554d2a16 | 12 | i2c.write(ADDRESS_1, data, 3, false); |
lcockerton62 | 0:0a5f554d2a16 | 13 | } |
lcockerton62 | 0:0a5f554d2a16 | 14 | |
lcockerton62 | 0:0a5f554d2a16 | 15 | // Read individual byte |
lcockerton62 | 0:0a5f554d2a16 | 16 | char i2c_read(int start_address){ |
lcockerton62 | 0:0a5f554d2a16 | 17 | char cmd[3]; |
lcockerton62 | 0:0a5f554d2a16 | 18 | cmd[0] = start_address; |
lcockerton62 | 0:0a5f554d2a16 | 19 | cmd[1] = start_address; |
lcockerton62 | 0:0a5f554d2a16 | 20 | i2c.write(ADDRESS_1, cmd, 2, true); |
lcockerton62 | 0:0a5f554d2a16 | 21 | |
lcockerton62 | 0:0a5f554d2a16 | 22 | char data_out; |
lcockerton62 | 0:0a5f554d2a16 | 23 | i2c.read(ADDRESS_1, &data_out, 1, false); |
lcockerton62 | 0:0a5f554d2a16 | 24 | return data_out; |
lcockerton62 | 0:0a5f554d2a16 | 25 | } |
lcockerton62 | 0:0a5f554d2a16 | 26 | |
lcockerton62 | 0:0a5f554d2a16 | 27 | // Page write |
lcockerton62 | 0:0a5f554d2a16 | 28 | void i2c_page_write(int start_address,int length, char data_out[] ){ |
lcockerton62 | 0:0a5f554d2a16 | 29 | |
lcockerton62 | 0:0a5f554d2a16 | 30 | i2c.write(ADDRESS_1, data_out, length, false); |
lcockerton62 | 0:0a5f554d2a16 | 31 | |
lcockerton62 | 0:0a5f554d2a16 | 32 | } |
lcockerton62 | 0:0a5f554d2a16 | 33 | // Page read |
lcockerton62 | 0:0a5f554d2a16 | 34 | void i2c_page_read(int start_address,int length, char data_in[]){ |
lcockerton62 | 0:0a5f554d2a16 | 35 | char cmd[2]; |
lcockerton62 | 0:0a5f554d2a16 | 36 | cmd[0] = start_address; |
lcockerton62 | 0:0a5f554d2a16 | 37 | cmd[1] = start_address + length; |
lcockerton62 | 0:0a5f554d2a16 | 38 | i2c.write(ADDRESS_1, cmd, length, true); |
lcockerton62 | 0:0a5f554d2a16 | 39 | |
lcockerton62 | 0:0a5f554d2a16 | 40 | i2c.read(ADDRESS_1, data_in, length, false); |
lcockerton62 | 0:0a5f554d2a16 | 41 | } |
lcockerton62 | 0:0a5f554d2a16 | 42 |