Part Number: ADS8332EVM
Tool/software: TI C/C++ Compiler
Hi,
I'm wondering if I can get some input on my code for the ADS8332.
The first thing I'm learning to do is turning on the ADS8332, and initialising it's registers.
Does this look okay for writing to the CFR (bits 15:12 are 1110), and setting the CFR? I'm curious if there is anything I should do before this to wake it up after being un-powered.
void ADS_On(void) {
PORTA.OUTCLR = PIN0_bm; // Bring CS low
mspi_xchange(0b11101101); // Write to CFR, set CFR's auto-trigger mode
mspi_xchange(0b01111101); // Set channel select mode, no tag bits
PORTA.OUTSET = PIN0_bm; // Bring CS high
}
The next thing I'm wondering about is reading a value. First I've made a function to select the channel, and then I made a function to retrieve the data.
void Input_Channel (uint8_t channel) {
PORTA.OUTCLR = PIN0_bm; // Bring CS Low
mspi_xchange((channel<<4) | 0x0); // Write the desired channel to bits 15:12, and leave the rest of the bits as zero
mspi_xchange(0x00); // (rest of the don't care 12 bits)
PORTA.OUTSET = PIN0_bm; // Bring CS High
}
Here is where I retrieve the 16-bit data
uint16_t Read_Data (void) {
PORTA.OUTCLR = PIN0_bm; // Bring CS low
mspi_xchange(0b11010000); // Set CMR to "Read Data", rest of the 12 bits aka the 'don't care' bits are set to zero
mspi_xchange(0x00); // (don't care bits)
uint8_t msb = mspi_xchange(0x00); // Read MSB of ADC data
uint16_t fullData = msb | mspi_xchange(0x00); // Read LSB of data
PORTA.OUTSET = PIN0_bm; // Bring CS high
return fullData;
}
Very much appreciated the input, thanks.