Jump to content
43oh

[Energia Library] OneWire DS18B20 (430 & Stellaris)


Recommended Posts

Hi all. I'm using the GFDS18B20V2 sketch and code works with no problem on MSP-EXP430F5529LP and CC3100BP.  I've added some code to read the mac address and print it in the serial monitor. After the call to sprintf i'm getting two results from the sensor.

// StellarisOW
// Have used arrays to hold retrieved information, so that it can be easily addressed by your code
// This sketch plus StellarisDS18B20.h will run as is on 430 & Stellaris LaunchPads
// Do a reset to view the One Wire ROM addresses. Have Fun.
// Grant Forest 29 Jan 2013.
// Had confusion with library names. Lib now called GFDS18B20
// GF 6 Feb 2913  cleaned up a bit of code.

//#include <StellarisDS18B20.h>
#include <GFDS18B20.h>

#include <SPI.h>
#include <WiFi.h>

#define OWPIN  P6_5  //11
#define MAXOW 1  //Max number of OW's used

byte ROMarray[MAXOW][8];
byte ROMtype[MAXOW];     // 28 for temp', 12 for switch etc.
byte ROMtemp[MAXOW];
byte result[MAXOW+5];

byte data[12];
byte i;
byte addr[8];
uint8_t ROMmax=0;
uint8_t ROMcount=0;
boolean foundOW =false;

char macAddr[6];
byte mac[6];
int test = 0;

DS18B20 ds(OWPIN);  // currently on PIN 11
void setup(void) {
 
  Serial.begin(9600);
  delay(500);
  Serial.print("G'day StellarisOW\n");
  findOW();
  displayOW();
}

void loop(void) {
  tempCMD();
  for (i=1; i<ROMmax+1;i++){
      if (ROMtype[i]==0x28) {
         readOW(i); 
         saveTemperature(i);
       }
  }  
  for (i=1;i<ROMmax+1;i++){
    if (ROMtype[i]==0x28) {
        foundOW=true;
         Serial.print("OW");
         Serial.print(i);
         Serial.print("=");
         Serial.print(result[i]); 
         Serial.print("C ");
     }  
 } 
 if (foundOW) Serial.println();  
 
 if ((test > 5) & (test < 15)) {
   WiFi.macAddress(mac);
   sprintf(macAddr, "%02x:%02x:%02x:%02x:%02x:%02x", mac[5], mac[4], mac[3], mac[2], mac[1], mac[0]);
   Serial.println(macAddr);
 }
 test++;
 delay(4000);
}

void tempCMD(void){      //Send a global temperature convert command
  ds.reset();
  ds.write_byte(0xcc);  // was ds.select(work); so request all OW's to do next command
  ds.write_byte(0x44);  // start conversion, with parasite power on at the end
  delay(1000);
}
void saveTemperature(uint8_t ROMno){
  int32_t newtemp32;
  uint8_t i;
  newtemp32=data[1]<<8;
  newtemp32=newtemp32+data[0]>>4;
  result[ROMno]=byte(newtemp32);
  i=(data[0] & 0x0F)* 625/1000;
  if (i>=5)  result[ROMno]++;
}
void readOW(uint8_t ROMno)
{
   uint8_t i;
   ds.reset();
   ds.select(ROMarray[ROMno]);
   ds.write_byte(0xBE);         // Read Scratchpad
   for ( i = 0; i < 9; i++) {   // need 9 bytes
      data[i] = ds.read_byte();
#if TEST
      if (data[i]<16) Serial.print("0");
      Serial.print(data[i], HEX);
      Serial.print(" ");
#endif   
  }
}
void findOW(void)
{
 byte addr[8]; 
 uint8_t i; 
 ROMmax=0;  ///////////////////////////////////////////////////////
 while (true){  //get all the OW addresses on the buss
   i= ds.search(addr);
   if ( i<10) {
      Serial.print("ret=("); 
      Serial.print(i);
      Serial.print(") No more addresses.\n");
      ds.reset_search();
      delay(500);
      return;
    }
   Serial.print("R=");
    for( i = 0; i < 8; i++) {
       if (i==0)  ROMtype[ROMmax+1]=addr[i];  // store the device type
         
      ROMarray[ROMmax+1][i]=addr[i];     

      if (addr[i]<16) Serial.print("0"); 
      Serial.print(addr[i], HEX);
      Serial.print(" ");
    }
    ROMmax++;
  Serial.print ("\t(OW");
    Serial.print (ROMmax,HEX);
    Serial.print (") Type="); 
    Serial.println (ROMtype[ROMmax],HEX);
  
    
 } 
}
void displayOW(void)
{
  uint8_t i;
  Serial.println ("From array");
  for (ROMcount=1; ROMcount<ROMmax+1; ROMcount++) {   
  ds.reset();
    for( i = 0; i < 8; i++) {
      if (ROMarray[ROMcount][i]<16) Serial.print("0");
      Serial.print( ROMarray[ROMcount][i], HEX);
      Serial.print(" ");
    }
    Serial.println("");
  }
}

Regards, Vasilis.

Link to post
Share on other sites
  • 2 weeks later...
  • Replies 85
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

G'day, I now have a working Dallas Library that works on both 430 and Stellaris using Energia IDE. Have fun. Grant StellarisDS18B20.zip

Opps, zip file now attached GFDS18B20.zip

Tks Pivden, Yes your correct, no idea how the microsec's snuck through, they seem to do that at 2AM. Have updated the zip file. Tks again GFDS18B20V2.zip

Posted Images

@@Marvi,

 

Have you started talking to the sensor yet?

Have you gotten anything back from the sensor?

 

It should be a simple matter of reading the data from the sensor then computing the corresponding result.  

 

I'm in the middle of designing the PCB for a MAX31850K device so I haven't written any code just yet. The family code is 0x3B. 

 

Here is the datasheet for the MAX31859.  

 

On page 13, it describes the temperature data format. This explains how to convert the hex value into a floating point number.

 

On page 15, it describes the transaction sequence required to talk with the sensor.

 

On page 22, Table 6 describes the steps to complete an example operation with the sensor.

 

@bluehash: We should probably create a new thread for each new one wire sensor.

Link to post
Share on other sites
  • 4 weeks later...

@@lmaafternoon,

 

Yes, you are doing something wrong but we need more information to troubleshoot successfully.

 

Please tell us:

  1. Which LaunchPad you are using? 
  2. Which One Wire sensor you are using?  ie: DS18B20, DS18S20, MAX31859, etc
  3. What code are you using?  ie: Energia or C
  4. Have you read the datasheet for your sensor?
  5. Anything else you would like to share?

 

In the meantime, here's my guess:  If you are using a DS18B20 sensor then you will have to test to see if Bits[11..15] are positive. If they are then the temperature is a negative value and the conversion math is affected. This is explained on page 3 and 4 of the DS18B20 datasheet.

 

Note: I an not an Energia user. I program in C and my answer comes from that point of view.

 

By the way, I recommend starting a new thread for this troubleshooting exercise.

Link to post
Share on other sites

Hello ! Sorry for not providing any information. I'm using Energia 14 and the example code provided with the library. The sensor is the DS18B20. The launchpad is the F5529. I'll read the datasheet and the library's code and post any update. Thank you for you help.

 

 

 

Sent from my iPhone using Tapatalk

Link to post
Share on other sites

I have just found this thread, I also am needing to use a DS18S20 sensor with the OneWire library. I can use the OneWire library by Paul Stoeffregen without any problem in Arduino.

 

I tried to download the library attached here http://forum.43oh.com/topic/3314-energia-library-onewire-ds18b20-430-stellaris/#entry29813

 

But Energia 0015 will not start, I receive an error saying that the application cannot be launched. As soon as I delete the library, Energia launches again just fine. I believe there is some kind of incompatibility with the latest Energia version?

 

EDIT: I see the problem was simply that the example folder cannot be included with the library as is, this will block the application. Removing the example folder let me use the library nicely on an MSP430G2553.

Link to post
Share on other sites
  • 3 months later...

I tried the StellarisDS18B20 lib and example on a CC3200 launchPad and sometimes it does not find the type 28 device and hangs and the results have frequent 0's and some occational out of range high number.   Is there a more accurate/robust lib i should use on the cc3200 launchpad?

 

G'day StellarisOW

ROM=11 00 00 00 70 00 00 00 (OW1) Type=11
ROM=28 1C 97 F1 05 00 00 15 (OW2) Type=28
No more addresses.
From array
11 00 00 00 70 00 00 00 
28 1C 97 F1 05 00 00 15 
OW2=F 
OW2=F 
OW2=75F 
OW2=185F 
OW2=F 
OW2=75F 
OW2=F 
OW2=75F 
OW2=75F 
OW2=F 
Link to post
Share on other sites
  • 4 months later...

Anybody got the DS18B20 working on CC3200 ?

 

 

 

 

 

I tried the StellarisDS18B20 lib and example on a CC3200 launchPad and sometimes it does not find the type 28 device and hangs and the results have frequent 0's and some occational out of range high number.   Is there a more accurate/robust lib i should use on the cc3200 launchpad?

 

G'day StellarisOW

ROM=11 00 00 00 70 00 00 00 (OW1) Type=11
ROM=28 1C 97 F1 05 00 00 15 (OW2) Type=28
No more addresses.
From array
11 00 00 00 70 00 00 00 
28 1C 97 F1 05 00 00 15 
OW2=F 
OW2=F 
OW2=75F 
OW2=185F 
OW2=F 
OW2=75F 
OW2=F 
OW2=75F 
OW2=75F 
OW2=F 

 

Link to post
Share on other sites
  • 5 months later...
  • 1 year later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...