tajiknomi
Member level 4
I am using 3 wire interface for communication with the RTC. The IDE i am using is MicroC Pro. And the simulation is done through proteus. Development language is C.
I am trying to communicate with DS1302 (RTC) using **broken link removed**MCU. In this project I'm also using LCD to display time/date etc and for that purpose i have wrote modules for LCD and they work just fine. Now i am trying to write methods for SPI,but before that, i just tried to read a single register (let say Hour-register) of DS1302 and put its value on a certain PORT/LCD so that i know how communication will take place b/w MCU and RTC. But i am doing something wrong because everytime i get the same value i.e. 0x01 when i read either date,hour,minutes or seconds etc.
Here is how i am doing to read the byte from RTC.
Here is setup
Here is the timing diagram for Read/Write of RTC
I don't want to use built-in libraries.
Any help would be appreciated.
I am trying to communicate with DS1302 (RTC) using **broken link removed**MCU. In this project I'm also using LCD to display time/date etc and for that purpose i have wrote modules for LCD and they work just fine. Now i am trying to write methods for SPI,but before that, i just tried to read a single register (let say Hour-register) of DS1302 and put its value on a certain PORT/LCD so that i know how communication will take place b/w MCU and RTC. But i am doing something wrong because everytime i get the same value i.e. 0x01 when i read either date,hour,minutes or seconds etc.
Here is how i am doing to read the byte from RTC.
Code:
sbit EN at PORTC.B2;
sbit SCLK at PORTC.B3;
sbit SDI at PORTC.B4;
sbit SDO at PORTC.B5;
sbit EN_Direction at TRISC2_bit;
sbit SCLK_Direction at TRISC3_bit;
sbit SDI_Direction at TRISC4_bit;
sbit SDO_Direction at TRISC5_bit;
// SPI Initialization Fucntion
void SPI_init(void){
INTCON |= 0xC0; // GIE and PEIE enable
SSPSTAT.SMP = 0; // Sample at MIDDLE
SSPSTAT.CKE = 1; // Data send on Rising Edge
SSPCON |= 0x21; // Serial Port Enable, Idle state Clk is Low, F/16 => 31 KiloBytes/sec
SCLK_Direction=0;
SDO_Direction =0;
EN_Direction =0; // Output Ports
SDI_Direction =1;
EN = 1;
}
// ============== Main function =============
void main(){
SPI_init();
EN=0; // Active low signal
SSPBUF = 0x85; // Hour Address
while(SSPSTAT.BF == 0); // Adress Transmission not complete ? Stay here
value=SSPBUF; // Read to Clear BufferFullStatusBit
while(SSPSTAT.BF == 0); // Recieve byte not complete ? Stay here
value=SSPBUF; // Store the recieved Byte
EN=1; // Fininsh Reading
PORTB=value; // Transfer byte to PORTB
}
Here is setup
Here is the timing diagram for Read/Write of RTC
I don't want to use built-in libraries.
Any help would be appreciated.
Last edited: