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

Can not search and get value from OneWire Ds18B20 or HDT22/11

4 posters

Go down  Message [Page 1 of 1]

firefox66



Hi,

At the beginning, I work with LCD through i2c (it done), then show up the  temperature of DS18B20 or DHT22/11 through OneWire (1Wire). And I can not get thing done with search device method (notthing show up on LCD because no device through OneWire has been deteced).

In addition, I uploaded a same hex on my real board, I Work fine (detected 1 devices, get ROM CODE, Show temperature...)

Conclusion, Do anyone succeed in searching and show up value with these devices DS18B20 and DHT22/11 or any advice for solution?

Thanks.

Can not search and get value from OneWire Ds18B20 or HDT22/11 _a35603c5bc69144f6fa2c4fa99753ca4 Can not search and get value from OneWire Ds18B20 or HDT22/11 _e570f83b15c9149c0e496980098a1514 Can not search and get value from OneWire Ds18B20 or HDT22/11 _15359103fb68ed8e5c6e0c471f406b77 Can not search and get value from OneWire Ds18B20 or HDT22/11 _e06f0a9bd1afe38a462eaf611035dd46 Can not search and get value from OneWire Ds18B20 or HDT22/11 _4d6778c3b43a51c19df600ac475618d8 Can not search and get value from OneWire Ds18B20 or HDT22/11 E795024bd2ff6a226ab1fcfcdd061a36
Attachments
Can not search and get value from OneWire Ds18B20 or HDT22/11 AttachmentLcdI2c_DS18B20_DHT22.zip
You don't have permission to download attachments.
(10 Kb) Downloaded 3 times



Last edited by arcachofo on Wed Jun 08, 2022 6:55 pm; edited 1 time in total (Reason for editing : Mark as solved (green color))

Defran

Defran

Attach the source program, please.

arcachofo likes this post

arcachofo

arcachofo

DHT11/22 does not use Dallas 1-Wire protocol, it needs it's own libraries.
There is an example in simulide:
Left_Panel->File_Browser->Examples->Micro->Sensors-Arduino_DHT22
(open serial monitor to see readings)

DS18B20 is not finished, so somethings might not work.
Anyway attached a working example reading 3 devices.
Attachments
Can not search and get value from OneWire Ds18B20 or HDT22/11 AttachmentDS18B20.zip
You don't have permission to download attachments.
(11 Kb) Downloaded 3 times

firefox66



arcachofo wrote:DHT11/22 does not use Dallas 1-Wire protocol, it needs it's own libraries.
There is an example in simulide:
Left_Panel->File_Browser->Examples->Micro->Sensors-Arduino_DHT22
(open serial monitor to see readings)

DS18B20 is not finished, so somethings might not work.
Anyway attached a working example reading 3 devices.

I Agree with you that DHT22/11 code in different method than DS18B20 and DS18B20 have a lot thing to be done with this but please, finished what you have started with DS18B20.

P/S: I have no idea why Sensor in SimulIDE work on Arduio Uno with it LIB belong to? may be someone should try it on WinAVR (trandition code for AVR Chip).

Conclusion, I have just tested same code, same hex in Proteus Simulate, it work fine without any problem and compare with my real board.

Thanks

Can not search and get value from OneWire Ds18B20 or HDT22/11 Aebe33830e85f64ab1f0af8f4be115e3 Can not search and get value from OneWire Ds18B20 or HDT22/11 24d149ecc31aea1e2da7f2fbf0d6635d Can not search and get value from OneWire Ds18B20 or HDT22/11 Ac3464b4747653cac5ca57f1b4957e21



Last edited by firefox66 on Wed Jun 08, 2022 12:01 am; edited 1 time in total

firefox66



Defran wrote:Attach the source program, please.

Code:

// main.c

#include "projConfig.h"

// Declare your global variables here
char lcd_buffer[33];
int varTemp;

/* maximum number of DS18B20 connected to the 1 Wire bus */
#define MAX_DEVICES 8

/* DS18B20 devices ROM code storage area */
unsigned char rom_code[MAX_DEVICES][9];

void init(void) {  // init all port
 // Crystal Oscillator division factor: 1
#pragma optsize-
 CLKPR = (1 << CLKPCE);
 CLKPR = (0 << CLKPCE) | (0 << CLKPS3) | (0 << CLKPS2) |
  (0 << CLKPS1) | (0 << CLKPS0);
 #ifdef _OPTIMIZE_SIZE_
#pragma optsize+
 #endif


 // USART initialization
 // Communication Parameters: 8 Data, 1 Stop, No Parity
 // USART Receiver: Off
 // USART Transmitter: On
 // USART Mode: Asynchronous
 // USART Baud Rate: 9600
 UCSR0A = (0 << RXC0) | (0 << TXC0) | (0 << UDRE0) |
 (0 << FE0) | (0 << DOR0) | (0 << UPE0) | (0 << U2X0) |
 (0 << MPCM0);
 UCSR0B = (0 << RXCIE0) | (0 << TXCIE0) | (0 << UDRIE0) |
 (0 << RXEN0) | (1 << TXEN0) | (0 << UCSZ02) |
 (0 << RXB80) | (0 << TXB80);
 UCSR0C = (0 << UMSEL01) | (0 << UMSEL00) | (0 << UPM01) |
 (0 << UPM00) | (0 << USBS0) | (1 << UCSZ01) |
 (1 << UCSZ00) | (0 << UCPOL0);
 UBRR0H = 0x00;
 UBRR0L = 0x33;

 // TWI initialization
 // Mode: TWI Master
 // Bit Rate: 100 kHz
 twi_master_init(100);

 // 1 Wire Bus initialization
 // 1 Wire Data port: PORTC
 // 1 Wire Data bit: 0
 // Note: 1 Wire port settings are specified in the
 // Project|Configure|C Compiler|Libraries|1 Wire menu.
 w1_init();

 // Globally enable interrupts
#asm("sei")

 // I2C LCD Shield initialization for TWI
 // PCF8574 I2C bus address: 0x27
 // LCD characters/line: 16
 lcd_twi_init(0x27, 16);

}

void main(void) {
 // Declare your local variables here
 unsigned char devices;
 unsigned char i, j;

 // Init all port
 init();

 lcd_printfxy(0, 0, "LCD I2C Ds18B20");
 delay_ms(600);
 lcd_clear();

 devices = w1_search(0xf0, rom_code);
 sprintf(lcd_buffer, "%u DS18B20\nDevice detected", devices);
 lcd_puts(lcd_buffer);
 delay_ms(1000);
 lcd_clear();

 // display the ROM codes for each device
 if (devices) {
 for (i = 0; i < devices; i++) {
 sprintf(lcd_buffer, "Device #%u ROM\nCode is:", i + 1);
 lcd_clear();
 lcd_puts(lcd_buffer);
 delay_ms(2000);
 lcd_clear();
 for (j = 0; j < 8; j++) {
 sprintf(lcd_buffer, "%02X ", rom_code[i][j]);
 lcd_puts(lcd_buffer);
 if (j == 3) lcd_gotoxy(0, 1);
 };
 delay_ms(2000);
 };
 } else
 while (1);  // stop here if no devices were found
 lcd_clear();

 lcd_gotoxy(0, 0);
 lcd_puts("Nhiet cam bien");

 while (1) {

 lcd_gotoxy(0, 1);
 varTemp = ds18b20_temperature(&rom_code[0][0]);
 sprintf(lcd_buffer, "%i.%u", varTemp,
  abs(varTemp % 10));
 lcd_puts(lcd_buffer);


 }
}

arcachofo

arcachofo

There are 2 different isues here: DHT22 and DS18B20.
Ideally you should open a topic for each one, but we can continue with both here.

To find what is the problem I need to test your circuit and code.
So I need the circuit and source code for each issue.

The circuit in your first post is for DHT22, but there is no source code.
The source code in your last post is for DS18B20, but there is no circuit.

Also the source code must be complete, if not I can't test it.
The source code in your last post includes another file "projConfig.h" so I can't compile it.

arcachofo

arcachofo

I think you are using DS18B20 code with DHT22 component.
That doesn't work.

firefox66 likes this post

n3645



The latest working code for DS18B20 is here:
https://simulide.forumotion.com/t607p50-creating-ds18b20

I have worked on it. Unfortunately, I'm still quite busy in order to complete it, but anyway the last code should work in the most cases, arduino libraries and direct coding for 1-wire protocol.

firefox66



arcachofo wrote:I think you are using DS18B20 code with DHT22 component.
That doesn't work.

At the first time, my schematic is DS18B20. It didn't work then I replace it with DHT22/11 and take a picture (in my real board I included at the first post, I tested DS18B20 in stead of DHT22/11). Sorry about this to make you confused.

In addition, I wrote all my project in CodeVision AVR and even though I  give you the code then you can not compile without license install file. It still has command-line in compile but it checks for license before do all processing.

Sorry about this inconvenience problem. I dont't make a code on WinAVR or Arduino... But I sure that my hex file work on Real board, Proteus simulator and I think that It also works well with SimulIDE if it running in correct programmable device.

P/S: My project larger than permitting size for upload - error code:
Uploaded file is not valid: exceeded attachment maxsize (50 kB).

Can not search and get value from OneWire Ds18B20 or HDT22/11 E4ded536fa9efbcfc51cfb73fdfbf9f5
Attachments
Can not search and get value from OneWire Ds18B20 or HDT22/11 Attachmentproj008_CAVR__LcdI2c_DS12B80.zip
You don't have permission to download attachments.
(48 Kb) Downloaded 4 times

arcachofo

arcachofo

Ok, now I understand.

It is good to have the source code even if I can't compile, because at least I can see what the code is trying to do.
I guess that CodeVision libraries are propietary and there is no source code available.
Then it is really difficult to know what is going on.

I can dissassemble the hex file and try to understand what is happening, but that is no easy task...

firefox66 likes this post

firefox66



arcachofo wrote:Ok, now I understand.

It is good to have the source code even if I can't compile, because at least I can see what the code is trying to do.
I guess that CodeVision libraries are propietary and there is no source code available.
Then it is really difficult to know what is going on.

I can dissassemble the hex file and try to understand what is happening, but that is no easy task...


I also included main.cof for debug. I hope it will help you to finish DS18B20 simulating device. when all done, I will post this to "project with SimulIDE"

n3645



Well, what is the 1-Wire bus? There is an weird signal on C0.

What is exact frequency? Internal 8Mhz?

Is it D18B20 in parasite or external power mode?

Pull up resistor on the bus is way too large. Should be 4.7K at most instead 10K. Although now that shouldn't be an issue.

arcachofo

arcachofo

Finally the problem was not in D18B20 but in AVR pins: PINx register not updating correctly in some cases.
Solved at Rev 1233.

firefox66 likes this post

firefox66



arcachofo wrote:Finally the problem was not in D18B20 but in AVR pins: PINx register not updating correctly in some cases.
Solved at Rev 1233.

That why Arduino work fine instead of avr chip. thanks your hard work

arcachofo likes this post

Sponsored content



Back to top  Message [Page 1 of 1]

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