Miramar Beach, Florida
Offline
Faraday Member
Karma: 50
Posts: 3457
|
 |
« Reply #45 on: November 06, 2012, 05:24:13 pm » |
You have another problem. There is another device active on the SPI bus. 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. 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. digitalWrite(10,HIGH);
|
|
|
|
« Last Edit: November 06, 2012, 05:35:30 pm by SurferTim »
|
Logged
|
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 54
|
 |
« Reply #46 on: November 07, 2012, 05:57:58 am » |
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é
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 54
|
 |
« Reply #47 on: November 07, 2012, 04:01:19 pm » |
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é
|
|
|
|
|
Logged
|
|
|
|
|
Miramar Beach, Florida
Offline
Faraday Member
Karma: 50
Posts: 3457
|
 |
« Reply #48 on: November 07, 2012, 04:20:01 pm » |
I'm not sure. Is there a thermocouple attached? The formula should be correct for Celsius, but 144 degrees C is pretty hot.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 54
|
 |
« Reply #49 on: November 07, 2012, 04:37:24 pm » |
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é
|
|
|
|
|
Logged
|
|
|
|
|
Miramar Beach, Florida
Offline
Faraday Member
Karma: 50
Posts: 3457
|
 |
« Reply #50 on: November 07, 2012, 04:49:35 pm » |
Here is the datasheet. http://datasheets.maximintegrated.com/en/ds/MAX6675.pdfPage 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.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 54
|
 |
« Reply #51 on: November 07, 2012, 05:05:12 pm » |
should i try to run Henrique exemple from the library ? did u took a look at the Max library ?
|
|
|
|
|
Logged
|
|
|
|
|
Miramar Beach, Florida
Offline
Faraday Member
Karma: 50
Posts: 3457
|
 |
« Reply #52 on: November 07, 2012, 05:23:40 pm » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 54
|
 |
« Reply #53 on: November 08, 2012, 06:28:57 pm » |
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
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 54
|
 |
« Reply #54 on: November 08, 2012, 06:41:42 pm » |
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é
|
|
|
|
|
Logged
|
|
|
|
|
Miramar Beach, Florida
Offline
Faraday Member
Karma: 50
Posts: 3457
|
 |
« Reply #55 on: November 08, 2012, 09:34:34 pm » |
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.
|
|
|
|
« Last Edit: November 08, 2012, 10:20:31 pm by SurferTim »
|
Logged
|
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 54
|
 |
« Reply #56 on: November 09, 2012, 04:26:28 am » |
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 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
|
|
|
|
« Last Edit: November 09, 2012, 05:04:22 am by jmaxado »
|
Logged
|
|
|
|
|
Miramar Beach, Florida
Offline
Faraday Member
Karma: 50
Posts: 3457
|
 |
« Reply #57 on: November 09, 2012, 06:40:35 am » |
Is this a microsecond or millisecond delay? Can you tell by the code? _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: 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?).
|
|
|
|
« Last Edit: November 09, 2012, 09:58:45 am by SurferTim »
|
Logged
|
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 54
|
 |
« Reply #58 on: November 09, 2012, 10:22:14 am » |
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é
|
|
|
|
|
Logged
|
|
|
|
|
Miramar Beach, Florida
Offline
Faraday Member
Karma: 50
Posts: 3457
|
 |
« Reply #59 on: November 09, 2012, 10:24:51 am » |
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.
|
|
|
|
« Last Edit: November 09, 2012, 10:33:01 am by SurferTim »
|
Logged
|
|
|
|
|
|