used write_TPL2_2 for global write to the CID config,
Currently trying to get the cyclic measurements running, was able to read SYS_CFG_1 of 33772 and modifing it to 0x5001 instead of 0x1001.
int write_TPL2_2(unsigned int d_add, unsigned int c_add, unsigned int count, unsigned char reg_add, unsigned short data)
{
unsigned char len =6;
int ret = 0;
frame[0]=frame[1]=frame[2]=frame[3]=frame[4]=frame[5]=frame[6]=0;
if (d_add > 63)
{
return MCP_33665_ERROR;
}
if (reg_add > 0x7f)
{
return MCP_33665_ERROR;
}
//Data - 0 frame[0]
frame[0] = (data & 0xff00)>>8;
//Data - 1 frame[1]
frame[1] = (data & 0xff);
frame[2] = 0x00 | (reg_add & 0x7f); //MS Bit with 0
frame[3] = d_add & 0x3f; //MADD/src=0, CADD[2] = 0
if(c_add == 0x1) {
frame[4] = 0x17;
} else {
frame[4] = ((count & 0xf) <<4) | ((c_add & 0x3) << 2) | 0x2; //MS count with write [0x1]
}
frame[5]= 0x42;
CRC8(frame[5],frame[0]);
CRC8(frame[5],frame[1]);
CRC8(frame[5],frame[2]);
CRC8(frame[5],frame[3]);
CRC8(frame[5],frame[4]);
CAN.sendMsgBuf(0x622, 0, 6, frame);
sprintf(pbuf, "WR:0x%x:0x%x,0x%x,0x%x,0x%x,0x%x,0x%x\n", reg_add, frame[0], frame[1], frame[2], frame[3],frame[4],frame[5]);
Serial.print(pbuf);
delay(1);
//CAN.readMsgBuf(&len, buf);
return 0;//(buf[0]<<8 | buf[1]);
//Data - 1 frame[4] - Msg CNT and CMD
}
init() {
//CAN.readMsgBuf(&len, buf);
nop_TPL2(0x1,0x0,0xCAFE);
delay(3);
nop_TPL2(63,0x7,0x00);
sprintf(pbuf, "-------------Init_PHY:-------------\n");
Serial.print(pbuf);
delay(50);
reg = read_TPL2(0x1, 0x0, 1, EVH_MCUIF_ERR_STAT, 0x0);
sprintf(pbuf, "EVH_MCUIF_ERR_STAT:0x%x:0x%x,0x%x,0x%x\n", reg, rbuf[0], rbuf[1], rbuf[2]);
Serial.print(pbuf);
write_TPL2(0x1,0x0,0x1,SYS_COM_TO_CFG,0x00FF);
delay(5);
write_TPL2(0x1,0x0,0x1,SYS_CAN_CFG,0x01);
delay(5);
nop_TPL2(0x1,0x0,0xCAFE);
delay(50);
reg = read_TPL2(0x1, 0x0, 1, EVH_MCUIF_ERR_STAT, 0x0);
sprintf(pbuf, "EVH_MCUIF_ERR_STAT:0x%x:0x%x,0x%x,0x%x\n", reg, rbuf[0], rbuf[1], rbuf[2]);
Serial.print(pbuf);
sprintf(pbuf, "-------------PHY:-------------\n");
Serial.print(pbuf);
write_TPL2(0x1,0x0,0x1,SYS_CAN_CFG,0x01);
delay(1);
write_TPL2(0x1,0x0,0x1,SYS_PORT0_CFG,0x108F);
delay(1);
write_TPL2(0x1,0x0,0x1,SYS_CAN_CFG,0x01);
delay(1);
reg = read_TPL2(0x1, 0x0, 1, SYS_VERSION, 0x0);
sprintf(pbuf, "SYS_VERSION:0x%x:0x%x,0x%x,0x%x\n", reg, buf[0], buf[1], buf[2]);
Serial.print(pbuf);
reg = read_TPL2(0x1, 0x0, 1, SYS_PROD_VER, 0x0);
sprintf(pbuf, "SYS_PROD_VER:0x%x:0x%x,0x%x,0x%x\n", reg, buf[0], buf[1], buf[2]);
Serial.print(pbuf);
delay(50);
reg = read_TPL2(0x1, 0x0, 1, EVH_MCUIF_ERR_STAT, 0x0);
sprintf(pbuf, "EVH_MCUIF_ERR_STAT:0x%x:0x%x,0x%x,0x%x\n", reg, rbuf[0], rbuf[1], rbuf[2]);
Serial.print(pbuf);
reg = read_TPL2(0x1, 0x0, 1, SYS_VERSION, 0x0);
sprintf(pbuf, "SYS_VERSION:0x%x:0x%x,0x%x,0x%x\n", reg, buf[0], buf[1], buf[2]);
Serial.print(pbuf);
delay(50);
reg = read_TPL2(0x1, 0x0, 1, EVH_MCUIF_ERR_STAT, 0x0);
sprintf(pbuf, "EVH_MCUIF_ERR_STAT:0x%x:0x%x,0x%x,0x%x\n", reg, rbuf[0], rbuf[1], rbuf[2]);
reg = read_TPL2(0x1, 0x0, 1, SYS_UID_LOW, 0x0);
sprintf(pbuf, "SYS_UID:0x%x:0x%x,0x%x,0x%x\n", reg, buf[0], buf[1], buf[2]);
Serial.print(pbuf);
reg = read_TPL2(0x1, 0x0, 1, (SYS_UID_LOW+1), 0x0);
sprintf(pbuf, "SYS_UID:0x%x:0x%x,0x%x,0x%x\n", reg, buf[0], buf[1], buf[2]);
Serial.print(pbuf);
delay(50);
reg = read_TPL2(0x1, 0x0, 1, EVH_MCUIF_ERR_STAT, 0x0);
sprintf(pbuf, "EVH_MCUIF_ERR_STAT:0x%x:0x%x,0x%x,0x%x\n", reg, rbuf[0], rbuf[1], rbuf[2]);
reg = read_TPL2(0x1, 0x0, 1, SYS_CFG_CRC, 0x0);
sprintf(pbuf, "SYS_CFG_CRC:0x%x:0x%x,0x%x,0x%x\n", reg, buf[0], buf[1], buf[2]);
Serial.print(pbuf);
delay(50);
reg = read_TPL2(0x1, 0x0, 1, EVH_MCUIF_ERR_STAT, 0x0);
sprintf(pbuf, "EVH_MCUIF_ERR_STAT:0x%x:0x%x,0x%x,0x%x\n", reg, rbuf[0], rbuf[1], rbuf[2]);
Serial.print(pbuf);
reg = read_TPL2(0x1, 0x0, 1, EVH_WAKEUP_REASON, 0x0);
sprintf(pbuf, "EVH_WAKEUP_REASON:0x%x:0x%x,0x%x,0x%x\n", reg, buf[0], buf[1], buf[2]);
Serial.print(pbuf);
reg = read_TPL2(0x1, 0x0, 1, EVH_GENERAL_ERR_STAT, 0x0);
sprintf(pbuf, "EVH_GENERAL_ERR_STAT:0x%x:0x%x,0x%x,0x%x\n", reg, buf[0], buf[1], buf[2]);
Serial.print(pbuf);
delay(50);
reg = read_TPL2(0x1, 0x0, 1, EVH_MCUIF_ERR_STAT, 0x0);
sprintf(pbuf, "EVH_MCUIF_ERR_STAT:0x%x:0x%x,0x%x,0x%x\n", reg, rbuf[0], rbuf[1], rbuf[2]);
Serial.print(pbuf);
sprintf(pbuf, "------------------CMC_INIT---------------\n");
Serial.print(pbuf);
#if 1
reg = read_TPL2(0x1, 0x0, 1, SCHED_STAT, 0x0);
sprintf(pbuf, "SCHED_STAT:0x%x:0x%x,0x%x,0x%x\n", reg, buf[0], buf[1], buf[2]);
Serial.print(pbuf);
write_TPL2(0x1,0x0,0x1,SCHED_CMD,0x1004);
delay(50);
nop_TPL2(0x1,0x0,0xCAFE);
delay(50);
write_TPL2(0x1,0x0,0x1,SCHED_CMD,0x0006);
delay(50);
nop_TPL2(0x1,0x0, 0xCAFE);
write_TPL2(0x1,0x0,0x1,SCHED_EVENT,0x0001);
delay(50);
write_TPL2(0x1,0x0,0x1,SCHED_CMD,0x0008);
delay(50);
write_TPL2_2(0x0,0x1,0x0,MC33772C_INIT,0x2);
delay(50);
write_TPL2_2(0x0,0x1,0x0,MC33772C_INIT,0x3);
delay(20);;
reg = read_TPL2(0x1, 0x0, 1, SYS_VERSION, 0x0);
sprintf(pbuf, "SYS_VERSION:0x%x:0x%x,0x%x,0x%x\n", reg, buf[0], buf[1], buf[2]);
Serial.print(pbuf);
delay(20);
reg = read_TPL2(0x1, 0x0, 1, EVH_MCUIF_ERR_STAT, 0x0);
sprintf(pbuf, "EVH_MCUIF_ERR_STAT:0x%x:0x%x,0x%x,0x%x\n", reg, rbuf[0], rbuf[1], rbuf[2]);
Serial.print(pbuf);
delay(10);
}
did a global write with 0x11 instead of local write 0x10 for the CID/INIT register. Will update more once I get it completely working