rtc.c File Reference

#include <avr/io.h>
#include <avr/pgmspace.h>
#include <stdio.h>
#include <inttypes.h>
#include "util.h"
#include "rtc.h"
Include dependency graph for rtc.c:

Defines

#define DDRRTCSEL   DDRB
#define PORTRTCSEL   PORTB
#define DDRSPI   DDRB
#define PORTSPI   PORTB
#define RTCSEL   6
#define MISO   4
#define MOSI   3
#define SCK   5

Functions

void rtc_init ()
void rtc_send (uint8_t b)
void rtc_over ()
uint8_t rtc_rw (uint8_t addr, int8_t value)
uint16_t rtc_gettime (uint8_t ss)
void rtc_dump ()

Define Documentation

#define DDRRTCSEL   DDRB
#define DDRSPI   DDRB
#define MISO   4
#define MOSI   3
#define PORTRTCSEL   PORTB
#define PORTSPI   PORTB
#define RTCSEL   6
#define SCK   5

Function Documentation

void rtc_dump (  ) 

00073                 {
00074     uint8_t i;
00075     
00076     rtc_send(0); 
00077     for (i = 0; i < 0x1a; i++) {
00078         rtc_send(0); 
00079         printf_P(PSTR("%02x:%02x   "), i, SPDR);
00080     }
00081     rtc_over();
00082 }

Here is the call graph for this function:

uint16_t rtc_gettime ( uint8_t  ss  ) 

00053                                  {
00054     uint16_t time = 0;
00055 
00056     // address 0 for seconds, minutes; minutes, hours otherwise   
00057     rtc_send(ss ? 0 : 1);
00058 
00059     // data 1
00060     rtc_send(0);
00061     time = SPDR; 
00062     
00063     // data 2
00064     rtc_send(0);
00065     while (!(SPSR & _BV(SPIF)));
00066     time |= SPDR<<8;
00067     
00068     rtc_over();
00069           
00070     return time; 
00071 }

Here is the call graph for this function:

void rtc_init (  ) 

00024                 {
00025     //DDRD |= _BV(4);     // RTCSEL#
00026     DDRRTCSEL |= _BV(RTCSEL);
00027     
00028     DDRSPI |= BV2(MOSI,SCK);
00029     DDRB &= ~_BV(MISO);
00030     
00031     PORTRTCSEL |= _BV(RTCSEL);
00032     
00033     SPCR = BV4(SPE, MSTR, CPHA, SPR1);
00034 }

void rtc_over (  ) 

00042                 {
00043     PORTRTCSEL |= _BV(RTCSEL);
00044 }

uint8_t rtc_rw ( uint8_t  addr,
int8_t  value 
)

00046                                            {
00047     rtc_send(addr | (value == -1 ? 0 : 0200));
00048     rtc_send(value);
00049     rtc_over();
00050     return SPDR;
00051 }

Here is the call graph for this function:

void rtc_send ( uint8_t  b  ) 

00036                          {
00037     PORTRTCSEL &= ~_BV(RTCSEL); 
00038     SPDR = b;
00039     spi_wait();
00040 }


Generated on Wed Jan 27 00:29:58 2010 for Patashnik by  doxygen 1.6.1