N
N
nemoforum2013-09-11 15:03:40
Do it yourself
nemoforum, 2013-09-11 15:03:40

Examples of using the DS18B20 driver from CooCox for STM32 (multiple sensors on the line)

Hello habrauser!

I'm trying to get the DS18B20 driver from CooCox for STM32 www.coocox.org/driver_comp/ds18b20-temperature-driver-using-1-wire-c12.html .
I didn't find any usage examples anywhere.

This is the code that builds but doesn't work:

#include "xhw_types.h"
#include "xsysctl.h"
#include "xgpio.h"
#include "xcore.h"
#include "xhw_memmap.h"
#include "DS18B20.h"


void pinSet()
{
}

int main(void)
{
// Set System Clock
xSysCtlClockSet(24000000, xSYSCTL_OSC_MAIN | xSYSCTL_OSC_INT);


tDS18B20Dev dev;
dev.ulPort = xGPIO_PORTB_BASE;
dev.ulPin = xGPIO_PIN_3;
dev.PinSet = pinSet;
DS18B20Init(&dev);

xtBoolean status = DS18B20Reset(&dev);
DS18B20ROMSkip(&dev);
DS18B20TempConvert(&dev);

float temp = 0.0;

status = DS18B20Reset(&dev);
DS18B20ROMSkip(&dev);
DS18B20TempRead(&dev, &temp);

    while(1)
    {
    }
}


Help with a working example, please, or with a working library for several sensors on a line.

Answer the question

In order to leave comments, you need to log in

7 answer(s)
D
DROS, 2013-09-11
@DROS

Hmm, isn't it necessary to put the polling of the sensors just in the while(1) {} loop???

O
Ocelot, 2013-09-11
@Ocelot

1. What does DS18B20Reset() return? Do the devices on the line even respond to the reset pulse?
2. Did you mess up anything with the timing? Does the controller operate at exactly the frequency that is needed? If the timings are wrong, 1-wire will not work.
It would be ideal to take an oscilloscope and see what exactly is happening on the line. It will be at least clear whether the skis are not moving ... or the problem is in the sensor polling, or in the interpretation of the result.

S
smartly, 2013-09-11
@smartly

I don't see any delay here between starting the conversion and reading the result. Well, SkipRom will not work with multiple sensors. How many are connected?

N
N0Good, 2013-09-13
@N0Good

At one time, I wrote in BASIC (Horror! The language requirement was related to the software used.) The implementation of the search function for devices on the 1-wire line.
If you don’t know the ROM device codes in advance, then you must necessarily implement a search. And, having received the ROM_Code, proceed further. If you know, then instead of DS18B20ROMSkip you need to use (I don’t know the exact function, but most likely there will be something similar) DS18B20ROMSelect (ROM_Code). Ie the function of selecting a device on the line.

N
N0Good, 2013-09-13
@N0Good

And if this is not done, then naturally it will not work with several sensors. After all, when executing DS18B20ROMSkip, you skip the selection of a device on the line (that is, initially assuming that there is only one device).
By the way, the search function may already be implemented in your library, read it.

E
Eddy_Em, 2013-09-18
@Eddy_Em

Working example: habrahabr.ru/post/161863/ (see link to sosforge).

T
tarasii, 2013-10-10
@tarasii

articles:
we.easyelectronics.ru/STM32/stm32-1-wire-dma-prodolzhenie.html
we.easyelectronics.ru/STM32/stm32-1-wire-dma.html
and my
habrahabr.ru/post/153395/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question