eeprom test failed (somebody help)
This commit is contained in:
@ -2,7 +2,8 @@
|
||||
#define INC_24LC02_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#define EEPROM_ADDR 0b1010000
|
||||
|
||||
#define EEPROM_ADDR 0b1010111
|
||||
|
||||
uint8_t eeprom_init();
|
||||
uint8_t eeprom_write(uint8_t addr, uint8_t data);
|
||||
|
||||
@ -1,19 +1,19 @@
|
||||
// Write Code:
|
||||
// ICOMx[3:0]
|
||||
#define I2C_START 0b0110
|
||||
#define I2C_STOP 0b0001
|
||||
#define I2C_STRT 0b0110
|
||||
#define I2C_STP 0b0001
|
||||
#define BLANK 0b0000
|
||||
#define NO_TRANSMIT 0b0111
|
||||
|
||||
// FCOMx[3:0]
|
||||
#define MSTR_ACK 0b0000
|
||||
#define MSTR_NO_ACK 0b1000
|
||||
#define MSTR_NO_ACK_ST 0b1001
|
||||
#define MSTR_NO_ACK_STP 0b1001
|
||||
|
||||
// Read Code:
|
||||
// ICOMx[3:0]
|
||||
#define MSTR_START 0b0110
|
||||
#define MSTR_STOP 0b0001
|
||||
#define MSTR_SRT 0b0110
|
||||
#define MSTR_STP 0b0001
|
||||
#define BLANK_LOW 0b0000
|
||||
#define BLANK_HIGH 0b0111
|
||||
|
||||
@ -21,5 +21,5 @@
|
||||
#define MSTR_ACK 0b0000
|
||||
#define SLV_ACK 0b0111
|
||||
#define SLV_NO_ACK 0b1111
|
||||
#define SLV_ACK_STOP 0b0001
|
||||
#define SLV_NO_ACK_STOP 0b1001
|
||||
#define SLV_ACK_STP 0b0001
|
||||
#define SLV_NO_ACK_STP 0b1001
|
||||
@ -28,7 +28,7 @@ uint16 updateDataPEC(uint16 currentPEC, uint8 din);
|
||||
uint8 checkDataPEC(uint8* data, uint8 datalen);
|
||||
|
||||
uint8 writeCMD(uint16 command, uint8* args, uint8 arglen);
|
||||
uint8 writeCMD_I2C(uint16 command, uint8* args, uint8 arglen);
|
||||
uint8 writeCMD_I2C(uint16 command, uint16_t waitTime, uint8* args, uint8 arglen);
|
||||
uint8 readCMD(uint16 command, uint8* buffer, uint8 buflen);
|
||||
uint8 pollCMD(uint16 command);
|
||||
|
||||
|
||||
@ -7,25 +7,13 @@ uint8_t eeprom_init() {
|
||||
uint8_t StartAddr = 0;
|
||||
uint8_t data = 0;
|
||||
|
||||
if (amsWriteComm(EEPROM_ADDR, StartAddr, data) != 0){
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return amsWriteComm(EEPROM_ADDR, StartAddr, data);
|
||||
}
|
||||
|
||||
uint8_t eeprom_write(uint8_t addr, uint8_t data) {
|
||||
if (amsWriteComm(EEPROM_ADDR, addr, data) != 0){
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return amsWriteComm(EEPROM_ADDR, addr, data);
|
||||
}
|
||||
|
||||
uint8_t eeprom_read(uint8_t addr, uint8_t* data) {
|
||||
if (amsReadComm(EEPROM_ADDR, addr, &data) != 0){
|
||||
return 1;
|
||||
};
|
||||
|
||||
return 0;
|
||||
return amsReadComm(EEPROM_ADDR, addr, &data);
|
||||
}
|
||||
@ -34,7 +34,7 @@ uint8 amsReset() {
|
||||
CHECK_RETURN(writeCMD(CLRFLAG, buffer, 6)); //clear flags,
|
||||
CHECK_RETURN(writeCMD(CLOVUV, buffer, 6)); //OVUV flags
|
||||
CHECK_RETURN(writeCMD(ADCV | ADCV_CONT | ADCV_RD, NULL, 0)); //start continuous cell voltage measurement with redundancy
|
||||
CHECK_RETURN(writeCMD(ADAX | ADAX_CONV_ALL, NULL, 0)); //start aux measurement
|
||||
CHECK_RETURN(writeCMD(ADAX, NULL, 0)); //start aux measurement
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -124,7 +124,7 @@ uint8 amsAuxAndStatusMeasurement(Cell_Module* module) {
|
||||
module->analogSupplyVoltage = mV_from_ADBMS6830(rxbuffer[2] | (rxbuffer[3] << 8));
|
||||
module->refVoltage = mV_from_ADBMS6830(rxbuffer[4] | (rxbuffer[5] << 8));
|
||||
|
||||
CHECK_RETURN(writeCMD(ADAX | ADAX_CONV_ALL, NULL, 0)); //start aux measurement for next cycle
|
||||
CHECK_RETURN(writeCMD(ADAX, NULL, 0)); //start aux measurement for next cycle
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -248,29 +248,36 @@ uint8 amsReadCellVoltages(Cell_Module* module) {
|
||||
|
||||
uint8_t amsWriteComm(uint8_t device, uint8_t addr, uint8_t data) {
|
||||
uint8_t ctrlByte = (device << 1);
|
||||
uint8_t txbuf[6] = {I2C_START << 4 | SLV_ACK, ctrlByte,
|
||||
uint8_t txbuf[6] = {I2C_STRT << 4 | SLV_ACK, ctrlByte,
|
||||
BLANK << 4 | SLV_ACK, addr,
|
||||
BLANK << 4 | SLV_ACK_STOP, data};
|
||||
BLANK << 4 | SLV_ACK_STP, data};
|
||||
CHECK_RETURN(writeCMD(WRCOMM, txbuf, COMM_GROUP_SIZE));
|
||||
CHECK_RETURN(writeCMD(STCOMM, NULL, 0));
|
||||
uint8_t rxbuf[6] = {0,0,0,0,0,0};
|
||||
readCMD(RDCOMM, rxbuf, COMM_GROUP_SIZE);
|
||||
if (rxbuf[6] != txbuf[6]) {
|
||||
while(1){}
|
||||
}
|
||||
CHECK_RETURN(writeCMD_I2C(STCOMM, 72, NULL, 0));
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t amsReadComm(uint8_t device, uint8_t addr, uint8_t* buf) {
|
||||
uint8_t ctrlByteW = (device << 1);
|
||||
uint8_t txbuf[6] = {I2C_START << 4 | SLV_ACK, ctrlByteW,
|
||||
uint8_t txbuf[6] = {I2C_STRT << 4 | SLV_ACK, ctrlByteW,
|
||||
BLANK << 4 | SLV_ACK, addr,
|
||||
0, 0};
|
||||
CHECK_RETURN(writeCMD(WRCOMM, txbuf, COMM_GROUP_SIZE));
|
||||
CHECK_RETURN(writeCMD_I2C(STCOMM, NULL, 0));
|
||||
CHECK_RETURN(writeCMD_I2C(STCOMM, 48, NULL, 0));
|
||||
|
||||
uint8_t ctrlByteR = ctrlByteW | 1;
|
||||
uint8_t rxbuf[6] = {I2C_START << 4 | SLV_ACK, ctrlByteR,
|
||||
BLANK << 4 | SLV_NO_ACK_STOP, 0,
|
||||
uint8_t ctrlByteR = (device << 1) | 1;
|
||||
uint8_t rxbuf[6] = {I2C_STRT << 4 | SLV_ACK, ctrlByteR,
|
||||
BLANK << 4 | MSTR_NO_ACK_STP, 0,
|
||||
0, 0};
|
||||
CHECK_RETURN(writeCMD(WRCOMM, rxbuf, COMM_GROUP_SIZE));
|
||||
CHECK_RETURN(writeCMD_I2C(STCOMM, NULL, 0));
|
||||
CHECK_RETURN(readCMD(RDCOMM, rxbuf, COMM_GROUP_SIZE));
|
||||
CHECK_RETURN(writeCMD_I2C(STCOMM, 48, NULL, 0));
|
||||
if(readCMD(RDCOMM, rxbuf, COMM_GROUP_SIZE) != 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
*buf = rxbuf[4];
|
||||
|
||||
|
||||
@ -267,7 +267,7 @@ uint8 writeCMD(uint16 command, uint8* args, uint8 arglen) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint8 writeCMD_I2C(uint16 command, uint8* args, uint8 arglen) {
|
||||
uint8 writeCMD_I2C(uint16 command, uint16_t waitTime, uint8* args, uint8 arglen) {
|
||||
uint8 ret;
|
||||
if (arglen > 0) {
|
||||
uint8 buffer[6 + arglen]; //command + PEC (2 bytes) + data + DPEC (2 bytes)
|
||||
@ -295,7 +295,10 @@ uint8 writeCMD_I2C(uint16 command, uint8* args, uint8 arglen) {
|
||||
|
||||
ret = mcuSPITransmit(buffer, 4);
|
||||
|
||||
HAL_Delay(1);
|
||||
// HAL_Delay(1);
|
||||
for (int i=0; i<64000 * waitTime; i++){
|
||||
__ASM volatile ("NOP");
|
||||
}
|
||||
|
||||
mcuAdbmsCSHigh();
|
||||
}
|
||||
|
||||
@ -67,7 +67,7 @@ uint8_t AMS_Idle_Loop() {
|
||||
if(eeprom_write(0, 7) != 0){
|
||||
while(1){}
|
||||
}
|
||||
int eepromBuf;
|
||||
int8_t eepromBuf = 0;
|
||||
if(eeprom_read(0, &eepromBuf) != 0){
|
||||
while(1){}
|
||||
}
|
||||
|
||||
@ -169,7 +169,7 @@ static void MX_SPI2_Init(void)
|
||||
hspi2.Init.CLKPolarity = SPI_POLARITY_LOW;
|
||||
hspi2.Init.CLKPhase = SPI_PHASE_1EDGE;
|
||||
hspi2.Init.NSS = SPI_NSS_SOFT;
|
||||
hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16;
|
||||
hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_32;
|
||||
hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB;
|
||||
hspi2.Init.TIMode = SPI_TIMODE_DISABLE;
|
||||
hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
|
||||
|
||||
Reference in New Issue
Block a user