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

max6675
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
madhusuthanan



Joined: 23 Aug 2017
Posts: 15

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

max6675
PostPosted: Wed Aug 23, 2017 8:24 am     Reply with quote

Hi, I'm communicating with a max6675 through a pic16f72. I have the code below that shows only 00.0 in 7-segment display. Please help me to resolve this problem.
Code:

#include <16F72.h>
#device adc=8

#FUSES NOWDT
#FUSES HS       
#FUSES NOPUT
#FUSES NOPROTECT
#FUSES NOBROWNOUT

#use delay(clock=20000000)

#USE SPI (MASTER, CLK=PIN_C3, DI=PIN_C5, DO=PIN_C4,ENABLE=PIN_C6, MODE=0, BITS=8, STREAM=SPI_1, MSB_FIRST)

#define MAX_CS PIN_C6
#define MAX_DO PIN_C5
#define MAX_CLK PIN_C3


int thermocouple_error;   
int16 data;
int16 value;

void init_TC(void)
{
    output_low(MAX_CLK);
    //output_low(MAX_DO);
    output_low(MAX_CS);
    setup_spi(SPI_MASTER | SPI_L_TO_H | SPI_CLK_DIV_16);
    delay_cycles(1);
    output_high(MAX_CS);
}

int16 read_TC(void)         
{
    BYTE datah, datal=0;
    int16 data=0;

    output_low(MAX_CS);
    delay_cycles(1);
    datah=SPI_READ(0);
    datal=SPI_READ(0);
    output_high(MAX_CS);
 
    if( bit_test(datal,2))
    {
      thermocouple_error = 1;
        bit_set(data,15);
        return(data);
    }
      thermocouple_error = 0;

    data = datah<<8;
    data = data | datal;

    return(data);
}

int16 sortout(int16 raw)
{
    return(0x0FFF & (raw>>3));
}

int16 toCalc_TC(int16 tmp)
{
   return((int16)tmp * 10/4);   
}

int16 do_everything(void)
{
   init_TC(); 
   return(toCalc_TC(sortout(read_TC())));
}

unsigned int Hex(int a)

 switch(a)
    {
      case 1: return 0x06;
      case 2: return 0x5B;
      case 3: return 0x4F;
      case 4: return 0x66;
      case 5: return 0x6D;
      case 6: return 0x7D;
      case 7: return 0x07;
      case 8: return 0x7F;
      case 9: return 0x6F;
      case 0: return 0x3F;
      case 'e': return 0x79;
      case 'r': return 0x70;
    }
}


void main()
{
   int16 value;
   unsigned long Temp;
   char error[] = "err";

   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256|RTCC_8_bit);
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_4);
   setup_timer_2(T2_DISABLED,0,1);
   enable_interrupts(GLOBAL);

   set_timer0(0);
   set_timer1(0);

   setup_adc_ports(AN0_AN1_AN3);
   setup_adc(ADC_CLOCK_INTERNAL);
   set_adc_channel(0);
   delay_us(10);

   while(1) {
      if (input(pin_A4)) {
        if (!(thermocouple_error)) {
            Temp = value*10 /4;
            output_b(Hex(Temp %10));
            output_low (pin_c2);
            output_high (pin_c1);
            output_high (pin_c0);
            delay_ms(8);
            output_b((Hex((Temp/10) %10)) | 0x80);
            output_high (pin_c2);
            output_low (pin_c1);
            output_high (pin_c0);
            delay_ms(8);
            output_b(Hex((Temp/100) %10));
            output_high (pin_c2);
            output_high (pin_c1);
            output_low (pin_c0);
            delay_ms(8);
        }
        else {
            output_b(Hex(error[0]));
            output_low (pin_c2);
            output_high (pin_c1);
            output_high (pin_c0);
            delay_ms(8);
            output_b(Hex(error[1]));
            output_high (pin_c2);
            output_low (pin_c1);
            output_high (pin_c0);
            delay_ms(8);
            output_b(Hex(error[2]));
            output_high (pin_c2);
            output_high (pin_c1);
            output_low (pin_c0);
            delay_ms(8);
        }
      }
   }
}
Ttelmah



Joined: 11 Mar 2010
Posts: 13357

View user's profile Send private message

PostPosted: Wed Aug 23, 2017 1:04 pm     Reply with quote

You are mixing SPI operations.

Look at the data sheet. Look at the entry for #use spi. Do you see any reference to setup_spi, or spi_read?. Look at spi_setup. Do you see any reference to #use?. The setup, was the older way of oeperating SPI, with more limited capabilities. #use spi, is designed to work with spi_xfer _only_ they are not designed for cross mixing.

You are also making things more complex than they need to be.

The device is designed to have the clock idling low, with data transferred on the rising edge of the clock. This is mode 0. So:

Code:

#USE SPI (MASTER, CLK=PIN_C3, DI=PIN_C5, DO=PIN_C4, MODE=0, BITS=16, STREAM=SPI_1)

//Then use no other setup or read commands.
//Just use:

   unsigned int16 value; //any suitable 16bit variable

   output_low(MAX_CS);
   value=spi_xfer(SPI_1, 0L); //transfer the value
   output_high(MAX_CS);



Nothing more is needed to read the 16bits from the SPI using #USE!.

This transfers the whole 16bits, in one operation.

There may well be other problems in your code, but start by using this and verifying you are getting the 16bits from the chip.
madhusuthanan



Joined: 23 Aug 2017
Posts: 15

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

max6675
PostPosted: Sun Nov 26, 2017 9:33 am     Reply with quote

hi i'm communicating the max6675 through software spi communication. I have the 7 segment problem. It is not displaying correct value.


Code:
#include <16F72.h>
#device adc=8

#FUSES NOWDT
#FUSES HS   
#FUSES NOPUT   
#FUSES NOPROTECT         
#FUSES NOBROWNOUT   

#use delay(clock=20000000)

#define MAX_CS PIN_C6
#define MAX_DO PIN_C5
#define MAX_CLK PIN_C3


int thermocouple_error;
                           
int16 data;
int16 value;
void init_TC(void)
{
    output_low(MAX_CLK);
    output_low(MAX_DO);
    output_low(MAX_CS);
    setup_spi(SPI_MASTER | SPI_L_TO_H | SPI_CLK_DIV_16);
    delay_cycles(1);
    output_high(MAX_CS);
}

int16 read_TC(void)   
{
    BYTE datah, datal=0;
    int16 data=0;
    int i;

    output_low(MAX_CS);
   for (i = 0; i<16; i++) {
      output_high(MAX_CLK);
      delay_cycles(1);
      output_low(MAX_CLK);
      shift_left(&data,2,input(MAX_DO));
   }
 
  thermocouple_error = bit_test(data,2);
  output_high(MAX_CS);
    return(data);
}

int16 sortout(int16 raw)
{
    return(0x0FFF & (raw>>3));
}

int16 toCalc_TC(int16 tmp)
{
   return((int16)tmp * 10/4);
}

int16 do_everything(void)
{
   init_TC(); 
   return(toCalc_TC(sortout(read_TC())));
}

unsigned int Hex(int a) { 
 switch(a) {
      case 1: return 0x06;
      case 2: return 0x5B;
      case 3: return 0x4F;
      case 4: return 0x66;
      case 5: return 0x6D;
      case 6: return 0x7D;
      case 7: return 0x07;
      case 8: return 0x7F;
      case 9: return 0x6F;
      case 0: return 0x3F;
      case 'e': return 0x79;
      case 'r': return 0x70;
  }
}


void main()
{
   int16 value;
   unsigned long Temp;
   char error[] = "err";
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256|RTCC_8_bit);
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_4);      //52.4 ms overflow
   setup_timer_2(T2_DISABLED,0,1);
   enable_interrupts(GLOBAL);
   set_timer0(0);
   set_timer1(0);

   setup_adc_ports(AN0_AN1_AN3);
   setup_adc(ADC_CLOCK_INTERNAL);
   set_adc_channel(0);
   delay_us(10);
   while(1) {
      if (input(pin_A4)) {
            value = do_everything();
       
        if (!(thermocouple_error)) {
            Temp = value*100/4;
            output_b(Hex(Temp %10));
            output_low (pin_c2);
            output_high (pin_c1);
            output_high (pin_c0);
            delay_ms(8);
            output_b((Hex((Temp/10) %10)) | 0x80);
            output_high (pin_c2);
            output_low (pin_c1);
            output_high (pin_c0);
            delay_ms(8);
            output_b(Hex((Temp/100) %10));
            output_high (pin_c2);
            output_high (pin_c1);
            output_low (pin_c0);
            delay_ms(8);
        }
        else {
            output_b(Hex(error[0]));
            output_low (pin_c2);
            output_high (pin_c1);
            output_high (pin_c0);
            delay_ms(8);
            output_b(Hex(error[1]));
            output_high (pin_c2);
            output_low (pin_c1);
            output_high (pin_c0);
            delay_ms(8);
            output_b(Hex(error[2]));
            output_high (pin_c2);
            output_high (pin_c1);
            output_low (pin_c0);
            delay_ms(8);
        }
      }
      delay_ms(500);
   }
}



Pease help me to resolve.
PCM programmer



Joined: 06 Sep 2003
Posts: 20360

View user's profile Send private message

PostPosted: Sun Nov 26, 2017 12:10 pm     Reply with quote

madhusuthanan wrote:
void init_TC(void)
{
output_low(MAX_CLK);
//output_low(MAX_DO);
output_low(MAX_CS);
setup_spi(SPI_MASTER | SPI_L_TO_H | SPI_CLK_DIV_16);
delay_cycles(1);
output_high(MAX_CS);
}

You are using the wrong SPI mode. You are using SPI mode 1.

MAX6675 uses SPI mode 0. This is shown on page 6 of the data sheet
in this diagram:
Quote:
Figure 1b. Serial Interface Timing

Look at the diagram. The clock idles at a low level and samples the data
on the rising edge. This is mode 0.

Here are the #define statements for the SPI modes:
Code:

// SPI mode definitions (for 16F and 18F PICs).
#define SPI_MODE_0  (SPI_L_TO_H | SPI_XMIT_L_TO_H)
#define SPI_MODE_1  (SPI_L_TO_H)
#define SPI_MODE_2  (SPI_H_TO_L)
#define SPI_MODE_3  (SPI_H_TO_L | SPI_XMIT_L_TO_H)
madhusuthanan



Joined: 23 Aug 2017
Posts: 15

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

PostPosted: Tue Nov 28, 2017 12:17 am     Reply with quote

hi pcm programmer,



I changed to spi mode 0. still this is showing the same problem. I'm using thermocouple module max6675 .


Code:

#include <16F72.h>
#device adc=8

#FUSES NOWDT   
#FUSES HS                 
#FUSES NOPUT           
#FUSES NOPROTECT   
#FUSES NOBROWNOUT

#use delay(clock=20000000)

#define MAX_CS PIN_C6
#define MAX_DO PIN_C5
#define MAX_CLK PIN_C3


int thermocouple_error;
int16 data;
int16 value;
void init_TC(void)
{
    output_low(MAX_CLK);
    output_low(MAX_DO);
    output_low(MAX_CS);
    setup_spi(SPI_MASTER | SPI_L_TO_H | SPI_XMIT_L_TO_H | SPI_CLK_DIV_16);
    delay_cycles(1);
    output_high(MAX_CS);
}

int16 read_TC(void)     
{
    int datah, datal=0;
    int16 data=0;
    int i;

    output_low(MAX_CS);
   for (i = 0; i<16; i++) {
      delay_cycles(1);
      output_high(MAX_CLK);
      delay_cycles(1);
      output_low(MAX_CLK);
      shift_left(&data,2,input(MAX_DO));
   }
 
  thermocouple_error = bit_test(data,2);
  delay_cycles(1);
  output_high(MAX_CS);

    return(data);
}

int16 sortout(int16 raw)
{
    return(0x0FFF & (raw>>3));      //returns only the bits converning temperature
}

int16 toCalc_TC(int16 tmp)
{
   return((int16)tmp * 10/4);      //adjusts data to floating point format, and accounts for the decimal point
}

int16 do_everything(void)
{
   init_TC(); 
   return(toCalc_TC(sortout(read_TC())));
}

unsigned int Hex(int a) { 
 switch(a) {
      case 1: return 0x06;
      case 2: return 0x5B;
      case 3: return 0x4F;
      case 4: return 0x66;
      case 5: return 0x6D;
      case 6: return 0x7D;
      case 7: return 0x07;
      case 8: return 0x7F;
      case 9: return 0x6F;
      case 0: return 0x3F;
      case 'e': return 0x79;
      case 'r': return 0x70;
  }
}


void main()
{
   int16 value;
   unsigned long Temp;
   char error[] = "err";
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256|RTCC_8_bit);
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_4);      //52.4 ms overflow
   setup_timer_2(T2_DISABLED,0,1);
   enable_interrupts(GLOBAL);
   set_timer0(0);
   set_timer1(0);

   setup_adc_ports(AN0_AN1_AN3);
   setup_adc(ADC_CLOCK_INTERNAL);
   set_adc_channel(0);
   delay_us(10);
   while(1) {
      if (input(pin_A4)) {
       
        if (!(thermocouple_error)) {
            //value = value>>3;
            Temp = value*100/4;
            output_b(Hex(Temp %10));
            output_low (pin_c2);
            output_high (pin_c1);
            output_high (pin_c0);
            delay_ms(8);
            output_b((Hex((Temp/10) %10)) | 0x80);
            output_high (pin_c2);
            output_low (pin_c1);
            output_high (pin_c0);
            delay_ms(8);
            output_b(Hex((Temp/100) %10));
            output_high (pin_c2);
            output_high (pin_c1);
            output_low (pin_c0);
            delay_ms(8);
        }
        else {
            output_b(Hex(error[0]));
            output_low (pin_c2);
            output_high (pin_c1);
            output_high (pin_c0);
            delay_ms(8);
            output_b(Hex(error[1]));
            output_high (pin_c2);
            output_low (pin_c1);
            output_high (pin_c0);
            delay_ms(8);
            output_b(Hex(error[2]));
            output_high (pin_c2);
            output_high (pin_c1);
            output_low (pin_c0);
            delay_ms(8);
        }
      }
   }
}
Ttelmah



Joined: 11 Mar 2010
Posts: 13357

View user's profile Send private message

PostPosted: Tue Nov 28, 2017 1:52 am     Reply with quote

Er. Nowhere in the code you show, do you actually read the chip.....

Your main sets up three timers, and enables the GLOBAL interrupt (why?...). Configures the internal ADC (incorrectly - what does the data sheet say about using the internal RC clock?). It then loops testing a value 'thermocouple_error', and the input bit A4, but doesn't ever call any of the thermocouple routines. Duh...

You are not going to get anything from the chip till you call the routines to access it. It doesn't communicate by telepathy.
madhusuthanan



Joined: 23 Aug 2017
Posts: 15

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

temperature value
PostPosted: Fri Dec 01, 2017 3:49 am     Reply with quote

I check this code this always read only 00.0 value only from max6675 module. Please guide me to solve this issue.

Code:

#include <16F72.h>
#device adc=8

#FUSES NOWDT   
#FUSES HS                 
#FUSES NOPUT           
#FUSES NOPROTECT   
#FUSES NOBROWNOUT

#use delay(clock=20000000)

#define MAX_CS PIN_C6
#define MAX_DO PIN_C5
#define MAX_CLK PIN_C3


int thermocouple_error;
int16 data;
int16 value;
void init_TC(void)
{
    output_low(MAX_CLK);
    output_low(MAX_DO);
    output_low(MAX_CS);
    setup_spi(SPI_MASTER | SPI_L_TO_H | SPI_XMIT_L_TO_H | SPI_CLK_DIV_4);
    delay_cycles(1);
    output_high(MAX_CS);
}

int16 read_TC(void)     
{
    int datah, datal=0;
    int16 data=0;
    int i;

    output_low(MAX_CS);
   for (i = 0; i<16; i++) {
      delay_cycles(1);
      output_high(MAX_CLK);
      delay_cycles(1);
      output_low(MAX_CLK);
      shift_left(&data,2,input(MAX_DO));
   }
 
  thermocouple_error = bit_test(data,2);
  delay_cycles(1);
  output_high(MAX_CS);

    return(data);
}

int16 sortout(int16 raw)
{
    return(0x0FFF & (raw>>3));      //returns only the bits converning temperature
}

int16 toCalc_TC(int16 tmp)
{
   return((int16)tmp * 10/4);      //adjusts data to floating point format, and accounts for the decimal point
}

int16 do_everything(void)
{
   init_TC(); 
   return(toCalc_TC(sortout(read_TC())));
}

unsigned int Hex(int a) { 
 switch(a) {
      case 1: return 0x06;
      case 2: return 0x5B;
      case 3: return 0x4F;
      case 4: return 0x66;
      case 5: return 0x6D;
      case 6: return 0x7D;
      case 7: return 0x07;
      case 8: return 0x7F;
      case 9: return 0x6F;
      case 0: return 0x3F;
      case 'e': return 0x79;
      case 'r': return 0x70;
  }
}


void main()
{
   int16 value;
   unsigned long Temp;
   char error[] = "err";
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256|RTCC_8_bit);
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_4);      //52.4 ms overflow
   setup_timer_2(T2_DISABLED,0,1);
   enable_interrupts(GLOBAL);
   set_timer0(0);
   set_timer1(0);

   setup_adc_ports(AN0_AN1_AN3);
   setup_adc(ADC_CLOCK_INTERNAL);
   set_adc_channel(0);
   delay_us(10);
   while(1) {
      if (input(pin_A4)) {
       
        if (!(thermocouple_error)) {
            //value = value>>3;
            Temp = value*100/4;
            output_b(Hex(Temp %10));
            output_low (pin_c2);
            output_high (pin_c1);
            output_high (pin_c0);
            delay_ms(8);
            output_b((Hex((Temp/10) %10)) | 0x80);
            output_high (pin_c2);
            output_low (pin_c1);
            output_high (pin_c0);
            delay_ms(8);
            output_b(Hex((Temp/100) %10));
            output_high (pin_c2);
            output_high (pin_c1);
            output_low (pin_c0);
            delay_ms(8);
        }
        else {
            output_b(Hex(error[0]));
            output_low (pin_c2);
            output_high (pin_c1);
            output_high (pin_c0);
            delay_ms(8);
            output_b(Hex(error[1]));
            output_high (pin_c2);
            output_low (pin_c1);
            output_high (pin_c0);
            delay_ms(8);
            output_b(Hex(error[2]));
            output_high (pin_c2);
            output_high (pin_c1);
            output_low (pin_c0);
            delay_ms(8);
        }
      }
   }
}
temtronic



Joined: 01 Jul 2010
Posts: 6214
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Dec 01, 2017 6:29 am     Reply with quote

ALL of Mr. T's comments are still valid !

Your program NEVER accesses the TC device, the ADC is setup wrong, and the ISRs are enabled...

fix those 3 items and it may work

I can't confirm as I don't have those device here to physically test.
Ttelmah



Joined: 11 Mar 2010
Posts: 13357

View user's profile Send private message

PostPosted: Fri Dec 01, 2017 6:49 am     Reply with quote

I wonder.
Does the poster realise that declaring a routine, does not result in it being executed?.

The processor only executes the 'main', and anything it calls.

Currently the code is never calling the routines to access the chip.
temtronic



Joined: 01 Jul 2010
Posts: 6214
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Dec 01, 2017 7:40 am     Reply with quote

the 'hint'
...
in your code....

while(1) {
if (input(pin_A4)) {
//
// you
// need
// to
// add
// function calls
// here
// to
// read( access )
// the
//TC device
//
if (!(thermocouple_error)) {
madhusuthanan



Joined: 23 Aug 2017
Posts: 15

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

termocouple value
PostPosted: Fri Dec 01, 2017 8:04 am     Reply with quote

thank you temtronic,

Still I'm getting 00.0 value in the display . Please guide me to solve this issue.


Code:
#include <16F72.h>
#device adc=8

#FUSES NOWDT   
#FUSES HS                 
#FUSES NOPUT           
#FUSES NOPROTECT   
#FUSES NOBROWNOUT

#use delay(clock=20000000)

#define MAX_CS PIN_C6
#define MAX_DO PIN_C5
#define MAX_CLK PIN_C3


int thermocouple_error;
int16 data;
int16 value;
void init_TC(void)
{
    output_low(MAX_CLK);
    output_low(MAX_DO);
    output_low(MAX_CS);
    setup_spi(SPI_MASTER | SPI_L_TO_H | SPI_XMIT_L_TO_H | SPI_CLK_DIV_4);
    delay_cycles(1);
    output_high(MAX_CS);
}

int16 read_TC(void)     
{
    int datah, datal=0;
    int16 data=0;
    int i;

    output_low(MAX_CS);
   for (i = 0; i<16; i++) {
      delay_cycles(1);
      output_high(MAX_CLK);
      delay_cycles(1);
      output_low(MAX_CLK);
      shift_left(&data,2,input(MAX_DO));
   }
 
  thermocouple_error = bit_test(data,2);
  delay_cycles(1);
  output_high(MAX_CS);

    return(data);
}

int16 sortout(int16 raw)
{
    return(0x0FFF & (raw>>3));      //returns only the bits converning temperature
}

int16 toCalc_TC(int16 tmp)
{
   return((int16)tmp * 10/4);      //adjusts data to floating point format, and accounts for the decimal point
}

int16 do_everything(void)
{
   init_TC(); 
   return(toCalc_TC(sortout(read_TC())));
}

unsigned int Hex(int a) { 
 switch(a) {
      case 1: return 0x06;
      case 2: return 0x5B;
      case 3: return 0x4F;
      case 4: return 0x66;
      case 5: return 0x6D;
      case 6: return 0x7D;
      case 7: return 0x07;
      case 8: return 0x7F;
      case 9: return 0x6F;
      case 0: return 0x3F;
      case 'e': return 0x79;
      case 'r': return 0x70;
  }
}


void main()
{
   int16 value;
   unsigned long Temp;
   char error[] = "err";
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256|RTCC_8_bit);
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_4);      //52.4 ms overflow
   setup_timer_2(T2_DISABLED,0,1);
   enable_interrupts(GLOBAL);
   set_timer0(0);
   set_timer1(0);

   setup_adc_ports(AN0_AN1_AN3);
   setup_adc(ADC_CLOCK_INTERNAL);
   set_adc_channel(0);
   delay_us(10);
   while(1) {
      if (input(pin_A4)) {
        value = do_everything();
        if (!(thermocouple_error)) {
            //value = value>>3;
            Temp = value*100/4;
            output_b(Hex(Temp %10));
            output_low (pin_c2);
            output_high (pin_c1);
            output_high (pin_c0);
            delay_ms(8);
            output_b((Hex((Temp/10) %10)) | 0x80);
            output_high (pin_c2);
            output_low (pin_c1);
            output_high (pin_c0);
            delay_ms(8);
            output_b(Hex((Temp/100) %10));
            output_high (pin_c2);
            output_high (pin_c1);
            output_low (pin_c0);
            delay_ms(8);
        }
        else {
            output_b(Hex(error[0]));
            output_low (pin_c2);
            output_high (pin_c1);
            output_high (pin_c0);
            delay_ms(8);
            output_b(Hex(error[1]));
            output_high (pin_c2);
            output_low (pin_c1);
            output_high (pin_c0);
            delay_ms(8);
            output_b(Hex(error[2]));
            output_high (pin_c2);
            output_high (pin_c1);
            output_low (pin_c0);
            delay_ms(8);
        }
      }
   }
}
temtronic



Joined: 01 Jul 2010
Posts: 6214
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Dec 01, 2017 8:17 am     Reply with quote

OK...

here..

if (input(pin_A4)) {
// value = do_everything(); //temporarily delete this
// add this
value = 123 // a KNOWN number
//

See what is displayed. Change 'value' for several numbers within you desired range of valid numbers.

IF the numbers are NOT correct, the error is in your 'display' code.
IF the numbers ARE correct, the error is in your 'TC data acquistions' code.
Ttelmah



Joined: 11 Mar 2010
Posts: 13357

View user's profile Send private message

PostPosted: Fri Dec 01, 2017 8:27 am     Reply with quote

There are a couple of very dubious things with the code:

First he is setting up the hardware SPI, but then reads the chip using software SPI. This in itself may cause problems. One or the other...

Then the setup should only be done once.
madhusuthanan



Joined: 23 Aug 2017
Posts: 15

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

max6675
PostPosted: Fri Dec 01, 2017 9:12 am     Reply with quote

thank you Ttelmah. Please give me the sample software spi program.
Ttelmah



Joined: 11 Mar 2010
Posts: 13357

View user's profile Send private message

PostPosted: Fri Dec 01, 2017 9:49 am     Reply with quote

You are using software SPI. Use the hardware:
Code:

int16 read_TC(void)     
{
    int datah, datal;;
    int16 data=0;
    int i;

    output_low(MAX_CS);
    datah=spi_read(0);
    datal=spi_read(0);
    data=make_16(datah,datal);
    thermocouple_error = bit_test(data,2);
    output_high(MAX_CS);

    return(data);
}

The code you copied here was obviously using hardware SPI (since it already had the two variables for the separate bytes declared), but you had it doing software manually. However you had already enabled the hardware SPI module on the same pins....

Honestly provided your compiler is reasonably modern, using #USE SPI and either hardware or software is even easier.
Only call the init code once. Before your while loop. In the loop just read the chip.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2, 3  Next
Page 1 of 3

 
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