- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am new to SPI interfacing and I have just got a PIC talking to a CY14B256PA so that I can read the device ID just fine.
My next challenge is to talk to the RTC. At this stage I simply want to read the data that is in the RTC in the device (it hasn't been programmed yet but I'm trying to do the simple stuff first).
The data sheet says that I need to set the Read bit in the flags register before I can read the data, and also that I do not have to set the Write bit to set the read bit. I am not certain what the sequence is to achieve this.
Do I need to enable CS, Write to register 00 first using WRTC to set the Read bit, then clear CS, then set CS, perform the RDRTC to read the data, clear CS, then perform another WRTC cycle to clear the read bit, or do I do the whole lot in one CS cycle?
Any help you can give would be most appreciated.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
That's correct, you got it. I missed the WREN while giving the Read sequence as well. Here is the updated
1. Enable Chip select (CS = 0)
2. Set WREN
3. Disable Chip select (CS = 1)
4. Enable Chip select (CS = 0)
5. Set Read bit in flags register using WRTC. Sequence will be 0x12, 0x00, 0x01
6. Disable Chip select (CS = 1)
7. Enable Chip select (CS = 0)
8. Read RTC registers using RDRTC. For example, to read seconds register, sequence will be 0x13, 0x09, Seconds_Data
9. Disable Chip select (CS = 1)
10. Enable Chip select (CS = 0)
11. Set WREN
12. Disable Chip select (CS = 1)
13. Enable Chip select (CS = 0)
14. Clear Read bit in flags register using WRTC. Sequence will be 0x12, 0x00, 0x00
15. Disable Chip select (CS = 1)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
You need to toggle CS between each write or read operation. Following is the sequence for reading from RTC registers.
1. Enable Chip select (CS = 0)
2. Set Read bit in flags register using WRTC. Sequence will be 0x12, 0x00, 0x01
3. Disable Chip select (CS = 1)
4. Enable Chip select (CS = 0)
5. Read RTC registers using RDRTC. For example, to read seconds register, sequence will be 0x13, 0x09, Seconds_Data
6. Disable Chip select (CS = 1)
7. Enable Chip select (CS = 0)
8. Clear Read bit in flags register using WRTC. Sequence will be 0x12, 0x00, 0x00
9. Disable Chip select (CS = 1)
Similarly writes to RTC can also be performed by setting the W bit in flags register.
Please ensure that bit7, OSCEN = 0 in register 0x08. This enables the RTC. Without this, the RTC time won't increment.
The RTC write and read pseudo code is documented on page 14 of code example www.cypress.com/CE204087
Let me know if you have any questions based on this.
Regards,
Harsha
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Harsha that is exactly what I need.
Unfortunately I program in assembly code and do not understand C so the code examples do not help much.
Could you give a similar example for write to RTC? I am confused about when I have to set WREN, WRTC and when exactly the data I have sent is transferred into the RTC registers?
Is the sequence (CS asserted and de-asserted between each one)
Set WRTC
Set WREN
Send data
Clear WRTC
or do I toggle WREN to set the data AFTER I have sent it?
EDIT: Got it.
If anyone else picks up on this thread, the correct sequence is
Set WREN
Set WRTC
Set WREN
send data
Set WREN
clear WRTC
with CS asserted for each op and de-asserted after.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
That's correct, you got it. I missed the WREN while giving the Read sequence as well. Here is the updated
1. Enable Chip select (CS = 0)
2. Set WREN
3. Disable Chip select (CS = 1)
4. Enable Chip select (CS = 0)
5. Set Read bit in flags register using WRTC. Sequence will be 0x12, 0x00, 0x01
6. Disable Chip select (CS = 1)
7. Enable Chip select (CS = 0)
8. Read RTC registers using RDRTC. For example, to read seconds register, sequence will be 0x13, 0x09, Seconds_Data
9. Disable Chip select (CS = 1)
10. Enable Chip select (CS = 0)
11. Set WREN
12. Disable Chip select (CS = 1)
13. Enable Chip select (CS = 0)
14. Clear Read bit in flags register using WRTC. Sequence will be 0x12, 0x00, 0x00
15. Disable Chip select (CS = 1)