Microchip Technology ARD00330 データシート

ページ / 480
 2010 Microchip Technology Inc.
Preliminary
DS39979A-page 291
PIC18F87J72 FAMILY
EXAMPLE 22-4:
WRITING AND READING AFE REGISTERS THROUGH THE MSSP
///////////////////////////////////////////////////////////////////////////////////////////////
// STEP 4: Write to AFE registers
// Initialize the AFE by writing to PHASE, GAIN, STATUS, CONFIG1 and CONFIG2 registers.
// Below is an example. The registers can be programmed with values as required
// by the application.
///////////////////////////////////////////////////////////////////////////////////////////////
LATDbits.LATD7=0;
//Chipselect enable for Delta Sigma ADC
if (SSPSTATbits.BF==1)
Dummy_Read=SSPBUF;
SSPBUF = 0x0E;
//Address and Write command for Gain Register
// A6-A5--->00;A4-A0---->0x07;R/W---0 for write
while(!SSPSTATbits.BF);
Dummy_Read=SSPBUF;
//Dummy read to clear Buffer Full Status bit
SSPBUF =0x00;
//PHASE Register: No Delay
while(!SSPSTATbits.BF);
Dummy_Read=SSPBUF;
SSPBUF =0x04;
//Address automatically incremented GAIN Register
//CH1 gain 16, CH0 gain 1, No Boost
while(!SSPSTATbits.BF);
Dummy_Read=SSPBUF;
SSPBUF = 0xA0;
//Address automatically incremented STATUS Register
//Default values
while(!SSPSTATbits.BF);
Dummy_Read=SSPBUF;
SSPBUF = 0x10;
//Address automatically incrementedData for CONFIG1 Register
//No Dither, Other values are default
while(!SSPSTATbits.BF);
Dummy_Read=SSPBUF;
SSPBUF = 0x01;
//Address automatically incremented Data for CONFIG2 Register
//CLKEXT bit should be always programmed to 1
while(!SSPSTATbits.BF);
Dummy_Read=SSPBUF;
LATDbits.LATD7=1;
//Disable chip select after read/write of each set of registers
///////////////////////////////////////////////////////////////////////////////////////////////
// Read from AFE registers to verify; this step is optional and does not affect AFE Operation.
// As an example, only GAIN, STATUS, CONFIG1 and CONFIG2 are read.
///////////////////////////////////////////////////////////////////////////////////////////////
LATDbits.LATD7=0;
//Chip select enable for AFE
SSPBUF = 0x11;
//Address and Read command for Gain Register
// A6-A5--->00;A4-A0---->0x08;R/W---1 for read
while(!SSPSTATbits.BF);
Dummy_Read=SSPBUF;
//Dummy read to clear Buffer Full Status bit
SSPBUF =0x00;
while(!SSPSTATbits.BF);
D_S_ADC_data1=SSPBUF;
//Data from GAIN Register
SSPBUF =0x00;
while(!SSPSTATbits.BF);
D_S_ADC_data2=SSPBUF;
//Data from STATUS Register, Address automatically incremented
SSPBUF =0x00;
while(!SSPSTATbits.BF);
D_S_ADC_data3=SSPBUF;
//Data from CONFIG1 Register, Address automatically incremented
SSPBUF = 0x00;
while(!SSPSTATbits.BF);
D_S_ADC_data4=SSPBUF;
//Data from CONFIG2 Register, Address automatically incremented
LATDbits.LATD7=1;
//Disable chip select after read/write of each set of registers