Problem in reading the 2nd data from pcf8563 real time clock by i2c

In summary, if the 2nd data can be read after the first data, but i need to restart the condition the only can read the 2nd data. By that, i have read the slave address again before the 2nd data has been read. So how should i solve it?
  • #1
lolkc2
3
0
Suppose the 2nd data can be read after the first data, but i need to restart the condition the only can read the 2nd data. By that, i have read the slave address again before the 2nd data has been read. So how should i solve it?
 
Engineering news on Phys.org
  • #2
lolkc2 said:
Suppose the 2nd data can be read after the first data, but i need to restart the condition the only can read the 2nd data. By that, i have read the slave address again before the 2nd data has been read. So how should i solve it?

Welcome to the PF.

Why do you need to restart anything? Can't you just read the two data bytes out in order? Can you describe the problem in a bit more detail?

PCF8563 RTC I2C Slave datasheet -- http://www.nxp.com/documents/data_sheet/PCF8563.pdf:smile:
 
Last edited:
  • #3
;/**
; * EXP 1
; *
; * This program displays the character '0' on one
; * of the seven segment displays.
; */

list p = 18f4520

include "p18f4520.inc"

CONFIG OSC = INTIO67
CONFIG PWRT = ON
CONFIG WDT = OFF
CONFIG DEBUG = ON, LVP = OFF

WriteSlaveAddr EQU b'10100010'
ReadSlaveAddr EQU b'10100011'
SecsAddr EQU 0x02
SecsData EQU b'01010000'
MinsAddr EQU 0x03
MinsData EQU b'01011001'
HoursAddr EQU 0x04
HoursData EQU b'00000010'

ORG 0

start
clrf TRISC
bsf TRISC,3
bsf TRISC,4

;/BAUD RATE
movlw b'00001001'
movwf SSPADD
nop
nop

;/SLEW RATE CONTROL
movlw b'00000000'
movwf SSPSTAT
nop
nop

;/ENABLE SERIAL PORT
movlw b'00101000'
movwf SSPCON1
nop
nop

;SET TIME
call i2c_start
movlw WriteSlaveAddr
call i2c_send
call check_ack
movlw SecsAddr
call i2c_send
call check_ack
movlw SecsData
call i2c_send
call check_ack
movlw MinsData
call i2c_send
call check_ack
movlw HoursData
call i2c_send
call check_ack
call i2c_restart
movlw WriteSlaveAddr
call i2c_send
call check_ack
movlw SecsAddr
call i2c_send
call check_ack
call i2c_restart
movlw ReadSlaveAddr
call i2c_send
call check_ack
call receive_mode
; call i2c_restart
call i2c_send
call check_ack
call receive_mode
; call i2c_restart
call i2c_send
call check_ack
call receive_mode
call send_nack
call i2c_stop

;/START CONDITION
i2c_start
bsf SSPCON2,SEN
call check
nop
nop
return

;/I2C SEND
i2c_send
movwf SSPBUF
call check
nop
nop
return

;/STOP CONDITION
i2c_stop
bsf SSPCON2,PEN
call check
nop
nop
bz ending
return

;/INTERRUPT
check
btfss PIR1,SSPIF
goto check
bcf PIR1,SSPIF
nop
nop
return

check_ack
btfsc SSPCON2,ACKSTAT
goto i2c_fail
nop
nop
return

i2c_restart
bsf SSPCON2,RSEN
call check
nop
nop
return

send_nack
bsf SSPCON2,ACKDT
bsf SSPCON2,ACKEN
call check
nop
nop
return

receive_mode
bsf SSPCON2,RCEN
call check
nop
nop
return

i2c_fail
call i2c_stop

ending
bra ending


END
 
  • #4
This is my code. If i didn't add the restart condition, the 2nd data cannot be read. But the data sheet mention that the data can be transfer continuous without any restart. So I need to figure out the problem. Is it any problem in my code?
 
  • #5


There are a few potential solutions to this problem. One option would be to use a "dummy read" before attempting to read the second data from the real-time clock. This involves performing a read operation on a register that does not contain any useful data, just to ensure that the clock is ready for the second read operation. Another option could be to use a software delay between the two read operations, allowing enough time for the clock to process the first read before attempting the second one. Additionally, ensuring that the I2C bus is properly configured and that the communication between the master and slave devices is stable could also help to prevent any issues with reading the second data. It may also be helpful to review the datasheet for the real-time clock to ensure that all necessary steps and timing requirements are being followed for proper communication and data retrieval.
 

What is the PCF8563 real time clock?

The PCF8563 is a clock and calendar chip that uses the I2C protocol to communicate with other devices. It can keep track of time, date, and even leap years.

Why is there a problem in reading the 2nd data from the PCF8563 real time clock?

The problem may be caused by a number of reasons, such as incorrect wiring, faulty connections, or incorrect configuration of the I2C protocol.

How can I troubleshoot the issue with reading the 2nd data from the PCF8563 real time clock?

First, check all connections and wiring to ensure they are correct and secure. Then, check the I2C configuration to make sure it is set up correctly. If the issue persists, try using a different clock or consulting the manufacturer's documentation for troubleshooting tips.

Can I use a different protocol to communicate with the PCF8563 real time clock?

Yes, the PCF8563 can also communicate using the SPI protocol. However, this may require different wiring and configuration.

Is there a way to prevent this problem from occurring in the first place?

To prevent issues with reading the 2nd data from the PCF8563 real time clock, make sure to carefully follow the manufacturer's instructions for wiring and configuring the device. Also, regularly check and maintain the connections to ensure they are secure.

Similar threads

  • Special and General Relativity
Replies
26
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
10
Views
1K
  • STEM Educators and Teaching
Replies
5
Views
659
  • Engineering and Comp Sci Homework Help
Replies
7
Views
1K
  • Programming and Computer Science
Replies
1
Views
278
  • Special and General Relativity
3
Replies
95
Views
4K
  • Programming and Computer Science
Replies
11
Views
995
  • General Math
Replies
1
Views
812
  • Electrical Engineering
Replies
2
Views
2K
Back
Top