| View previous topic :: View next topic |
| Author |
Message |
JerryR
Joined: 07 Feb 2008 Posts: 195
|
| Can't write (or read) byte to MCP79411 |
Posted: Wed Nov 04, 2026 8:17 am |
|
|
Hello group:
Hope someone can help me with this issue.
I'm using PCWH v5.121 and the driver for the MCP79411 as published in the code library. Excellent work by Daniel Pechmann !
I'm attempting to adjust the ADR_CAL register (0x08) without success. Time functions all work correctly, however. It appears that I can't either read or write to any particular register. After a write, I always receive 0xA5.
As far as hardware, pretty typical. 2.2Kohm pull-ups on both SDA and SCK lines. No other devices share the I2C port. Using hardware I2C port on PIC16F1619.
Here's the test code:
| Code: |
//updated version v2.0
#include <16f1619.h>
#use delay(clock=16000000)
#include <MCP79411_driver.c>
#fuses HS //high speed external crystal
#fuses NOWDT, NOPLLEN, NOPROTECT, NOLVP, NOBROWNOUT
//===========================================================================
void main(void)
{
int8 Trim_Val;
//initialize RTCC
rtc_Init();
Trim_Val= rtc_read_byte(ADDR_CAL);
rtc_write_byte(ADDR_CAL, 0x1C);
Trim_Val= rtc_read_byte(ADDR_CAL);
delay_us(1);
while(TRUE)
{
}
}
|
Using I2C setup in driver file:
| Code: |
#use i2c(master, sda=RTC_SDA, scl=RTC_SCL, FAST=400000)
|
Using unmolested MCP79411_driver.c file.
Any help would be most appreciated. THANKS |
|
 |
Ttelmah
Joined: 11 Mar 2010 Posts: 20150
|
|
Posted: Wed Nov 04, 2026 12:27 pm |
|
|
An issue straight away. The rtc_read_byte function is for reading the
rtc registers, which are BCD coded. Not a binary register like the calibration
one. To read the value from that you'd need to code your own version
of the read function without the bcd conversions. May not be the problem
but needs to be fixed. |
|
 |
JerryR
Joined: 07 Feb 2008 Posts: 195
|
|
Posted: Wed Nov 04, 2026 12:50 pm |
|
|
Hi Ttelmah:
Yes, understand that, so not an issue to retrieve non BCD data. However, polling any register with this code returns 0xA5. I'm wondering if I'm actually setting correct information in a register with the write byte routines, but not reading a register correctly.
Can't believe no one has ever noticed this before.
Thanks for your help |
|
 |
JerryR
Joined: 07 Feb 2008 Posts: 195
|
|
Posted: Wed Nov 04, 2026 3:44 pm |
|
|
Hi Ttelmah:
Solved:
Yes, you were certainly right that reads, as his code provided, were converted to BCD. However, both reads and writes were addressing the EEPROM region in the MCP79411, not the SRAM/RTCC region as I required to write to.
Simply closely examining the data sheet and writing my own code to address the SRAM/RTCC area fixed the issue. Thanks for your kind assistance.
All the best |
|
 |
|