MAX31865 Reading zeros with Fault status register 0x00

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Sunny_Sky
 
Posts: 3
Joined: Wed Dec 07, 2022 11:55 pm

MAX31865 Reading zeros with Fault status register 0x00

Post by Sunny_Sky »

Hello, there:
I am using ATmega256 (usartA0)to read temperature from MAX31865 with a 2 wired pt100. The msb and lsb are zeros.
The pt100 is measured 108ohms. Then I used a 118ohms resistor, it still reads zero. I took the resistor out, leave it break, it still reads zero.

I tried both one-shot, or automode, it does not change anything. The basic codes are listed below. I have stuck with this max31865 for a week now. Really run out of ideas now.
Any advice will help? Thanks a lot.


Code: Select all


#define USART_MAX3186			&USARTA0
#define MAX3186_0_CS		IOPORT_CREATE_PIN(PORTB,4)  //1   E,3;D,7
#define MAX3186_1_CS		IOPORT_CREATE_PIN(PORTB,2)  //D,5
#define MAX3186_DRDY0       IOPORT_CREATE_PIN(PORTB,5)  //3
#define MAX3186_DRDY1       IOPORT_CREATE_PIN(PORTB,6) //4


//Registers defined in Table 1 on page 12 of the datasheet
#define READ_CONFIGURATION		0x00 //0b00000000	// 0x00H
#define WRITE_CONFIGURATION		0x80 //0b10000000	// 0x80H
#define READ_RTD_MSB			0x01 //0b00000001	// 0x01H
#define READ_RTD_LSB			0x02 //0b00000010	// 0x02H

#define READ_HIGH_FAULT_TRESHOLD_MSB	0x03 //0b00000011	// 0x03H
#define WRITE_HIGH_FAULT_TRESHOLD_MSB	0x83 //0b10000011	// 0x83H
#define READ_HIGH_FAULT_TRESHOLD_LSB	0x04 //0b00000100	// 0x04H
#define WRITE_HIGH_FAULT_TRESHOLD_LSB	0x84 //0b10000100	// 0x84H
#define READ_LOW_FAULT_TRESHOLD_MSB	    0x05 //0b00000101	// 0x05H
#define WRITE_LOW_FAULT_TRESHOLD_MSB	0x85 //0b10000101	// 0x85H
#define READ_LOW_FAULT_TRESHOLD_LSB	    0x06 //0b00000110	// 0x06H
#define WRITE_LOW_FAULT_TRESHOLD_LSB	0x86 //0b10000110	// 0x86H
#define FAULT_STATUS                    0x07 //0b00000111	// 0x07H

#define CONFIG_FAULTSTAT                0x02 //0b0000 0010 set D1 in the configuration reg. to clear all faults

void max_clear_fault(uint8_t max3186_pt_id)
{
	uint8_t config;
    /*"""Clear any fault state previously detected by the sensor."""*/
	   	usart_spi_select_device(USART_MAX3186, &max3186[max3186_pt_id]);
	   	/*Write RTD DATA register*/
	   	usart_spi_write_packet(USART_MAX3186,&READ_CONFIGURATION_ADDRESS,1); 
		usart_spi_read_packet(USART_MAX3186,&config,1);
		usart_spi_deselect_device(USART_MAX3186, &max3186[max3186_pt_id]);
		config &= ~0x2C;
	    config |= CONFIG_FAULTSTAT;
	   	usart_spi_select_device(USART_MAX3186, &max3186[max3186_pt_id]);
	   	/*Write RTD DATA register*/
	   	usart_spi_write_packet(USART_MAX3186,&WRITE_CONFIGURATION_ADDRESS,1);
	   	usart_spi_write_packet(USART_MAX3186,&config,1);
	   	usart_spi_deselect_device(USART_MAX3186, &max3186[max3186_pt_id]);
}
void max_config_one_shot(uint8_t max3186_pt_id)
{
	uint8_t config;
	/*"""Clear any fault state previously detected by the sensor."""*/
	usart_spi_select_device(USART_MAX3186, &max3186[max3186_pt_id]);
	usart_spi_write_packet(USART_MAX3186,&READ_CONFIGURATION_ADDRESS,1);
	usart_spi_read_packet(USART_MAX3186,&config,1);
	usart_spi_deselect_device(USART_MAX3186, &max3186[max3186_pt_id]);
	delay_us(10);
	config|=CONFIGURE_ONE_SHOT[1];
	usart_spi_select_device(USART_MAX3186, &max3186[max3186_pt_id]);
	usart_spi_write_packet(USART_MAX3186,&WRITE_CONFIGURATION_ADDRESS,1);
	usart_spi_write_packet(USART_MAX3186,&config,1);
	usart_spi_deselect_device(USART_MAX3186, &max3186[max3186_pt_id]);
}

void max_config_automode(uint8_t max3186_pt_id)
{
	uint8_t config;
	/*"""Clear any fault state previously detected by the sensor."""*/
	usart_spi_select_device(USART_MAX3186, &max3186[max3186_pt_id]);
	usart_spi_write_packet(USART_MAX3186,&READ_CONFIGURATION_ADDRESS,1);
	usart_spi_read_packet(USART_MAX3186,&config,1);
	usart_spi_deselect_device(USART_MAX3186, &max3186[max3186_pt_id]);
	delay_us(10);
	config|=CONFIGURE_AUTOMODE[1];
	usart_spi_select_device(USART_MAX3186, &max3186[max3186_pt_id]);
	usart_spi_write_packet(USART_MAX3186,&WRITE_CONFIGURATION_ADDRESS,1);
	usart_spi_write_packet(USART_MAX3186,&config,1);
	usart_spi_deselect_device(USART_MAX3186, &max3186[max3186_pt_id]);
}
// Reading data from max
uint16_t max_get_data(uint8_t max3186_pt_id,ioport_pin_t DRDY_PIN)
{
	/*
		In normal operation function returns RTD or temperature multiplexed by 10
		If new conversion result is not available - DRDY is high, wait to ready
	*/
	
	uint8_t lsb_rtd, msb_rtd;
	uint8_t DRDY_state;

	uint16_t RTD, lmsb;

	while(DRDY_state){DRDY_state=ioport_get_pin_level(DRDY_PIN);} 

	usart_spi_select_device(USART_MAX3186, &max3186[max3186_pt_id]);
	/*Write RTD DATA register*/
	usart_spi_write_packet(USART_MAX3186,&READ_RTD_MSB_ADDRESS,1);
	/*Read out ODR register*/
// 	usart_spi_read_packet(USART_MAX3186,&msb_rtd,1);	
//	delay_us(1);

// 	usart_spi_write_packet(USART_MAX3186,&READ_RTD_LSB_ADDRESS,1);
// 	/*Read out ODR register*/
//  	usart_spi_read_packet(USART_MAX3186,&lsb_rtd,1);
// 	delay_us(1);
	usart_spi_read_packet(USART_MAX3186,&lmsb,2);
	/*Pull chip select high to finish SPI transfer*/
	usart_spi_deselect_device(USART_MAX3186, &max3186[max3186_pt_id]);
	_delay_ms(1);
	
	
// 	msb_rtd=lmsb>>8;
// 	lsb_rtd=lmsb&0xFF;
	

// 		lsb_rtd = max_spi_read(READ_RTD_LSB);
// 		msb_rtd = max_spi_read(READ_RTD_MSB);

//		RTD = (msb_rtd << 7)+((lsb_rtd & 0xFE) >> 1);

//		RTD =((lmsb<<8)|((lmsb>>8)&0xFE))>>1;
//		RTD = (msb_rtd << 8)+lsb_rtd;		
		RTD=lmsb;
			
		// Basic temperature calculation, the accuracy for temperatures 
		// between -75°C - 100°C is max +-1.5°C
		
//	*temperature = (float) RTD / 32 - 256; //(10*RTD)>>5 - 2560;	// (10*RTD>>5) - 2560; //RTD / 32 - 256
 }


/*Initializes accelerometer by setting the operating mode and testing the port for proper data output*/
uint8_t initialize_max3186_pt1000(uint8_t max3186_pt_id)
{
	uint8_t conf=0;

	max3186[max3186_pt_id].id = max3186_ids[max3186_pt_id];
	/*If the system is configured using , set up the devices with a SPI mode 3 clock (CPOL 1, CPHA 1) as specified in the datasheet*/
	usart_spi_setup_device(USART_MAX3186,&max3186[max3186_pt_id],CPOL_1_CPHA_1, MAX3168_BAUD_RATE,&max3186[max3186_pt_id].id);
	delay_us(1);
	
		max_clear_fault(max3186_pt_id);
		
		usart_spi_select_device(USART_MAX3186, &max3186[max3186_pt_id]);
		usart_spi_write_packet(USART_MAX3186,&CONFIGURE_BIAS,2);		//TURN ON BIAS	
		usart_spi_deselect_device(USART_MAX3186, &max3186[max3186_pt_id]);	
		_delay_ms(15);  //wait for max to power up and stablize 11.5ms
		
		max_config_automode(max3186_pt_id);
	
		_delay_ms(65);	
				
		// Reading Configuration register to verify communication	
		usart_spi_select_device(USART_MAX3186, &max3186[max3186_pt_id]);
		/*Write address ofReading*/
		usart_spi_write_packet(USART_MAX3186,&READ_CONFIGURATION_ADDRESS,1);
		/*Read out configuration register*/
		usart_spi_read_packet(USART_MAX3186,&conf,1);
		watch_conf=conf;
		/*Pull chip select high to finish SPI transfer*/
		usart_spi_deselect_device(USART_MAX3186, &max3186[max3186_pt_id]);		
		
		if((conf & 0b10000000)==0x80)
		{
			return 1;
		}
		else
		{
			return 0;
		}		
		
}

/*Reads max31865*/
void measure(float *temperature_measured)
{
	uint16_t RTDM;
	uint8_t max_connected, conf, conf1, Fault_Error;
	float pt1000_temp;
	ioport_configure_pin(max3186_ids[0],IOPORT_DIR_OUTPUT|IOPORT_INIT_HIGH|IOPORT_MODE_PULLUP);
 	ioport_configure_pin(max3186_ids[1],IOPORT_DIR_OUTPUT|IOPORT_INIT_HIGH|IOPORT_MODE_PULLUP);
	ioport_configure_pin(MAX3186_DRDY0,IOPORT_DIR_INPUT|IOPORT_INIT_LOW|IOPORT_MODE_PULLDOWN);
	ioport_configure_pin(MAX3186_DRDY1,IOPORT_DIR_INPUT|IOPORT_INIT_LOW|IOPORT_MODE_PULLDOWN);		
	/*Initialize USART SPI Options*/
	usart_opts.baudrate = USART_SPI_BAUDRATE;		//Baud rate 
	usart_opts.data_order = 0;						//Standard-ordered data
 	usart_opts.spimode = CPOL_1_CPHA_1;	//Clock polarity set to "base state high" and clock phase set to "capture on rising edge"
	/*Initialize SPI using options set above*/
	usart_init_spi(USART_MAX3186,&usart_opts);
	
	/*Enable USART Module for data collection using SPI.*/
	usart_spi_enable(USART_MAX3186);
	
	/*Wait for Max31865 to boot*/
	_delay_ms(65);
	
	/*Model-specific parameter initialization*/
	for(int i=0;i<NUM_TEMP_SENSORS;i++)
	{
		max_connected=initialize_max3186_pt1000(i);
		
		if(max_connected==0)  
			{
// 				 /*if not connected, then clear fault, and re-initialize it* / 			
					initialize_max3186_pt1000(i);// Initializes communication with max
			}


			RTDM=max_get_data(i, MAX_DRDY[i]);
//			RTD=(RTD>>8)|(RTD<<8);
			
		 if ((RTDM & 0x01) == 0)	// No fault
			 {
				//RTD = (msb_rtd << 7)+((lsb_rtd & 0xFE) >> 1);
				temperature_measured[i]=(float) (RTDM>>1) / 32 - 256 +t_offset[i];
			 }
			 // Any fault have been detected
			 else
			 {
				temperature_measured[i] = 88.88;
				
					// Reading Configuration register to verify communication	
				usart_spi_select_device(USART_MAX3186, &max3186[i]);
					/*Write address ofReading*/
				usart_spi_write_packet(USART_MAX3186,&CONFIGURE_FAULT,1);
					/*Read out configuration register*/
				usart_spi_read_packet(USART_MAX3186,&conf,1);
				Fault_Error=conf;
					/*Pull chip select high to finish SPI transfer*/
				usart_spi_deselect_device(USART_MAX3186, &max3186[i]);
			}
		}
}

User avatar
adafruit_support_carter
 
Posts: 29168
Joined: Tue Nov 29, 2016 2:45 pm

Re: MAX31865 Reading zeros with Fault status register 0x00

Post by adafruit_support_carter »

Are you using an Adafruit MAX31865 breakout?
https://www.adafruit.com/product/3328

If so, have you tried using it per the guide?
https://learn.adafruit.com/adafruit-max ... amplifier/

User avatar
Sunny_Sky
 
Posts: 3
Joined: Wed Dec 07, 2022 11:55 pm

Re: MAX31865 Reading zeros with Fault status register 0x00

Post by Sunny_Sky »

Thanks, Carter:
yes, I use the adafruit breakout board. I did read your guideline and datasheet carefully. It worked for my other mcu (attiny816) a while ago. Now I need to use atmega256 for wireless communication. But I cann't figure out where is the problem.

User avatar
adafruit_support_carter
 
Posts: 29168
Joined: Tue Nov 29, 2016 2:45 pm

Re: MAX31865 Reading zeros with Fault status register 0x00

Post by adafruit_support_carter »

Try running the example Arduino sketch from the guide on the MEGA.

User avatar
Sunny_Sky
 
Posts: 3
Joined: Wed Dec 07, 2022 11:55 pm

Re: MAX31865 Reading zeros with Fault status register 0x00

Post by Sunny_Sky »

Hi, Carter, thank you very much.
I tried arduino uno and used the max31865 library and sketch. It works fine.
Is there anyway I can see the original code from the library so that I can migrate to atmega256?

User avatar
adafruit_support_carter
 
Posts: 29168
Joined: Tue Nov 29, 2016 2:45 pm

Re: MAX31865 Reading zeros with Fault status register 0x00

Post by adafruit_support_carter »

The library code is here:
https://github.com/adafruit/Adafruit_MAX31865

It shouldn't require any modifications for use with a Mega though. Just need to select the correct board in the Arduino IDE.

Locked
Please be positive and constructive with your questions and comments.

Return to “General Project help”