UC3-A3 Xplained EK and DS3231

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

Greetings,

 

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"

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

int main(void)
{
	board_init();
	static const gpio_map_t TWI_GPIO_MAP =
	{
		{AVR32_TWIMS0_TWCK_0_0_PIN,	AVR32_TWIMS0_TWCK_0_0_FUNCTION},
		{AVR32_TWIMS0_TWD_0_0_PIN,	 AVR32_TWIMS0_TWD_0_0_FUNCTION},
	};
	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);
 twim_master_enable(TWI_EXAMPLE);
 
   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!

 

Cheers!

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

1)
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.


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


3)
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

3h:15m:45s

5/4/1906

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!