This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] CCS/BQ76PL455EVM:TMS570 LaunchPad 和 BQ76PL455EVM 代码

Guru**** 2319830 points
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/power-management-group/power-management/f/power-management-forum/594666/ccs-bq76pl455evm-tms570-launch-pad-and-bq76pl455evm-code

器件型号:BQ76PL455EVM

工具/软件:Code Composer Studio

您好!

我将 TMS570 Launchpad 和 BQ76PL455EVM 用于 BMS。

我将在下面的代码片段部分向您解释该问题。

////////////////////////////////////////////////////////////////////////

Nsent = WriteReg (0、107、0x8000、2、FRMWRT_All_NR); //清除所有故障摘要标志

int WriteReg (字节 bid、uint16 wAddr、uint64 dwData、字节 bLen、字节 bWriteType)

   int Bres = 0;
   字节 bBuf[4]={0、0、0、0};
   开关(bLen)
   {
   案例1:
      bBuf[0]= dwData & 0x0000000000FF;
      BRes = WriteFrame (BID、wAddr、bBuf、1、bWriteType);
      中断;
   案例2:
      bBuf[0]=(dwData & 0x0000000000000000FF00)>> 8;
      bBuf[1]= dwData & 0x0000000000FF;
      BRes = WriteFrame (BID、wAddr、bBuf、2、bWriteType);
      中断;
   案例3:
      bBuf[0]=(dwData & 0x0000000000FF0000)>> 16;
      bBuf[1]=(dwData & 0x0000000000000000FF00)>> 8;
      bBuf[2]= dwData & 0x0000000000FF;
      BRes = WriteFrame (BID、wAddr、bBuf、3、bWriteType);
      中断;
   案例4:
      bBuf[0]=(dwData & 0x0000FF000000)>> 24;
      bBuf[1]=(dwData & 0x0000000000FF0000)>> 16;
      bBuf[2]=(dwData & 0x0000000000000000FF00)>> 8;
      bBuf[3]= dwData & 0x0000000000FF;
      BRes = WriteFrame (BID、wAddr、bBuf、4、bWriteType);
      中断;
   情况5:
      bBuf[0]=(dwData & 0x000000FF00000000)>> 32;
      bBuf[1]=(dwData & 0x0000FF000000)>> 24;
      bBuf[2]=(dwData & 0x0000000000FF0000)>> 16;
      bBuf[3]=(dwData & 0x0000000000000000FF00)>> 8;
      bBuf[4]= dwData & 0x0000000000FF;
      BRes = WriteFrame (BID、wAddr、bBuf、5、bWriteType);
      中断;
   案例6:
      bBuf[0]=(dwData & 0x0000FF000000)>> 40;
      bBuf[1]=(dwData & 0x000000FF00000000)>> 32;
      bBuf[2]=(dwData & 0x0000FF000000)>> 24;
      bBuf[3]=(dwData & 0x0000000000FF0000)>> 16;
      bBuf[4]=(dwData & 0x0000000000000000FF00)>> 8;
      bBuf[5]= dwData & 0x0000000000FF;
      BRes = WriteFrame (BID、wAddr、bBuf、6、bWriteType);
      中断;
   案例7:
      bBuf[0]=(dwData & 0x00FF00000000)>> 48;
      bBuf[1]=(dwData & 0x0000FF000000)>> 40;
      bBuf[2]=(dwData & 0x000000FF00000000)>> 32;
      bBuf[3]=(dwData & 0x0000FF000000)>> 24;
      bBuf[4]=(dwData & 0x0000000000FF0000)>> 16;
      bBuf[5]=(dwData & 0x0000000000000000FF00)>> 8;
      bBuf[6]= dwData & 0x0000000000FF;;
      BRes = WriteFrame (BID、wAddr、bBuf、7、bWriteType);
      中断;
   案例8:
      bBuf[0]=(dwData & 0xFF00000000)>> 56;
      bBuf[1]=(dwData & 0x00FF00000000)>> 48;
      bBuf[2]=(dwData & 0x0000FF000000)>> 40;
      bBuf[3]=(dwData & 0x000000FF00000000)>> 32;
      bBuf[4]=(dwData & 0x0000FF000000)>> 24;
      bBuf[5]=(dwData & 0x0000000000FF0000)>> 16;
      bBuf[6]=(dwData & 0x0000000000000000FF00)>> 8;
      bBuf[7]= dwData & 0x0000000000FF;
      BRes = WriteFrame (BID、wAddr、bBuf、8、bWriteType);
      中断;
   默认值:
      中断;
   }
   返回 Bres;

int WriteFrame (字节 bid、uint16 wAddr、字节* pData、字节 bLen、字节 bWriteType)

   int     bPktLen = 0;
   字节  pFrame [32];
   字节* pBuf = pFrame;
   uint16  wCRC;

   if (bLen =7 || bLen >8)
      返回0;

   memset (pFrame、0x7F、sizeof (pFrame));
   if (wAddr > 255)   {
      *pBuf++= 0x88 | bWriteType | bLen;   //使用16位地址
      if (bWriteType = FRMWRT_SGL_R || bWriteType = FRMWRT_SGL_NR || bWriteType = FRMWRT_GRP_R || bWriteType = FRMWRT_GRP_RT)//(bWriteType!= FRMWRT_All_NR)|/(bWriteType!)
      {
         *pBuf++=(BID & 0x00FF);
      }
      *pBuf++=(wAddr & 0xFF00)>> 8;
      *pBuf++= wAddr & 0x00FF;
   }
   否则{
      *pBuf++= 0x80 | bWriteType | bLen;   //使用8位地址
      if (bWriteType = FRMWRT_SGL_R || bWriteType = FRMWRT_SGL_NR || bWriteType = FRMWRT_GRP_R || bWriteType = FRMWRT_GRP_NR)
      {
         *pBuf++=(BID & 0x00FF);
      }
      *pBuf++= wAddr & 0x00FF;
   }

   while (bLen--)
      *pBuf++=*pData++;

   bPktLen = pBuf - pFrame;

   wCRC = CRC16 (pFrame、bPktLen);
   *pBuf++= wCRC 和0x00FF;
   *pBuf++=(wCRC 和0xFF00)>> 8;
   bPktLen += 2;

   sciSend (scilinREG、bPktLen、pFrame);

   返回 bPktLen;

//////////////////////////////////////////////////////////////////////////////////////

nsent 给出 WriteReg -- Bres 的返回值。

BRes 给出 Writeframe 的返回值-- bPktLen。

因此、实际上 nSent 给出了 bPktLen 的值。

如果我将 bLen 保持为2、将 nSent 设置为6、将 bLen 保持为3、将 nSent 设置为7。

那么、bLen 和 bPktLen 之间的关系是什么? 两者是否不同?

请帮助我理解。

谢谢

Ritul Shah

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    您好 Ritul、

    听起来您的理解是、它将仅返回发送的数据字节数。

    要回答您的直接问题、BRes = bPktLen。

    与 PL455之间发送的数据包也具有数据包标头(1字节)和 CRC (2字节)。 还有器件地址字节和寄存器地址字节。

    您会看到:数据包标头(1字节)|寄存器地址(1字节)|数据(2字节)| CRC (2字节)

    总计:发送6个字节