| 
	
	|  |  |  
	
		| View previous topic :: View next topic |  
		| Author | Message |  
		| JBM 
 
 
 Joined: 12 May 2004
 Posts: 54
 Location: edinburgh, Scotland
 
 
			    
 
 | 
			
				| MAX6675 driver |  
				|  Posted: Sun Feb 26, 2006 4:33 pm |   |  
				| 
 |  
				| Below is my driver for the MAX6675, a chip which interfaces to a K-type thermocouple over a simple SPI bus. 
 The driver implements a software SPI port, so there is no need for dedicateed hardware- any 3 GPIO pins can be used.
 
 Notice I am releasing this under the GPL, so make sure you understand what rights and responsibilites this gives you before including it in your own projects. It is free software (as in freedom), just make sure you abide by the terms of the lisence.
 
 -JBM
 
 
  	  | Code: |  	  | /**************************************************************************************
 *   max6675.c - communicates with a MAX6675 thermcouple interface chip                *
 *   Copyright Jimbob's Ma 2006                                                        *
 *                                                                                     *
 *   This program is free software; you can redistribute it and/or                     *
 *   modify it under the terms of the GNU General Public License                       *
 *   as published by the Free Software Foundation version 2                            *
 *   of the License.                                                                   *
 *                                                                                     *
 *   This program is distributed in the hope that it will be useful,                   *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of                    *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                     *
 *   GNU General Public License for more details.                                      *
 *                                                                                     *
 *   You should have received a copy of the GNU General Public License                 *
 *   along with this program; if not, write to the Free Software                       *
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.   *
 **************************************************************************************/
 
 /*
 This is a diver for the MAX6675 K-type thermocouple interface chip. It implements an SPI
 bus without the need for dedicated hardware (aka a bit-banged interface). The result from
 toFloat_TC() is the temperature in degrees celcius of the thermocouple tip. The rest should
 be self-evident. Have a look at the end of the file for example usage.
 */
 
 #ifndef TC_CLK
 #define TC_CLK               PIN_B1            //edit these pins as necessary
 #endif
 
 #ifndef TC_CS
 #define TC_CS               PIN_B2
 #endif
 
 #ifndef TC_DATA
 #define TC_DATA               PIN_B3
 #endif
 
 
 int1 thermocouple_error;         //a handy dandy global error flag to tell you if a thermocouple is connected or not
 
 void init_TC(void)
 {
 output_low(TC_CLK);
 output_low(TC_DATA);
 output_high(TC_CS);            //if we idle high, the chip keeps doing conversions. Change this if you like
 }
 
 int16 read_TC(void)               //It takes 200ms (ish) for the MAX6675 to perform a conversion
 {
 int8 i;
 int16 data;
 
 output_low(TC_CS);            //stop any conversion processes
 delay_us(1);               //and give it some time to power up (not very much, admittedly)
 
 for (i=0;i<16;i++){
 shift_left(&data,2,input(TC_DATA));      //reads in 2 bytes to data from the pin TC_DATA
 output_high(TC_CLK);
 output_low(TC_CLK);
 }
 
 thermocouple_error=bit_test(data,2);      //this is the thermocouple status bit
 
 output_high(TC_CS);
 return(data);
 }
 
 int16 sortout(int16 raw)
 {
 return(0x0FFF & (raw>>3));      //returns only the bits converning temperature
 }
 
 float toFloat_TC(int16 tmp)
 {
 return((float)tmp/4.0);      //adjusts data to floating point format, and accounts for the decimal point
 }
 
 float do_everything(void)
 {
 init_TC();
 delay_ms(200);               //200ms is a long time to be doing nothing. use a timer interrupt to avoid wasting time here
 return(toFloat_TC(sortout(read_TC())));
 }
 
 
 /*
 
 //example program
 
 #define TC_CLK               PIN_B2
 #define TC_CS               PIN_B2
 #define TC_DATA               PIN_B1
 
 #include "max6675.c"
 
 void main()
 {
 char msg[32];
 delay_ms(50);      //allow oscillator to stabilise
 
 while(1){
 delay_ms(800);
 sprintf(msg,"%01.2f%cC\r\n",do_everything(),0xB0);
 
 if(thermocouple_error)
 printf("Thermocouple not connected\r\n");
 else
 printf("%s",msg);
 }
 }
 
 */
 
 | 
 |  |  
		|  |  
		| deniska_gus 
 
 
 Joined: 11 Jul 2006
 Posts: 42
 Location: Minden, Germany
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Tue Jul 11, 2006 7:48 am |   |  
				| 
 |  
				| Hello! I have just one question. I need to connect this max6675 with rs232. I use pic16f877 and i have no idea, how i can do it. Could you please help me? 
 Regards. Dennis
 |  |  
		|  |  
		| kender 
 
 
 Joined: 09 Aug 2004
 Posts: 768
 Location: Silicon Valley
 
 
			          
 
 | 
			
				|  |  
				|  Posted: Tue Jul 11, 2006 2:13 pm |   |  
				| 
 |  
				|  	  | deniska_gus wrote: |  	  | I need to connect this max6675 with rs232. I use pic16f877 and i have no idea, how i can do it. Could you please help me? ** | 
 
 If all you need to do is to connect MAX6675 to a computer, you can do it via parallel port with minimum hardware and without microcontroller.  The approach is shown in this app note by maxim http://www.maxim-ic.com/appnotes.cfm/appnote_number/980
 
 ---------
 **  This type of a request is for the General Forum rather than for the Code Library.
 |  |  
		|  |  
		| Analyzer 
 
 
 Joined: 07 Sep 2003
 Posts: 32
 
 
 
			    
 
 |  |  
		|  |  
		|  |  
  
	| 
 
 | You cannot post new topics in this forum You cannot reply to topics in this forum
 You cannot edit your posts in this forum
 You cannot delete your posts in this forum
 You cannot vote in polls in this forum
 
 |  
 Powered by phpBB © 2001, 2005 phpBB Group
 
 |