Hi everyone,
I am trying to read values from an 18-bit ADC using SPI and LPC54608.
I would like to know what would be the best way to read the values from the ADC.
Here is the code I wrote:
uint32_t readSPIvalueInitSPI4(){
return readSPIvalueInit2(&SPI4_InterruptDriverState);
}uint32_t readSPIvalueInit2(cmsis_spi_interrupt_driver_state_t *spi){
return readSPIvalue(spi->resource->base);
}uint32_t readSPIvalue(SPI_Type *base){
base->CFG |= (1 << 8); // polarity SSEL0 - active high
base->DLY |= (0x8 << 8); // End Of Frame delay - 8 clock times inserteduint32_t readFIFO = ADC_LT2336(base);
return readFIFO;
}
uint32_t ADC_LT2336(SPI_Type *base){
base->FIFOWR = 15 | 0xf0e0000; // data = 15 + Assert SSL0, de-assert SSL[1,2,3], no-EOT // (EndOfTransfer de-assert), length = 16
base->FIFOWR = 15 | 0x31e0000; // data = 15 + Assert SSL0, de-assert SSL[1,2,3], EOT (EndOfTransfer // de-assert), End Of Frame delay = 15 CLK, length = 4
uint_32_t read_MSB = base->FIFORD;
uint_32_t read_LSB = base->FIFORD;return read_MSB; // only returning the MSB because I don't need the last 2 bits
}
int main(void) {
uint32_t ADCvalue = readSPIvalueInitSPI4();
}
In the "ADC_LT2336(SPI_Type *base)" function, I am not sure whether I should read MSB before sending the second write command, or if I should do like in the code above (1st send the two write commands, and then two read commands).
If it can be of any help, the ADC I am using is the LTC2336 from Analog Devices, and here is the link to the datasheet of this ADC: http://www.analog.com/media/en/technical-documentation/data-sheets/233618fa.pdf
Thanks in advance,
Nathan Sowie
Hi,
The LPC54608 SPI function supports separate transmit and receive FIFOs with 8 entries each.
From your application, you only use two receive FIFO.
That will be ok for your both operations ( read MSB before sending the second write command, or 1st send the two write commands, and then two read commands).
Wish it helps.
Have a great day,
Mike
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hi,
Thank you for this answer, this will surely help !
Thanks,
Nathan