22.4.1 Sensor Communication Code Example
// Read BiSS C SCD Frame, Sensor Data int startupDelay; // Variable to read startup delay value into int sensorValue; // Variable to store sensor values 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.CRCLEN0 = 0b0000110; // Setting CRC polynomial to dedicated value, 0x43 B1CLTCON0bits.IDADISCLNTID0 = 0b0; // Setting the Client ID for Channel 0, in this case the Client ID is 0x00 B1CTRLCONbits. CMDCLNTID21 = 0b00; // 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 startupDelay = B1SCDATA0L; // Optional to read startup delay and save to variable B1INSTRbits.AGS = 1; // Starting automatic data transmission int i = 10; // Creating while loop to read sensor ten times while(i--){ sensorValue = B1SCDATA0L; // Reading sensor value into variable 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 }