24.5.2 Read Register Code Example

// Read BiSS C Register Data 
    int registerValue; // Variable to store register value
    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 = 0x00; // Setting the Client ID for Channel 0, in this case the Client ID is 0x00 
    B1CTRLCONbits.CMDCLNTID21 = 0b00;

    // Setup for Register Read
    B1CTRLCONbits.CTS = 1; // Setting CTS for Register 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

    // Asserting BiSS Communication 
    B1CONbits.ON = 1; // Turn on the BiSS Module
    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 assert a register read
    while(B1CONbits.INSTRWA == 1);        // Waiting for instruction to complete before any further write to instruction register
    // Waiting for Valid Receive

    while(B1STATbits.EOT == 0);          // Waiting for the End of Transmission status bit to confirm receive has occurred
    while(B1STATbits.CLSCDV0 == 0);      // Waiting for the Client SCD Valid bit to confirm a successful receive has occurred
    while(B1STATbits.REGEND == 0);       // Waiting for the register receive to complete
    registerValue = B1RDATA0;            // Saving register value to a variable