CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

ds1923

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
zio_pecos



Joined: 24 Oct 2004
Posts: 21
Location: italy

View user's profile Send private message

ds1923
PostPosted: Fri Nov 19, 2004 2:56 am     Reply with quote

hi,

i wrote this code to obtain an humidity measurement with ds1923

Code:

 if(touch_present()){

//starting up RTC


touch_write_byte(0xcc);//skip rom command


touch_write_byte(0x0f);

touch_write_byte(0x00);//low   TA1, beginning offset
touch_write_byte(0x02);//high  TA2

touch_write_byte(0x00);
touch_write_byte(0x00);//hour
touch_write_byte(0x0a);

touch_write_byte(0x1b);
touch_write_byte(0x0a);//day
touch_write_byte(0x04);

touch_write_byte(0x0a);//sample rate
touch_write_byte(0x00);


touch_write_byte(0x00);
touch_write_byte(0x00);
touch_write_byte(0x00);//humdity and temperature alarm (off)
touch_write_byte(0x00);


touch_write_byte(0xff);
touch_write_byte(0xff);//indirizzi 020ch 020dh 020eh 020fh
touch_write_byte(0xff);
touch_write_byte(0xff);


touch_write_byte(0x00);//temp alarm off

touch_write_byte(0xfc);//hum alarm off

touch_write_byte(0x01);//low sample rate

touch_write_byte(0xc8);//general control mission register

touch_write_byte(0xff);//alarm status
touch_write_byte(0xff);//general status    (questi registri nn sono accessibili in scrittura!!ecco xkè scrivo così)

touch_write_byte(0x00);
touch_write_byte(0x00);//mission start delay
touch_write_byte(0x00);


touch_write_byte(0xff);touch_write_byte(0xff);touch_write_byte(0xff);touch_write_byte(0xff);touch_write_byte(0xff);
touch_write_byte(0xff);touch_write_byte(0xff);


                 if(touch_present()){

touch_write_byte(0xcc);//skip rom

touch_write_byte(0xaa);//verify scracthpad


c=touch_read_byte();//receiving ta1  00h
d=touch_read_byte();//receiving ta2  02h
e=touch_read_byte();//receiving E/S  1fh
//f=touch_read_byte();//receiving data byte

for(m=0;m<32;m++)
{
 m1[m]=touch_read_byte();//leggo i 32byte che ho scritto nello scratchpad
}

                 if(touch_present()){

touch_write_byte(0xcc);//skip rom



touch_write_byte(0x99);//copy scratchpad command


touch_write_byte(0x00);//transmitting ta1
touch_write_byte(0x02);//transmitting ta2
touch_write_byte(0x1f);//transmitting e/s


            touch_write_byte(0xff);//
            touch_write_byte(0xff);//
            touch_write_byte(0xff);//
            touch_write_byte(0xff);//
            touch_write_byte(0xff);//         64 bit dummy password
            touch_write_byte(0xff);//
            touch_write_byte(0xff);//
            touch_write_byte(0xff);//


                 if(touch_present()){



touch_write_byte(0xcc);//skip rom

             touch_write_byte(0x55);//forced conversion

//After the command code the master has to send one FFh byte to get the conversion started

            touch_write_byte(0xff);//dummy byte

output_high(touch_pin);
delay_ms(1000);//the conversion needs 666ms


        if(touch_present()){

        touch_write_byte(0xcc);//skip rom command


touch_write_byte(0x69);

      touch_write_byte(0x0e);//low   
      touch_write_byte(0x02);//high


            touch_write_byte(0xff);//
            touch_write_byte(0xff);//
            touch_write_byte(0xff);//
            touch_write_byte(0xff);//
            touch_write_byte(0xff);//         64 bit dummy password
            touch_write_byte(0xff);//
            touch_write_byte(0xff);//
            touch_write_byte(0xff);//



hrl=touch_read_byte();
hrh=touch_read_byte();


someone of you can tell me if this code is correct

i ask you this because i've just burnt 2 ds1923...

moreover someone has tested code for this sensor???


thank you very much
zio_pecos



Joined: 24 Oct 2004
Posts: 21
Location: italy

View user's profile Send private message

PostPosted: Tue Nov 23, 2004 12:55 am     Reply with quote

noone can help me?
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

Re: ds1923
PostPosted: Tue Nov 23, 2004 5:45 am     Reply with quote

zio_pecos wrote:

i ask you this because i've just burnt 2 ds1923...


This sounds mor like a wiring problem than code problem...describe your circuit.
zio_pecos



Joined: 24 Oct 2004
Posts: 21
Location: italy

View user's profile Send private message

PostPosted: Tue Nov 23, 2004 9:44 am     Reply with quote

A temperature or humidity
conversion must not be attempted while the RTC oscillator is
stopped. This causes the device to enter into an unrecoverable state.

i programmed my devices and while the RTC oscillator was
stopped!!


so i've burnt them...
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue Nov 23, 2004 11:56 am     Reply with quote

1) Your code is hard to read because of irregular indenting.
2) Your code is incomplete:
- No function headers
- Several times a '{' , but never a '}' character.
- Missing functions.


A '1 wire' protocol is error prone, that's why they implemented several security checks. You are doing the required read commands, but you never check the results. So how can you be sure the RTC is enabled?

After the Copy Scratchpad command you should add a test for the AA (Authorization Accepted) flag being set. Without this flag being set by the DS1923 you know the Copy command failed.

You discovered the 'forced conversion' command can bring the device in an infinite undefined state. So why aren't you checking the RTC is running before executing this oommand? This is another murder waiting to happen.
zio_pecos



Joined: 24 Oct 2004
Posts: 21
Location: italy

View user's profile Send private message

PostPosted: Tue Nov 23, 2004 4:49 pm     Reply with quote

this is the whole code...



Code:

#include "C:\USB\generale\sensori.h"
//Tells the CCS PIC USB firmware to include HID handling code.
#DEFINE USB_HID_DEVICE  TRUE
//Set this to FALSE if you only want to test enumeration.  Some USB test programs,


//such as USBCHECK, crash if you are trying to test enumeration and the device
//starts sending data once configured.
#DEFINE USB_RUN_WHEN_CONFIGURED  TRUE

//the following defines needed for the CCS USB PIC driver to enable the TX endpoint 1
#define USB_EP1_TX_ENABLE  1   //turn on EP1 for IN bulk/interrupt transfers
#define USB_EP1_TX_SIZE    8   //if you change this, be sure to change the hid descriptor

//the following defines needed for the CCS USB PIC driver to enable the RX endpoint 1
#define USB_EP1_RX_ENABLE  1   //turn on EP1 for OUT bulk/interrupt transfers
#define USB_EP1_RX_SIZE    8   //if you change this, be sure to change the hid descriptor




#include "C:\USB\usb_desc_bruno.h"
#include <pic_usb.h>
#include <usb.c>
#include <TOUCH.C>


void main() {

   int8 c,d,e,m,m1[32];

   int8 hrl,hrh;

   int8 out_data[USB_EP1_TX_SIZE];//array outgoing data


 
 usb_init();
 usb_wait_for_enumeration();

   if(usb_enumerated())

       while(1){

              if(touch_present())//inizializzazione
               {
                 if(touch_present()){


//starting up RTC


touch_write_byte(0xcc);//skip rom command
touch_write_byte(0x0f);//Write Scratchpad command,

touch_write_byte(0x00);//low   TA1, beginning offset
touch_write_byte(0x02);//high  TA2

touch_write_byte(0x00);
touch_write_byte(0x00);//hour
touch_write_byte(0x0a);

touch_write_byte(0x1b);
touch_write_byte(0x0a);//day
touch_write_byte(0x04);

touch_write_byte(0x0a);//sample rate
touch_write_byte(0x00);


touch_write_byte(0x00);
touch_write_byte(0x00);
touch_write_byte(0x00);//humdity and temperature alarm (off)
touch_write_byte(0x00);


touch_write_byte(0xff);
touch_write_byte(0xff);
touch_write_byte(0xff);
touch_write_byte(0xff);


touch_write_byte(0x00);//temp alarm off

touch_write_byte(0xfc);//hum alarm off

touch_write_byte(0x01);//low sample rate

touch_write_byte(0xc8);//general control mission register

touch_write_byte(0xff);//alarm status
touch_write_byte(0xff);//general status

touch_write_byte(0x00);
touch_write_byte(0x00);//mission start delay
touch_write_byte(0x00);
//these 25 bytes set the rtc


touch_write_byte(0xff);touch_write_byte(0xff);touch_write_byte(0xff);touch_write_byte(0xff);touch_write_byte(0xff);
touch_write_byte(0xff);touch_write_byte(0xff);
//these 7 byte complete the scratchpad writing


                 if(touch_present()){

touch_write_byte(0xcc);//skip rom

touch_write_byte(0xaa);





c=touch_read_byte();//receiving ta1  00h
d=touch_read_byte();//receiving ta2  02h
e=touch_read_byte();//receiving E/S  1fh

for(m=0;m<32;m++)
{
 m1[m]=touch_read_byte();

}

                 if(touch_present()){

touch_write_byte(0xcc);//skip rom



touch_write_byte(0x99);//copy scratchpad command



touch_write_byte(0x00);//transmitting ta1
touch_write_byte(0x02);//transmitting ta2
touch_write_byte(0x1f);//transmitting e/s


            touch_write_byte(0xff);//
            touch_write_byte(0xff);//
            touch_write_byte(0xff);//
            touch_write_byte(0xff);//
            touch_write_byte(0xff);//         64 bit dummy password
            touch_write_byte(0xff);//
            touch_write_byte(0xff);//
            touch_write_byte(0xff);//


                 if(touch_present()){





touch_write_byte(0xcc);//skip rom

             touch_write_byte(0x55);//The Forced Conversion



            touch_write_byte(0xff);//dummy byte



output_high(touch_pin);
delay_ms(1000);//the conversion needs 666ms



      if(usb_enumerated()){


        if(touch_present()){//device reset as is written in the datasheet on page 32



        touch_write_byte(0xcc);//skip rom command




touch_write_byte(0x69);

      touch_write_byte(0x0e);//low   
      touch_write_byte(0x02);//high


            touch_write_byte(0xff);//
            touch_write_byte(0xff);//
            touch_write_byte(0xff);//
            touch_write_byte(0xff);//
            touch_write_byte(0xff);//         64 bit dummy password
            touch_write_byte(0xff);//
            touch_write_byte(0xff);//
            touch_write_byte(0xff);//



hrl=touch_read_byte();
hrh=touch_read_byte();

if(touch_present()){//device reset as is written in the datasheet on page 31



             out_data[0]=hrl;
             out_data[1]=hrh;
             out_data[2]=0;
             out_data[3]=0;
             out_data[4]=0;
             out_data[5]=0;
             out_data[6]=0;
             out_data[7]=0;


            usb_put_packet(1, out_data, USB_EP1_TX_SIZE, TOGGLE);
             delay_ms(500);




}}}}}}}}}}


it's the same of the previous!!

i don't understand why i must check if the rtc starts as you are telling me...

the datasheet don't tells about this...

i wrote a code following the datasheet instructions

noone use pcw to communicate with the ds1923

noone used this sensor all over the world ??

i only need to know if using this code i'll receive the bytes that contain the humidity measurement.


thank you very much!
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue Nov 23, 2004 5:53 pm     Reply with quote

Quote:
this is the whole code...
No it isn't. For example the #fuse line is missing.

Quote:
it's the same of the previous!!
Not! This one is more complete.

Quote:
i don't understand why i must check if the rtc starts as you are telling me...
the datasheet don't tells about this...
You are the one quoting from the manual that the RTC must be running before issuing a 'read sensor 'command. You murdered two devices, very likely because of this situation occurring. Don't you think it starts making sense then to incorporate a test?....

Quote:
i wrote a code following the datasheet instructions
95% of your code looks correct to me, but at page 47 (and other places) it says "Read scratchpad data and verify". You do the read, but you don't check the values. So if you had some kind of communication error, the device will not be configured correctly and strange things might happen....

Quote:
i only need to know if using this code i'll receive the bytes that contain the humidity measurement.
I only need to know the winning lottery numbers to become a milionair....
Apart from the missing verify it looks alright. You'll have to test to know for sure. You didn't give all your code. If you have an interrupt routine in the other files, this might destroy the timings.
zio_pecos



Joined: 24 Oct 2004
Posts: 21
Location: italy

View user's profile Send private message

PostPosted: Wed Nov 24, 2004 1:34 am     Reply with quote

i have to insert this code before the code to make the ds1923 run
look there
http://www.ccsinfo.com/forum/viewtopic.php?t=20980&highlight=measure

this will destroy timings?

say no please

so i must use a pic to read from ds1923
and other pics to make someelse??

thank you
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Wed Nov 24, 2004 5:30 am     Reply with quote

In the link you refer to several options are discussed. We recommended you to use the solution without interrupts as it is easier and more accurate. You didn't say which option you choose, but it seems like you have a preference for the interrupt driven solution. Interrupts will influence your timing to the DS1923, whether this will result in errors I can not say.

Quote:
so i must use a pic to read from ds1923
and other pics to make someelse??
No, you can do it all with one processor, but it requires a good design.

From the other posts it looks like you are new to the embedded software programming. Maybe you should start with an easier project first.
zio_pecos



Joined: 24 Oct 2004
Posts: 21
Location: italy

View user's profile Send private message

PostPosted: Wed Nov 24, 2004 9:36 am     Reply with quote

ckielstra wrote:

[...]
Interrupts will influence your timing to the DS1923, whether this will result in errors I can not say.


Quote:
so i must use a pic to read from ds1923
and other pics to make someelse??
No, you can do it all with one processor, but it requires a good design.

From the other posts it looks like you are new to the embedded software programming. Maybe you should start with an easier project first.



yes i am a beginner but i cannot choose a easier project... in my university there is no one that could help me you are the only ones that, in my opinion, can help me in solving my troubles...

when you say : "you can do it all with one processor, but it requires a good design" what did you mean??

this is my design...

Code:

#include "D:\Bruno\appunti\__Tirocinio\_C\PIC16C745---porta usb\Finale\12312412.h"
//Tells the CCS PIC USB firmware to include HID handling code.
#DEFINE USB_HID_DEVICE  TRUE
//Set this to FALSE if you only want to test enumeration.  Some USB test programs,


//such as USBCHECK, crash if you are trying to test enumeration and the device
//starts sending data once configured.
#DEFINE USB_RUN_WHEN_CONFIGURED  TRUE

//the following defines needed for the CCS USB PIC driver to enable the TX endpoint 1
#define USB_EP1_TX_ENABLE  1   //turn on EP1 for IN bulk/interrupt transfers
#define USB_EP1_TX_SIZE    8   //if you change this, be sure to change the hid descriptor

//the following defines needed for the CCS USB PIC driver to enable the RX endpoint 1
#define USB_EP1_RX_ENABLE  1   //turn on EP1 for OUT bulk/interrupt transfers
#define USB_EP1_RX_SIZE    8   //if you change this, be sure to change the hid descriptor




#include "D:\Bruno\appunti\__Tirocinio\_C\PIC16C745---porta usb\usb_desc_bruno.h"
#include <pic_usb.h>
#include <usb.c>
#include <TOUCH.C>

//--------------------------------------------------------------------------
// CCP1 Data
//
int16 CCP1Value;
int16 CCP1OldValue;
BOOLEAN CCP1Captured;

//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
// CCP2 Data
//
int16 CCP2Value;
int16 CCP2OldValue;
BOOLEAN CCP2Captured;

//--------------------------------------------------------------------------
#int_CCP1
CCP1_isr()
 {
CCP1Value = CCP_1 - CCP1OldValue;
CCP1OldValue = CCP_1;
CCP1Captured = TRUE;
}
//--------------------------------------------------------------------------
#int_CCP2
CCP2_isr()
{
CCP2Value = CCP_2 - CCP2OldValue;
CCP2OldValue = CCP_2;
CCP2Captured = TRUE;
}
//--------------------------------------------------------------------------



void main() {

   int8 c,d,e,m,m1[32];

   int16 periodo,per;
   int16 periodo1,per1;
   int h1,h2,h3,h4;

    int8 hrl,hrh;
 
   int8 out_data[USB_EP1_TX_SIZE];//array outgoing data
   int8 value,te;



   setup_counters(RTCC_INTERNAL,RTCC_DIV_256);
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
   setup_ccp1(CCP_CAPTURE_RE|CCP_CAPTURE_DIV_16);
   setup_ccp2(CCP_CAPTURE_RE|CCP_CAPTURE_DIV_16);
   enable_interrupts(INT_CCP1);
   enable_interrupts(INT_CCP2);
   enable_interrupts(global);

CCP1Value = 0;
CCP1OldValue = 0;
CCP1Captured = TRUE;

CCP2Value = 0;
CCP2OldValue = 0;
CCP2Captured = TRUE;



usb_init();//inizializza la trasmissione tramite porta usb

usb_wait_for_enumeration();

   if(usb_enumerated())

       while(1){


if (CCP1Captured) {

//---
// F = 1/T
// Timer1 prescaler DIV_BY_1
// Pic16C745 at 24Mz -> 4/24M= 1.66666e-7;ans*(timeprescaler/ccpprescaler)
//

periodo=((float)CCP1Value*4/(24e6)/16)*100000000;
per=periodo;
CCP1Captured = FALSE;
}


h2= make8(per, 1);
h1= make8(per, 0);


if (CCP2Captured) {



periodo1=((float)CCP2Value*4/(24e6)/16)*100000000;
per1=periodo1;
CCP2Captured = FALSE;
}

h4= make8(per1, 1);
h3= make8(per1, 0);




usb_enumerated();
              if(touch_present())//inizializzazione
               {
                 if(touch_present()){



//starting up RTC


touch_write_byte(0xcc);//skip rom command


touch_write_byte(0x0f);//Write Scratchpad command,

touch_write_byte(0x00);//low   TA1, beginning offset
touch_write_byte(0x02);//high  TA2


touch_write_byte(0x00);
touch_write_byte(0x00);//ora
touch_write_byte(0x0a);

touch_write_byte(0x1b);
touch_write_byte(0x0a);//giorno
touch_write_byte(0x04);

touch_write_byte(0x0a);//sample rate
touch_write_byte(0x00);


touch_write_byte(0x00);
touch_write_byte(0x00);
touch_write_byte(0x00);//humdity and temperature alarm (off)
touch_write_byte(0x00);


touch_write_byte(0xff);
touch_write_byte(0xff);
touch_write_byte(0xff);
touch_write_byte(0xff);


touch_write_byte(0x00);//temp alarm off

touch_write_byte(0xfc);//hum alarm off

touch_write_byte(0x01);//low sample rate

touch_write_byte(0xc8);//general control mission register

touch_write_byte(0xff);//alarm status
touch_write_byte(0xff);//general status   

touch_write_byte(0x00);
touch_write_byte(0x00);//mission start delay
touch_write_byte(0x00);


touch_write_byte(0xff);touch_write_byte(0xff);touch_write_byte(0xff);touch_write_byte(0xff);touch_write_byte(0xff);
touch_write_byte(0xff);touch_write_byte(0xff);


                 if(touch_present()){

touch_write_byte(0xcc);//skip rom

touch_write_byte(0xaa);




c=touch_read_byte();//receiving ta1  00h
d=touch_read_byte();//receiving ta2  02h
e=touch_read_byte();//receiving E/S  1fh

for(m=0;m<32;m++)
{
 m1[m]=touch_read_byte();
}

                 if(touch_present()){

touch_write_byte(0xcc);//skip rom



touch_write_byte(0x99);//copy scratchpad command


touch_write_byte(0x00);//transmitting ta1
touch_write_byte(0x02);//transmitting ta2
touch_write_byte(0x1f);//transmitting e/s


            touch_write_byte(0xff);//
            touch_write_byte(0xff);//
            touch_write_byte(0xff);//
            touch_write_byte(0xff);//
            touch_write_byte(0xff);//         64 bit dummy password
            touch_write_byte(0xff);//
            touch_write_byte(0xff);//
            touch_write_byte(0xff);//


                 if(touch_present()){



touch_write_byte(0xcc);//skip rom

touch_write_byte(0x55);//Forced Conversion command


            touch_write_byte(0xff);//dummy byte



output_high(touch_pin);
delay_ms(1000);//the conversion needs 666ms



      if(usb_enumerated()){


        if(touch_present()){//device reset as is written in the datasheet on page 32



        touch_write_byte(0xcc);//skip rom command




touch_write_byte(0x69);

      touch_write_byte(0x0e);//low   
      touch_write_byte(0x02);//high


            touch_write_byte(0xff);//
            touch_write_byte(0xff);//
            touch_write_byte(0xff);//
            touch_write_byte(0xff);//
            touch_write_byte(0xff);//         64 bit dummy password
            touch_write_byte(0xff);//
            touch_write_byte(0xff);//
            touch_write_byte(0xff);//



hrl=touch_read_byte();
hrh=touch_read_byte();

if(touch_present()){//device reset as is written in the datasheet on page 31



             out_data[0]=hrl;
             out_data[1]=hrh;

             out_data[2]=0;

             out_data[3]=h1;
             out_data[4]=h2;
             out_data[5]=h3;
             out_data[6]=h4;
             out_data[7]=0;


            usb_put_packet(1, out_data, USB_EP1_TX_SIZE, TOGGLE);
             delay_ms(500);




}}}}}}}}}}



the following is the include file
Code:
#include <16C745.h>
#device *=16
#device adc=8
#use delay(clock=24000000)
#fuses H4,NOWDT



is this a good design?

thank you
Guest








PostPosted: Thu Nov 25, 2004 12:07 pm     Reply with quote

up
Sanjuro
Guest







PostPosted: Fri Nov 26, 2004 4:23 am     Reply with quote

RTC control register is 0212h. 0200h is only setings of time register.
zio_pecos



Joined: 24 Oct 2004
Posts: 21
Location: italy

View user's profile Send private message

PostPosted: Fri Nov 26, 2004 4:43 am     Reply with quote

which part to my code are you referring to ?
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group