0
  • 聊天消息
  • 系统消息
  • 评论与回复
登录后你可以
  • 下载海量资料
  • 学习在线课程
  • 观看技术视频
  • 写文章/发帖/加入社区
创作中心

完善资料让更多小伙伴认识你,还能领取20积分哦,立即完善>

3天内不再提示

DS1390/DS1391 RTC与带SPI的摩托罗拉DSP接口

星星科技指导员 来源:ADI 作者:ADI 2023-01-11 09:50 次阅读

本应用笔记介绍如何将DS1390连接至内置SPI™接口模块的摩托罗拉DSP。该电路使用摩托罗拉DSP56F800DEMO演示板和CodeWarrior® IDE。

描述

DS1390实时时钟(RTC)可通过SPI接口与微控制器(μC)或数字信号处理(DSP)单元连接。本应用笔记介绍如何将DS1390连接至内置SPI接口模块的摩托罗拉DSP。该电路使用摩托罗拉DSP56F800DEMO演示板和CodeWarrior IDE。

使用示例软件

示例软件是从空白项目开始开发的。按照摩托罗拉套件安装指南(教程:创建 CodeWarrior 项目)中的说明进行操作,了解详细信息。在main.c中添加本应用笔记中包含的代码。

操作

该程序使用GPIO端口来控制DS1390上的CS。软件初始化SPI控制器模块,DSP将时间和日期写入DS1390。然后,软件循环读取时间和日期。DS1390和DS1391支持SPI模式1和3。

电路原理图如图1所示。该电路包括连接到摩托罗拉演示板的子卡。请注意,图1中的电路包括几个带SPI接口的RTC。一次只能使用一个RTC,软件仅支持DS1390。该软件如图 2 所示。

pYYBAGO-FduALTAvAAATf3MyVuA217.gif


图1.

poYBAGO-Fd2ABCWHAAAgcfcswNg840.gif?imgver=1


图 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);
}

审核编辑:郭婷

声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉
  • dsp
    dsp
    +关注

    关注

    544

    文章

    7681

    浏览量

    344331
  • 控制器
    +关注

    关注

    112

    文章

    15214

    浏览量

    171135
  • GPIO
    +关注

    关注

    16

    文章

    1133

    浏览量

    50561
收藏 人收藏

    评论

    相关推荐

    摩托罗拉证实裁员计划

             摩托罗拉日前已经证实了业界长期传闻的公司裁员计划。公司
    发表于 06-18 10:49

    摩托罗拉对讲维修手册

    摩托罗拉对讲维修手册  [hide]摩托罗拉对讲维修.rar[/hide]
    发表于 10-14 09:14

    摩托罗拉PowerPC 5XX

    摩托罗拉PowerPC 5XX
    发表于 03-25 10:05

    DS1390/DS1391/DS1394 pdf datas

    The low-voltage serial-peripheral interface (SPI™)DS1390/DS1391/DS1394 and the low-vol
    发表于 08-10 10:35 42次下载

    DS1392, DS1393,pdf datasheet (

    The low-voltage serial-peripheral interface (SPI™) DS1390/DS1391/DS1394 and the low-vo
    发表于 09-03 07:51 28次下载

    Interfacing a DS1390/DS1391 RT

    This app note shows how to connect a DS1390 to a Motorola DSP that has a built-in SPIinterface
    发表于 04-25 10:21 18次下载

    Interfacing a DS1390/DS1391 RT

    Processing (DSP) unit using a SPI interface. This app note shows how to connect a DS1390 to a Motorola
    发表于 05-29 08:37 11次下载

    DS1390/DS1391 RTC与Motorola SPI

    摘要:本应用笔记说明了DS1390与内置SPI接口的Motorola DSP的连接方式,该电路使用了Motorola DSP5
    发表于 04-21 11:10 1436次阅读
    <b class='flag-5'>DS1390</b>/<b class='flag-5'>DS1391</b> <b class='flag-5'>RTC</b>与Motorola <b class='flag-5'>SPI</b>

    DS1390-DS1394低电压SPI/3线接口RTC

    低电压串行外设接口(SPI™) DS1390/DS1391/DS1394和低电压3线DS1392
    发表于 11-15 11:56 2880次阅读

    DS1390-DS1394数据资料

    The low-voltage serial-peripheral interface (SPI)DS1390/DS1391/DS1394 and the low-voltage
    发表于 11-15 12:09 40次下载
    <b class='flag-5'>DS1390-DS</b>1394数据资料

    DS1391 RTC

    DS1391 RTC,PCB学习好资料,欢迎下载学习。
    发表于 03-23 10:45 0次下载

    接口SPI RTC摩托罗拉DSP

    本应用笔记提供了一个例子的硬件和软件接口的串行外设接口SPIRTC摩托罗拉DSP,有一个内
    发表于 04-12 16:29 18次下载
    <b class='flag-5'>接口</b>的<b class='flag-5'>SPI</b> <b class='flag-5'>RTC</b>与<b class='flag-5'>摩托罗拉</b><b class='flag-5'>DSP</b>

    SPI RTC摩托罗拉DSP接口

      本应用笔记提供了用于将串行外设接口SPIRTC与内置SPI接口模块的摩托罗拉
    的头像 发表于 01-10 11:45 881次阅读
    <b class='flag-5'>SPI</b> <b class='flag-5'>RTC</b>与<b class='flag-5'>摩托罗拉</b><b class='flag-5'>DSP</b><b class='flag-5'>接口</b>

    DS1868 3线器件连接至SPI总线

    DS1868采用双通道数字电位器,具有3线(移位寄存器)接口。本应用笔记描述了将DS1868以及达拉斯半导体的3线器件连接至摩托罗拉SPI
    的头像 发表于 03-29 11:06 647次阅读
    将<b class='flag-5'>DS</b>1868 3线器件连接至<b class='flag-5'>SPI</b>总线

    DS1620与摩托罗拉SPI总线接口

    DS1620数字温度传感器IC的通信通过简单的3线接口实现。此接口摩托罗拉 SPI 之间存在许多差异™
    的头像 发表于 05-16 11:28 601次阅读
    <b class='flag-5'>DS</b>1620与<b class='flag-5'>摩托罗拉</b><b class='flag-5'>SPI</b>总线<b class='flag-5'>接口</b>