CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Problems with SPi 18F452 - >MAX6675

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Patrick Frank
Guest







Problems with SPi 18F452 - >MAX6675
PostPosted: Fri Jul 09, 2004 3:10 am     Reply with quote

Hi,
i want to read a 16bit value from a MAX6675.
I recieve data from the chip, but its allways the same data, it don`t send me the temperature i need.

Here is my code:
Code:

#include <18F452.h>
#use delay (clock= 4000000)
#fuses H4, PUT, NOPROTECT, BROWNOUT, NOWDT, NODEBUG, NOOSCSEN, NOLVP
#use fast_io ( A )              /* don't set TRIS on each I/O statement */
#use fast_io ( B )              /* don't set TRIS on each I/O statement */
#use fast_io ( C )              /* don't set TRIS on each I/O statement */
#use fast_io ( D )              /* don't set TRIS on each I/O statement */
#use fast_io ( E )              /* don't set TRIS on each I/O statement */

struct port_a_layout
{
short Opto_1_Out;  //RA.0
short Opto_2_Out;  //RA.1
short Relais_Out;  //RA.2
short CS_Out;      //RA.3
short Opto_1_In;   //RA.4
short blank2;      //RA.5
}porta;

struct port_b_layout
{
short Opto_2_In;   //RB.0
short Opto_3_In;   //RB.1
short Opto_4_In;   //RB.2
short Led_Start;   //RB.3
short Led_Stopp;   //RB.4
short blank1;      //RB.5
short blank2;      //RB.6
short blank3;      //RB.7
}portb;

struct port_c_layout
{
short Summer_Out;  //RC.0
short Relais_1_Out;//RC.1
short Relais_2_Out;//RC.2
short SCK;         //RC.3
short SDI;         //RC.4
short blank1;      //RC.5
short andere_tasten;//RC.6
short plus_minus_tasten;    //RC.7
}portc;

struct port_d_layout
{
int data:8; //Anzeige 7-Seg, einlesen Tasten
}portd;

struct port_e_layout
{
int mux_dis:3; //Umschaltung Mux 7-Seg
}porte;

int mux=0,data1=0,data2=0;
int16 datakomp=0;
int plus_minus=0,menu=0,plus_minus_temp=0,menu_temp=0;
int Ziffer0,Ziffer1,Ziffer2,Ziffer3,Ziffer4,Ziffer5;
int16 datatemp=0;

void main(void)
{
      set_tris_a ( 0x10 );     //00010000 1=IN 0=OUT
      set_tris_b ( 0x07 );     //00000111
      set_tris_c ( 0x10 );     //00010000
      set_tris_d ( 0x00 );     //00000000
      set_tris_e ( 0x00 );     //00000000
      portc.plus_minus_tasten=1;
      portc.andere_tasten=1;
      portd.data=0;
      porte.mux_dis=1;
      portc.Summer_Out=0;  //RC.0
      setup_spi(SPI_MASTER | SPI_L_TO_H | SPI_CLK_DIV_16);
      porta.CS_Out=1;
      delay_ms(600);

while(1)
 {
   porta.CS_Out=0;
   delay_cycles(1);
   data2 = spi_read(0);
   data1 = spi_read(0);
   porta.CS_Out=1;
   datakomp=make16(data2,data1);
   datakomp=datakomp>>3;
   datakomp=datakomp&&0x0FFF;
   datatemp=datakomp;
   delay_ms(600);
 }
}



I have connected RC3/SCK to SCK. RC4 SDI to SO. RA3 to CS/.
The Datasheet from the MAX6675 means that i must put CS/ low to communicate and high to get a new value. But i recieve everytime the same value and this value is wrong.

Has anybody a idea? The MAX6675 sends a 16Bit value. Can i read this with my 2 spi_read(0) ?

Thanks and Greets

Patrick Frank
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

View user's profile Send private message Send e-mail

PostPosted: Fri Jul 09, 2004 8:02 am     Reply with quote

Code:
 datakomp=datakomp&&0x0FFF;


Should probably be

Code:
 datakomp=datakomp & 0x0FFF;


If your goal is to mask off the top 4 bits.
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
Patrick Frank
Guest







PostPosted: Fri Jul 09, 2004 12:12 pm     Reply with quote

rwyoung wrote:
Code:
 datakomp=datakomp&&0x0FFF;


Should probably be

Code:
 datakomp=datakomp & 0x0FFF;


If your goal is to mask off the top 4 bits.

Hi,
I feel a bit sheepish about this. Embarassed
That was a mistake in writing.

But that is not my problem, the spi communication still don`t work.

Patrick
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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