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.

Tformat encoder experiment failed

Other Parts Discussed in Thread: C2000WARE, BOOSTXL-POSMGR

Hello,expert:

I am honored to have this opportunity to ask you a question. My experimental equipment mainly includes TI's F28379D launchpad + Boostl-POSMGR (encoder interface board).And the program I use is derived from TI , and its path is:D:\ti\c2000\C2000Ware_MotorControl_SDK_3_01_00_00\solutions\boostxl_posmgr\f2837xd. Because I thought the actual Tformat encoder CF ID I was using was different from the TI's sample, I changed this, but found the program stays at ESTOP0 inside the tformat_exCommands(void) function.As shown in the figure below, Figure 1 is DF of TI routine encoder(The encoder type isTS5700N8501 ).Figure. 2 shows the DF of the encoder I used.(The encoder type is TS5720N8401).Figure. 3shows My program is here to stay.

              Figure 1 TI sample(TS5700N8501 )

The following is TI source code:

uint16_t PM_tformat_setupCommand(uint16_t tformatDataID, uint16_t eepromAddr,
                                 uint16_t eepromData, uint16_t crcSend)
{
    uint16_t sendClks;
    uint16_t receiveClks;
    uint16_t dummySPIClks;
    uint16_t i;
    uint16_t word1, word2, word3, temp;
    uint16_t addrl, datal;

    tformat_resetCLB();
    tformatData.dataReady = 0;

    word1 = (tformatDataID << 6) | 0x903F;

    switch(tformatDataID)
    {
        case (PM_TFORMAT_DATAID0):
        case (PM_TFORMAT_DATAID1):
        case (PM_TFORMAT_DATAID7):
        case (PM_TFORMAT_DATAID8):
        case (PM_TFORMAT_DATAIDC):

            sendClks = ABIT + PACKET_BITS + IDLE_BITS;
            receiveClks = 6 * PACKET_BITS ;

            if(((sendClks + receiveClks) % 16) == 0)
            {
                tformatData.fifoLevel =  ((sendClks + receiveClks) / 16);
            }
            else
            {
                tformatData.fifoLevel = ((sendClks + receiveClks) / 16) + 1;
            }

            dummySPIClks = (tformatData.fifoLevel * 16) -
                            (sendClks + receiveClks);

            tformat_configureSPILen(15);

            //
            //void tformat_configureCLBLen(uint16_t CLB4_C1_M1,
            // uint16_t CLB4_C1_M2, uint16_t CLB4_R0)
            //
            tformat_configureCLBLen((PACKET_BITS + 2), sendClks,
                                    receiveClks + dummySPIClks);

            tformatData.sdata[0] = word1;
            tformatData.sdata[1] = 0xFFFF;
            tformatData.sdata[2] = 0xFFFF;
            tformatData.sdata[3] = 0xFFFF;
            for (i = 0;i < tformatData.fifoLevel;i++)
            {
                SPI_writeDataNonBlocking(PM_TFORMAT_SPI, tformatData.sdata[i]);
            }

        break;

        case (PM_TFORMAT_DATAID2):

            sendClks = ABIT + PACKET_BITS + IDLE_BITS;
            receiveClks = 4 * PACKET_BITS ;

            if(((sendClks + receiveClks) % 16) == 0)
            {
                tformatData.fifoLevel =  ((sendClks + receiveClks) / 16);
            }
            else
            {
                tformatData.fifoLevel = ((sendClks + receiveClks) / 16) + 1;
            }

            dummySPIClks = (tformatData.fifoLevel * 16) -
                           (sendClks + receiveClks);

            tformat_configureSPILen(15);

            tformat_configureCLBLen((PACKET_BITS + 2), sendClks,
                                    receiveClks + dummySPIClks);

            tformatData.sdata[0] = word1;
            tformatData.sdata[1] = 0xFFFF;
            tformatData.sdata[2] = 0xFFFF;
            tformatData.sdata[3] = 0xFFFF;
            for (i = 0;i < tformatData.fifoLevel;i++)
            {
                SPI_writeDataNonBlocking(PM_TFORMAT_SPI, tformatData.sdata[i]);
            }

        break;

        case (PM_TFORMAT_DATAID3):

            sendClks = ABIT + PACKET_BITS + IDLE_BITS;
            receiveClks = 11 * PACKET_BITS ;

            if(((sendClks + receiveClks) % 16) == 0)
            {
                tformatData.fifoLevel =  ((sendClks + receiveClks) / 16);
            }
            else
            {
                tformatData.fifoLevel = ((sendClks + receiveClks) / 16) + 1;
            }
            dummySPIClks = (tformatData.fifoLevel * 16) -
                            (sendClks + receiveClks);

            tformat_configureSPILen(15);

            //
            //void tformat_configureCLBLen(uint16_t CLB4_C1_M1,
            //uint16_t CLB4_C1_M2, uint16_t CLB4_R0)
            //
            tformat_configureCLBLen((PACKET_BITS + 2), sendClks,
                                    receiveClks + dummySPIClks);

            tformatData.sdata[0] = word1;
            tformatData.sdata[1] = 0xFFFF;
            tformatData.sdata[2] = 0xFFFF;
            tformatData.sdata[3] = 0xFFFF;
            for (i = 0;i < tformatData.fifoLevel;i++)
                {
                    SPI_writeDataNonBlocking(PM_TFORMAT_SPI,
                    tformatData.sdata[i]);
                }

        break;

        case (PM_TFORMAT_DATAIDD):
            sendClks = ABIT + 3 * PACKET_BITS + IDLE_BITS;
            receiveClks = 4 * PACKET_BITS ;

            addrl = (__flip32(eepromAddr) >> 24) & 0xFE;    // busy "0"
            temp = (addrl >> 4) & 0xF;
            word1 = (tformatDataID << 6) | 0x9020 | temp;
            temp = (addrl  & 0xF) << 12;
            word2 = temp | 0x803 | (crcSend << 2);

            if(((sendClks + receiveClks) % 16) == 0)
            {
                tformatData.fifoLevel =  ((sendClks + receiveClks) / 16);
            }
            else
            {
                tformatData.fifoLevel = ((sendClks + receiveClks) / 16) + 1;
            }
            dummySPIClks = (tformatData.fifoLevel * 16) -
                    (sendClks + receiveClks);

            tformat_configureSPILen(15);

            //
            //void tformat_configureCLBLen(uint16_t CLB4_C1_M1,
            //uint16_t CLB4_C1_M2, uint16_t CLB4_R0)
            //
            tformat_configureCLBLen((3 * PACKET_BITS + 2), sendClks,
                    receiveClks + dummySPIClks);

            tformatData.sdata[0] = word1;
            tformatData.sdata[1] = word2;
            tformatData.sdata[2] = 0xFFFF;
            tformatData.sdata[3] = 0xFFFF;
            for (i = 0;i < tformatData.fifoLevel;i++)
            {
                SPI_writeDataNonBlocking(PM_TFORMAT_SPI, tformatData.sdata[i]);
            }

        break;

        case (PM_TFORMAT_DATAID6):

            sendClks = ABIT + 4 * PACKET_BITS + IDLE_BITS;
            receiveClks = 4 * PACKET_BITS ;

            addrl = (__flip32(eepromAddr) >> 24) & 0xFE;    // busy "0"
            datal = (__flip32(eepromData) >> 24) & 0xFF;
            temp = (addrl >> 4) & 0xF;
            word1 = (tformatDataID << 6) | 0x9020 | temp;
            temp = (addrl  & 0xF) << 12;
            word2 = temp | 0x802 | (datal << 2);
            word3 = (crcSend << 8) | 0xFF;

            if(((sendClks + receiveClks) % 16) == 0)
            {
                tformatData.fifoLevel =  ((sendClks + receiveClks) / 16);
            }
            else
            {
                tformatData.fifoLevel = ((sendClks + receiveClks) / 16) + 1;
            }

            dummySPIClks = (tformatData.fifoLevel * 16) -
                    (sendClks + receiveClks);

            tformat_configureSPILen(15);

            tformat_configureCLBLen((4 * PACKET_BITS + 2), sendClks,
                                    receiveClks + dummySPIClks);

            tformatData.sdata[0] = word1;
            tformatData.sdata[1] = word2;
            tformatData.sdata[2] = word3;
            tformatData.sdata[3] = 0xFFFF;
            for (i = 0;i < tformatData.fifoLevel;i++)
            {
                SPI_writeDataNonBlocking(PM_TFORMAT_SPI, tformatData.sdata[i]);
            }

        break;

        default:
            word1 = 0;
        break;

    }
    return(word1);
}

uint16_t PM_tformat_receiveData(uint16_t tformatDataID)
{
    uint32_t len, bitIndex, wordNo;
    uint16_t word1;

    word1  = 1;

    switch(tformatDataID)
    {
        case (PM_TFORMAT_DATAID0):
        case (PM_TFORMAT_DATAID1):
        case (PM_TFORMAT_DATAID7):
        case (PM_TFORMAT_DATAID8):
        case (PM_TFORMAT_DATAIDC):

            len = 8;

            bitIndex = 13;
            wordNo = 1;
            tformatData.controlField = tformat_getBits (len, wordNo, bitIndex);

            wordNo = wordNo + (10 + (16 - bitIndex) ) / 16;
            bitIndex = 16 - ((10 + (16 - bitIndex)) % 16) ;
            tformatData.statusField = tformat_getBits (len, wordNo, bitIndex);

            wordNo = wordNo + (10 + (16 - bitIndex) ) / 16;
            bitIndex = 16 - ((10 + (16 - bitIndex)) % 16) ;
            tformatData.dataField0 = tformat_getBits (len, wordNo, bitIndex);

            wordNo = wordNo + (10 + (16 - bitIndex) ) / 16;
            bitIndex = 16 - ((10 + (16 - bitIndex)) % 16) ;
            tformatData.dataField1 = tformat_getBits (len, wordNo, bitIndex);

            wordNo = wordNo + (10 + (16 - bitIndex) ) / 16;
            bitIndex = 16 - ((10 + (16 - bitIndex)) % 16) ;
            tformatData.dataField2 = tformat_getBits (len, wordNo, bitIndex);

            wordNo = wordNo + (10 + (16 - bitIndex) ) / 16;
            bitIndex = 16 - ((10 + (16 - bitIndex)) % 16) ;
            tformatData.crc = tformat_getBits (len, wordNo, bitIndex);

            tformatData.rxPkts[0] = ((uint32_t) tformatData.controlField << 24)
                                    | ((uint32_t) tformatData.statusField << 16)
                                    | ((uint32_t) tformatData.dataField0 << 8)
                                    | ((uint32_t) tformatData.dataField1);

            tformatData.rxPkts[1] = ((uint32_t) tformatData.dataField2) ;

        break;

        case (PM_TFORMAT_DATAID2):
            len = 8;

            bitIndex = 13;
            wordNo = 1;
            tformatData.controlField = tformat_getBits (len, wordNo, bitIndex);

            wordNo = wordNo + (10 + (16 - bitIndex) ) / 16;
            bitIndex = 16 - ((10 + (16 - bitIndex)) % 16) ;
            tformatData.statusField = tformat_getBits (len, wordNo, bitIndex);

            wordNo = wordNo + (10 + (16 - bitIndex) ) / 16;
            bitIndex = 16 - ((10 + (16 - bitIndex)) % 16) ;
            tformatData.dataField0 = tformat_getBits (len, wordNo, bitIndex);

            wordNo = wordNo + (10 + (16 - bitIndex) ) / 16;
            bitIndex = 16 - ((10 + (16 - bitIndex)) % 16) ;
            tformatData.crc = tformat_getBits (len, wordNo, bitIndex);

            tformatData.rxPkts[0] = ((uint32_t) tformatData.controlField << 16)
                                    | ((uint32_t) tformatData.statusField << 8)
                                    | ((uint32_t) tformatData.dataField0);
        break;

        case (PM_TFORMAT_DATAID3):
            len = 8;
            bitIndex = 13;
            wordNo = 1;
            tformatData.controlField = tformat_getBits (len, wordNo, bitIndex);

            wordNo = wordNo + (10 + (16 - bitIndex) ) / 16;
            bitIndex = 16 - ((10 + (16 - bitIndex)) % 16) ;
            tformatData.statusField = tformat_getBits (len, wordNo, bitIndex);

            wordNo = wordNo + (10 + (16 - bitIndex) ) / 16;
            bitIndex = 16 - ((10 + (16 - bitIndex)) % 16) ;
            tformatData.dataField0 = tformat_getBits (len, wordNo, bitIndex);

            wordNo = wordNo + (10 + (16 - bitIndex) ) / 16;
            bitIndex = 16 - ((10 + (16 - bitIndex)) % 16) ;
            tformatData.dataField1 = tformat_getBits (len, wordNo, bitIndex);

            wordNo = wordNo + (10 + (16 - bitIndex) ) / 16;
            bitIndex = 16 - ((10 + (16 - bitIndex)) % 16) ;
            tformatData.dataField2 = tformat_getBits (len, wordNo, bitIndex);

            wordNo = wordNo + (10 + (16 - bitIndex) ) / 16;
            bitIndex = 16 - ((10 + (16 - bitIndex)) % 16) ;
            tformatData.dataField3 = tformat_getBits (len, wordNo, bitIndex);

            wordNo = wordNo + (10 + (16 - bitIndex) ) / 16;
            bitIndex = 16 - ((10 + (16 - bitIndex)) % 16) ;
            tformatData.dataField4 = tformat_getBits (len, wordNo, bitIndex);

            wordNo = wordNo + (10 + (16 - bitIndex) ) / 16;
            bitIndex = 16 - ((10 + (16 - bitIndex)) % 16) ;
            tformatData.dataField5 = tformat_getBits (len, wordNo, bitIndex);

            wordNo = wordNo + (10 + (16 - bitIndex) ) / 16;
            bitIndex = 16 - ((10 + (16 - bitIndex)) % 16) ;
            tformatData.dataField6 = tformat_getBits (len, wordNo, bitIndex);

            wordNo = wordNo + (10 + (16 - bitIndex) ) / 16;
            bitIndex = 16 - ((10 + (16 - bitIndex)) % 16) ;
            tformatData.dataField7 = tformat_getBits (len, wordNo, bitIndex);

            wordNo = wordNo + (10 + (16 - bitIndex) ) / 16;
            bitIndex = 16 - ((10 + (16 - bitIndex)) % 16) ;
            tformatData.crc = tformat_getBits (len, wordNo, bitIndex);

            tformatData.rxPkts[0] = ((uint32_t) tformatData.controlField << 24)
                                  | ((uint32_t) tformatData.statusField << 16)
                                  | ((uint32_t) tformatData.dataField0 << 8)
                                  | (uint32_t) tformatData.dataField1;

            tformatData.rxPkts[1] = ((uint32_t) tformatData.dataField2 << 24) |
                                    ((uint32_t) tformatData.dataField3 << 16) |
                                    ((uint32_t) tformatData.dataField4 << 8) |
                                    ((uint32_t) tformatData.dataField5);

            tformatData.rxPkts[2] = ((uint32_t) tformatData.dataField6 << 8) |
                                      ((uint32_t) tformatData.dataField7);

        break;

        case (PM_TFORMAT_DATAIDD):
            len = 8;

            bitIndex = 9;
            wordNo = 2;
            tformatData.controlField = tformat_getBits (len, wordNo, bitIndex);

            wordNo = wordNo + (10 + (16 - bitIndex) ) / 16;
            bitIndex = 16 - ((10 + (16 - bitIndex)) % 16) ;
            tformatData.eepromAddress = tformat_getBits (len,
                            wordNo, bitIndex);

            wordNo = wordNo + (10 + (16 - bitIndex) ) / 16;
            bitIndex = 16 - ((10 + (16 - bitIndex)) % 16) ;
            tformatData.eepromRdDtata = tformat_getBits (len,
                            wordNo, bitIndex);

            wordNo = wordNo + (10 + (16 - bitIndex) ) / 16;
            bitIndex = 16 - ((10 + (16 - bitIndex)) % 16) ;
            tformatData.crc = tformat_getBits (len, wordNo, bitIndex);

            tformatData.rxPkts[0] = ((uint32_t) tformatData.controlField << 16)
                                  | ((uint32_t) tformatData.eepromAddress << 8)
                                  | ((uint32_t) tformatData.eepromRdDtata);
        break;

        case (PM_TFORMAT_DATAID6):

            len = 8;

            bitIndex = 15;
            wordNo = 3;
            tformatData.controlField = tformat_getBits (len, wordNo, bitIndex);

            wordNo = wordNo + (10 + (16 - bitIndex) ) / 16;
            bitIndex = 16 - ((10 + (16 - bitIndex)) % 16) ;
            tformatData.eepromAddress = tformat_getBits (len, wordNo, bitIndex);

            wordNo = wordNo + (10 + (16 - bitIndex) ) / 16;
            bitIndex = 16 - ((10 + (16 - bitIndex)) % 16) ;
            tformatData.eepromRdDtata = tformat_getBits (len, wordNo, bitIndex);

            wordNo = wordNo + (10 + (16 - bitIndex) ) / 16;
            bitIndex = 16 - ((10 + (16 - bitIndex)) % 16) ;
            tformatData.crc = tformat_getBits (len, wordNo, bitIndex);

            tformatData.rxPkts[0] = ((uint32_t) tformatData.controlField << 16)
                                  | ((uint32_t) tformatData.eepromAddress << 8)
                                  | ((uint32_t) tformatData.eepromRdDtata);
            break;

    }

    return(word1);
}



uint16_t tformat_exCommands(void)
{

    uint16_t retval1; //used for function return val storage and checks
    uint32_t address, address_tmp, data, data_tmp;
    uint32_t crcResult;

    retval1 = PM_tformat_setupCommand (PM_TFORMAT_DATAID2, 0, 0, 0);
    PM_tformat_startOperation();
    while(tformatData.dataReady != 1) ;//{;}
    retval1 = PM_tformat_receiveData(PM_TFORMAT_DATAID2);

    crcResult = PM_tformat_getCRC(0, 24, 8, (uint16_t *)&tformatData.rxPkts,
                                  tformatCRCtable, 3);
    crcResult = crcResult ^ (0xFF);
     if(!tformat_checkCRC(crcResult, tformatData.crc))
     {
             ESTOP0;
     }

    SysCtl_delay(40000L); //DELAY_US(400L);
    retval1 = PM_tformat_setupCommand (PM_TFORMAT_DATAID0, 0, 0, 0);
    PM_tformat_startOperation();
    while(tformatData.dataReady != 1) {}
    retval1 = PM_tformat_receiveData(PM_TFORMAT_DATAID0);

    crcResult = PM_tformat_getCRC(0, 40, 8, (uint16_t *)&tformatData.rxPkts,
                                  tformatCRCtable, 5);

    crcResult = crcResult ^ (0xFF);
     if(!tformat_checkCRC(crcResult, tformatData.crc))
     {
             ESTOP0;
     }

    SysCtl_delay(40000L); //DELAY_US(400L);
    retval1 = PM_tformat_setupCommand (PM_TFORMAT_DATAID1, 0, 0, 0);
    PM_tformat_startOperation();
    while(tformatData.dataReady != 1) {}
    retval1 = PM_tformat_receiveData(PM_TFORMAT_DATAID1);

    crcResult = PM_tformat_getCRC(0, 40, 8, (uint16_t *)&tformatData.rxPkts,
                                  tformatCRCtable, 5);
    crcResult = crcResult ^ (0xFF);
     if(!tformat_checkCRC(crcResult, tformatData.crc))
     {
             ESTOP0;
     }

    SysCtl_delay(40000L); //DELAY_US(400L);
    address = 1;
    address_tmp = (__flip32(address) >> 24) & 0xFE; // includes busy "0"
    tformatData.rxPkts[0] = ((((uint32_t) PM_TFORMAT_DATAIDD) | 0x40) << 8) |
                            (uint32_t) address_tmp;
    crcResult = PM_tformat_getCRC(0, 16, 8, (uint16_t *)&tformatData.rxPkts,
                                  tformatCRCtable, 2);
    crcResult = (crcResult) ^ (0xFF);

    retval1 = PM_tformat_setupCommand (PM_TFORMAT_DATAIDD, address, 0, crcResult);
    PM_tformat_startOperation();
    while(tformatData.dataReady != 1) {}
    retval1 = PM_tformat_receiveData(PM_TFORMAT_DATAIDD);

    crcResult = PM_tformat_getCRC(0, 32, 8, (uint16_t *)&tformatData.rxPkts,
                                  tformatCRCtable, 4);
    crcResult = crcResult ^ (0xFF);
     if(!tformat_checkCRC(crcResult, tformatData.crc))
     {
             ESTOP0;
     }

    SysCtl_delay(40000L); //DELAY_US(400L);
    address = 1; data = 35;
    address_tmp = (__flip32(address) >> 24) & 0xFE; // includes busy "0"
    data_tmp = (__flip32(data) >> 24) & 0xFF;
    tformatData.rxPkts[0] = ((((uint32_t) PM_TFORMAT_DATAID6) | 0x40) << 16) |
                            (((uint32_t) address_tmp) << 8) |
                            ((uint32_t) data_tmp);
    crcResult = PM_tformat_getCRC(0, 24, 8, (uint16_t *)&tformatData.rxPkts,
                                  tformatCRCtable, 3);
    crcResult = (crcResult) ^ (0xFF);

    retval1 = PM_tformat_setupCommand (PM_TFORMAT_DATAID6, address, data, crcResult);
    PM_tformat_startOperation();
    while(tformatData.dataReady != 1) {}
    retval1 = PM_tformat_receiveData(PM_TFORMAT_DATAID6);

    crcResult = PM_tformat_getCRC(0, 32, 8, (uint16_t *)&tformatData.rxPkts,
                                  tformatCRCtable, 4);
    crcResult = crcResult ^ (0xFF);
     if(!tformat_checkCRC(crcResult, tformatData.crc))
     {
             ESTOP0;
     }

    SysCtl_delay(40000L); //DELAY_US(400L);
    address = 1;
    address_tmp = (__flip32(address) >> 24) & 0xFE; // includes busy "0"
    tformatData.rxPkts[0] = ((((uint32_t) PM_TFORMAT_DATAIDD) | 0x40) << 8) |
                            (uint32_t) address_tmp;
    crcResult = PM_tformat_getCRC(0, 16, 8, (uint16_t *)&tformatData.rxPkts,
                                  tformatCRCtable, 2);
    crcResult = (crcResult) ^ (0xFF);

    retval1 = PM_tformat_setupCommand (PM_TFORMAT_DATAIDD, address, 0, crcResult);
    PM_tformat_startOperation();
    while(tformatData.dataReady != 1) {}
    retval1 = PM_tformat_receiveData(PM_TFORMAT_DATAIDD);

    crcResult = PM_tformat_getCRC(0, 32, 8, (uint16_t *)&tformatData.rxPkts,
                                  tformatCRCtable, 4);
    crcResult = crcResult ^ (0xFF);
     if(!tformat_checkCRC(crcResult, tformatData.crc))
     {
             ESTOP0;
     }
     SysCtl_delay(4000L);
     return(retval1);

}


   while(1)
        {
            retVal1 = PM_tformat_setupCommand (PM_TFORMAT_DATAID3, 0, 0, 0);
            PM_tformat_startOperation();
            while(tformatData.dataReady != 1);// {}
            retVal1 = PM_tformat_receiveData(PM_TFORMAT_DATAID3);

            // uint16_t PM_tformat_getCRC(uint16_t inputCRCaccum, uint16_t nBitsData,uint16_t nBitsPoly, uint16_t * msg, uint16_t *crcTable, uint16_t rxLen)
            crcResult = PM_tformat_getCRC(0, 80, 8, (uint16_t *)&tformatData.rxPkts,tformatCRCtable, 10);
            crcResult = crcResult ^ (0xFF);
            if(!tformat_checkCRC(crcResult, tformatData.crc))
            {
                 ESTOP0;
            }


                Figure. 2 My encoder(TS5720N8401)

               Figure. 3.My program is here to stay.

The program I modified mainly consists of four functions. 

uint16_t PM_tformat_setupCommand(uint16_t tformatDataID, uint16_t eepromAddr, uint16_t eepromData, uint16_t crcSend):                                                                                                                               1.  Change the value of receiveClks       

 2.  Change dataReady value  0 to 1                                                                                                                                                           

 uint16_t PM_tformat_receiveData(uint16_t tformatDataID):                                                                                                             

 1.Add the code:tformatData.dataReady = 0;                                                                                                                               

 2.Modified the tformatData rxPkts                                                                                                                                                             

uint16_t tformat_exCommands(void)  and main function loops while:Modified the crcResult    

The details are shown as follows(The yellow part is the modification):

uint16_t PM_tformat_setupCommand(uint16_t tformatDataID, uint16_t eepromAddr,
uint16_t eepromData, uint16_t crcSend)
{
uint16_t sendClks;
uint16_t receiveClks;
uint16_t dummySPIClks;
uint16_t i;
uint16_t word1, word2, word3, temp;
uint16_t addrl, datal;

tformat_resetCLB();
tformatData.dataReady = 1;

word1 = (tformatDataID << 6) | 0x903F;

switch(tformatDataID)
{
case (PM_TFORMAT_DATAID2):
sendClks = ABIT + PACKET_BITS + IDLE_BITS;
receiveClks = 4*PACKET_BITS ;

if(((sendClks + receiveClks) % 16) == 0)
{
tformatData.fifoLevel = ((sendClks + receiveClks) / 16);
}
else
{
tformatData.fifoLevel = ((sendClks + receiveClks) / 16) + 1;
}

dummySPIClks = (tformatData.fifoLevel * 16) -(sendClks + receiveClks);

tformat_configureSPILen(15);//

//
//void tformat_configureCLBLen(uint16_t CLB4_C1_M1,
// uint16_t CLB4_C1_M2, uint16_t CLB4_R0)
//
tformat_configureCLBLen((PACKET_BITS + 2), sendClks,receiveClks + dummySPIClks);//PACKET_BITS + 2改为PACKET_BITS + 10**********************************************

tformatData.sdata[0] = word1;
tformatData.sdata[1] = 0xFFFF;
tformatData.sdata[2] = 0xFFFF;
tformatData.sdata[3] = 0xFFFF;
for (i = 0;i < tformatData.fifoLevel;i++)
{
SPI_writeDataNonBlocking(PM_TFORMAT_SPI, tformatData.sdata[i]);
}

break;

case (PM_TFORMAT_DATAID3):
sendClks = ABIT + PACKET_BITS + IDLE_BITS;
receiveClks = 11* PACKET_BITS ;

if(((sendClks + receiveClks) % 16) == 0)
{
tformatData.fifoLevel = ((sendClks + receiveClks) / 16);
}
else
{
tformatData.fifoLevel = ((sendClks + receiveClks) / 16) + 1;
}

dummySPIClks = (tformatData.fifoLevel * 16) -(sendClks + receiveClks);

tformat_configureSPILen(15);

//
//void tformat_configureCLBLen(uint16_t CLB4_C1_M1,
// uint16_t CLB4_C1_M2, uint16_t CLB4_R0)
//
tformat_configureCLBLen((PACKET_BITS + 2), sendClks,receiveClks + dummySPIClks);//*******************************************

tformatData.sdata[0] = word1;
tformatData.sdata[1] = 0xFFFF;
tformatData.sdata[2] = 0xFFFF;
tformatData.sdata[3] = 0xFFFF;
for (i = 0;i < tformatData.fifoLevel;i++)
{
SPI_writeDataNonBlocking(PM_TFORMAT_SPI, tformatData.sdata[i]);
}

break;

case (PM_TFORMAT_DATAID4):
sendClks = ABIT + PACKET_BITS + IDLE_BITS;
receiveClks = 7* PACKET_BITS ;

if(((sendClks + receiveClks) % 16) == 0)
{
tformatData.fifoLevel = ((sendClks + receiveClks) / 16);
}
else
{
tformatData.fifoLevel = ((sendClks + receiveClks) / 16) + 1;
}

dummySPIClks = (tformatData.fifoLevel * 16) -(sendClks + receiveClks);

tformat_configureSPILen(15);

//
//void tformat_configureCLBLen(uint16_t CLB4_C1_M1,
// uint16_t CLB4_C1_M2, uint16_t CLB4_R0)
//
tformat_configureCLBLen((PACKET_BITS + 2), sendClks,receiveClks + dummySPIClks);//******************************************************

tformatData.sdata[0] = word1;
tformatData.sdata[1] = 0xFFFF;
tformatData.sdata[2] = 0xFFFF;
tformatData.sdata[3] = 0xFFFF;
for (i = 0;i < tformatData.fifoLevel;i++)
{
SPI_writeDataNonBlocking(PM_TFORMAT_SPI, tformatData.sdata[i]);
}

break;

case (PM_TFORMAT_DATAID5):
sendClks = ABIT + PACKET_BITS + IDLE_BITS;
receiveClks =9* PACKET_BITS ;

if(((sendClks + receiveClks) % 16) == 0)
{
tformatData.fifoLevel = ((sendClks + receiveClks) / 16);
}
else
{
tformatData.fifoLevel = ((sendClks + receiveClks) / 16) + 1;
}

dummySPIClks = (tformatData.fifoLevel * 16) -(sendClks + receiveClks);

tformat_configureSPILen(15);

//
//void tformat_configureCLBLen(uint16_t CLB4_C1_M1,
// uint16_t CLB4_C1_M2, uint16_t CLB4_R0)
//
tformat_configureCLBLen((PACKET_BITS + 2), sendClks,receiveClks + dummySPIClks);//*************************

tformatData.sdata[0] = word1;
tformatData.sdata[1] = 0xFFFF;
tformatData.sdata[2] = 0xFFFF;
tformatData.sdata[3] = 0xFFFF;
for (i = 0;i < tformatData.fifoLevel;i++)
{
SPI_writeDataNonBlocking(PM_TFORMAT_SPI, tformatData.sdata[i]);
}

break;

case (PM_TFORMAT_DATAID7):
case (PM_TFORMAT_DATAID8):
case (PM_TFORMAT_DATAIDC):

sendClks = ABIT + PACKET_BITS + IDLE_BITS;
receiveClks = 6 * PACKET_BITS ;

if(((sendClks + receiveClks) % 16) == 0)
{
tformatData.fifoLevel = ((sendClks + receiveClks) / 16);
}
else
{
tformatData.fifoLevel = ((sendClks + receiveClks) / 16) + 1;
}

dummySPIClks = (tformatData.fifoLevel * 16) -(sendClks + receiveClks);

tformat_configureSPILen(15);

//
//void tformat_configureCLBLen(uint16_t CLB4_C1_M1,
// uint16_t CLB4_C1_M2, uint16_t CLB4_R0)
//
tformat_configureCLBLen((PACKET_BITS + 2), sendClks,receiveClks + dummySPIClks);//********************************

tformatData.sdata[0] = word1;
tformatData.sdata[1] = 0xFFFF;
tformatData.sdata[2] = 0xFFFF;
tformatData.sdata[3] = 0xFFFF;
for (i = 0;i < tformatData.fifoLevel;i++)
{
SPI_writeDataNonBlocking(PM_TFORMAT_SPI, tformatData.sdata[i]);
}

break;

case (PM_TFORMAT_DATAIDD):
sendClks = ABIT + 3 * PACKET_BITS + IDLE_BITS;
receiveClks = 4 * PACKET_BITS ;

addrl = (__flip32(eepromAddr) >> 24) & 0xFE; // busy "0"
temp = (addrl >> 4) & 0xF;
word1 = (tformatDataID << 6) | 0x9020 | temp;
temp = (addrl & 0xF) << 12;
word2 = temp | 0x803 | (crcSend << 2);

if(((sendClks + receiveClks) % 16) == 0)
{
tformatData.fifoLevel = ((sendClks + receiveClks) / 16);
}
else
{
tformatData.fifoLevel = ((sendClks + receiveClks) / 16) + 1;
}
dummySPIClks = (tformatData.fifoLevel * 16) -(sendClks + receiveClks);

tformat_configureSPILen(15);

//
//void tformat_configureCLBLen(uint16_t CLB4_C1_M1,
//uint16_t CLB4_C1_M2, uint16_t CLB4_R0)
//
tformat_configureCLBLen((3 * PACKET_BITS + 2), sendClks,receiveClks + dummySPIClks);//*****************************************

tformatData.sdata[0] = word1;
tformatData.sdata[1] = word2;
tformatData.sdata[2] = 0xFFFF;
tformatData.sdata[3] = 0xFFFF;
for (i = 0;i < tformatData.fifoLevel;i++)
{
SPI_writeDataNonBlocking(PM_TFORMAT_SPI, tformatData.sdata[i]);
}

break;

case (PM_TFORMAT_DATAID6):

sendClks = ABIT + 4 * PACKET_BITS + IDLE_BITS;
receiveClks = 4 * PACKET_BITS ;

addrl = (__flip32(eepromAddr) >> 24) & 0xFE; // busy "0" 0xFE=0000 0000 1111 1110 addrl=XXXX XXX0
datal = (__flip32(eepromData) >> 24) & 0xFF;//0xFF=0000 0000 1111 1111 data1=XXXX XXXX
temp = (addrl >> 4) & 0xF;//temp=0000 XXXX
word1 = (tformatDataID << 6) | 0x9020 | temp;// 0x9020=1001 0000 0010 0000 word1=(0000 0000 0000 1100<<6) | 1001 0000 0010 0000 | 0000 XXXX
temp = (addrl & 0xF) << 12;
word2 = temp | 0x802 | (datal << 2);
word3 = (crcSend << 8) | 0xFF;

if(((sendClks + receiveClks) % 16) == 0)
{
tformatData.fifoLevel = ((sendClks + receiveClks) / 16);
}
else
{
tformatData.fifoLevel = ((sendClks + receiveClks) / 16) + 1;
}

dummySPIClks = (tformatData.fifoLevel * 16) -(sendClks + receiveClks);

tformat_configureSPILen(15);

tformat_configureCLBLen((4 * PACKET_BITS + 2), sendClks,receiveClks + dummySPIClks);//**************************************

tformatData.sdata[0] = word1;
tformatData.sdata[1] = word2;
tformatData.sdata[2] = word3;
tformatData.sdata[3] = 0xFFFF;
for (i = 0;i < tformatData.fifoLevel;i++)
{
SPI_writeDataNonBlocking(PM_TFORMAT_SPI, tformatData.sdata[i]);

}

break;

default:
word1 = 0;
break;

}

return(word1);

}


uint16_t PM_tformat_receiveData(uint16_t tformatDataID)
{
uint32_t len, bitIndex, wordNo;
uint16_t word1;

word1 = 1;

tformatData.dataReady = 0;

switch(tformatDataID)
{
case (PM_TFORMAT_DATAID2):
len = 8;
bitIndex = 13;
wordNo = 1;
tformatData.controlField = tformat_getBits (len, wordNo, bitIndex);

wordNo = wordNo + (10 + (16 - bitIndex) ) / 16;
bitIndex = 16 - ((10 + (16 - bitIndex)) % 16) ;
tformatData.statusField = tformat_getBits (len, wordNo, bitIndex);

wordNo = wordNo + (10 + (16 - bitIndex) ) / 16;
bitIndex = 16 - ((10 + (16 - bitIndex)) % 16) ;
tformatData.dataField0 = tformat_getBits (len, wordNo, bitIndex);

wordNo = wordNo + (10 + (16 - bitIndex) ) / 16;
bitIndex = 16 - ((10 + (16 - bitIndex)) % 16) ;
tformatData.crc = tformat_getBits (len, wordNo, bitIndex);

tformatData.rxPkts[0] = ((uint32_t) tformatData.controlField << 16)
| ((uint32_t) tformatData.statusField << 8)
| ((uint32_t) tformatData.dataField0);
break;

case (PM_TFORMAT_DATAID3):
len = 8;
bitIndex = 13;
wordNo = 1;
tformatData.controlField = tformat_getBits (len, wordNo, bitIndex);

wordNo = wordNo + (10 + (16 - bitIndex) ) / 16;
bitIndex = 16 - ((10 + (16 - bitIndex)) % 16) ;
tformatData.statusField = tformat_getBits (len, wordNo, bitIndex);

wordNo = wordNo + (10 + (16 - bitIndex) ) / 16;
bitIndex = 16 - ((10 + (16 - bitIndex)) % 16) ;
tformatData.dataField0 = tformat_getBits (len, wordNo, bitIndex);

wordNo = wordNo + (10 + (16 - bitIndex) ) / 16;
bitIndex = 16 - ((10 + (16 - bitIndex)) % 16) ;
tformatData.dataField1 = tformat_getBits (len, wordNo, bitIndex);

wordNo = wordNo + (10 + (16 - bitIndex) ) / 16;
bitIndex = 16 - ((10 + (16 - bitIndex)) % 16) ;
tformatData.dataField2 = tformat_getBits (len, wordNo, bitIndex);

wordNo = wordNo + (10 + (16 - bitIndex) ) / 16;
bitIndex = 16 - ((10 + (16 - bitIndex)) % 16) ;
tformatData.dataField3 = tformat_getBits (len, wordNo, bitIndex);

wordNo = wordNo + (10 + (16 - bitIndex) ) / 16;
bitIndex = 16 - ((10 + (16 - bitIndex)) % 16) ;
tformatData.dataField4 = tformat_getBits (len, wordNo, bitIndex);

wordNo = wordNo + (10 + (16 - bitIndex) ) / 16;
bitIndex = 16 - ((10 + (16 - bitIndex)) % 16) ;
tformatData.dataField5 = tformat_getBits (len, wordNo, bitIndex);

wordNo = wordNo + (10 + (16 - bitIndex) ) / 16;
bitIndex = 16 - ((10 + (16 - bitIndex)) % 16) ;
tformatData.dataField6 = tformat_getBits (len, wordNo, bitIndex);

wordNo = wordNo + (10 + (16 - bitIndex) ) / 16;
bitIndex = 16 - ((10 + (16 - bitIndex)) % 16) ;
tformatData.dataField7 = tformat_getBits (len, wordNo, bitIndex);

wordNo = wordNo + (10 + (16 - bitIndex) ) / 16;
bitIndex = 16 - ((10 + (16 - bitIndex)) % 16) ;
tformatData.crc = tformat_getBits (len, wordNo, bitIndex);

tformatData.rxPkts[0] = ((uint32_t) tformatData.controlField << 24)
| ((uint32_t) tformatData.statusField << 16)
| ((uint32_t) tformatData.dataField0 << 8)
| (uint32_t) tformatData.dataField1;

tformatData.rxPkts[1] = ((uint32_t) tformatData.dataField2 << 24) |
((uint32_t) tformatData.dataField3 << 16) |
((uint32_t) tformatData.dataField4 << 8) |
((uint32_t) tformatData.dataField5);

tformatData.rxPkts[2] = ((uint32_t) tformatData.dataField6 << 8) |
((uint32_t) tformatData.dataField7);

break;

case (PM_TFORMAT_DATAID4):
len = 8;
bitIndex = 13;
wordNo = 1;
tformatData.controlField = tformat_getBits (len, wordNo, bitIndex);

wordNo = wordNo + (10 + (16 - bitIndex) ) / 16;
bitIndex = 16 - ((10 + (16 - bitIndex)) % 16) ;
tformatData.statusField = tformat_getBits (len, wordNo, bitIndex);

wordNo = wordNo + (10 + (16 - bitIndex) ) / 16;
bitIndex = 16 - ((10 + (16 - bitIndex)) % 16) ;
tformatData.dataField0 = tformat_getBits (len, wordNo, bitIndex);

wordNo = wordNo + (10 + (16 - bitIndex) ) / 16;
bitIndex = 16 - ((10 + (16 - bitIndex)) % 16) ;
tformatData.dataField1 = tformat_getBits (len, wordNo, bitIndex);

wordNo = wordNo + (10 + (16 - bitIndex) ) / 16;
bitIndex = 16 - ((10 + (16 - bitIndex)) % 16) ;
tformatData.dataField2 = tformat_getBits (len, wordNo, bitIndex);

wordNo = wordNo + (10 + (16 - bitIndex) ) / 16;
bitIndex = 16 - ((10 + (16 - bitIndex)) % 16) ;
tformatData.dataField3 = tformat_getBits (len, wordNo, bitIndex);

wordNo = wordNo + (10 + (16 - bitIndex) ) / 16;
bitIndex = 16 - ((10 + (16 - bitIndex)) % 16) ;
tformatData.crc = tformat_getBits (len, wordNo, bitIndex);

tformatData.rxPkts[0] = ((uint32_t) tformatData.controlField << 24)
| ((uint32_t) tformatData.statusField << 16)
| ((uint32_t) tformatData.dataField0 << 8)
| (uint32_t) tformatData.dataField1;

tformatData.rxPkts[1] = ((uint32_t) tformatData.dataField2 <<8) |
((uint32_t) tformatData.dataField3);

break;

case (PM_TFORMAT_DATAID5):
len = 8;
bitIndex = 13;
wordNo = 1;
tformatData.controlField = tformat_getBits (len, wordNo, bitIndex);

wordNo = wordNo + (10 + (16 - bitIndex) ) / 16;
bitIndex = 16 - ((10 + (16 - bitIndex)) % 16) ;
tformatData.statusField = tformat_getBits (len, wordNo, bitIndex);

wordNo = wordNo + (10 + (16 - bitIndex) ) / 16;
bitIndex = 16 - ((10 + (16 - bitIndex)) % 16) ;
tformatData.dataField0 = tformat_getBits (len, wordNo, bitIndex);

wordNo = wordNo + (10 + (16 - bitIndex) ) / 16;
bitIndex = 16 - ((10 + (16 - bitIndex)) % 16) ;
tformatData.dataField1 = tformat_getBits (len, wordNo, bitIndex);

wordNo = wordNo + (10 + (16 - bitIndex) ) / 16;
bitIndex = 16 - ((10 + (16 - bitIndex)) % 16) ;
tformatData.dataField2 = tformat_getBits (len, wordNo, bitIndex);

wordNo = wordNo + (10 + (16 - bitIndex) ) / 16;
bitIndex = 16 - ((10 + (16 - bitIndex)) % 16) ;
tformatData.dataField3 = tformat_getBits (len, wordNo, bitIndex);

wordNo = wordNo + (10 + (16 - bitIndex) ) / 16;
bitIndex = 16 - ((10 + (16 - bitIndex)) % 16) ;
tformatData.dataField4 = tformat_getBits (len, wordNo, bitIndex);

wordNo = wordNo + (10 + (16 - bitIndex) ) / 16;
bitIndex = 16 - ((10 + (16 - bitIndex)) % 16) ;
tformatData.dataField5 = tformat_getBits (len, wordNo, bitIndex);

tformatData.rxPkts[0] = ((uint32_t) tformatData.controlField << 24)
| ((uint32_t) tformatData.statusField << 16)
| ((uint32_t) tformatData.dataField0 << 8)
| (uint32_t) tformatData.dataField1;

tformatData.rxPkts[1] = ((uint32_t) tformatData.dataField2 << 24) |
((uint32_t) tformatData.dataField3 << 16) |
((uint32_t) tformatData.dataField4 << 8) |
((uint32_t) tformatData.dataField5);

break;

case (PM_TFORMAT_DATAID7):
case (PM_TFORMAT_DATAID8):
case (PM_TFORMAT_DATAIDC):

len = 8;

bitIndex = 13;
wordNo = 1;
tformatData.controlField = tformat_getBits (len, wordNo, bitIndex);

wordNo = wordNo + (10 + (16 - bitIndex) ) / 16;
bitIndex = 16 - ((10 + (16 - bitIndex)) % 16) ;
tformatData.statusField = tformat_getBits (len, wordNo, bitIndex);

wordNo = wordNo + (10 + (16 - bitIndex) ) / 16;
bitIndex = 16 - ((10 + (16 - bitIndex)) % 16) ;
tformatData.dataField0 = tformat_getBits (len, wordNo, bitIndex);

wordNo = wordNo + (10 + (16 - bitIndex) ) / 16;
bitIndex = 16 - ((10 + (16 - bitIndex)) % 16) ;
tformatData.dataField1 = tformat_getBits (len, wordNo, bitIndex);

wordNo = wordNo + (10 + (16 - bitIndex) ) / 16;
bitIndex = 16 - ((10 + (16 - bitIndex)) % 16) ;
tformatData.dataField2 = tformat_getBits (len, wordNo, bitIndex);

wordNo = wordNo + (10 + (16 - bitIndex) ) / 16;
bitIndex = 16 - ((10 + (16 - bitIndex)) % 16) ;
tformatData.crc = tformat_getBits (len, wordNo, bitIndex);

tformatData.rxPkts[0] = ((uint32_t) tformatData.controlField << 24)
| ((uint32_t) tformatData.statusField << 16)
| ((uint32_t) tformatData.dataField0 << 8)
| ((uint32_t) tformatData.dataField1);

tformatData.rxPkts[1] = ((uint32_t) tformatData.dataField2) ;

break;

case (PM_TFORMAT_DATAIDD):
len = 8;

bitIndex = 9;
wordNo = 2;
tformatData.controlField = tformat_getBits (len, wordNo, bitIndex);

wordNo = wordNo + (10 + (16 - bitIndex) ) / 16;
bitIndex = 16 - ((10 + (16 - bitIndex)) % 16) ;
tformatData.eepromAddress = tformat_getBits (len,
wordNo, bitIndex);

wordNo = wordNo + (10 + (16 - bitIndex) ) / 16;
bitIndex = 16 - ((10 + (16 - bitIndex)) % 16) ;
tformatData.eepromRdDtata = tformat_getBits (len,
wordNo, bitIndex);

wordNo = wordNo + (10 + (16 - bitIndex) ) / 16;
bitIndex = 16 - ((10 + (16 - bitIndex)) % 16) ;
tformatData.crc = tformat_getBits (len, wordNo, bitIndex);

tformatData.rxPkts[0] = ((uint32_t) tformatData.controlField << 16)
| ((uint32_t) tformatData.eepromAddress << 8)
| ((uint32_t) tformatData.eepromRdDtata);
break;

case (PM_TFORMAT_DATAID6):

len = 8;

bitIndex = 15;
wordNo = 3;
tformatData.controlField = tformat_getBits (len, wordNo, bitIndex);

wordNo = wordNo + (10 + (16 - bitIndex) ) / 16;
bitIndex = 16 - ((10 + (16 - bitIndex)) % 16) ;
tformatData.eepromAddress = tformat_getBits (len, wordNo, bitIndex);

wordNo = wordNo + (10 + (16 - bitIndex) ) / 16;
bitIndex = 16 - ((10 + (16 - bitIndex)) % 16) ;
tformatData.eepromRdDtata = tformat_getBits (len, wordNo, bitIndex);

wordNo = wordNo + (10 + (16 - bitIndex) ) / 16;
bitIndex = 16 - ((10 + (16 - bitIndex)) % 16) ;
tformatData.crc = tformat_getBits (len, wordNo, bitIndex);

tformatData.rxPkts[0] = ((uint32_t) tformatData.controlField << 16)
| ((uint32_t) tformatData.eepromAddress << 8)
| ((uint32_t) tformatData.eepromRdDtata);
break;

}

return(word1);

}

uint16_t tformat_exCommands(void)
{

uint16_t retval1; //used for function return val storage and checks
uint32_t address, address_tmp, data, data_tmp;
uint32_t crcResult;


retval1 = PM_tformat_setupCommand (PM_TFORMAT_DATAID2, 0, 0, 0);
PM_tformat_startOperation();

while(tformatData.dataReady != 1) ;//{;}
retval1 = PM_tformat_receiveData(PM_TFORMAT_DATAID2);

crcResult = PM_tformat_getCRC(0, 24, 8, (uint16_t *)&tformatData.rxPkts,
tformatCRCtable, 3);
crcResult = crcResult ^ (0xFF);
if(!tformat_checkCRC(crcResult, tformatData.crc))
{
ESTOP0;
}

SysCtl_delay(40000L); //DELAY_US(400L);
retval1 = PM_tformat_setupCommand (PM_TFORMAT_DATAID4, 0, 0, 0);
PM_tformat_startOperation();
while(tformatData.dataReady != 1) {}
retval1 = PM_tformat_receiveData(PM_TFORMAT_DATAID4);

crcResult = PM_tformat_getCRC(0, 48, 8, (uint16_t *)&tformatData.rxPkts,
tformatCRCtable, 6);

crcResult = crcResult ^ (0xFF);
if(!tformat_checkCRC(crcResult, tformatData.crc))
{
ESTOP0;
}


SysCtl_delay(40000L); //DELAY_US(400L);
retval1 = PM_tformat_setupCommand (PM_TFORMAT_DATAID5, 0, 0, 0);
PM_tformat_startOperation();
while(tformatData.dataReady != 1) {}
retval1 = PM_tformat_receiveData(PM_TFORMAT_DATAID5);

crcResult = PM_tformat_getCRC(0, 64, 8, (uint16_t *)&tformatData.rxPkts,
tformatCRCtable, 8);
crcResult = crcResult ^ (0xFF);
if(!tformat_checkCRC(crcResult, tformatData.crc))
{
ESTOP0;
}


SysCtl_delay(40000L); //DELAY_US(400L);
address = 1;
address_tmp = (__flip32(address) >> 24) & 0xFE; // includes busy "0"
tformatData.rxPkts[0] = ((((uint32_t) PM_TFORMAT_DATAIDD) | 0x40) << 8) |
(uint32_t) address_tmp;
crcResult = PM_tformat_getCRC(0, 16, 8, (uint16_t *)&tformatData.rxPkts,
tformatCRCtable, 2);
crcResult = (crcResult) ^ (0xFF);

retval1 = PM_tformat_setupCommand (PM_TFORMAT_DATAIDD, address, 0, crcResult);
PM_tformat_startOperation();
while(tformatData.dataReady != 1) {}
retval1 = PM_tformat_receiveData(PM_TFORMAT_DATAIDD);

crcResult = PM_tformat_getCRC(0, 32, 8, (uint16_t *)&tformatData.rxPkts,
tformatCRCtable, 4);
crcResult = crcResult ^ (0xFF);
if(!tformat_checkCRC(crcResult, tformatData.crc))
{
ESTOP0;
}


SysCtl_delay(40000L); //DELAY_US(400L);
address = 1; data = 35;
address_tmp = (__flip32(address) >> 24) & 0xFE; // includes busy "0"
data_tmp = (__flip32(data) >> 24) & 0xFF;
tformatData.rxPkts[0] = ((((uint32_t) PM_TFORMAT_DATAID6) | 0x40) << 16) |
(((uint32_t) address_tmp) << 8) |
((uint32_t) data_tmp);
crcResult = PM_tformat_getCRC(0, 24, 8, (uint16_t *)&tformatData.rxPkts,
tformatCRCtable, 3);
crcResult = (crcResult) ^ (0xFF);

retval1 = PM_tformat_setupCommand (PM_TFORMAT_DATAID6, address, data, crcResult);
PM_tformat_startOperation();
while(tformatData.dataReady != 1) {}
retval1 = PM_tformat_receiveData(PM_TFORMAT_DATAID6);

crcResult = PM_tformat_getCRC(0, 32, 8, (uint16_t *)&tformatData.rxPkts,
tformatCRCtable, 4);
crcResult = crcResult ^ (0xFF);
if(!tformat_checkCRC(crcResult, tformatData.crc))
{
ESTOP0;
}


SysCtl_delay(40000L); //DELAY_US(400L);
address = 1;
address_tmp = (__flip32(address) >> 24) & 0xFE; // includes busy "0"
tformatData.rxPkts[0] = ((((uint32_t) PM_TFORMAT_DATAIDD) | 0x40) << 8) |
(uint32_t) address_tmp;
crcResult = PM_tformat_getCRC(0, 16, 8, (uint16_t *)&tformatData.rxPkts,
tformatCRCtable, 2);
crcResult = (crcResult) ^ (0xFF);

retval1 = PM_tformat_setupCommand (PM_TFORMAT_DATAIDD, address, 0, crcResult);
PM_tformat_startOperation();
while(tformatData.dataReady != 1) {}
retval1 = PM_tformat_receiveData(PM_TFORMAT_DATAIDD);

crcResult = PM_tformat_getCRC(0, 32, 8, (uint16_t *)&tformatData.rxPkts,
tformatCRCtable, 4);
crcResult = crcResult ^ (0xFF);
if(!tformat_checkCRC(crcResult, tformatData.crc))
{
ESTOP0;
}
SysCtl_delay(4000L);
return(retval1);

}

while(1)
{
retVal1 = PM_tformat_setupCommand (PM_TFORMAT_DATAID3, 0, 0, 0);
PM_tformat_startOperation();
while(tformatData.dataReady != 1);// {}
retVal1 = PM_tformat_receiveData(PM_TFORMAT_DATAID3);

// uint16_t PM_tformat_getCRC(uint16_t inputCRCaccum, uint16_t nBitsData,uint16_t nBitsPoly, uint16_t * msg, uint16_t *crcTable, uint16_t rxLen)
crcResult = PM_tformat_getCRC(0, 80, 8, (uint16_t *)&tformatData.rxPkts,tformatCRCtable, 10);
crcResult = crcResult ^ (0xFF);
if(!tformat_checkCRC(crcResult, tformatData.crc))
{
ESTOP0;
}

//
//Invert the received bit sequence for position and
//turns for actual data
//
position =
((__flip32((uint32_t) tformatData.dataField0) >> 24 ) & 0xFF) |
((__flip32((uint32_t) tformatData.dataField1) >> 16 ) & 0xFF00) |
((__flip32((uint32_t) tformatData.dataField2) >> 8 ) & 0xFF0000);

turns =
((__flip32((uint32_t) tformatData.dataField4) >> 24 ) & 0xFF) |
((__flip32((uint32_t) tformatData.dataField5) >> 16 ) & 0xFF00) |
((__flip32((uint32_t) tformatData.dataField6) >> 8 ) & 0xFF0000);

To sum up:

1. Considering that the coder I used is different from TI, I modified the program. Please help to check whether the modification is correct.

2. Do other parts of the program need to be modified to complete the encoder experiment?

Thank you!

  • TS5720N8401

    I think the first thing to double check is that this encoder uses T-format.  Not all Tamagawa encoders use T-format.    I did a search and I find that some customers have used a TS5700N8401 but I'm not finding TS5720N8401.  I've also not heard any customers needing to change the command format.   

  • However, if I had not made the above changes, my program would have stuck at: while(tFormatData.dataready!= 1);/ / {}

  • Alanl,

    The line you show, where the CPU is stuck, is the solution waiting for a response from the encoder. 

    1. Confirm that the encoder supports T-Format.  Some Tamagawa encoders are not T-Format.  
    2. Check the signals coming out from the C2000:  
      1. TxEN: high during DATA_OUT being sent.
      2. SPICLKB:  
      3. DATA_OUT (SPISOMIB): 
    3. If you do not see any activity on SPISOMIB:
      1. Check that SPICLKB is connected to the SPI CLK coming out of the CLB (GPIO7).   SPICLKB must be driven by the CLB (GPIO 7).  If you have a LaunchPad and are checking signals without the BOOSTXL-POSMGR connected, you must tie these two pins together in order to see SPISOMIB.  If you are using BOOSTXL-POSMGR, then it connects these two signals.
    4. Check that SPICLKB is 2.5 MHz and the bit-width of DATA_OUT is 400ns.  400ns is required for T-Format and if this is not correct, the encoder will not respond. 
      1. If the bit width is not 400ns then the encoder will not respond and the clock needs to be adjusted.
      2. Use the TFORMAT_FREQ_DIVIDER in the file tformat.h. As provided it is setup for a 200MHz F2837xD. 
  • Lori ,

    Thank you very much for your patient reply. I will check it again according to your method. Thank you!

  • hello Lori ,

    I'm so sorry to bother you again.I have checked according to your method, and the specific situation is as follows:

    1.I have changed the encoder to TS5700N8401 (tFormat supported)

    2.Check the signals coming out from the C2000(I can detect the waveform, but the waveform looks a little strange): 

        a.TxEN waveform(It seems too narrow):

        

        b.SPICLKB waveform(SPICLKB is 2.5 MHz and the bit-width of DATA_OUT is 400ns):

        

        c.DATA_OUT (SPISOMIB):

       

    3.During the test, I used BOOSTXL-POSMGR throughout the test

    4.By measuring the waveform, I can confirm that it is set SPICLKB is 2.5 MHz and the bit-width of DATA_OUT is 400ns.

    Please help to check the above waveform, thank you!    

    In addition, I noticed that the waveform described in another of your posts is different from mine.

    e2e.ti.com/.../3469334

  • Thank you for the information.  I will review and get back to you by the end of the week. 

  • Thank you very much for your help.

  • I appreciate your patience. 

  • Lori,

    Thank you very much for your previous reply. I have some new discoveries to share with you.

    I changed the probe for the test, and the waveform looks a little similar to the waveform in your other post, as follows:

    Txen(GPIO9) is yellow   ;   SOMI(GPIO64) is green;   CLKs(GPIO7) is purple  

    but,I find the purple waveform is different from yours.

    e2e.ti.com/.../3469334

  • In the related post, I had modified the code to repeatedly send a command.  Without that modification, the code will send one command and then wait for a response from the encoder.  I think this is why you see a difference.

    It looks like commands are going out fine.  The encoder isn't responding.  The next thing I would check is that the encoder is getting proper power.  I have seen some issues powering an encoder from the booster pack.  Try bypassing the card for the power and sending it though an external supply. 

  • Lori,

    I am referring to your relevant post to modify the command, and the modified part is as follows:

    // retVal1 = tformat_exCommands(); <-- comment this out

    while(1)
    {
    retVal1 = PM_tformat_setupCommand (PM_TFORMAT_DATAID3, 0, 0, 0);
    PM_tformat_startOperation();
    DEVICE_DELAY_US(40L); <-- some delay
    }

    As you did above (using an external power supply), I've got the same waveform as you, but the code will still be: while(tFormatData.dataready!= 1);/ / {}

  • Lori,

    I am referring to your relevant post to modify the command, and the modified part is as follows:

    // retVal1 = tformat_exCommands(); <-- comment this out

    while(1)
    {
    retVal1 = PM_tformat_setupCommand (PM_TFORMAT_DATAID3, 0, 0, 0);
    PM_tformat_startOperation();
    DEVICE_DELAY_US(40L); <-- some delay
    }

    As you did above (using an external power supply), I've got the same waveform as you, but the code will still be: while(tFormatData.dataready!= 1);/ / {}

  • As you did above (using an external power supply), I've got the same waveform as you, but the code will still be: while(tFormatData.dataready!= 1);/ / {}

    That is strange - with the code change the processor should stay within the while(1) loop you added and continuously send a new command instead of waiting for a response.

    using an external power supply

    I'm starting to run out of ideas - it seems the C28x is doing the correct thing  (without the code modification):

    • - clocks have been checked
    • - voltage levels checked
    • - command is sent
    • - encoder is properly powered

    Is it possible to check the signals at the encoder side?  I know this may not be possible but that would be the next thing that comes to mind.  

  • Lori,

    You may have misunderstood me. After I got the same waveform as yours above, I thought I could confirm that C28X could work normally. Then I modified the code to get position information, as shown below:

    // retVal1 = tformat_exCommands(); <-- comment this out

    while(1)
    {
    retval1 = PM_tformat_setupCommand (PM_TFORMAT_DATAID0, 0, 0, 0);
    PM_tformat_startOperation();
    while(tformatData.dataReady != 1) {}
    retval1 = PM_tformat_receiveData(PM_TFORMAT_DATAID0);

    crcResult = PM_tformat_getCRC(0, 40, 8, (uint16_t *)&tformatData.rxPkts,
    tformatCRCtable, 5);

    crcResult = crcResult ^ (0xFF);
    if(!tformat_checkCRC(crcResult, tformatData.crc))
    {
    ESTOP0;
    }

    //
    //Invert the received bit sequence for position and
    //turns for actual data
    //
    position =
    ((__flip32((uint32_t) tformatData.dataField0) >> 24 ) & 0xFF) |
    ((__flip32((uint32_t) tformatData.dataField1) >> 16 ) & 0xFF00) |
    ((__flip32((uint32_t) tformatData.dataField2) >> 8 ) & 0xFF0000);

    turns =
    ((__flip32((uint32_t) tformatData.dataField4) >> 24 ) & 0xFF) |
    ((__flip32((uint32_t) tformatData.dataField5) >> 16 ) & 0xFF00) |
    ((__flip32((uint32_t) tformatData.dataField6) >> 8 ) & 0xFF0000);

    DEVICE_DELAY_US(400L);
    }

    In addition, I found that it is possible that the waveform of SIMO (yellow curve) is not correct.

  • Yes, I agree SIMO looks very noisy.  

  • Lori,

    Thank you very much for your patience and guidance for long time.It would be great if I could send my CCS project(

    In fact, the code is the same as TI, but I'm not using the lib libraries) to you ,but I worry you're quite busy now.

  • In fact, the code is the same as TI, but I'm not using the lib libraries

    Hello,

    Have you tried using the example as it was provided?  

    Thank you

    Lori

  • Lori,
    Thank you very much for your patience and guidance for long time.Through your patient guidance,my encoder (TS5667N2305, 17bit) is now able to receive data .If I plan to use the 23-bit encoder (TS5700N8401) for my experiment, what else do I need to change besides the tformat_getBits () function?
    Also, how can I modify the tformat_getBits () function?

  • Hello, 

    Thank you for letting me know it is working now.  Was there something you found that fixed it?  I would like to learn from your experience if you don't mind. 

    If I plan to use the 23-bit encoder (TS5700N8401) for my experiment, what else do I need to change besides the tformat_getBits () function?
    Also, how can I modify the tformat_getBits () function?

    I see that you opened another thread on this subject.  Thank you for doing that.  I will follow-up there. 

    Best Regards

    Lori

  • Lori,

    I am glad to have technical communication with you. I just changed the way of wiring.Not only does the encoder need to be connected to other stable power sources, but so does the BoostXL-POSmgr.As shown below:

    Best Regards

    Johnson Alanl

  • Thank you for the feedback!  The transceivers on the booster pack must be underpowered by the launchpad.  I regret this caused an issue for you and am glad you found a resolution.