Answer the question
In order to leave comments, you need to log in
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)
{
}
}
Answer the question
In order to leave comments, you need to log in
Hmm, isn't it necessary to put the polling of the sensors just in the while(1) {} loop???
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.
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?
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.
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.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question