jensnielsen / ds18b20

Quite portable driver for the ds18b20 temperature sensor
3 stars 2 forks source link

Need some help porting to Atmel SAM D21 #3

Open saurabh984 opened 9 years ago

saurabh984 commented 9 years ago

Hi,

I've been trying to port this to SAM D21 with no luck. Would it be anyway possible for you take a look and see where I might be going wrong? SAM D21 has a delay.h library with microsecond timeouts.

Thank you so much in advance!

/*
 * owhal.h
 *
 * Created: 25/12/2014 14:23:03
 *  Author: Saurabh
 */ 

#ifndef OWHAL_H_
#define OWHAL_H_

#include <port.h>

#define OW_PIN PIN_PA13

/* the ow hal needs to define the following macros */

/* todo: add disabling of interrupts in ownet */

/**
 * OW_OUTPUT - set one-wire gpio pin to output
 * OW_INPUT - set one-wire gpio pin to input
 */
#define OW_OUTPUT() \
    struct port_config pinout; \
    port_get_config_defaults(&pinout); \
    pinout.direction = PORT_PIN_DIR_OUTPUT; \
    pinout.input_pull = PORT_PIN_PULL_NONE; \
    port_pin_set_config(OW_PIN, &pinout);
#define OW_INPUT() \
    struct port_config pinin; \
    port_get_config_defaults(&pinin); \
    pinin.direction = PORT_PIN_DIR_INPUT; \
    pinin.input_pull = PORT_PIN_PULL_NONE; \
    port_pin_set_config(OW_PIN, &pinin);

/**
 * OW_HIGH - drive one-wire gpio pin high
 * OW_LOW - drive one-wire gpio pin low
 */
#define OW_HIGH() port_pin_set_output_level(OW_PIN, HIGH)
#define OW_LOW() port_pin_set_output_level(OW_PIN, LOW)

/**
 * OW_READ - read state of one-wire gpio pin
 */
#define OW_READ() port_pin_get_input_level(OW_PIN)

#endif /* OWHAL_H_ */
jensnielsen commented 9 years ago

Hi

Sorry I'm not familiar with the Atmel mcu's and to be honest I haven't looked at this project for ages... But as far as I can tell I don't see any problem with your implementation, what kind of problem do you have? Do you have an oscilloscope to check the behaviour on the wire? Are you running with or without OS?

BR /Jens

saurabh984 commented 9 years ago

Hi Jens,

Thank you for replying. I wish I had an oscilloscope or a logic analyser. Flying blind here. No OS. I guess it has something to do with timings. SAM D21 is a 48Mhz Arm Cortext M0+ CPU.

Any suggestions on the 5 defined time segments in your code? I'll try an find an analyser to see the what's going on.

Thanks again Saurabh

Sent from my iPhone

On 26 Dec 2014, at 9:20 am, Jens Nielsen notifications@github.com<mailto:notifications@github.com> wrote:

Hi

Sorry I'm not familiar with the Atmel mcu's and to be honest I haven't looked at this project for ages... But as far as I can tell I don't see any problem with your implementation, what kind of problem do you have? Do you have an oscilloscope to check the behaviour on the wire? Are you running with or without OS?

BR /Jens

Reply to this email directly or view it on GitHubhttps://github.com/jensnielsen/ds18b20/issues/3#issuecomment-68132478.

jensnielsen commented 9 years ago

Onewire is generally very insensitive to timing so you shouldn't need any particular precision on your delay function (I just use loops...)

I haven't double checked now and don't really remember but I should have chosen the delays somewhere in the middle of the allowed range so your delay function can be off in any direction without causing problems.

So unless your delay function is completely off (incorrectly configured clock or something) you should be fine. Maybe you can check the timing by using the delay function to just flash a led with 1 Hz? I don't think you need any better precision than you can verify by eye.

Otherwise I would double (or triple) check the wiring, I never implemented the parasite mode so you need all three pins (or modify the software accordingly) and make sure you have the proper pull-up.

BR /Jens

saurabh984 commented 9 years ago

Hi Jens,

Used the the onboard LED to verify the timing. It does seem correct. Even connected an LED to the pin instead of DS18B20 and it flashed I think 4 times which is the scan function. I'm not using parasite power mode.

Going to check if the sensor is working with Arduino to make sure it's not that which isn't working.

Thanks again for your help. I'll raise a PR for SAM D/R 21 owhal if I get this working.

S

Sent from my iPhone

On 26 Dec 2014, at 12:33 pm, Jens Nielsen notifications@github.com<mailto:notifications@github.com> wrote:

Onewire is generally very insensitive to timing so you shouldn't need any particular precision on your delay function (I just use loops...)

I haven't double checked now and don't really remember but I should have chosen the delays somewhere in the middle of the allowed range so your delay function can be off in any direction without causing problems.

So unless your delay function is completely off (incorrectly configured clock or something) you should be fine. Maybe you can check the timing by using the delay function to just flash a led with 1 Hz? I don't think you need any better precision than you can verify by eye.

Otherwise I would double (or triple) check the wiring, I never implemented the parasite mode so you need all three pins (or modify the software accordingly) and make sure you have the proper pull-up.

BR /Jens

Reply to this email directly or view it on GitHubhttps://github.com/jensnielsen/ds18b20/issues/3#issuecomment-68139496.

jensnielsen commented 9 years ago

Alright, sorry I couldn't be of any more help but now I don't know what else could be wrong. I'm quite biased to believe my code is correct... :)

If you're using my ds18b20.c as it is without any devices on the bus I think you should see two resets (bus low for ~500ms), one by the scan function which stops if it doesn't find any devices and another when issuing the first convert command. Maybe you can see something from the two bytes written to issue the actual command as well but after that it should be stuck waiting for any device to signal that conversion is complete. (That implementation could use some improvement but as I wrote in the readme it's just a dummy/guide to show how it can be used...)

Anyway, just let me know if you need any more help. I hope you can get it working, I'd be happy to pull your code

//Jens

coetzeec2380 commented 8 years ago

Has there a resolution porting ds18b20 code to samd21, regards

rennergade commented 6 years ago

This thread seems like its most likely dead, but was there ever a resolution here? I've ported this code for the SAMD21 but reading a bit always reads 1, and never 0.

jensnielsen commented 6 years ago

Yeah sorry I haven't used this stuff in several years and I don't have a samd21 to test with.. If anyone wants to contribute I'd be happy to pull it in though.