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

DS2432 connection problem
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
jojos



Joined: 30 Apr 2007
Posts: 64

View user's profile Send private message

DS2432 connection problem
PostPosted: Mon Jul 13, 2009 3:47 am     Reply with quote

Hi. I am using DS2432 with a PIC 18F2520. The read_rom command returns ERR_NODEVICE. I am using the code from CCS. I have connected the DS2432's PIN_1 to the ground and PIN_2 to PIC's PIN_A4 with a pull-up resistor to 5 Volts.

Below is my test code
Code:

#include "C:\SotirasLcd\18F2520.h"
#include <string.h>
#include <C:\SotirasLcd\stdlib.h>

//INTRC_IO
#fuses INTRC_IO ,PROTECT,NOLVP,PUT,NOPBADEN,NOBROWNOUT,MCLR//BROWNOUT_SW,BORV27//,BORV27  //INTERNAL OSCILLATOR NO CLOCK
#use delay(clock=4000000)//3276800)

#use fast_io(A)
#use fast_io(B)
#use fast_io(C)

#include "ds2432.c"

void init(void);

#define ON         1
#define OFF         0

#define TOUCH_PIN  PIN_A4

#define Led_Collision       PIN_C0
#define Led_Ok             PIN_C1
#define Led_Nodevice       PIN_C2      

//#bit Stick_bit      =0xF80.0

void main(void)
{
   unsigned char reg_matrix[20];
   unsigned char flag=15;
   unsigned int16 mn;
   
   delay_ms(1000);
   init();
   init_ds2432();

   delay_ms(2000);
   
while(1)
 {
   flag=read_rom(*reg_matrix);

   if(flag==ERR_COLLISION)
   {
      output_high(Led_Collision);
      output_low(Led_Ok);   
      output_low(Led_Nodevice);
   }
   else
   if(flag==ERR_OK)
   {
      output_low(Led_Collision);
      output_high(Led_Ok);   
      output_low(Led_Nodevice);
   }
 
   else
   if(flag==ERR_NODEVICE)
   {
      output_low(Led_Collision);
      output_low(Led_Ok);
      output_high(Led_Nodevice);   

   }

   delay_ms(10);

   //flag=15;      
   }   
}


void init(void)
{
   set_tris_a(0);
   set_tris_b(0);
   set_tris_c(0);

   PORTA=0;
   PORTB=0;
   PORTC=0;

   setup_adc(NO_ANALOGS);

   SETUP_CCP1(CCP_OFF);
   SETUP_CCP2(CCP_OFF);

   disable_interrupts(global);

return;
}





Can you see any error in my code?Thank you
Ttelmah
Guest







PostPosted: Mon Jul 13, 2009 7:05 am     Reply with quote

First thing, _simplify_.
Testing this chip, could be done with about a ten line program. Just load the libraries, and call the initial test. The more other code you have present, the greater the risk of unexpected effects. The first thing you do when trying to debug a program, should be to throw away code, till you have narrowed it right down.
As a general 'comment', put the #use delay, and fuse lines _above_ any library includes. Though it shouldn't cause a probelm with your code, if you load a library, that uses delays, unless the use delay is already present, you may get problems.
I'm not sure you can Use A4, for such a device. These, depend on detecting the rate of change of the voltage on an input, when the line is released. This will not be the same for A4, as for a normal logic I/O line....

Best Wishes
jojos



Joined: 30 Apr 2007
Posts: 64

View user's profile Send private message

PostPosted: Mon Jul 13, 2009 12:58 pm     Reply with quote

I've already tried another pin and the problem remains. I will put fuses up as you mentioned and see if it was a conflict. Thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jul 13, 2009 2:55 pm     Reply with quote

From the ds2432.c file:
Quote:
// int8 read_rom(int* chip)
//
// *Parameters:
// - chip - pointer to an array in which the chip registration data


Quote:

unsigned char reg_matrix[20];

flag = read_rom(*reg_matrix);

This is not correct. You're not passing a pointer to reg_matrix[] correctly.
How should you pass a pointer to an array ?

There is a difference between how a pointer is declared, and how it's passed.
jojos



Joined: 30 Apr 2007
Posts: 64

View user's profile Send private message

PostPosted: Tue Jul 14, 2009 1:40 am     Reply with quote

I use the touch_present function for a simple debug. Here is the code:

Code:

#include "C:\SotirasLcd\18F2520.h"
//INTRC_IO
#fuses INTRC_IO ,PROTECT,NOLVP,PUT,NOPBADEN,NOBROWNOUT,MCLR//BROWNOUT_SW,BORV27//,BORV27  //INTERNAL OSCILLATOR NO CLOCK
#use delay(clock=8000000)//3276800)

#use fast_io(A)
#use fast_io(B)
#use fast_io(C)


#include <string.h>
#include <C:\SotirasLcd\stdlib.h>

#include "ds2432.c"

void init(void);

#define ON         1
#define OFF         0

#define TOUCH_PIN  PIN_A5


#define Led_Collision       PIN_C0
#define Led_Ok             PIN_C1
#define Led_Nodevice       PIN_C2      

//#bit Stick_bit      =0xF80.0

void main(void)
{

   
   unsigned char reg_matrix[20];

   unsigned char flag=0;
   unsigned int16 mn;


   
   delay_ms(500);
   init();
   init_ds2432();

   delay_ms(500);
   

while(1)
 {

   flag=touch_present();

   if(flag==TRUE)
   output_high(Led_Ok);

   else
   output_low(Led_Ok);

   delay_ms(50);


   

   }   
}



void init(void)
{


   set_tris_a(0);
   set_tris_b(0);
   set_tris_c(0);

   PORTA=0;
   PORTB=0;
   PORTC=0;


   setup_adc(NO_ANALOGS);

   SETUP_CCP1(CCP_OFF);
   SETUP_CCP2(CCP_OFF);




   disable_interrupts(global);

return;

}





Again the led is off ,that means the DS2432 appears not to be present.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jul 14, 2009 11:00 am     Reply with quote

Read these instructions at the top of the ds2432.c file:
Quote:

// init_ds2432()
//
// Should call this function before any others.
// Will reset most 1-Wire devices on the network at once.
// *No returns.
jojos



Joined: 30 Apr 2007
Posts: 64

View user's profile Send private message

PostPosted: Tue Jul 14, 2009 11:49 pm     Reply with quote

Ok I have put the init_ds2432 as the first instruction in main. When the while loop executes for the first time the touch_present function gives a TRUE result but when it executes again it gives FALSE result all the time. Any ideas? I can't understand what seems to be the problem.


Edit:

I have changed the output_float(TOUCH_PIN) with
output_high (TOUCH_PIN) in the touch_present function and now it works.
I dont know if i will have to chabge something else in the other functions but the touch_present function now works.Any ideas why i had to make this change?Thank you.


Last edited by jojos on Wed Jul 15, 2009 12:17 am; edited 1 time in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jul 15, 2009 12:16 am     Reply with quote

It looks like you had it in there before, but I missed it. Did moving it
to the start of main() cause a change in symptoms ?

1. What is the size of the pull-up resistor on the Touch pin ?


Quote:
#use fast_io(A)
#use fast_io(B)
#use fast_io(C)

set_tris_a(0);
set_tris_b(0);
set_tris_c(0);

PORTA=0;
PORTB=0;
PORTC=0;

2. Get rid of the fast i/o, TRIS, and direct register i/o statements and
let the compiler set the TRIS. Comment out all 9 statements above.
Then compile and test it.
jojos



Joined: 30 Apr 2007
Posts: 64

View user's profile Send private message

PostPosted: Wed Jul 15, 2009 12:28 am     Reply with quote

PCM Programmer the problem was the #use fast_io directives. I let the set_tris directives and the PORTx=0; instructions and it works. I also changed back the output_float(TOUCH_PIN) instruction in the touch_present function.

I don't know how the #use fast_io directives made conflict with the program but now it works. If someone can explain this it's good to know. Thank you anyway for your help.
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Wed Jul 15, 2009 12:38 am     Reply with quote

Quote:
I don't know how the #use fast_io directives made conflict with the program I don't know how the #use fast_io directives made conflict with the program
That's rather obvious. Unless explicitly told different, CCS provided drivers are relying on default compiler settings, in this case #use standard_io. The one-wire interface involves a bidirectional pin, with standard_io in effect, the IO direction is automatically set with input() and output_xxx() statements, this operation is required by the driver.

Generally, it isn't a good idea to add arbitrary compiler settings without fully understanding their purpose.
jojos



Joined: 30 Apr 2007
Posts: 64

View user's profile Send private message

PostPosted: Wed Jul 15, 2009 12:57 am     Reply with quote

Thank you FvM for solving my confusion about this matter. It's always good to learn new things.
jojos



Joined: 30 Apr 2007
Posts: 64

View user's profile Send private message

PostPosted: Mon Jul 20, 2009 4:42 am     Reply with quote

I don't want to open a new thread so I am writing my question here. First of all I can't get any access to the full datasheet of DS2432, I believe that in there I can solve many of my wonderings. Maxim Dallas seems to ignore my emails about getting it. Second, DS2432 has 1Kb memory. In the CCS code library it says in the 'write_byte' command that I can set an address of 0-127 range. So how I can access the rest of the memory. I figure in some way the memory is splitted in pages or something like that. So how can I set these pages (if I am correct)? Same thing in the 'read_byte' command. Range for the address is 0-127,136-151. Thank you.
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Mon Jul 20, 2009 6:26 am     Reply with quote

Address range 0 to 127 is representing the 4 R/W memory pages. 128*8 equals 1 kbit, I think. Addresses starting from 128 are special function registers.
jojos



Joined: 30 Apr 2007
Posts: 64

View user's profile Send private message

PostPosted: Mon Jul 20, 2009 6:45 am     Reply with quote

Ok then. But how can I load the page I like before I set the address?
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Mon Jul 20, 2009 7:54 am     Reply with quote

I never used DS2432 with PIC or CCS driver, only with Maxim libraries. Thus I can't tell any details related to the DS2432 driver.

You should clarify, what you want to achieve with DS2432 and what's not working as expected.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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