ENGLISH 简体中文 日本語 한국어  


APPLICATION NOTE  3313

DS1390/DS1391 RTC와 SPI 기능이 있는 모토롤라 DSP와의 인터페이싱

개요: 이 애플리케이션 노트에서는 SPI™ 인터페이스 모듈을 내장한 모토롤라 DSP에 DS1390을 연결하는 방법을 설명한다. 이 회로는 모토롤라 DSP56F800DEMO 기판 및 CodeWarrior® IDE를 이용한 것이다.

설명

DS1390 실시간 클록(RTC)은 SPI 인터페이스를 통해 마이크로컨트롤러(µC)나 DSP에 인터페이스할 수 있다. 이 애플리케이션 노트에서는 SPI 인터페이스 모듈을 내장한 모토롤라 DSP에 DS1390을 연결하는방법을 설명한다. 이 회로는 모토롤라 DSP56F800DEMO 기판과 CodeWarrior IDE를 이용한 것이다.

예제 소프트웨어 사용

이 프로젝트를 위해서는 우선 예제 소프트웨어를 개발해야 한다. 이에 관해서는 모토롤라 설치 설명서("CodeWarrior 프로젝트 작성") 참조. 이 애플리케이션 노트에 포함된 코드를 main.c에 추가한다.

동작

이 프로그램은 GPIO 포트를 이용해서 DS1390의 CS를 제어한다. 소프트웨어가 SPI 컨트롤러 모듈을 초기화하면 DSP가 DS1390에 시간과 날짜를 기록한다. 그리고 소프트웨어가 시간과 날짜를 읽는다. DS1390 및 DS1391은 SPI 모드 1 및 3을 지원한다.

회로도는 그림 1과 같다. 이 회로의 부속 카드를 모토롤라 데모 기판에 연결한다. 이 그림의 회로도에는 SPI 인터페이스의 다수 RTC가 포함된다. 한 번에 한 RTC만 이용할 수 있으며 소프트웨어가 DS1390만 지원한다. 소프트웨어는 그림 2와 같다.

그림 1.
그림 1.

그림 2. 부속 카드 회로도
그림 2. 부속 카드 회로도

그림 3. 코드 리스팅

/* File: DS1390.c */
/* This example program was developed using the Motorola
56F800 Demo Board Kit.  Follow the kit instalation guide
for creating a CodeWarrior Project.  Use the shell of the
new project for this example.  Note: This program is for
example only and is not supported by Dallas Semiconductor
Maxim. */

#include "port.h"
#include "stdio.h"
#include "stdlib.h"

/*******************************************************
* Main program for use with Embedded SDK
*******************************************************/

extern sampleASM (void);

void reset_spi(void);
void wbyte_spi(unsigned char);
void init_sci0(Word16);
tx_sci0(unsigned char);
void bcd2ascii(unsigned char);
unsigned char  rbyte_spi(void);

#define	REG_BASE 0x0000
#define	SCI0_BASE 0x0F00
#define	SPI_BASE 0x0F20
#define	GPIOA_BASE 0x0FB0
#define	GPIOB_BASE 0x0FC0

#define	SCI0_SCIBR *(volatile UWord16 *)(SCI0_BASE + 0)
#define	SCI0_SCICR *(volatile UWord16 *)(SCI0_BASE + 1)
#define	SCI0_SCISR *(volatile UWord16 *)(SCI0_BASE + 2)
#define	SCI0_SCIDR *(volatile UWord16 *)(SCI0_BASE + 3)

#define	SPSCR *(volatile UWord16 *)(SPI_BASE + 0)
#define	SPDSR *(volatile UWord16 *)(SPI_BASE + 1)
#define	SPDRR *(volatile UWord16 *)(SPI_BASE + 2)
#define	SPDTR *(volatile UWord16 *)(SPI_BASE + 3)

#define	GPIO_A_PUR *(volatile UWord16 *)(GPIOA_BASE + 0)
#define	GPIO_A_DR *(volatile UWord16 *)(GPIOA_BASE + 1)
#define	GPIO_A_DDR *(volatile UWord16 *)(GPIOA_BASE + 2)
#define	GPIO_A_PER *(volatile UWord16 *)(GPIOA_BASE + 3)

#define	GPIO_B_PUR *(volatile UWord16 *)(GPIOB_BASE + 0)
#define	GPIO_B_DR *(volatile UWord16 *)(GPIOB_BASE + 1)
#define	GPIO_B_DDR *(volatile UWord16 *)(GPIOB_BASE + 2)
#define	GPIO_B_PER *(volatile UWord16 *)(GPIOB_BASE + 3)

void main (void)
{
unsigned char	msec=0, min=0x26, sec=0x00, hr=0x17, dow=0x06,
				date=0x26, mon=0x12, yr=0x03, write = 0;

	reset_spi();
	init_sci0(195);			// 30MHz / 195 = 9600 baud

	GPIO_B_DR = 0x0008;		// disable RTC - CS high

	GPIO_B_DR = 0;			// enable RTC - CS low
	wbyte_spi(0x8d);		// control register write address
	rbyte_spi();			// dummy read
	wbyte_spi(0x18);		// enable osc, 32kHz sqw
	rbyte_spi();
	GPIO_B_DR = 0x0008;		// disable RTC - CS high

	if(write)
	{
		GPIO_B_DR = 0;			// enable RTC - CS low
		wbyte_spi(0x80);		// select seconds register write address
		rbyte_spi();			// dummy read
		wbyte_spi(msec);		// milliseconds register data
		rbyte_spi();
		wbyte_spi(sec);			// seconds register data
		rbyte_spi();
		wbyte_spi(min);			// minutes register
		rbyte_spi();
		wbyte_spi(hr);			// hours register
		rbyte_spi();
		wbyte_spi(dow);			// day of week register
		rbyte_spi();
		wbyte_spi(date);		// date register
		rbyte_spi();
		wbyte_spi(mon);			// month register
		rbyte_spi();
		wbyte_spi(yr);			// year register
		rbyte_spi();
		GPIO_B_DR = 0x0008;		// disable RTC - CS high
	}
	while(1)
	{
		GPIO_B_DR = 0u;			// enable RTC - CS low

		wbyte_spi(0);			// seconds register read address
		rbyte_spi();			// dummy read
		wbyte_spi(0);
		msec = rbyte_spi();		// read milliseconds register
		wbyte_spi(0);
		sec = rbyte_spi();		// read seconds register
		wbyte_spi(0);
		min = rbyte_spi();		// ditto minutes
		wbyte_spi(0);
		hr = rbyte_spi();		// and so on
		wbyte_spi(0);
		dow = rbyte_spi();
		wbyte_spi(0);
		date = rbyte_spi();
		wbyte_spi(0);
		mon = rbyte_spi();
		wbyte_spi(0);
		yr = rbyte_spi();

		GPIO_B_DR = 0x0008;		// disable RTC - CS high
		
		tx_sci0(0x0d);			// sequence to print time & date
		tx_sci0(0x0a);
		bcd2ascii(yr);
		tx_sci0('/');
		bcd2ascii(mon);
		tx_sci0('/');
		bcd2ascii(date);
		tx_sci0(' ');
		bcd2ascii(hr);
		tx_sci0(':');
		bcd2ascii(min);
		tx_sci0(':');
		bcd2ascii(sec);
	}

	return;
}

//SPSCR
//15 14  13   12     11   10    9     8    7       6       5    4        3    2    1    0
// r MSB SPRF ERRIE  ovrf modf spte modfen spr1   spr0   sprie spmstr   cpol cpha spe  spite

void reset_spi()
{
int	val;
	SPSCR = 0x0056;	// SPR0, SPMSTR, CPHA, SPE
	SPDSR = 0x0007;	// 8-bit size

	SPSCR &= 0xfffd;	// clear spe, resets SPI (partial)
	SPSCR |= 0x0002;	// set spe, new values take effect

	GPIO_B_PER = 0x00f3;	// use GPIOB3 as CS for RTC
	GPIO_B_DDR = 0x000d;	// direction is output

	GPIO_A_PER = 0x00f9;	// enable/disable per function (1=enable)
	GPIO_A_DDR = 0x0006;	// direction is output (1=output)
	GPIO_A_DR  = 0;			// write bits low (0=low)
}
 
void  wbyte_spi( unsigned char  wbyte)	// ------ write one byte -------
{
	while (!(SPSCR & 0x0200));	// wait for transmitter empty flag

	SPDTR = wbyte;	
}

void	bcd2ascii(unsigned char dat)	// ----- convert bcd to ascii and send to sci ----
{
	tx_sci0( (dat >> 4) + 0x30);
	tx_sci0( (dat & 0x0f) + 0x30);
}
unsigned char rbyte_spi(void)	// -------- read one byte ----------
{
	while (!(SPSCR & 0x2000));	// wait for receiver full flag

	return(SPDRR);
   
}

void	init_sci0(Word16 baud)
{
	GPIO_B_PER = 0x00f3;	// set up
	GPIO_B_DDR = 0x000d;	// direction is output

	SCI0_SCIBR = baud;		// baud rate
	SCI0_SCICR = 0x2000;	// control reg
}
tx_sci0(unsigned char val)
{
UWord16	reg;

	SCI0_SCICR &= 0xfffb;	// turn receiver off
	SCI0_SCICR |= 8;		// turn transmitter on
	do
	{
		reg = SCI0_SCISR;		// clear flag by reading
	}	while( (reg & 0x8000) == 0);	// wait until RDRF is false

	SCI0_SCIDR = (unsigned int) (val);
}


의견을 보내주세요!
위 내용이 도움이 되셨나요?
여러분의 의견을 기다립니다 — Maxim은 보내주신 정정이나 제안사항을 반영하고 있습니다. 이 페이지를 평가하고 의견을 보내주십시오.


자동 업데이트
관심있는 분야의 애플리케이션 노트가 나올 때 자동으로 업데이트 받고 싶으세요? 그렇다면 EE-Mail™을 신청하십시오.



추가 정보  APP 3313: Jan 17, 2005
DS1390 트리클 충전기가 내장된 저전압 SPI/3-Wire RTC 전체 데이터 시트
(PDF, 388kB)
무료 샘플
DS1391 트리클 충전기가 내장된 저전압 SPI/3-Wire RTC 전체 데이터 시트
(PDF, 388kB)
무료 샘플
 

다운로드, PDF 형식다운로드, PDF 형식 (41kB)
 AN3313, AN 3313, APP3313, Appnote3313, Appnote 3313



         



   Copyright © 2008 by Maxim Integrated Products, Dallas Semiconductor    법적 고지    개인정보보호 정책