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 CCS Technical Support

I2C Help!!
Goto page Previous  1, 2, 3, 4, 5  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
fiasgardone



Joined: 19 Jan 2010
Posts: 71

View user's profile Send private message

PostPosted: Wed Jan 20, 2010 6:49 pm     Reply with quote

PCM .. again tested the program down as you said, with the driver changed, and the LCD displays nothing!

slowly we get!

Code also changed.

Code:

#include <16F877A.h>
#fuses XT,NOWDT,NOPROTECT,PUT,NOLVP,NOBROWNOUT
#use delay(clock=4000000)

#include <flex_lcd.c>

// Tell the driver to use pins D0 and D1 for the i2c bus.
#define DAL_SCL PIN_D0
#define DAL_SDA PIN_D1
#include <DS1631.c>

//=================================
void main()
{
signed long result;

lcd_init();
init_temp();

while(1)
  {
   delay_ms(1000);
   result = read_full_temp();
   //printf(lcd_putc,"\f %ld", result);
  }
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jan 20, 2010 7:34 pm     Reply with quote

It would be much easier to debug this program if you had rs232 output
from your board. Then you could put printf statements in the code to
follow the progress of the program, and to display diagnostic messages
on the terminal window.

It's not that easy with just an LCD display.
fiasgardone



Joined: 19 Jan 2010
Posts: 71

View user's profile Send private message

PostPosted: Thu Jan 21, 2010 7:24 am     Reply with quote

PCM .. My board does not have rs232 ! unfortunately!
I think that yesterday many tests, to the end, no longer runs it well.
So today I went to do further testing, and has an error that I do not understand!

In the program, if I compile as you said the compiler sends the following error message!
***Error14"testing DS1631.c" Line22(9,10): Missing #ENDIF
f I remove these two lines, the compiler compiles normal, but nothing shows on the LCD
Code:

#define DAL_SCL PIN_D0
#define DAL_SDA PIN_D1 


I changed my DS1631 but the result is same.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jan 21, 2010 1:34 pm     Reply with quote

Quote:

if I compile as you said the compiler sends the following error message!
***Error14"testing DS1631.c" Line22(9,10): Missing #ENDIF

The ds1631.c driver in vs. 4.068 has a bug. It's missing the last #endif
statement. To fix it, edit the file and add the line shown in bold below:
Quote:

#ifndef DAL_SCL
#if defined(__PCD__)
#define DAL_SCL PIN_D0
#define DAL_SDA PIN_D1
#else
#define DAL_SCL PIN_B0
#define DAL_SDA PIN_B1
#endif
#endif
fiasgardone



Joined: 19 Jan 2010
Posts: 71

View user's profile Send private message

PostPosted: Thu Jan 21, 2010 2:00 pm     Reply with quote

PCM programmer wrote:
Quote:

if I compile as you said the compiler sends the following error message!
***Error14"testing DS1631.c" Line22(9,10): Missing #ENDIF

The ds1631.c driver in vs. 4.068 has a bug. It's missing the last #endif
statement. To fix it, edit the file and add the line shown in bold below:
Quote:

#ifndef DAL_SCL
#if defined(__PCD__)
#define DAL_SCL PIN_D0
#define DAL_SDA PIN_D1
#else
#define DAL_SCL PIN_B0
#define DAL_SDA PIN_B1
#endif
#endif


PCM .. I added the driver line you said, but the error continues?
I do not see ,why?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jan 21, 2010 2:10 pm     Reply with quote

Maybe you have more than one ds1631.c file on your PC ?
Maybe you are editing one file, but MPLAB is using a different copy of it ?
Search your system for all copies of ds1631.c.
fiasgardone



Joined: 19 Jan 2010
Posts: 71

View user's profile Send private message

PostPosted: Thu Jan 21, 2010 2:36 pm     Reply with quote

Incredible! now sends the following message;

Quote:
***Error 100"C:\Programme\PICC\drivers\DS1631.c"Line 34(5,41).USE parameter value ist out of range Not a mumber:PIN_D1

This line;
#use i2c(master,sda=DAL_SDA,scl=DAL_SCL)
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jan 21, 2010 2:45 pm     Reply with quote

Re-install the compiler. Start fresh.
fiasgardone



Joined: 19 Jan 2010
Posts: 71

View user's profile Send private message

PostPosted: Thu Jan 21, 2010 2:46 pm     Reply with quote

PCM after restarting the compiler, the program complile without problems and now the LCD shows the following;
19 E0
19 F0
19 C0
19 BO
19 A0
19 90

The number 19 is constant, the other is variable, I checked 10 minutes and was observed that

Now is improving?
fiasgardone



Joined: 19 Jan 2010
Posts: 71

View user's profile Send private message

PostPosted: Fri Jan 22, 2010 6:38 am     Reply with quote

Hi PCM, I noticed that the values shown in the LCD change depending on the temperature.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jan 22, 2010 9:10 pm     Reply with quote

It looks like it's probably working now. Remove the diagnostic code
and put the normal code back in.
fiasgardone



Joined: 19 Jan 2010
Posts: 71

View user's profile Send private message

PostPosted: Sat Jan 23, 2010 8:13 am     Reply with quote

Hi PCM...I removed the diagnostic code and tested it with the source code below, and the result shows that the LCD is for example "temp.22.3". If I can finger on the sensor values go up, if I remove the finger values fall, but the conversion is slow.
Not sure if the mathematical conversion is correct!

Please check for errors, or can improve the code!
Thanks!
Code:

#include <16F877A.h>
#fuses XT,NOWDT,NOPROTECT,PUT,NOLVP,NOBROWNOUT
#use delay(clock=4000000)

#include <flex_lcd.c>                                           

// Tell the driver to use pins D0 and D1 for the i2c bus.

#define DAL_SCL PIN_D0
#define DAL_SDA PIN_D1 
#include <DS1631.c>             
                                       
//=================================

void main()                                                                   
{       
float value;       
lcd_init();
 delay_ms(100);
   init_temp();             
                                                                                     
while(1)
  {                             
   delay_ms(1000);
   value = read_full_temp();
   value /= 100.0;                                                                     
       value=(value-32)/1.8;
       lcd_gotoxy(15,2);                   
        printf(lcd_putc,"temp.%04.1f", value);

  }     
}
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Sat Jan 23, 2010 9:07 am     Reply with quote

Quote:
but the conversion is slow

You may want to reduce delay_ms(1000); Smile
fiasgardone



Joined: 19 Jan 2010
Posts: 71

View user's profile Send private message

PostPosted: Sun Jan 24, 2010 2:41 pm     Reply with quote

Code:

#include <16F877A.h>
#fuses XT,NOWDT,NOPROTECT,PUT,NOLVP,NOBROWNOUT
#use delay(clock=4000000)

#include <flex_lcd.c>                                           

// Tell the driver to use pins D0 and D1 for the i2c bus.

#define DAL_SCL PIN_D0
#define DAL_SDA PIN_D1 
#include <DS1631.c>             
                                       
//=================================

void main()                                                                   
{       
float value;       
lcd_init();
 delay_ms(100);
   init_temp();             
                                                                                     
while(1)
  {                             
   delay_ms(100);
   value = read_full_temp();
   value /= 100.0;                                                                     
       value=(value-32)/1.8;
       lcd_gotoxy(15,2);                   
        printf(lcd_putc,"temp.%04.1f", value);

  }     
}


Hi,..What is wrong in the code above, I compared the temperature shows the DS1631 in the LCD, with a thermometer I bought, and DS1631 shows 2 °C above the thermometer bought!
Why this difference?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jan 24, 2010 3:18 pm     Reply with quote

Read the DS1631 data sheet.
Code:
Table 6. RESOLUTION CONFIGURATION

R1 R0   RESOLUTION  CONVERSION TIME
         (BITS)        (MAX)
0  0       9          93.75 ms
0  1      10         187.5 ms
1  0      11         375 ms
1  1      12         750 ms


The ds1631 driver writes 0x0C to the Config register.
This sets bits R0 and R1 = 1. So it's using 12-bit resolution.
So, it takes at least 750 ms to get an accurate result.
Your current delay loop is a lot less than 750 ms.
There is a "trade off" between accuracy and conversion time.
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 Previous  1, 2, 3, 4, 5  Next
Page 3 of 5

 
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