A device driver of MAX31855 Cold-Junction Compensated Thermocouple-to-Digital Converter for AVR. This code is a part of pAVRlib.
Requirement
-
wait.asm (a part of pAVRlib)
-
bin2bcd16.asm (a part of pAVRlib)
-
frac2bcd.asm (a part of pAVRlib)
The followings are also required if you use this program with USE_USART:
-
usart.asm (a part of pAVRlib)
-
usart-puthex.asm (a part of pAVRlib)
-
bin2ascii.asm (a part of pAVRlib)
How to use
Define F_CPU (frequency of CPU) and the port settings of CK (clock),
CS (chip select) and DO (data output) before you call the functions.
-
MAX_CK_DDR,MAX_CK_PORT,MAX_CK_PIN,MAX_CK -
MAX_CS_DDR,MAX_CS_PORT,MAX_CS_PIN,MAX_CS -
MAX_DO_DDR,MAX_DO_PORT,MAX_DO_PIN,MAX_DO
max31855-config.h will be included if you define USE_MAX31855_CONFIG.
For example:
#ifndef __MAX31855_CONFIG_H__
#define __MAX31855_CONFIG_H__
#define MAX_CK_DDR DDRD
#define MAX_CK_PORT PORTD
#define MAX_CK_PIN PIND
#define MAX_CK 7
#define MAX_CS_DDR DDRD
#define MAX_CS_PORT PORTD
#define MAX_CS_PIN PIND
#define MAX_CS 6
#define MAX_DO_DDR DDRD
#define MAX_DO_PORT PORTD
#define MAX_DO_PIN PIND
#define MAX_DO 5
#endif /* __MAX31855_CONFIG_H__ */Subroutine
In this section "TCTemp" means a thermocouple temperature and "IntTemp" an internal (cold-junction) temperature.
void MAX31855_INIT_PORTS() (in: (none), out: (none))
initializes the ports (pins).
You need define MAX_CK_DDR etc. (see above) before you call this function.
unsigned long MAX31855_READDATA() (in: (none), out: r25:r24:r23:r22)
read data from MAX31855 and returns a raw data. See the data sheet of MAX31855 for more details.
unsigned long MAX31855_FORMAT_TEMP(unsigned long rawdata) (in: r25:r24:r23:r22, out: r25:r24:r23:r22)
converts a MAX31855 raw data to 14 bit (12.2) and 12 bit (8.4) format temperatures. See also the data sheet of MAX31855.
-
r25:r24 : TCTemp
| D15 | D14 | D13 | … | D0 |
| Sign | Sign | MSB $2^{10}$ | … | LSB $2^{-2}$ |
-
r23:r22 : IntTemp
| D15 | D14 | D13 | D12 | D11 | D10 | … | D0 |
| Sign | Sign | Sign | Sign | Sign | MSB $2^{6}$ | … | LSB $2^{-4}$ |
unsigned long MAX31855_TCTEMP_BCD(unsigned int TCTemp) (in: r25:r24, out: r25:r24:r23:r22)
converts a TCTemp of 14 bit format to BCD. In r25:r24 will be stored the integer part of absolute value of TCTemp in BCD and in r23:r22 the fraction part of absolute value of TCTemp in BCD.
Example:
If you call this routine with r25:r24 = 0000 0001 1001 0011 (= +100.75), it will return r25:r24:r23:r22 = 0x01:0x00:0x75:0x00 (r22 is always 0x00).
unsigned long MAX31855_INTTEMP_BCD(unsigned int IntTemp) (in: r25:r24, out: r25:r24:r23:r22)
converts a IntTemp of 12 bit format to BCD. In r25:r24 will be stored the integer part of absolute value of IntTemp in BCD and in r23:r22 the fraction part of absolute value of IntTemp in BCD.
Example:
If you call this routine with r25:r24 = 0000 0110 0100 1001 (= +100.5625), it will return r25:r24:r23:r22 = 0x01:0x00:0x56:0x25.
void MAX31855_USART_TCTEMP(int TCTemp) (in: r25:r24, out: (none))
shows TCTemp via USART.
This routine will be assembled only when USE_USART is defined.
Note that
-
the leading 0s are not truncated, and
-
no newline will be sent.
void MAX31855_USART_INTTEMP(int IntTemp) (in: r25:r24, out: (none))
shows IntTemp via USART.
This routine will be assembled only when USE_USART is defined.
Note that
-
the leading 0s are not truncated, and
-
no newline will be sent.
Examples
../examples/max31855-test.asm
This program reads data from MAX31855 and shows the data via USART for each second.
See also: examples/README.org