I am trying to read from an ADC chip http://www.ti.com/lit/ds/symlink/ads1232.pdf using SPI2 and I'm not having any success yet.
There is no need for MOSI, since the chip only spews out data. Also is it mandatory that I use the spiSelectI()? Going low on this line shuts down the ADC.
When I initiate the Receive routine from the serial shell, the DOUT(MISO) line goes high for a bit, but the SCK line only clocks out one pulse.
Any help or suggestions is greatly appreciated!!
My relevant code:
Code: Select all
/*
* SPI2 configuration structure.
* Speed 21MHz, CPHA=0, CPOL=0, 16bits frames, MSb transmitted first.
* The slave select line is the pin 12 on the port GPIOB.
*/
static const SPIConfig spi2cfg = {
spicb,
/* HW dependent part.*/
GPIOB,
12,
SPI_CR1_DFF
};
/*
* Initializes the SPI driver 2. The SPI2 signals are routed as follow:
* PB12 - NSS.
* PB13 - SCK.
* PB14 - MISO.
*/
palSetPadMode(GPIOB, 12, PAL_MODE_OUTPUT_PUSHPULL |
PAL_STM32_OSPEED_HIGHEST); /* NSS. */
palSetPadMode(GPIOB, 13, PAL_MODE_ALTERNATE(5) |
PAL_STM32_OSPEED_HIGHEST); /* SCK. */
palSetPadMode(GPIOB, 14, PAL_MODE_ALTERNATE(5) |
PAL_STM32_OSPEED_HIGHEST); /* MISO. */
palSetPad(GPIOB, 12);
spiStart(&SPID2, &spi2cfg);
static void cmd_adc(BaseSequentialStream *chp, int argc, char *argv[]) {
uint32_t value = 0;
uint16_t samples[2];
chprintf(chp, "Reading ADC\r\n");
//spiSelectI(&SPID2);
/* If data line goes low, data is ready */
while(palReadPad(GPIOB, GPIOB_SPI2_MISO));
/* Read 24bits of data, MSB First */
//chSysLockFromIsr();
spiStartReceiveI(&SPID2, 3, samples);
//chSysUnlockFromIsr();
//palSetPad(GPIOB, 13);
value = (samples[0] << 16) + samples[1];
/* Print ADC Data */
chprintf((BaseSequentialStream *)&SDU1, "ADC Result: %d\r\n", value);
return;
}
/*
* SPI end transfer callback.
*/
static void spicb(SPIDriver *spip) {
/* On transfer end just releases the slave select line.*/
chSysLockFromIsr();
//spiUnselectI(spip);
chSysUnlockFromIsr();
}