Hi,mates
I'm working on UC3C2512 + DS3231(I2C RTC from Maxim).
I setup a project by UC3C-EK:AT24CXX_EXAMPLE. And I set CPU to UC3C2512, AT24CXX_TWI_ADDRESS to 0x68(DS3231 Addr).
Because the OSC0 is 14.7456M,I modified the defines as follow
Code:
#define FOSC0 14745600
#define BOARD_OSC0_HZ 14745600
#define FCPU_HZ 14745600
#define FPBA_HZ 14745600
here is the main
// main function
int main(void) {
init_sys_clocks();
init_dbg_rs232(FPBA_HZ);
print_dbg("AT24CXX Example\r\n");
irq_initialize_vectors();
twi_init();
/* Power up delay: This device needs a maximum of 230ms before it
* can be accessed. Another method would be to wait until the the
* detect line goes low but this won't work during a debugging session
* since the device is not reset.*/
cpu_delay_ms(230, FCPU_HZ);
at24cxx_init(FCPU_HZ);
// !!! Don't write
//print_dbg("Write @0: 0x55 - @1: 0xAA");
//at24cxx_write_byte(0,0x55);
//at24cxx_write_byte(1,0xaa);
//print_dbg("- Done\r\n");
// !!! read 0x13 bytes
U8 tmp1,tmp2;
for(tmp1=0;tmp1<=0x12;tmp1++)
{
tmp2 = at24cxx_read_byte(tmp1);
print_dbg("Read @0x");
print_dbg_char_hex(tmp1);
print_dbg(": 0x");
print_dbg_char_hex(tmp2);
print_dbg("\r\n");
}
while(true);
}
What I got from UART is
AT24CXX Example
Read @0x00: 0x00
Read @0x01: 0x01
Read @0x02: 0x02
Read @0x03: 0x03
Read @0x04: 0x04
Read @0x05: 0x05
Read @0x06: 0x06
Read @0x07: 0x07
Read @0x08: 0x08
Read @0x09: 0x09
Read @0x0A: 0x0A
Read @0x0B: 0x0B
Read @0x0C: 0x0C
Read @0x0D: 0x0D
Read @0x0E: 0x0E
Read @0x0F: 0x0F
Read @0x10: 0x10
Read @0x11: 0x11
Read @0x12: 0x12
Data was read successfully. But the data was wrong.
I am exausted and I need your help. Thanks a lot.
$ Fixed code tags - JS $ |