SparkFun Forums 

Where electronics enthusiasts find answers.

Discussions on the software and hardware for Atmel's STK standard.
By mcodesmart
#130318
Does the Atmega 2560 have an RTC available with an alarm?

How can you implement an RTC with an alarm on this chip?
User avatar
By phalanx
#130324
It does not. If you use a proper oscillator, you could make a software RTC without too much trouble. Your other option would be to use an external RTC like a DS1307 or equivalent.

-Bill
By mcodesmart
#130330
I did a google search on the DS1305.. I want to use three wire interface...

Not SPI! :cry:

Any leads??
By stevech
#130337
That ATMega has plenty of code and RAM for you to implement an RTC in firmware using a timer.
However, if battery backup on the RTC is needed, then an outboard chip is best and there are 10 or more to choose from.
User avatar
By phalanx
#130372
mcodesmart wrote:I did a google search on the DS1305.. I want to use three wire interface...

Not SPI! :cry:

Any leads??
SPI can be a 3 wire interface so I'm not sure what you are asking.

-Bill
By mcodesmart
#130383
SPI used 4 wire.. CS, SCLK, MSDI and MSDO..

Three wire interface uses the same line for MSDI and MDSO and it not used widely.. only for simple components like RTC clocks and some simple sensor..

Some maxim-ic products use this...

However, I am having difficulty with it..

By the way, are you the only one who read this forum :?:
User avatar
By phalanx
#130385
I see what you are going after now. CS does not have to be part of the SPI signal even though many ICs use it for latching purposes. In cases where the slave permits it, you can get by with SCLK, MSDI, and MSDO for bidirectional communication.

The DS1305 you mentioned DOES support the 3 wire mode you are talking about where MSDI and MSDO share the same pin. All you have to do is tie the SERMODE pin to GND. I'm not ultra familiar with Atmegas but I'm pretty sure there are no hardware modules on board that directly support 3 wire mode. The built in SPI module does not have a bidirectional data pin. A 3 wire serial port could easily be handled in software however but that is inefficient when you have hardware modules waiting to be used in your controller.

Why can't you spare the 4th wire for SPI? You are using a 100-pin device so I would imagine you have plenty of pins or is this just an exercise to see if you can do it? SPI is extremely easy to make work, very easy to troubleshoot, can offer extremely fast full duplex tranfer rates, and is supported in hardware by your microcontroller. If you can't spare the pins, why not use an I2C RTC like the DS1307. That only needs 2 wires and is supported in hardware with your controller's TWI (Two Wire Interface).

-Bill
User avatar
By phalanx
#130386
I'm not the only person who reads these forums although I admit I don't check the AVR section as often as I do the PIC section. I know PICs much better than AVRs so I tend to look there first. I would imagine that most new users of AVRs who are looking for help are probably using an Arduino and don't fully grasp the difference between it and an AVR.

I also moderate the posts here so when I see one in the queue that I can answer I have the chance to before other people chime in.

-Bill
By ella
#133805
There is an I2C based RTC: DS1307

Just for you:
Code: Select all
uint8_t ds1307_reg_write( uint8_t ra, uint8_t data )
{
    twi_start();

    twi_write( DS1307_SA<<1 );
    if( twi_acked() )
        return -1;

    twi_write( ra );
    if( twi_acked() )
        return -1;

    twi_write( data );
    if( twi_acked() )
        return -1;

    twi_stop();
    return 0;
}

uint8_t ds1307_reg_read ( uint8_t ra, uint8_t* data )
{
    twi_start();

    twi_write( DS1307_SA<<1 );
    if( twi_acked() )
        return -1;

    twi_write( ra );
    if( twi_acked() )
        return -1;

    twi_start();

    twi_write( (DS1307_SA<<1)|0x01 );
    if( twi_acked() )
        return -1;

    twi_read( data );
    twi_nacking();
    twi_stop();

    return 0;
}
I like AVR much more then PIC (but actually they are the same more or less). For me most important is availability of GCC port for AVR.

These are my projects made on AVR:
http://www.xdimax.com/sub20/sub20.html
http://www.xdimax.com/cool/cool.html
http://www.xdimax.com/interX/interX.html