Problem with AT24CXX_EXAMPLE and TWIM

Go To Last Post
4 posts / 0 new
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


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

#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) {
  print_dbg("AT24CXX Example\r\n");



  /* 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);

// !!! Don't write 
  //print_dbg("Write @0: 0x55 - @1: 0xAA");
  //print_dbg("- Done\r\n");

// !!! read 0x13 bytes
  U8 tmp1,tmp2;
  tmp2 = at24cxx_read_byte(tmp1);
  print_dbg("Read @0x");
  print_dbg(": 0x");

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 $

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I had the same problem on uc3-ek.
And worse:
on my custom board i am using twim2, which won't work at all. ASF is pretty over-buggy concerning TWI.

No solution yet, sorry.

very strange:
read@0: 0x00
read@1: 0x00
read@2: 0xff
read@3: 0xff
read@4: 0xff

I believe that the read at24cxx_read_...-functions seem to work properly. But the write-functions seem to be buggy.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Has anyone found a solution to this ? I'm running ASF 3.2.1 (AT32UC3C0512C) and am having exactly the same issue listed here.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I found the point.
The TWI functions ,such as at24cxx_read_byte, uses two-byte address. But the DS3231 only need one-byte address. When I use at24cxx_read_byte, this function send the address as 0x00 0x68. But the address should be 0x68 without 0x00. After I modified this, it works.