835
/* Includes ------------------------------------------------------------------*/ #include "main.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ #include "Max31855.h" #include<stdio.h> #include<string.h> #include <math.h> /* Private variables ---------------------------------------------------------*/ SPI_HandleTypeDef hspi1; UART_HandleTypeDef huart1; /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); static void MX_GPIO_Init(void); static void MX_SPI1_Init(void); static void MX_USART1_UART_Init(void); int main(void) { /* USER CODE BEGIN 1 */ char MSG[100]="MAX31855 test\n\r"; char MSG0[100]="Initializing sensor...\n\r"; char MSG1[100]="ERROR\n\r"; char MSG2[100]="DON. \n\r "; char MSG3[100]="Thermocouple fault(s) detected!\n\r"; char MSG4[100]="FAULT: Thermocouple is open - no connections.\n\r"; char MSG5[100]="FAULT: Thermocouple is short-circuited to GND.\n\r"; char MSG6[100]="FAULT: Thermocouple is short-circuited to VCC.\n\r"; char MSG7[100]; char MSG8[100]; char MSG9[100]="$$***************************************$$\n\r"; char MSG10[100]; /* USER CODE END 1 */ HAL_Init(); SystemClock_Config(); MX_GPIO_Init(); MX_SPI1_Init(); MX_USART1_UART_Init(); /* USER CODE BEGIN 2 */ HAL_UART_Transmit(&huart1,(uint8_t*)MSG,sizeof(MSG), 100); HAL_UART_Transmit(&huart1,(uint8_t*)MSG0,sizeof(MSG0), 100); if (!begin()) { HAL_UART_Transmit(&huart1,(uint8_t*)MSG1,sizeof(MSG1), 100); while (1) HAL_Delay(10); } HAL_UART_Transmit(&huart1,(uint8_t*)MSG2,sizeof(MSG2), 100); /* USER CODE END 2 */ while (1) { sprintf(MSG10,"Internal Temp = %f \n\r",readInternal()); HAL_UART_Transmit(&huart1,(uint8_t*)MSG10, sizeof(MSG10), 100); double c = readCelsius(); if (!isnan(c)) { sprintf(MSG7,"C = %f \n\r",c); HAL_UART_Transmit(&huart1,(uint8_t*)MSG7, sizeof(MSG7), 100); sprintf(MSG8,"F = %f \n\r",readFahrenheit()); HAL_UART_Transmit(&huart1,(uint8_t*)MSG8, sizeof(MSG8), 100); HAL_UART_Transmit(&huart1,(uint8_t*)MSG9, sizeof(MSG9), 100); HAL_Delay(1000); } else { HAL_UART_Transmit(&huart1,(uint8_t*) MSG3, sizeof(MSG3), 100); uint8_t e = readError(); if (e & MAX31855_FAULT_OPEN) HAL_UART_Transmit(&huart1, (uint8_t*) MSG4, sizeof(MSG4), 100); if (e & MAX31855_FAULT_SHORT_GND) HAL_UART_Transmit(&huart1, (uint8_t*) MSG5, sizeof(MSG5), 100); if (e & MAX31855_FAULT_SHORT_VCC) HAL_UART_Transmit(&huart1, (uint8_t*) MSG6, sizeof(MSG6), 100); }}}