MAX6675

Hello guys this is my first bug report,
I just built my own 3d printer with a max6675 thermocouple and found out that there are some troubles.
In the Extrudder.cpp the method "read_max6675":

#ifdef SUPPORT_MAX6675
int16_t read_max6675(uint8_t ss_pin)
{
int16_t max6675_temp = 0;
HAL::spiInit(1);
HAL::digitalWrite(ss_pin, 0); // enable TT_MAX6675
HAL::delayMicroseconds(1); // ensure 100ns delay - a bit extra is fine
max6675_temp = HAL::spiReceive(0);
max6675_temp <<= 8;
max6675_temp |= HAL::spiReceive(0);
HAL::digitalWrite(ss_pin, 1); // disable TT_MAX6675
return max6675_temp & 4 ? 2000 : max6675_temp &gt;&gt; 3; // thermocouple open?
}
#endif

tries to hand over some parameters to the spiReceive() method, I changed it because the spiReceive() method doesn't want any parameters, also the SPI-BUS has not been enabled so I changed spiInit() to spiBegin().
There
are also some timing issues because the MAX6675 needs more time to
finish the temperature conversion, so I added the delays.
I think this leads to a slower processing speed and should be handled through an interrupt which starts a new conversion after the returning the current temperature. But that's to hard for an Arduino Beginner like me.

#ifdef SUPPORT_MAX6675
int16_t read_max6675(uint8_t ss_pin)
{
int16_t max6675_temp = 0;
HAL::spiBegin(); //activate spi Bus

HAL::digitalWrite(ss_pin,0);// initiate the conversion
HAL::delayMilliseconds(2);// wait 2ms till conversion finished
HAL::digitalWrite(ss_pin,1);// pull low to read result
HAL::delayMilliseconds(220);// wait 220ms till result in register

HAL::digitalWrite(ss_pin, 0); // enable TT_MAX6675
HAL::delayMicroseconds(1); // ensure 100ns delay - a bit extra is fine
max6675_temp = HAL::spiReceive(); //read higher byte
max6675_temp <<= 8;
max6675_temp |= HAL::spiReceive(); //read lower byte
HAL::digitalWrite(ss_pin, 1); // disable TT_MAX6675

return (max6675_temp & 4 ? 2000 : max6675_temp &gt;&gt; 3); // thermocouple open?
}
Sign In or Register to comment.