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.

TM4C129XNCZAD: How to check the data packet in code

Part Number: TM4C129XNCZAD
Other Parts Discussed in Thread: ADS1248

Hi,

I am working with TM4C129XNZAD microcontroller, from that project I need to transfer some live data to table communication. For live data transfer I am using IBP Simulator. from this I dont know how the simulator data is storing and which variable the data is storing. And also please tell me how to check the data packets. I will share the code in below attachment. Anyone please help me on this how to check the data packet and simulator variable.

The code is below,

[Code removed due to excess size]

  • IBP code and data packet code:

    /*
    * IBP.c
    *
    * Created on: 24-Jul-2017
    * Author: Adhitya GN
    */


    /***************************************************************
    *
    * COPYRIGHT 2018, Vasmed Health Sciences Pvt. Ltd..
    *
    * Filename: IBP.c
    * Author: Adhitya GN
    * $Revision: -
    * $Date: -
    *
    * Description:
    * ALl the codes related to IBP board and forming data packets and sending the data packets will be executed from here.
    *
    *
    *****************************************************************/

    #include "Main.h"
    #include "IBP.h"
    #include "SPPLEDemo.h"

    #include <stdbool.h>
    #include <stdint.h>
    #include "SPPLEDemo.h"
    #include "inc/hw_memmap.h"
    #include "driverlib/gpio.h"
    #include "driverlib/ssi.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/watchdog.h"

    //*****************************************************************************

    //****************************************typedef*************************************

    typedef struct hex_val
    {
    uint32_t Parameters[3];
    } hex_value;

    //*****************************************************************************


    //*************************function declaration************************************************

    void IBP_initialize();
    void send_data(unsigned char );
    void receive_data(int);
    hex_value receive_data1(int);
    void ibp_exec();
    void bt_transmit(hex_value);
    bool ibp_self_test();


    //********************************************************************************************


    //********************************global variables*******************************************

    bool self_test_indicator=false; // this tells to all functions that self test is finished or no// true= finished.

    bool live_procedure=false; // after entering patient info, after going to live screen, then only equalize should work.
    Byte_t data[DATA_PACKET_SIZE]; // the data packet.
    bool lock;

    //********************************************************************************************


    /*************************************************************
    * Function: IBP_initialize()
    *
    * Description: This function is called from Main.c before the scheduling function and
    * before the self test. This is called after initializng IBP board(mux,speed,etc)
    * This is used to initilaize the registers of ADC required for operation of IBP board
    * and doing internal adc calibration.
    *
    * Parameters: NULL
    *
    * Returns: NULL
    *
    * Reentrancy: No
    *
    * Execution Requirements/Assumptions: NULL
    *
    *************************************************************/


    void IBP_initialize()
    {
    Display(("\n IBP_initialize"));

    uint32_t pui32DataRx[NUM_SSI_DATA];
    while(SSIDataGetNonBlocking(SSI2_BASE, &pui32DataRx[0]))
    {

    }

    SysCtlDelay(650000); //= 17ms.
    SysCtlDelay(50000);
    send_data(ADS1248_CMD_RESET);
    SysCtlDelay(50000);
    send_data(ADS1248_CMD_SDATAC);

    send_data(ADS1248_CMD_SELFOCAL);
    receive_data(1);
    SysCtlDelay(6500000); //17ms

    send_data(ADS1248_CMD_WREG); //40h
    send_data(ADS1248_3_SYS0); //03h
    send_data(ADS1248_1_VBIAS); //01h
    send_data(ADS1248_0_MUX0); //00h
    send_data(ADS1248_2_MUX1); //03h
    //send_data(ADS1248_14_GAIN); //42h ADS1248_14_SPS
    send_data(ADS1248_15_SPS); // from 5sps(above) to 1000sps it is set. currently set at 160(or something) sps.

    //Display(("\n testing- rx=8---------------------1\n"));
    receive_data(8);

    send_data(ADS1248_CMD_RREG); //20h
    send_data(ADS1248_3_SYS0); //03h


    // Display(("\nReceiving-- rx=2--------1\n"));
    receive_data(2);
    // Display(("\nReceiving= original-----2\n"));
    send_data(ADS1248_CMD_NOP);
    receive_data(1);
    send_data(ADS1248_CMD_NOP);
    receive_data(1);
    send_data(ADS1248_CMD_NOP);
    receive_data(1);
    send_data(ADS1248_CMD_NOP);
    receive_data(1);

    send_data(ADS1248_CMD_SYSGCAL);
    receive_data(1);
    SysCtlDelay(6500000); //17ms

    //14-----Write the respective register configuration with the WREG command (40h, 03h, 01h, 00h, 03h and 42h); --pg 37 datasheet
    send_data(ADS1248_CMD_WREG); //40h
    send_data(ADS1248_3_SYS0); //03h
    send_data(ADS1248_1_VBIAS); //01h
    send_data(ADS1248_0_MUX0); //00h
    send_data(ADS1248_0_MUX0); //03h
    send_data(ADS1248_15_SPS); //42h

    receive_data(6);

    send_data(ADS1248_CMD_RREG); //20h
    send_data(ADS1248_3_SYS0);
    receive_data(2);

    send_data(ADS1248_CMD_NOP);
    receive_data(1);
    send_data(ADS1248_CMD_NOP);
    receive_data(1);
    send_data(ADS1248_CMD_NOP);
    receive_data(1);
    send_data(ADS1248_CMD_NOP);
    receive_data(1);

    send_data(ADS1248_CMD_SYNC); //05h
    send_data(ADS1248_CMD_SYNC); //05h-------////because we have to give sync command twice---pg 38
    receive_data(2);
    SysCtlDelay(650000);
    //GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_2, GPIO_PIN_2);
    }


    /*************************************************************
    * Function: send_data()
    *
    * Description: Sends the data to ADC( to communicate with adc registers) for communication through ssi from
    * baseboard board to adc of ibp board
    *
    * Parameters: Data to be sent to adc
    *
    * Returns: NULL
    *
    * Reentrancy: Yes. Every 10ms, when ibp_exec() function is scheduled to execute, this will also be executed at that time.
    *
    * Execution Requirements/Assumptions: NULL
    *
    *************************************************************/


    void send_data(unsigned char Byte)
    {
    SSIDataPut(SSI2_BASE, Byte);
    while(SSIBusy(SSI2_BASE))
    {

    }
    }


    /*************************************************************
    * Function: receive_data()
    *
    * Description: Receives the data from adc to baseboard through ssi. this data is mainly junk data. In ssi,
    * for every data you send( data to registers to access read/write/anything), there will same number of
    * bytes you will be receiving. Those datas are junk datas. So, that is received here.
    *
    * Parameters: Number of bytes to read/receive.
    *
    * Returns: NULL
    *
    * Reentrancy: Yes. Every 10ms, when ibp_exec() function is scheduled to execute, this will also be executed at that time.
    *
    * Execution Requirements/Assumptions: NULL
    *
    *************************************************************/


    void receive_data(int n)
    {
    uint8_t ui32Index;
    uint32_t pui32DataRx[10];
    //uint32_t comp[10];

    for(ui32Index = 0; ui32Index < n; ui32Index++)
    {
    //
    // Receive the data using the "blocking" Get function. This function
    // will wait until there is data in the receive FIFO before returning.
    //
    SSIDataGet(SSI2_BASE, &pui32DataRx[ui32Index]);
    //
    // Since we are using 8-bit data, mask off the MSB.
    //
    pui32DataRx[ui32Index] &= 0x00FF;

    //
    // Display the data that SSI0 received.
    //

    //comp[ui32Index]= (0xFF- pui32DataRx[ui32Index])+0x01;

    }
    }

    /*************************************************************
    * Function: receive_data1()
    *
    * Description: In the above function, receive_data(), we received junk values. But in this function, the
    * actual data is received. After we send out NOPs, and then we received the junk data for sending NOP,
    * then, we will call this function to receive the required data. The ADC used is 24 bit. So, 3 bytes of data
    * will be present and we need all 3 bytes of data to form the adc pressure value from raw ADC values. SO,
    * all the 3 bytes should be in a single variable/structure.
    *
    * Parameters: Number of bytes to read/receive.
    *
    * Returns: The structure where all 3 bytes of raw adc data is stored.
    *
    * Reentrancy: Yes. Every 10ms, when ibp_exec() function is scheduled to execute, this will also be executed at that time.
    *
    * Execution Requirements/Assumptions: NULL
    *
    *************************************************************/


    hex_value receive_data1(int n) // this function will give adc value which is necessary
    {
    Byte_t x_2; // has 2nd byte of raw adc data. This is the most important byte of all three.
    uint8_t ui32Index;
    uint32_t pui32DataRx[3]; // captures data read from ssi.
    // 2 is initial. 0=not connected. 1=connected.
    struct hex_val value; // the structure where adc raw data of 3 bytes is stored. This will be the return value.


    uint8_t count=0; // similar to ui32Index. this is for 2nd time.
    uint32_t ibp_collect[3]; // similar to pui32DataRx. this is for 2nd time.

    for(ui32Index = 0; ui32Index < n; ui32Index++)
    {
    //Display(("\n1"));
    //
    // Receive the data using the "blocking" Get function. This function
    // will wait until there is data in the receive FIFO before returning.
    //

    SSIDataGet(SSI2_BASE, &pui32DataRx[ui32Index]);
    pui32DataRx[ui32Index] &= 0x00FF;
    // Display(("ui32=%x",pui32DataRx[ui32Index]));

    if(ui32Index==0) //MSB
    {
    // do nothing as I dont need MSB. It has 0 always when pressure is there.
    value.Parameters[0]=pui32DataRx[ui32Index];
    }

    else if(ui32Index==1) //middle data. 2nd byte
    {
    value.Parameters[1]=pui32DataRx[ui32Index];
    x_2=pui32DataRx[ui32Index]; //x_2 has adc value. i.e, middle data
    //Display(("x=%d",x));
    }

    else if(ui32Index==2) //LSB. all 3 bytes received now
    {
    //Display(("\n2"));
    value.Parameters[2]=pui32DataRx[ui32Index];

    if( (x_2 == IBP_LOWER_LIMIT) || (x_2 > IBP_UPPER_LIMIT) ) //if ibp not working //---if =0 or greater than 75
    {
    // Display(("\n ibp is not working"));

    //Display(("\nx_2=%"));
    GPIOPinWrite(GPIO_PORTK_BASE, GPIO_PIN_2, 0x00); // off the power control so ibp board is off
    //SysCtlDelay(900); //-- IMPORTANT--------------- // these off/on is to tackle emi/emc issue.
    GPIOPinWrite(GPIO_PORTK_BASE, GPIO_PIN_2, GPIO_PIN_2); // on the power control so ibp board is on
    //SysCtlDelay(10000);
    send_data(ADS1248_CMD_RDATA); // 13h // these 5 lines were done in ibp_exec initially. now, this is 2nd round
    receive_data(1);
    send_data(ADS1248_CMD_NOP);
    send_data(ADS1248_CMD_NOP);
    send_data(ADS1248_CMD_NOP);
    err=AO_SENSORE_NOT_ATTACHED; // problem in reading data from sensor.
    lock=false;
    ErrorHandler( false,4 );

    for(count = 0; count < n; count++) //2nd count
    {
    //Display(("\n4"));
    SSIDataGet(SSI2_BASE, &ibp_collect[count]);
    ibp_collect[count] &= 0x00FF;

    if(count==0)
    {
    value.Parameters[0]=ibp_collect[count];
    }

    else if(count==1)
    {
    value.Parameters[1]=ibp_collect[count];
    x_2=ibp_collect[count];
    }

    else if(count==2) //2nd if
    {
    //Display(("\n5"));
    value.Parameters[2]=ibp_collect[count];

    }


    } //end of else ibp=ok in 1st try
    } // end of (if uindex==2), 1st try 3rd byte, inside. msb-ignored, middle-captured, 3rd, this one.

    else
    {

    // Display(("\n lock========%d",err));
    if( (lock==false))
    {

    // Display(("\n ibp is working"));
    lock=true;
    err=AO_SENSORE_ATTACHED;
    // Display(("\nx_2========%d",err));

    ErrorHandler( true,4 );
    }

    }

    }// end of for loop, 1st try 3bytes are recieved.

    //Display(("\nx_2========%d",x_2));

    }//function

    return(value); // return 3 byte/ structure.

    }


    /*************************************************************
    * Function: ibp_exec()
    *
    * Description: This is called from the scheduling algorithm. This is the main function in IBP.c
    * After self test is finished, this will be called to collect-
    * 1- ibp data, 2- form data packet, 3- call a function to send data packet via bluetooth, 4- wake up from stand-by mode
    * But in this function, only stand-by will actually happen. other things are happened from this function by this function
    * making function calls to execute other points: 1,2,3 happen.
    *
    * Parameters: NULL
    *
    * Returns: NULL
    *
    * Reentrancy: Yes. Every 10ms
    *
    * Execution Requirements/Assumptions: NULL
    *
    *************************************************************/


    void ibp_exec()
    {

    bool emc_issue=false;
    if(emc_issue==false)
    {
    err=ERR_PD_ATTACHED;
    ErrorHandler( true,5 );
    Display(("\nibp_exec"));
    emc_issue=true;
    }

    struct hex_val x_1; // the 3 bytes structure of raw adc value will be collected here.

    if(self_test_indicator==true) // if self test is finished. when i am going inside standby_mode, then also i will make self test
    // as not finished.
    {
    send_data(ADS1248_CMD_RDATA); // 13h // to read data from adc ic register where adc conversion happened.
    receive_data(1); // receive junk data (from ssi comm'n') which i explained in above in this file.
    send_data(ADS1248_CMD_NOP); // 3 byte ADC. So, send 3 8bit clock via ssi communication.
    send_data(ADS1248_CMD_NOP);
    send_data(ADS1248_CMD_NOP);
    x_1=receive_data1(3); //------here is where actual adc data is received from ssi communication

    bt_transmit(x_1); // transmit the data via bluetooth to tablet.( get ibp single data from 3 bytes, form data packet,
    // send the data packet via bluetooth.
    }


    }


    /*************************************************************
    * Function: bt_transmit()
    *
    * Description: This function will 1-get two bytes from 3 bytes of raw adc value. 2- form data packet,
    * 3- calls a function(which is in sppdemo.c) to send data via bluetooth communication.
    *
    * Parameters: Takes the 3 byte structure of ibp raw adc data as argument.
    *
    * Returns: NULL
    *
    * Reentrancy: Yes
    *
    * Execution Requirements/Assumptions: NULL
    *
    *************************************************************/

    void bt_transmit(hex_value x)
    {
    uint8_t var=0;
    int crc=0,crc1=0; //WARNING----- DO NOT INTERCHANGE THIS AND BELOW THIS ONE. IF IT IS NOT IN THIS ORDER, YOU WILL
    uint8_t crc_i=0;

    Display(("\n bt_transmit"));

    static int seq;


    //--------------------------------------forming data packet-----------------------------------


    for(var=0;var<DATA_PACKET_SIZE;var++) // to form 6 byte data-packet format
    {
    switch(var)
    {
    case 0: //indication bit whther it's data or command.

    data[var]=PACKET_DATAS; // 0 indicates, it's data ( for command=1)

    //Display(("\nressult[var] , var0=%d--> %d",var,data[var]));
    break;

    case 1: //for rjc msb

    data[var]= SPPLEBuffer[var-1];
    Display(("\nresult[var] , var1--> %d",data[var]));

    break;

    case 2: //for rjc lsb

    data[var]= SPPLEBuffer[var-2];
    Display(("\nresult[var] , var2--> %d",data[var]));
    break;

    case 3: //for ibp middle. ignore ibp MSB

    data[var]=x.Parameters[1];
    // Display(("\nresult[var] , var3=%d-->",data[var]));

    break;

    case 4: //ibp LSB

    data[var]=x.Parameters[2];
    // Display(("\nresult[var] , var4=%d---->",data[var]));

    break;

    case 5: // for keypad- register 01

    data[var]=0x22; //-otherwise, if it doesnt go to any 'if--else' condition, junk value will be there.
    //-95=ff^ENC KEY --3-4-18

    // Display(("\nresult[var] , var5=%d---->",data[var]));

    break;

    case 6: //for keypad register= 00.
    data[var]=0x54;
    // Display(("\nresult[var] , var6=%d---->",data[var]));


    break;

    case 7: // for error codes

    data[var]=err;
    if(data[var]!=0)
    {
    //Display(("\n-------------------------- came ----------------err= %x\n",data[var]));
    //Display(("\n,--err=dec= %d\n",data[var]));
    }

    // Display(("\nresult[var] , var7=%d---->",data[var]));

    err=0;
    break;

    case 8: // for sequence numbers

    data[var]=seq;


    seq++; // it will go from 0 to 124
    if(seq==125)
    {
    seq=0;
    }
    // Display(("\nresult[var] , var8=%d---->",data[var]));

    break;

    case 9: // for checksum.

    data[var]=0x55;

    // Display(("\nresult[var] , var9=%d---->",data[var]));

    for(crc_i=0;crc_i<9;crc_i++) // not 9 because not including this crc byte for crc calculation. only previous 8 bytes
    {
    crc=crc+data[crc_i];
    }
    if(crc > 255) // refer software document for forumla calculation
    {
    crc1=crc/256;
    crc1=crc1*256;
    crc=crc-crc1;
    data[var]=crc;
    //Display(("\nresult[var]=%d\n",data[var]));
    }
    else
    {
    data[var]=crc;
    }

    break;

    default:

    break;
    }
    //Display(("\nresult--[var] , var=%d--> %x",var,data[var]));
    }


    //------------------------------ sending to bluetooth---------------------------

    ProcessCommandLine1(data,DATA_PACKET_SIZE); // this is in line 4307 in sppdemo.c
    ProcessCommandLine3();
    }

    /*************************************************************
    * Function: ibp_self_test()
    *
    * Description: This is the self test of IBP board called during warmup
    * from Main.c.
    *
    * Parameters: NULL
    *
    * Returns: value indicating whether self test is passed or failed.
    *
    * Reentrancy: Yes. During self_Test, and till self test finishes, this will keep on executing.
    *
    * Execution Requirements/Assumptions: NULL
    *
    *************************************************************/


    bool ibp_self_test() //checking for id of adc. if id returned =90H, then correct ID.so self test of ibp=ok
    {
    // Display(("\n ibp_self_test"));


    uint32_t pui32DataRx[NUM_SSI_DATA];
    send_data(ADS1248_CMD_ID);
    send_data(ADS1248_CMD_WAKEUP);
    receive_data(2);
    //Display(("\n ---------ibp\n"));
    send_data(ADS1248_CMD_NOP);
    SSIDataGet(SSI2_BASE, &pui32DataRx[0]);
    pui32DataRx[0] &= 0x00FF;
    //Display(("\n ---ibp======%x\n", pui32DataRx[0]));

    if(pui32DataRx[0]==ADC_ID)
    {
    //ErrorHandler( true,3 );
    return(true);// correct
    }
    else
    {
    //ErrorHandler( false,3 );
    return(false);// not ok
    }
    }

  • Hello Jansi,

    We do not provide full code reviews and the code you posted exceeded what can be posted as plain text on the forums. For large code files you need to attach them as .c files.

    For details on how to check data in your code, please refer to the following guide on how to watch variables and expressions in Code Composer Studio: https://software-dl.ti.com/ccs/esd/documents/users_guide/ccs_debug-main.html#watching-variables-expressions-and-registers

    Best Regards,

    Ralph Jacobi