+ Post New Thread
Results 1 to 1 of 1
  1. #1
    Newbie level 3
    Points: 309, Level: 3

    Join Date
    Aug 2017
    Location
    Bangalore
    Posts
    4
    Helped
    0 / 0
    Points
    309
    Level
    3

    Can any one share max31865 RTD (PT1000) library for stm32?

    I am trying to read temperature data from sensor through SPI using max31865 module , i am not getting data i am using SPI11 pins for PA5 -SCK PA6 -SDO PA7 -SDI PB6 -CS Wired MAX31865 with PT1000 RTD 2 WIRE sensor properly,Please let me know if are there any mistakes in code to read data .Any help for this would be really appreciated .

    Code:

    Code C - [expand]
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    
    /* SPI TIMEOUT Value*/
      #define TIMEOUT_VAL                 60
     
     /* Read Register Address */
     #define REG_CONFIG                  0x00
     #define REG_RTD_MSB                 0x01
     #define REG_RTD_LSB                 0x02
     #define REG_HIGH_FAULT_THR_MSB      0x03
     #define REG_HIGH_FAULT_THR_LSB      0x04
     #define REG_LOW_FAULT_THR_MSB       0x05
     #define REG_LOW_FAULT_THR_LSB       0x06
     #define REG_FAULT_STATUS            0x07
     #define WR(reg)                 ( (reg) | 0x80 )
     
     
     SPI_HandleTypeDef hspi1;
     
     
     struct __attribute__((packed)) var_max31865
      {
       uint16_t rtd_res_raw;            // RTD IC raw resistance register
       uint8_t  status;                 // RTD status - full status code
       uint8_t  conf_reg;               // Configuration register readout
       uint16_t  HFT_val;               // High fault threshold register readout
       uint16_t  LFT_val;               // Low fault threshold register readout
       };
     
      struct var_max31865 rtd_data;
      uint8_t read_addr = 0x00; //Read address of Configuration register
      double Temperature,RTD;
      void MAX31865_full_read(void)
      {
      uint8_t read_data[8]; //variable to store the contents of the registers
      uint8_t i = 0; //loop variable
      CS_ENABLE
      HAL_SPI_Transmit(&hspi1, &read_addr, 1, TIMEOUT_VAL);
      for(i = 0; i < 8; i++)
        {
        HAL_SPI_Receive(&hspi1, &read_data[i], 1, TIMEOUT_VAL);
        }
     
       //   HAL_Delay(10);
       CS_DISABLE
       rtd_data.conf_reg = read_data[0]; //Store config reg data
       rtd_data.rtd_res_raw = ((read_data[1] << 8) | read_data[2]) >> 1; 
       rtd_data.HFT_val = ((read_data[3] << 8) | read_data[4]) >> 1; 
       rtd_data.LFT_val = (read_data[5] << 8) | read_data[6]; 
       rtd_data.status = read_data[7]; //Store fault status reg data    
        }
     
      int main(void)
       {
     
      uint8_t config_reg_write[] = {WR(REG_CONFIG), 0xC2}; //( 0x80 ,0xC2)
      //char Rrtd[30]; //array to print RTD resistance
      //char Trtd[30]; //array to print RTD temperature
      HAL_Init();
      /* Configure the system clock */
      SystemClock_Config();
      /* Initialize all configured peripherals */
      MX_GPIO_Init();
      MX_SPI1_Init();
      CS_ENABLE
      HAL_Delay(10); 
      HAL_SPI_Transmit(&hspi1, &config_reg_write[0], 1, TIMEOUT_VAL);
      HAL_SPI_Transmit(&hspi1, &config_reg_write[1], 1, TIMEOUT_VAL);
      CS_DISABLE
      HAL_Delay(100);
      while (1)
      {
      HAL_Delay(500);
      MAX31865_full_read();
      RTD = ((double)rtd_data.rtd_res_raw * 4700) / 32768; 
      HAL_Delay(2000);
      Temperature = ((double)rtd_data.rtd_res_raw / 32) - 256;
      // sprintf(Trtd, "Trtd = %lf deg C\n", tmp);
      // HAL_UART_Transmit(&huart2, (uint8_t *)Trtd, 30, TIMEOUT_VAL); 
      HAL_Delay(2000);  }
      }
    Last edited by FvM; 30th November 2017 at 12:38. Reason: Added syntax tags

    •   AltAdvertisement

        
       

--[[ ]]--