Reading from DS1305

General discussion on mikroC.
Post Reply
Author
Message
Bigote
Posts: 67
Joined: 09 Aug 2009 12:51
Location: Willemstad

Reading from DS1305

#1 Post by Bigote » 15 Jul 2011 02:31

Hi fellow programmers

I just started with a project that consist of reading from a DS1305 RTC. I know that my code will not give me the correct readings from the register i am trying to read from but i just want to be sure that my phisical connections are OK so i can focus on the software. Below here you can see my code:

// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;

sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections

// RTC connections
sbit Chip_Select at RC0_bit;
sbit Chip_Select_Direction at TRISC0_bit;
// End DAC module connections

unsigned int sec;
char convert[7];
unsigned buffer;

void Set_RTC()
{
Chip_Select = 1; // Select RTC
SPI1_Write(143); // Address Control register
Delay_ms(10);
SPI1_Write(0); // Set registers
Delay_ms(10);
Chip_Select = 0; // Deselect RTC
}

void InitMain()
{
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Chip_Select = 0; // Deselect RTC
Chip_Select_Direction = 0; // Set CS# pin as Output
SPI1_Init(); // Initialize SPI module
}


void Read_Time()
{
Chip_Select = 1; // Select RTC
Delay_ms(10);
SPI1_Write(128); // Address Seconde register
Delay_ms(10);
sec=SPI1_Read(buffer);
Delay_ms(10);
Chip_Select = 0; // Deselect RTC
IntToStr(sec,convert);
}

void Display_LCD()
{
Lcd_Out(1,1,convert);
}

void main()
{
ANSEL = 0;
ANSELH = 0;
InitMain(); // Perform main initialization
Set_RTC();

while (1) // Endless loop
{
Read_Time();
Display_LCD();
Delay_ms(950);
}

}


I am suppose to get different readings each second so but the only thing i get is 255 and it does not change. Help anyone?

Bigote
Posts: 67
Joined: 09 Aug 2009 12:51
Location: Willemstad

Re: Reading from DS1305

#2 Post by Bigote » 15 Jul 2011 02:35

I just realize that i posted my questions inside the wrong forum. I would like to receive help in using MikroC Pro version.

Post Reply

Return to “mikroC General”