24.5.5 Addressed Command Code Example

// Send Addressed Command
    B1CTRLCONbits.PROTOSEL = 1; // Setting the protocol selection to BiSS C 

    // Configuring Host Clock for BiSS Module
    B1CONbits.CLKDIV = 5;        // Setting CLKDIV divider
    B1CTRLCONbits.SFREQ = 5;     // Setting SFREQ divider
    B1CCONbits.FREQAGS = 0x7C;   // Setting FREQAGS to AGSMIN, host will automatically trigger another SCD cycle once the previous has finished

    // Configuring BiSS First Channel, Channel 0
    B1CTRLCONbits.CHSEL = 1;    // Setting CTRLCON such that 1st channel, Channel 0, is being used for communication
    B1CHCONbits.CLCHCFG0 = 1;   // Setting CLCHCFG0 such that 1st channel, Channel 0, is configured for BiSS C
    B1CLTCON0bits.SCDEN0 = 1;   // Enabling SCD data
    B1CLTCON0bits.SCDLEN0 = 29; // Configuring SCD data length, 28 data bits, 1 error bit, 1 warning bit 
    B1CLTCON0bits.CRCSEL0 = 0;  // Setting CRCSEL such that the CRC value will be calculated based on CRCLEN dedicated polynomial
    B1CLTCON0bits.CRCLEN0CRCPOLY0 = 0b0000110; // Setting CRC polynomial to dedicated value, 0x43
    B1CTRLCONbits.IDADISCLNTID0 = 0b1; // Setting the Client ID for Channel 0, in this case the Client ID is 0x01
    B1CTRLCONbits.CMDCLNTID21 = 0b00;

    // Setup for Addressed Command
    B1CTRLCONbits.CTS = 0;         // Setting CTS for Command communication
    B1RCCONbits.WNR = 0; // Setting WNR for Read Register
    B1RCCONbits.STRTADDR = 0x00;   // Start reading data at start address of 0x00 in BiSS Client
    B1RCCONbits.REGNUM = 0;        // Declare how many registers to read from the BiSS Client, 0 means read 1 register 
    B1CTRLCONbits.CMDCLNTID21 = 2; // Setting what command value to send, this should be described in Client documentation
    B1IDS0bits.IDS0 = 0x80;        // Setting the Client address for sending command 

    // Turning the module on and starting communication
    B1CONbits.ON = 1;
    B1INSTRbits.INIT = 1; // Initialize sequence which resets status registers and initializes a line delay sense 
    while(B1CONbits.INSTRWA == 1); // Waiting for initialization/instruction to complete before any further write to instruction register
    B1INSTRbits.AGS = 1; // Starting automatic data transmission 

    // Initializing Register Read
    while(B1STATbits.CDMTO == 0); // Waiting until CDM Time Out to Read Register
    B1INSTRbits.INSTR = 0b100; // Using INSTR code to send command(INSTR value is the same as read register command but CTS = 1 means send a command)
    while(B1CONbits.INSTRWA == 1); // Waiting for instruction to complete before any further write to instruction register