Would you like to react to this message? Create an account in a few clicks or log in to continue.

You are not connected. Please login or register

Creating DS18B20

2 posters

Go to page : 1, 2, 3  Next

Go down  Message [Page 1 of 3]

1Creating DS18B20 Empty Re: Creating DS18B20 Mon Apr 25, 2022 2:39 pm

n3645



I have started to implement this. However, truly 1-Wire protocol is not implemented at all? Thus one device is possible per pin? Protocol must exists, to support several commands and several devices. That is not possible currently, as ROM of the device must be read for identification...

I can create reading/writing temp. but that is not enough to support multiple devices on the same line..

2Creating DS18B20 Empty Re: Creating DS18B20 Mon Apr 25, 2022 3:39 pm

arcachofo

arcachofo

truly 1-Wire protocol is not implemented at all?
No, it's not implemented because there is no component using it.

Protocol must exists, to support several commands and several devices. That is not possible currently, as ROM of the device must be read for identification
You need to implement 1-Wire protocol in your component.

3Creating DS18B20 Empty Re: Creating DS18B20 Mon Apr 25, 2022 6:08 pm

n3645



I can hardly do that, as I have no deeper insight in your software.

All is related to Dallas Semiconductor 1-Wire devices and is the same for all...

Notice as well that 1-Wire bus can handle up to 63 devices. I.e. 63 connections per node, one more for pull-up resistor and MCU pin and each for VCC and GND. That means 100s lines per joint for multiple buses need to be implemented for proper handling, while current software handles only few....

Plus, 1-Wire devices can work on parasitic power... But then they may behaves a bit differently....

The 1-Wire bus is unique and must be carefully implemented, which is beyond my abilities, as I'm hardly scratched the essence in your software... What I can do is just to encode/decode data which specific device's commands produces. But protocol itself is something you have to implement as it is the same for all 1-Wire devices...

Probably, changes are way too complex to do all properly...

4Creating DS18B20 Empty Re: Creating DS18B20 Mon Apr 25, 2022 9:12 pm

arcachofo

arcachofo

I can hardly do that, as I have no deeper insight in your software.
DHT22 uses a custom 1 wire protocol.
You can use it as a reference.
It's all about adapting it to Dallas Semiconductor 1-Wire protocol.

5Creating DS18B20 Empty Re: Creating DS18B20 Mon Apr 25, 2022 9:43 pm

n3645



Unfortunately, 1-Wire protocol is much more complicated than that...

If and when you can do it, it is entirely on you. Basic sequence:
- Reset
- Enumerate devices. Search devices / reading ROM for each device on the bus
- Sending commands and receiving data to/from specific device

Implementing bit-banging protocol in your software is not in my power.

6Creating DS18B20 Empty Creating DS18B20 Mon Apr 25, 2022 10:18 pm

arcachofo

arcachofo

Implementing bit-banging protocol in your software is not in my power.
Implementing communication is quite simple:
1- Detect Reset: exactly the same than DHT22 but different timing.
2- Send "ACK": exactly the same than DHT22 but different timing.
3- Start to read bits: exactly the same than Detect Reset but different timing.
4- Every 8 bits = 1 byte received: Do whatever with each byte received.

I don't know much about this protocol, but if I understand correctly Master also clocks the Slave to send each bit.
If so, sending data is even easier than DHT22:
1-  Detect start signal: exactly the same than Detect Reset  but different timing.
2- If bit = 0: Pull line down  exactly the same than Send "ACK" but different timing.
   If bit = 1: Do nothing.

All this is implemented in DHT22::voltChanged() and DHT22::runEvent() functions.


Unfortunately, 1-Wire protocol it is much more complicated than that...

If and when you can do it, it is entirely on you. Basic sequence:
- Reset
- Enumerate devices
- Search devices
- Read ROM
- Sending command and receiving data
As far as I know that is what the Master does.
The slave just receive bytes and takes actions depending on the byte number ant content.
So some kind of "state machine" must be implemented that do whatever with received bytes.

Tomorrow I will send you a basic implementation of the bit-banging protocol:
Basically copy-paste from DHT22 with some changes.

7Creating DS18B20 Empty Re: Creating DS18B20 Tue Apr 26, 2022 11:24 am

arcachofo

arcachofo

Attached basic implementation for DS18B20.
Full component ready for use with bitbanging implemented (NOT TESTED).
It's basically a mix betwen DHT22 and DS1621.

Add it to src/gui/circuitwidget/itemlibrary.cpp:
After line 47:
Code:
#include "ds1307.h"
#include "ds1621.h"
#include "ds18b20.h" // Add this line

After line 240:
Code:
    addItem( Dht22::libraryItem() );
    addItem( DS1621::libraryItem() );
    addItem( Ds18b20::libraryItem() ); // Add this line

Component is now available in component list: Micro->Sensors.

Now you can do stuff at
Ds18b20::byteReceived() // a byte has been received (it's in m_data)
Ds18b20::byteSent() // Last byte has been sent

To send data just use:
sendByte( data );

It is not tested, so expect errors, but all the "infrastucture" to receive and send data is there.
I would start by testing that it's actually receiving data correctly.
Then you can start to implement whatever must be done with that data.
Attachments
Creating DS18B20 Attachmentds18b20.zip
You don't have permission to download attachments.
(4 Kb) Downloaded 8 times



Last edited by arcachofo on Tue Apr 26, 2022 12:53 pm; edited 2 times in total (Reason for editing : Add attachment)

8Creating DS18B20 Empty Re: Creating DS18B20 Tue Apr 26, 2022 11:34 am

n3645



Can you check, I do not see any attachment here...

9Creating DS18B20 Empty Re: Creating DS18B20 Tue Apr 26, 2022 12:51 pm

arcachofo

arcachofo

Sorry, forgot to click some button...
Attachment added in previous post.

10Creating DS18B20 Empty Re: Creating DS18B20 Tue Apr 26, 2022 2:30 pm

n3645



OK... I will look on it later.

11Creating DS18B20 Empty Re: Creating DS18B20 Wed Apr 27, 2022 11:55 pm

n3645



I have added some code, which should work independently (tested). However, existed simulator code reading and sending bytes with some problems, I'm unable to fix

The simulator read something, but not correctly. I believe bits are mirrored (should be read LSB to MSB, not MSB to LSB) and/or skip or miss interpreted some signals...

It is really necessary to create 1-Wire protocol lib, as similarly existed for I2C and others...

Attached current DS18B20 code, simulator file with Arduino samples. One uses Arduino lib, others not.

Try first with DS18B20_nolib1.ino and debug code which sending CCh.. Simulator wrongly received 19h...

By side of datasheet and flow chart, look also these:

Detailed explanation of the 1-Wire protocol Part 1-6:
https://www.youtube.com/watch?v=UR_cAvNjUZc&list=PLHZCZKKB20XZ6gE3Ki8A7TVkjJRkA12Xk

1-Wire – Through the Looking Glass (Scope) and Down the Rabbit Hole (Bit Level):
https://www.youtube.com/watch?v=UIx8R1LV6HM
Attachments
Creating DS18B20 AttachmentDS18B20_test.zip
You don't have permission to download attachments.
(42 Kb) Downloaded 6 times

12Creating DS18B20 Empty Re: Creating DS18B20 Thu Apr 28, 2022 2:25 am

arcachofo

arcachofo

The simulator read something, but not correctly. I believe bits are mirrored (should be read LSB to MSB, not MSB to LSB)
Yes, that was the problem.
Solved at Rev 1129;

13Creating DS18B20 Empty Re: Creating DS18B20 Thu Apr 28, 2022 3:05 am

arcachofo

arcachofo

sendByte() fixed at Rev 1130.

14Creating DS18B20 Empty Re: Creating DS18B20 Thu Apr 28, 2022 3:36 am

n3645



Thank you for the feedback.

You will then continue on this to add rest?

BTW, seems that sending bytes still have a problem.

15Creating DS18B20 Empty Re: Creating DS18B20 Thu Apr 28, 2022 10:33 am

arcachofo

arcachofo

You will then continue on this to add rest?
No.

16Creating DS18B20 Empty Re: Creating DS18B20 Thu Apr 28, 2022 10:55 am

n3645



OK, I will then...

But first, please fix that problem with sending data.

17Creating DS18B20 Empty Re: Creating DS18B20 Thu Apr 28, 2022 11:08 am

arcachofo

arcachofo

But first, please fix that problem with sending data.
Can you define the problem?
How to reproduce it?

18Creating DS18B20 Empty Re: Creating DS18B20 Thu Apr 28, 2022 11:12 am

n3645



Yes, send multiple bytes to master. E.g. execute "Read ROM" command (33h). Nothing is sent or just one byte with 00h...

Also look at byteSent(), it is never executed, or just for one byte, instead all 8 bytes, for upper command 33h.

19Creating DS18B20 Empty Re: Creating DS18B20 Thu Apr 28, 2022 11:42 am

arcachofo

arcachofo

E.g. execute "Read ROM" command (33h). Nothing is sent or just one byte with 00h
Is that command implemented?
That's what needs to be done: implementing commands.

Also look at byteSent(), it is never executed
Is executed when you call it.
When the byte is sent then byteSent() is called.

or just for one byte, instead all 8 bytes
That's what you have to implement.

20Creating DS18B20 Empty Re: Creating DS18B20 Thu Apr 28, 2022 12:03 pm

n3645



Well, I did and I have sent you all with examples yesterday...
You have not implemented that, just fixed bugs with receive bytes.

I did insert all that codes with new version and tested - it failed to send data.

I will resend you all with some added new code...

21Creating DS18B20 Empty Re: Creating DS18B20 Thu Apr 28, 2022 1:03 pm

arcachofo

arcachofo

Well, I did and I have sent you all with examples yesterday...
Sorry I didn't realize.

Some issues I found:
Code:
void Ds18b20::readROM()
{
    /// Code: 33h
    /// If there is only one device on the bus, no need for search ROM procedure
    /// Master demands ROM address of it

    for(int i=0; i<8; i++)
    {
       sendByte(m_ROM[i]);
    }
}
You can't do that.
You need to send one byte, when that byte is sent then you send next one and so on.
same for Ds18b20::readScratchpad().

Ds18b20::command is never called.

22Creating DS18B20 Empty Re: Creating DS18B20 Thu Apr 28, 2022 1:23 pm

n3645



And the way to do that properly is?

I have told you that I have no deeper insight in your software. It is probably heavily threaded, but I really do not have a time to look deeper.

And for instance, temperature reading in real device (command 44h) last 750ms max (for 12-bit resolution). How to accomplish that here, not to affect overall performance?

Commands was in process of implementation, that code was current implementation and could be called directly for test...

I have almost implemented all commands, just need solution for upper...

23Creating DS18B20 Empty Re: Creating DS18B20 Thu Apr 28, 2022 2:31 pm

arcachofo

arcachofo

And the way to do that properly is?
You need to send one byte.
When the byte is sent then byteSent() is called.
Then you send next byte and so on.

I have told you that I have no deeper insight in your software.
This is not specific for simulide.
You just need to implement some way to send an array one byte at a time.

Probably implementing a method: sendData( std::vector<uint8_t> data )
Consider using std::vector instead of plain arrays.
For example something like this:
- Save the vector to send.
- Send first byte.
- In byteSent():
   Vector is empty?
   True: Transaction finished.
   False: Use data.pop_back() to take the last byte and call sendByte()

And for instance, temperature reading in real device (command 44h) last 750ms max (for 12-bit resolution). How to accomplish that here, not to affect overall performance?
As I understand this is not critical by now.
This can be fine tuned later.

24Creating DS18B20 Empty Re: Creating DS18B20 Mon May 02, 2022 12:25 am

n3645



This is preliminary code. Many things still missing, but basic is fully functional.

What is working are basic examples with 1-wire Arduino libraries. I will add some basic examples later (test I'm using require quite a bit of cleaning), if needed.

Dallas Semiconductor lib will not work, since search ROM is still not implemented.
Attachments
Creating DS18B20 Attachmentds18b20 - 2022.05.01 preliminary code.zip
You don't have permission to download attachments.
(10 Kb) Downloaded 4 times

arcachofo likes this post

25Creating DS18B20 Empty Re: Creating DS18B20 Tue May 03, 2022 8:05 pm

n3645



According to latest bug report regarding different speed when interrupts are disabled, this may  explain why this component is unstable.

For instance, 1-wire lib use that method for precise delay timings:
https://github.com/PaulStoffregen/OneWire/blob/master/OneWire.cpp

Sponsored content



Back to top  Message [Page 1 of 3]

Go to page : 1, 2, 3  Next

Permissions in this forum:
You cannot reply to topics in this forum