22.4.3 Write Register Code Example
// Write BiSS C Register Data 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 B1CTRLCONbits.IDADISCLNTID0 = 0b0; // Setting the Client ID for Channel 0, in this case the Client ID is 0x00 B1CTRLCONbits. CMDCLNTID21 = 0b00; // Setup for Register Write B1CTRLCONbits.CTS = 1; // Setting CTS for Register communication B1RCCONbits.WNR = 1; // Setting WNR for Write Register B1RCCONbits.STRTADDR = 0x50; // Start writing data at start address of 0x50 in BiSS Client B1RCCONbits.REGNUM = 0; // Declare how many registers to write from the BiSS Client, 0 means read 1 register B1CONbits.TXRDEN = 1; // Setting the transmit RAM enable bit to enable transmission // 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 B1RDATA0 = 0x23; // Setting the desired register value to transmit // Initializing Register Write while(B1STATbits.CDMTO == 0); // Waiting until CDM Time Out to Write Register B1INSTRbits.INSTR = 0b100; // Using INSTR code to assert a register write while(B1CONbits.INSTRWA == 1); // Waiting for instruction to complete before any further write to instruction register // Waiting for Valid Transmissions while(B1STATbits.EOT == 0); // Waiting for the End of Transmission status bit to confirm transmission has occurred while(B1STATbits.CLSCDV0 == 0); // Waiting for the Client SCD Valid bit to confirm a successful transmission has occurred while(B1STATbits.REGEND == 0); // Waiting for the register transmission to complete
