0

I am using STM32F767ZI nucleo board. I have configured SPI with 750kBits/sec. I have tested the hardware connections for max31856 and they are good. I ran a mBed code to test the Max31856 and it works well and sends the correct temperature. But I am not able to replicate that with HAL libraries - STM32CubeIDE alone with Max31856.

I am sending 0xFD to CR0 address and I am receiving 0x7e. I am sending 0x04 to CR1 address and I am receiving 0x02. I feel I am seeing a missing bit - LSB while receiving it or while sending it. I am not sure where the missing bit happens. I have tested with 0x08 and I get back 0x04. It looks like a clock or timing issue in my code. My code below.

https://gist.github.com/jayaram12391/31e060bd7fb97092cc3bf4eddcb7dadf

Any suggestions appreciated.

Jayaram
  • 21
  • 2
  • It might be a pointer issue, on line 55: `HAL_SPI_Receive(&hspi1, &read_data[0], 1, 100);`. – rel Feb 23 '21 at 08:46
  • The dropped bit is likely caused by running SPI comms to Max31856 in an unsupported mode. According to Max31856's datasheet the only modes supported are modes 1 (CPOL=0, CPHA=1) and 3 (CPOL=1,CPHA=1). It is likely that you are initialising the interface to operate in modes 0 or 2, are you able to share the interface initialisation configuration you are using? Have you checked to see both the mBed code and the STM Hal based code setup the interface in the same mode? – Anakin Feb 24 '21 at 09:24
  • I changed the &read_data[0] to &read_data and later read the value as read_data[0]. Please check the full code in the link. I have initialized SPI as CPOL = HIGH and CPHASE = 1 EDGE. Thanks. https://gist.github.com/jayaram12391/31e060bd7fb97092cc3bf4eddcb7dadf – Jayaram Feb 24 '21 at 21:32
  • If you want to pass a pointer to the first element of an uint8_t array, either get the address of the first element (i.e. `&read_data[0]`) or simply pass `read_data` (which is less explicit). - `(uint8_t *)&read_data` is not going to work, it will result in the "address of the that pointer" (in the updated example on line 122). – rel Feb 27 '21 at 16:15
  • I looked at Hal_SPI_Receive and its definition is HAL_SPI_Receive(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size, uint32_t Timeout) where the read_data that i send needs to be an address. I think I am not clear on the pointer concept and I need to go through it. Thanks. – Jayaram Mar 01 '21 at 22:23
  • Anakin - You were right. I had it in mode 0 instead of mode 1 and now it works. Thanks. – Jayaram Mar 02 '21 at 22:16

0 Answers0