Wil tijd op glcd krijgen, dat lukt, maar DS1307 loopt niet.
Hij geeft alleen maar de datum 01-01-2000 door, en als tijd 00:00:00. Als ik overigens de sdk verbinding eruit trek, wordt datum ook 00-00-2000, dus naar mijn mening reageert hij wel, maar waarom doet hij verder niets?
Iemand een idee?
Lucky Luke
Eluke.nl | handgetypt | I'm a poor, lonesome cowboy, with a long, long way to go.
Zit het kristal wel vast aan de ds1307?
Ergens in het register voor de seconden zit een bitje osc disable oid. Is dat 0? (of moest het nou 1 zijn? RT*M/D!)
Kristal zit vast, zelfs al verwisseld....
Code is als volgt:
//*************************************************************
//***** FUNCTIONS FOR RTC DS1307 ON I2C COMMUNICATION *****
//*************************************************************
//Controller: ATmega32 (16Mhz Crystal)
//Compiler: ICCAVR Ver
//Author: CC Dharmani, Chennai, India
//Date: Aug 2008
//*************************************************************
#include "ds1307.h"
#include "i2c.h"
#include "T6963c.h"
unsigned char ds1307_register[7];
unsigned char time[10]; //xx:xx:xx;
unsigned char date[12]; //xx/xx/xxxx;
unsigned char day;
//******************************************************************
//Function to
//******************************************************************
void DS1307_setStartAddress(void)
{
unsigned char errorStatus;
errorStatus = i2c_start(DS1307_W);
if(errorStatus == 1)
{
//Error 1;
i2c_stop();
return;
}
errorStatus = i2c_write(0x00);
if(errorStatus == 1)
{
//Error 3;
i2c_stop();
return;
}
i2c_stop();
}
//******************************************************************
//Function to read
//******************************************************************
void DS1307_read(void)
{
unsigned char errorStatus, i, data;
errorStatus = i2c_start(DS1307_W);
if(errorStatus == 1)
{
//Error 4;
i2c_stop();
return;
}
errorStatus = i2c_write(0x00);
if(errorStatus == 1)
{
//Error 6;
i2c_stop();
return;
}
errorStatus = i2c_rep_start(DS1307_R);
if(errorStatus == 1)
{
//Error 7;
i2c_stop();
return;
}
for(i=0;i<7;i++)
{
if(i == 6) //no Acknowledge after receiving the last byte
data = i2c_readNak();
else
data = i2c_readAck();
if(data == ERROR_CODE)
{
T6963cPutStringXY_P(10, 10, PSTR("ERROR"));
i2c_stop();
return;
}
ds1307_register[i] = data;
}
i2c_stop();
}
//******************************************************************
//Function to read
//******************************************************************
void DS1307_getTime(void)
{
DS1307_read();
time[9] = 0x00; //NIL
time[8] = ' ';
time[7] = (SECONDS & 0x0f) | 0x30; //seconds(1's)
time[6] = ((SECONDS & 0x70) >> 4) | 0x30; //seconds(10's)
time[5] = ':';
time[4] = (MINUTES & 0x0f) | 0x30;
time[3] = ((MINUTES & 0x70) >> 4) | 0x30;
time[2] = ':';
time[1] = (HOURS & 0x0f) | 0x30;
time[0] = ((HOURS & 0x30) >> 4) | 0x30;
}
//******************************************************************
//Function to read
//******************************************************************
void DS1307_getDate(void)
{
DS1307_read();
date[11] = 0x00; //NIL
date[11] = ' ';
date[9] = (YEAR & 0x0f) | 0x30;
date[8] = ((YEAR & 0xf0) >> 4) | 0x30;
date[7] = '0';
date[6] = '2';
date[5] = '/';
date[4] = (MONTH & 0x0f) | 0x30;
date[3] = ((MONTH & 0x10) >> 4) | 0x30;
date[2] = '/';
date[1] = (DATE & 0x0f) | 0x30;
date[0] = ((DATE & 0x30) >> 4) | 0x30;
}
//******************************************************************
//Function to read
//******************************************************************
void DS1307_displayTime(void)
{
DS1307_getTime();
T6963cPutStringXY_P(0, 2, PSTR("Tijd:"));
T6963cPutStringXY(5, 2, time);
}
//******************************************************************
//Function to read
//******************************************************************
void DS1307_displayDate(void)
{
DS1307_getDate();
T6963cPutStringXY_P(0, 0, PSTR("Datum:"));
T6963cPutStringXY(6, 0, date);
DS1307_displayDay();
}
//******************************************************************
//Function to read
//******************************************************************
void DS1307_displayDay(void)
{
T6963cPutStringXY_P(0, 1, PSTR("Dag:"));
switch(DAY)
{
case 0:T6963cPutStringXY_P(5, 1, PSTR("Zondag"));
break;
case 1:T6963cPutStringXY_P(5, 1, PSTR("Maandag"));
break;
case 2:T6963cPutStringXY_P(5, 1, PSTR("Dinsdag"));
break;
case 3:T6963cPutStringXY_P(5, 1, PSTR("Woensdag"));
break;
case 4:T6963cPutStringXY_P(5, 1, PSTR("Donderdag"));
break;
case 5:T6963cPutStringXY_P(5, 1, PSTR("Vrijdag"));
break;
case 6:T6963cPutStringXY_P(5, 1, PSTR("Zaterdag"));
break;
default:T6963cPutStringXY_P(5, 1, PSTR("Onbekend"));
}
}
//******************************************************************
//Function to read
//******************************************************************
void DS1307_updateRegisters(void)
{
SECONDS = ((time[6] & 0x07) << 4) | (time[7] & 0x0f);
MINUTES = ((time[3] & 0x07) << 4) | (time[4] & 0x0f);
HOURS = ((time[0] & 0x03) << 4) | (time[1] & 0x0f);
DAY = date[10];
DATE = ((date[0] & 0x03) << 4) | (date[1] & 0x0f);
MONTH = ((date[3] & 0x01) << 4) | (date[4] & 0x0f);
YEAR = ((date[8] & 0x0f) << 4) | (date[9] & 0x0f);
}
//******************************************************************
//Function to read
//******************************************************************
unsigned char DS1307_writeTime(void)
{
unsigned char errorStatus, i;
errorStatus = i2c_start(DS1307_W);
if(errorStatus == 1)
{
//Error 10;
i2c_stop();
return(1);
}
errorStatus = i2c_write(0x00);
if(errorStatus == 1)
{
//Error 12;
i2c_stop();
return(1);
}
for(i=0;i<3;i++)
{
errorStatus = i2c_write(ds1307_register[i]);
if(errorStatus == 1)
{
//Error 13;
i2c_stop();
return(1);
}
}
i2c_stop();
return(0);
}
//******************************************************************
//Function to read
//******************************************************************
unsigned char DS1307_writeDate(void)
{
unsigned char errorStatus, i;
errorStatus = i2c_start(DS1307_W);
if(errorStatus == 1)
{
//Error 14;
i2c_stop();
return(1);
}
errorStatus = i2c_write(0x03);
if(errorStatus == 1)
{
//Error 16;
i2c_stop();
return(1);
}
for(i=3;i<7;i++)
{
errorStatus = i2c_write(ds1307_register[i]);
if(errorStatus == 1)
{
//Error 17;
i2c_stop();
return(1);
}
}
i2c_stop();
return(0);
}
CLOCK AND CALENDAR
The time and calendar information is obtained by reading the appropriate register bytes. The RTC registers are illustrated in Figure 3. The time and calendar are set or initialized by writing the appropriate register bytes. The contents of the time and calendar registers are in the BCD format. Bit 7 of register 0 is the clock halt (CH) bit. When this bit is set to a 1, the oscillator is disabled. When cleared to a 0, the oscillator is enabled.
0 dus
En dit helpt niet:
http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&am…
Batterij is gewoon goed aangesloten, nagemeten op IC
[Bericht gewijzigd door Henry S. op (0%)]
picsels
Volgend project: 7-seg gaming displays; dan dec-1982 labvoeding afmaken, dan funcgen met ad9833 afmaken, dan...
int main()
{
//Initialize
//XOR mode, internal CG, Text and Graphic, Blinking Cursor
T6963cInit( T6963C_MODE_XOR | T6963C_CG_INTERNALROM,
T6963C_TEXT_GRAPHIC | T6963C_CURSOR_BLINK );
i2c_init();
//MCUCR = 0x00;
//TIMSK = 0x00; //timer interrupt sources
//Cursorheight: 4px
T6963cCursorPattern(4);
//Relocate cursor
T6963cSetCursorXY(3, 8);
//Write a Sample Pic (Works only in 8x8 Font mode)
//T6963cWriteChunkAt_P(T6963C_ADDR_GRAPHIC, g_SamplePic, sizeof(g_SamplePic));
//Write a Custom Char for use with Character '\x80'
//T6963cWriteChunkAt_P(T6963C_ADDR_CGRAMH, g_CustomChars, sizeof(g_CustomChars));
for (;;)
{
DS1307_displayDate();
DS1307_displayTime();
T6963cPutStringXY_P(8, 8, PSTR("Piep"));
delay(2);
T6963cPutStringXY_P(8, 8, PSTR("Klaar"));
delay(2);
}
while(1)
{
asm volatile ("nop");
}
return 0;
}picsels
Volgend project: 7-seg gaming displays; dan dec-1982 labvoeding afmaken, dan funcgen met ad9833 afmaken, dan...
Correct me if I'm wrong, maar je initialiseert nergens de RTC.
Dat moet je tenminste éénmaal doen (of steeds als de spanning eraf is geweest).
Daardoor wordt ook dat CH bit ingesteld en gaat de klok lopen.
[edit]
Met andere woorden tenminste eenmaal 'DS1307_writeTime()' aanroepen.
[Bericht gewijzigd door picsels op (16%)]
Even tijd updaten, en daarna write_time deed wonderen!
Super, eindelijk een werkende tijd op mijn lcd, tijd voor de volgende stap!
picsels
Volgend project: 7-seg gaming displays; dan dec-1982 labvoeding afmaken, dan funcgen met ad9833 afmaken, dan...