Giter VIP home page Giter VIP logo

avr-ds18b20's Introduction

avr-ds18b20

The MIT License Travis CI

avr-ds18b20 is an AVR library for controlling DS18B20 temperature sensors. It can be easily compiled for every micro-controller supported by avr-gcc.

Usage example

#include <avr/io.h>
#include <util/delay.h>
#include <stdio.h>

#include <ds18b20/ds18b20.h>

int main( )
{
	int temp;

	while ( 1 )
	{
		//Start conversion (without ROM matching)
		ds18b20convert( &PORTB, &DDRB, &PINB, ( 1 << 0 ), NULL );

		//Delay (sensor needs time to perform conversion)
		_delay_ms( 1000 );

		//Read temperature (without ROM matching)
		ds18b20read( &PORTB, &DDRB, &PINB, ( 1 << 0 ), NULL, &temp );

		//Somehow use data stored in `temp` variable
	}

	return 0;
}

For more information visit wiki.

avr-ds18b20's People

Contributors

arcadien avatar jacajack avatar thorbane avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

avr-ds18b20's Issues

Failed to reading data from non-liquid sensor

Hi and thanks for avr-ds18b20.

I'm trying to read temp from a non-liquid DS18B20 sensor (+ 4.7K pull-up resistor) using an ATmega8A.
The simple routine looks like this:

#include <avr/io.h>
#include <stdio.h>

#define F_CPU 11059200
#include <util/delay.h>

#define D4 eS_PORTB0
#define D5 eS_PORTB1
#define D6 eS_PORTB2
#define D7 eS_PORTB3
#define RS eS_PORTB5
#define EN eS_PORTB4
#include "lcd.h"

#include "ds18b20/ds18b20.h"

int main() {
	DDRB = 0xFF;
	Lcd4_Init();

	char buff[16];
	int temperature;
	uint8_t code1, code2;

	while (1) {
		code1 = ds18b20convert(&PORTC, &DDRC, &PINC, (1 << PORTC0), NULL);
		_delay_ms(1000);
		code2 = ds18b20read(&PORTC, &DDRC, &PINC, (1 << PORTC0), NULL, &temperature);

		sprintf(buff, "%d %d %d", code1, code2, temperature);
		Lcd4_Clear();
		Lcd4_Write_String(buff);
	}
	return 0;
}

But the reading and converting procedures both will fail with error code DS18B20_ERROR_COMM.
I'm 100% sure of the sensor (already tested with Arduino) and the circuitry.
What might be the problem here ?

Regards.

ds18b20.o is defining things like "__TEXT_REGION_LENGTH__"

I have noticed a peculiarity with your output from the makefile. It defines things it really shouldn't, for example

ericu@raspberry:~/builds/avr-ds18b20$ avr-objdump -t obj/ds18b20.o 

obj/ds18b20.o:     file format elf32-avr

SYMBOL TABLE:
00000000 l    d  .text	00000000 .text
00000000 l    d  .data	00000000 .data
00000000 l    d  .bss	00000000 .bss
00000000 l    d  .comment	00000000 .comment
00000000 l    df *ABS*	00000000 onewire.c
0000003e l       *ABS*	00000000 __SP_H__
0000003d l       *ABS*	00000000 __SP_L__
0000003f l       *ABS*	00000000 __SREG__
00000000 l       *ABS*	00000000 __tmp_reg__
00000001 l       *ABS*	00000000 __zero_reg__
00000000 l    df *ABS*	00000000 ds18b20.c
0000003e l       *ABS*	00000000 __SP_H__
0000003d l       *ABS*	00000000 __SP_L__
0000003f l       *ABS*	00000000 __SREG__
00000000 l       *ABS*	00000000 __tmp_reg__
00000001 l       *ABS*	00000000 __zero_reg__
0000ffa0 g       *ABS*	00000000 __DATA_REGION_LENGTH__
00000078 g     F .text	00000068 onewireWriteBit
00000142 g     F .text	00000050 onewireReadBit
00000400 g       *ABS*	00000000 __LOCK_REGION_LENGTH__
00000422 g     F .text	00000060 ds18b20csp
000002e0 g     F .text	000000ba ds18b20rsp
000004ee g     F .text	000000d0 ds18b20rom
00000400 g       *ABS*	00000000 __SIGNATURE_REGION_LENGTH__
00000220 g     F .text	0000006e ds18b20match
00000482 g     F .text	0000006c ds18b20read
0000028e g     F .text	00000052 ds18b20convert
000001f8 g     F .text	00000028 ds18b20crc8
00000400 g       *ABS*	00000000 __USER_SIGNATURE_REGION_LENGTH__
00000192 g     F .text	00000066 onewireRead
00000000 g     F .text	00000078 onewireInit
0000039a g     F .text	00000088 ds18b20wsp
00010000 g       *ABS*	00000000 __EEPROM_REGION_LENGTH__
000000e0 g     F .text	00000062 onewireWrite
00000400 g       *ABS*	00000000 __FUSE_REGION_LENGTH__
00002000 g       *ABS*	00000000 __TEXT_REGION_LENGTH__

These values like __TEXT_REGION_LENGTH__ are actually chip specific (not even arch. specific). In my case I have lost about 2 hours trying to understand why avr-gcc thinks a 8kb program is too large.

Inspecting the object in obj/tmp/ds18b20.o reveals that these values are not present. They are somehow being added when your makefile does avr-ld -r ...

My suggestion would be to avoid using avr-ld in this way. I don't have enough experience with the avr gcc compiler to know how to avoid these symbols

Having only DS18B20_ERROR_COMM

Hello,

I spent some times on this library to know how to use it, but I'm still having the same error.

I saw the issue of @IMAN4K.

To remove this error, simply add the F_CPU define to all files that contain the util/delay.h library

Of course, this define must be added before calling the util/delay.h include.

Exemple :
#define F_CPU 16000000UL #include <util/delay.h>

This means that the correct F_CPU define must be added to the :

  • ds18b20.c
  • onewire.c
  • and of course main.py

Here it is, I hope it will help some people, so they don't waste time.

TheAce58

ds18b20_romsearch() improvements

Currently, if there's not enough space to store all the discovered ROM addresses, ROM count is returned as zero and no ROMs are written to the provided array.

Instead, the function shall return number of successfully read ROMs, that is the number of ROM addresses that fit in the provided array.

avr-ds18b20/src/romsearch.c

Lines 130 to 140 in 9ace5f9

if ( roms != NULL )
{
//Check if ROM buffer can be written
if ( ( currom << 3 ) + ( i >> 3 ) >= buflen )
{
*romcnt = 0;
SREG = sreg;
return DS18B20_ERROR_OTHER;
}
arrbitw( &roms[currom << 3], i, bit );
}

interrupts

Hi, I am using you ds18b20 library in my modbus project on atmega328. I wants to inform you about little issue, yaMBSiavr modbus library doesn't work until I comment all cli() interrupt disable functions. I know this functions needed for proper readings of sensor. But without cli() sensor works fine with multiple other connected sensors like dht22, mq135 on the same board.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.