cancel
Showing results for 
Search instead for 
Did you mean: 

How to receive SPI data from MAX31855 with Nucleo WB55 ?

LVolp.2
Associate II

Hello,

I use a Nucleo WB55 and I would like to receive temperature data from MAX31855.

The protocol used is SPI.

1) Connections

Firstly I tested the MAX31855 with an Arduino and I managed to get data. I used the same MAX31855 and double-checked the wires between the Nucleo and the MAX and this seems good. I chose SPI1 (NSS = PA4 / SCK = PA5 / MISO = PA6).

0693W00000Y7TCrQAN.png 

I think that these connections are right.

2) SPI mode

Regarding the MAX chronogram, I think that the right mode is 0.

0693W00000Y7TG3QAN.png3) Configuration file IOC

0693W00000Y7THuQAN.png 

Data Size is limited to 16 bits but the MAX sends 32bits. Is it ok if I use twice HAL_SPI_Receive_DMA() ?

(Full code is available at point 4)

uint8_t pData1[2] = {0};
uint8_t pData2[2] = {0};
 
...
 
HAL_SPI_Receive_DMA(hspi, pData1, 2);
HAL_SPI_Receive_DMA(hspi, pData2, 2);

SCK Rise and Fall time is 200ns. so I made this operation to find the baud rate :

Baud Rate = 1 bit / SCK Rise and Fall time = 1/(200 x 10^-9) = 5 x 10^-6 = 5Mbits/s 

In IOC file, the maximum baud rate (Prescaler = 2) is 2Mbits/s which is not enough.

How can I set a good baud rate?

DMA configuration :

0693W00000Y7TNYQA3.png 

4) Code

main.c :

int main(void)
{
  HAL_Init();
 
  SystemClock_Config();
 
  PeriphCommonClock_Config();
 
  MX_GPIO_Init();
  MX_DMA_Init();
  MX_SPI1_Init();
 
  /* USER CODE BEGIN WHILE */
  //LED2 OFF
  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_RESET);
 
  HAL_StatusTypeDef status;
 
  while (1)
  {
    /* USER CODE BEGIN 3 */
 
	  status = HAL_SPI_Init(&hspi1);
	  blinkLed2();
 
	  Get_SPI1_DMA_Data(&hspi1);
	  blinkLed2();
  }
  /* USER CODE END 3 */
}

spi.h :

#ifndef INC_SPI_H_
#define INC_SPI_H_
#include "stm32wbxx_hal.h"
 
#define SPI_SCK_PIN   GPIO_PIN_5
#define SPI_MISO_PIN  GPIO_PIN_6
#define SPI_CS_PIN    GPIO_PIN_4
 
#define SPI_GPIO_PORT GPIOA
 
void blinkLed2(void);
void Get_SPI1_DMA_Data(SPI_HandleTypeDef *hspi);
void Get_SPI1_Polling_Data(SPI_HandleTypeDef *hspi);
 
#endif /* INC_SPI_H_ */

spi.c :

#include "spi.h"
#include "main.h"
 
uint8_t overflow = 0;
uint8_t pData1[2] = {0};
uint8_t pData2[2] = {0};
 
void blinkLed2(void)
{
	HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_RESET);
	HAL_Delay(500);
	HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_SET);
	HAL_Delay(500);
	HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_RESET);
	HAL_Delay(500);
	HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_SET);
	HAL_Delay(500);
	HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_RESET);
	HAL_Delay(500);
}
 
void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef *hspi)
{
	overflow = 1;
}
 
void Get_SPI1_DMA_Data(SPI_HandleTypeDef *hspi)
{
	HAL_GPIO_WritePin(SPI_GPIO_PORT, SPI_CS_PIN, GPIO_PIN_RESET);
	//HAL_Delay(500);
 
	HAL_SPI_Receive_DMA(hspi, pData1, 2);
 
	HAL_SPI_Receive_DMA(hspi, pData2, 2);
	HAL_Delay(500);
 
	HAL_GPIO_WritePin(SPI_GPIO_PORT, SPI_CS_PIN, GPIO_PIN_SET);
	HAL_Delay(500);
 
	if (overflow == 1)
	{
		//[32:18] = Temp
		//[17] = Reserved, always 0
		//[16] = 0(OK)/1(Fault)
		//[15:4] = Cold junction temp
		//[3] = Reserved, always 0
		//[2] = 0(OK)/1(SCV Fault = Short-circuited to VCC)
		//[1] = 0(OK)/1(SCG Fault = Short-circuited to GND)
		//[0] = 0(OK)/1(OC Fault = Open thermocouple)
	}
	overflow = 0;
 
}

Have a nice day

Laora

1 REPLY 1
LVolp.2
Associate II

 I forgot to show the data output :

0693W00000Y7TZ5QAN.png 

Here is the data mapping :

0693W00000Y7TZFQA3.png