UC3-A3 Xplained EK and DS3231

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



i have connected Clock module DS3231 with UC3A3-EK via TWI on Header J1 and this are the signals that I got:

this is my code:

#include "board.h"
#include "sysclk.h"
#include "twi_master.h"
#include "led.h"
#include "conf_board.h"
#include "gpio.h"
#include "conf_twim.h"

#define EEPROM_BUS_ADDR			    0x68	  //!< TWI slave bus address
#define EEPROM_MEM_WRITE_ADDR       0b11010000		
#define EEPROM_MEM_READ_ADDR		0b11010001		
#define TWI_SPEED				    400000	 //!< TWI data transfer rate

int main(void)
	static const gpio_map_t TWI_GPIO_MAP =
	gpio_enable_module(TWI_GPIO_MAP, sizeof(TWI_GPIO_MAP) / sizeof(TWI_GPIO_MAP[0]));
  // TWI master initialization options.
  twi_master_options_t opt = {
		.pba_hz = FOSC0,
	    .speed  = TWI_SPEED,
	    .chip   = EEPROM_BUS_ADDR
 twim_master_init(TWI_EXAMPLE, &opt);
   twi_package_t packet_write = {

    .addr		  = EEPROM_MEM_WRITE_ADDR,      // TWI slave memory address data MSB
    .addr_length  = sizeof (uint8_t),		 // TWI slave memory address data size
    .chip         = EEPROM_BUS_ADDR,		  // TWI slave bus address
    .buffer       = (void *)test_pattern,	// transfer data source buffer
    .length       = sizeof(test_pattern)	 // transfer data size (bytes)
 while (twi_master_write(TWI_EXAMPLE, &packet_write) != TWI_SUCCESS);
   twi_package_t packet_read = {

    .addr      = EEPROM_MEM_READ_ADDR,      // TWI slave memory address data MSB
    .addr_length  = sizeof (uint8_t),     // TWI slave memory address data size
    .chip         = EEPROM_BUS_ADDR,      // TWI slave bus address
    .buffer       = data_received,        // transfer data destination buffer
    .length       = 10					// transfer data size (bytes)
   while (twi_master_read(TWI_EXAMPLE, &packet_read) == TWI_SUCCESS);

This code is from ASF and slightly modified for my needs. I think that my problem is somwhere in my code. As you can see, SDA signal are the Slave device addresses/commands for read and write and there is nothing in between where the written and readed data should be. I am trying to get this:



Any help is more tha welcome!



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

Why do you mix the ASF twim_...() routines with twi_....() routines ?
The UC3A3/4xxx and UC3Cxxx and UC3Lxxx have a TWIM module, the UC3A0/1xxx and UC3Bxxx have a TWI module., those modules are NOT the same.

It is a good idea to check the return values from all ASF routines.
eg. twim_master_init(,) should return STATUS_OK, etc.

The addresses of the internal registers in the DS3231 are 0x00 to 0x12


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

Thank you for the help. Its working now but as a result i am gettin



and counting


I found this code online to convert the data from DS3231


struct clock
    uint8_t seconds;
    uint8_t minute;
    uint8_t hours;
    uint8_t day;
    uint8_t datum;
    uint8_t month;
    uint16_t year;


struct clock time;


time.seconds = (tbuffer[0] & 0x0f)+((tbuffer[0] &0xf0)>>4)*10;
time.minute = (tbuffer[1] & 0x0f)+((tbuffer[1] &0xf0)>>4)*10;
time.hours = (tbuffer[2] & 0x0f)+((tbuffer[2] &0x10)+(tbuffer[2]&0x20)>>4)*10; //noch
time.day = (tbuffer[3] & 0x07);
time.datum = (tbuffer[4] & 0x0f)+((tbuffer[4] & 0xf0)>>4)*10;
time.month = (tbuffer[5] & 0x0f)+((tbuffer[5] & 0x10)>>4)*10;
time.year = (tbuffer[6] & 0x0f)+((tbuffer[6] &0xf0)>>4)*10+((tbuffer[5] & 0x80)>>7)*100 + 1900 ;


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

1) I have no idea of what you did to make it 'work'.
2) That 'online' code should be ok if you can read at least 6 bytes from the DS3231, starting at register 0x00, into tbuffer[].
3)The DS3231 must be initialised with a time and date at some point., it does not have non-volatile storage to remember the time/date when the main power (VCC) is removed.

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

Magic :D

I had to change the whole code a little bit (read: a lot). I will post the whole project later when i finnish. Till now I have successfully connected UC3-A3 Xplained with: Inclinometer SDA8301 via SPI, Clock DS3231 via TWI and currently trying to connect LCD Display 2004A 4x20 also via TWI but for now without success.

I am not quite sure how to initialies the DS3231. Can you give me some example?


Thank you very much for the help and patience!