One clue(?): I found that I had to change the palmode for the SPI3 NSS pin - I had to remove the pushpull bit setting or I was getting bad data back.
Im trying to figure out how to debug this - stepping thru the spi_receive code didnt give me anything obvious. Any ideas? Init code is below.
Ugly debug oriented read code is below that (no flames about reading in single bytes - Im debugging
static const SPIConfig spi2cfg = { NULL,
/* HW dependent part.*/
SPI_GPIO2, 12, 0 };
static const SPIConfig spi3cfg = { NULL,
/* HW dependent part.
* Slave select is on pin 15 of GPIOA
*/
SPI3_CS_GPIO, SPI3_CS_PIN, 0 };
spiStart(&SPID2, &spi2cfg);
palSetPad(SPI_GPIO2, SPI2_CS_PIN);
palSetPadMode(SPI_GPIO2, SPI2_CS_PIN, PAL_MODE_OUTPUT_PUSHPULL |
PAL_STM32_OSPEED_HIGHEST); /* NSS. */
palSetPadMode(SPI_GPIO2, SPI2_SCK_PIN, PAL_MODE_ALTERNATE(5) |
PAL_STM32_OSPEED_HIGHEST); /* SCK. */
palSetPadMode(SPI_GPIO2, SPI2_MISO_PIN, PAL_MODE_ALTERNATE(5)); /* MISO. */
palSetPadMode(SPI_GPIO2, SPI2_MOSI_PIN, PAL_MODE_ALTERNATE(5) |
PAL_STM32_OSPEED_HIGHEST); /* MOSI. */
// init the thermocouple SPI driver. this is a max31855 chip
/*
* Initializes the SPI driver 3. The SPI3 signals are routed as follow:
* P - NSS. to pin 6 of 31855
* P - SCK. to pin 5 of 31855
* P - MISO. Master In Slave Out to pin 7 of 31855
* P - MOSI. - not connected to 31855
* red lead of thermocouple to pin 3 of 31855
* blue lead of thermocouple to pin 2 of 31855
*
*/
palSetPadMode(SPI3_CS_GPIO, SPI3_CS_PIN,
PAL_STM32_OSPEED_HIGHEST | PAL_MODE_ALTERNATE(6) ); /* NSS. */
palSetPad(SPI3_CS_GPIO, SPI3_CS_PIN);
palSetPadMode(SPI_GPIO3, SPI3_SCK_PIN, PAL_MODE_ALTERNATE(6) |
PAL_STM32_OSPEED_HIGHEST); /* SCK. */
palSetPadMode(SPI_GPIO3, SPI3_MISO_PIN, PAL_MODE_ALTERNATE(6)); /* MISO. */
palSetPadMode(SPI_GPIO3, SPI3_MOSI_PIN, PAL_MODE_ALTERNATE(6) |
PAL_STM32_OSPEED_HIGHEST); /* MOSI. */
// spiStart(&SPID3, &spi3cfg);
void readThermoCouple3(void)
{
static int8_t buf[4];
char c;
/* Read thermocouple data over SPI3.*/
spiStart(&SPID3, &spi3cfg);
spiSelect(&SPID3);
spiReceive(&SPID3, 1, buf); // 4th byte
c=buf[0];
headTemp=c; // 3rd byte of temp
headTemp=headTemp<<4;
// chprintf(chp,"%02X ",buf[0]); //delay
spiReceive(&SPID3, 1, buf); // 3rd byte
c=buf[0];
// chprintf(chp,"%02X ",buf[0]); //delay
spiFault=c;
spiFault&=1; // only want the low bit;
c=c>>4;
headTemp+=c;
spiReceive(&SPID3, 1, buf); // 2nd byte
c=buf[0];
spiIntTemp=c;
// chprintf(chp,"%02X ",buf[0]); //delay
spiReceive(&SPID3, 1, buf); // low byte
c=buf[0];
spiData=c;
spiData&=7;
// chprintf(chp,"%02X\r\n",buf[0]); //delay
spiUnselect(&SPID3);
spiStop(&SPID3);
}