Go Down

Topic: max6675+ethernet+sd card (Read 8154 times) previous topic - next topic

SurferTim

#45
Nov 06, 2012, 11:24 pm Last Edit: Nov 06, 2012, 11:35 pm by SurferTim Reason: 1
You have another problem. There is another device active on the SPI bus.
Quote
Starting SD..ok
Starting w5100..192.168.1.96
Setup complete
0.-25
0.-25
0.-25
0.-25
0.-25

The output should be like this with pin 50 disconnected.
Quote
Starting SD..ok
Starting w5100..192.168.1.96
Setup complete
0.0
0.0
0.0
0.0
0.0

Something is returning -1 on the SPI bus. ??

edit: Try removing the ethernet shield, connect the max to pin 50 and try the code in reply #35. That is all I can suggest...except insure you disabled the w5100 SPI after the Ethernet.begin() call.
Code: [Select]
digitalWrite(10,HIGH);


jmaxado

Hello
That is strange since all I have connect are a few of DS18S20 sensors.
One LDR connected to an analog port.
I also have an DTH22, could this one be the one using the SPI bus ?

José

jmaxado

Hello
Removing the ethernet shield, connecting pin 50 and using code frompost #35 I get:

Setup complete
144.0
144.0
144.0
144.0

Is this expected ?

José

SurferTim

I'm not sure. Is there a thermocouple attached? The formula should be correct for Celsius, but 144 degrees C is pretty hot.

jmaxado

Yes there is a thermocouple attached.
But the temp is to low.
The thermocouple is measuring the temp of the burning chamber so it should be arround 250º at least. And the temp is not changing enough.

By the way I also disconnected the DTH22 sensor.

José

SurferTim

Here is the datasheet.
http://datasheets.maximintegrated.com/en/ds/MAX6675.pdf
Page 6 states the max6675 will return 16 bits (2 bytes) in this format:
bit 15 is always 0
bits 14-3 contain the temp in 1/4 degrees C
bit 2 is the thermocouple input
bit 1 is the device id
bit 0 is tri-state

So to convert that, the code combines the bytes into an integer, then shifts that right 3 bits. That value should be the temperature in 1/4 degrees C. That is why it is divided by 4.



jmaxado

should i try to run Henrique exemple from the library ? did u took a look at the Max library ?

SurferTim

I did not look at the code, but I recommend trying it to see how the conversion turns out with it. If it is the same, then your device output section may be malfunctioning like Maxim tech support thought.

jmaxado

Ok
Soory for not saying nothing before but I've been very busy.
Today I tested with the example from the library I am using and the thermocouple behaves as it's suposted.
I just have the mega and the max pluged, nothing else.
Now, I have to check the diferences between surfer tim program and the one used in the examples of the library.


Jose

jmaxado

Hello
I just compared the code from the library with the code from post 35 where you read directly the data from the spi and this is over my head.
But one thing I noticed is that the library besides turning the CS pin low and then High it does the same with the clock pin.
Because the clock pin is common to all spi devices could this be the problem ?

José

SurferTim

#55
Nov 09, 2012, 03:34 am Last Edit: Nov 09, 2012, 04:20 am by SurferTim Reason: 1
If the slave select on a device is HIGH, the device ignores any clock pulses. There are no clock pulses between transfers, only during a transfer. For your Maxim device, it should set the slave select low, pulse the clock high then low 16 times, then set the slave select high.

Your code may manipulate the SPI pins directly. That should not cause a problem. It should obtain the same result.

edit: The only thing that may cause a problem would be not enough time from the slave select pin going LOW, and the first SPI transfer. There should be at least 100ns delay between those events. It might require a couple NOPs in there.

jmaxado

#56
Nov 09, 2012, 10:26 am Last Edit: Nov 09, 2012, 11:04 am by jmaxado Reason: 1
Hello
Following your sugestion I putted some delaies on the code from post #35 but no luck.
I keep getting a reading about one third of the correct one.
Besides it semans your code from post #35 is nor reading all the data since I dont get any decimal numbers in the readings.

Looking at the max library it's exactly what it does

Code: [Select]
byte MAX6675::spiread(void) {
  int i;
  byte d = 0;

  for (i=7; i>=0; i--)
  {
    digitalWrite(sclk, LOW);
    _delay_ms(1);
    if (digitalRead(miso)) {
      //set the bit to 0 no matter what
      d |= (1 << i);
    }

    digitalWrite(sclk, HIGH);
    _delay_ms(1);
  }

  return d;
}


Alternating between clk low and high

José

Jose

SurferTim

#57
Nov 09, 2012, 12:40 pm Last Edit: Nov 09, 2012, 03:58 pm by SurferTim Reason: 1
Is this a microsecond or millisecond delay? Can you tell by the code?
Code: [Select]
   _delay_ms(1);
Maybe my code transfers too fast? The datasheet says it will handle a 4.3MHz clock, but 4MHz may be too close to that to work correctly.

edit: I do not want to slow up the SPI on the ethernet, so I want to try this first. Replace the readMax() function with this:
Code: [Select]
int  readMax() {
 int maxLow;
 int maxData;

 // reduce SPI clock to 1MHz
 SPI.setClockDivider(SPI_CLOCK_DIV16);
 
 //  enable max SPI
 digitalWrite(49,LOW);

 // delay 1 us for data to set up.
 delayMicroseconds(1);

 // do the 16 bit read  
 maxData = SPI.transfer(0x00);
 maxLow = SPI.transfer(0x00);
 
 // disable max SPI and start next conversion
 digitalWrite(49,HIGH);

 // increase SPI clock to 4MHz
 SPI.setClockDivider(SPI_CLOCK_DIV4);

 // convert to an integer from the two bytes
 maxData = maxData << 8;
 maxData = maxData | (maxLow & 0xff);

 // shift temp reading into position
 maxData = maxData >> 3;
 
 // return 1/4 degrees Celsius
 return maxData;
}


edit: Keep your leads to that device as short as possible. If your test setup has long wires to the max6675, you may want to reduce the SPI clock even more just to compensate for the long leads (and prototype board?).

jmaxado

Hy
It´s miliseconds.

I cannot even upload this latest code you posted. It just hangs on the uploading stage.
Yes I know this is just the code for the readMax function. I used the rest of the code from post #35
Since the library I have for the max 6675 is working can't I just use it and go back to the problem of combining this library with the library of the erthernet shield ?

José


SurferTim

#59
Nov 09, 2012, 04:24 pm Last Edit: Nov 09, 2012, 04:33 pm by SurferTim Reason: 1
If you do not use the hardware SPI pins, you should have no problem. Use other pins for that library software SPI, and it won't interfere.

edit: I ran that code on my Mega/Ethernet/SD device and it compiled and uploaded fine. I did not have the max6675 connected, so it showed "0.0" every second. I removed the Ethernet shield for this test.

Go Up