色哟哟视频在线观看-色哟哟视频在线-色哟哟欧美15最新在线-色哟哟免费在线观看-国产l精品国产亚洲区在线观看-国产l精品国产亚洲区久久

Interfacing the DS1620 to the

來源:本站整理 作者:佚名2009年04月18日 10:46
[導(dǎo)讀] Abstract: Communication with the DS1620 digital temperature sensor IC is achieved via a simple 3-wire interface. There are a number of differences between this interface and the Motorola SPI™ interface. However, a few minor hardware
關(guān)鍵詞:bus
Abstract: Communication with the DS1620 digital temperature sensor IC is achieved via a simple 3-wire interface. There are a number of differences between this interface and the Motorola SPI™ interface. However, a few minor hardware and software modifications allow the DS1620 to be effectively incorporated into an SPI based system.

This application note is a courtesy of Michel St-Hilaire and Marc Desjardins from XyryX Technologies, Quebec city, Province of Quebec, Canada.

Introduction

The DS1620 Digital Thermometer and Thermostat provides 9-bit temperature readings which indicate the temperature of the device. With three thermal alarm outputs, the DS1620 can also act as a thermostat. Temperature settings and temperature readings are all communicated to/from the DS1620 over a simple 3-wire interface.

However, the SPI interface found on many Motorola processors cannot directly communicate with the 3-wire interface found on the DS1620. First, the data flow to and from the DS1620 is multiplexed on only one pin (DQ) while SPI needs two separate signals (MOSI, MISO).

Second, most SPI interfaces are limited to 8-bit data transfer, complicating sending and receiving the 9-bit temperature readings to and from the DS1620. In addition, the DS1620's interface transfers LSB first, while SPI is an MSB-first communication protocol.

Lastly, the RST-bar is unlike a CS-bar (chip select) signal in that RST-bar must be high from the beginning of a transfer (protocol) to the end of all transfer of data (e.g. 9th bit transferred when reading temperature value).

Despite all these constraints, a fairly simple solution can be found which allows an SPI interface to communicate with a DS1620. This technique is described in this application note.

SPI Interface

The circuit shown in Figure 1 can be used to control data flow direction with an SPI bus interfaced to a DS1620. This circuit could be integrated into a small PAL if desired.

The purpose of the DIR signal is to select between sending data to or receiving data from the DS1620. When DIR is low, the DS1620 is receiving data; if DIR is high, data is being read by the SPI controller.

The resistor is necessary to prevent contention between the output of the tri-state buffer on the MOSI line and the DQ pin of the DS1620, because after a READ command protocol has been received by the DS1620, its DQ pin changes direction from input to output in a few hundred nanoseconds. This time is much too short for the microprocessor controlling the DIR signal to take action.

When connecting multiple peripherals on the same SPI bus, the MISO signal must be tri-stated when the DS1620 is not accessed to prevent contention with the MISO signal of other peripherals. That is why the RST-bar signal is necessary in the logic which determines the data direction.

Note that the SPI clock is wired directly to the CLK pin of the DS1620. The software has to take care of the polarity and phase of the SPI clock to be compatible with the CLK timing requirements of the DS1620.

Figure 1. SPI to DS1620 interface circuit.
Figure 1. SPI to DS1620 interface circuit.

Software for the Interface

While the hardware for the interface is relatively straightforward, the rest of the SPI/DS1620 interface must be handled by software. The following example shows a way to do this in the case of reading the temperature from the DS1620. This code fragment assumes that the DS1620 has already been initialized, that the configuration register is set up properly, and that temperature conversions have been initiated. See the DS1620 data sheet for details on these operating modes.

Before accessing the DS1620, the DIR signal must be asserted low for a WRITE transfer to occur. RST-bar must be driven high to enable the DS1620. The SPI controller sends out the protocol (eight bits long) to the DS1620. Again, note that SPI sends information MSB first, while the DS1620 communicates LSB first. In order to accomplish this, a software "mirror" should be used to reverse the bit order. An example of such a function is given by:

unsigned char mirror(unsigned char value)
{
     unsigned char i;
     unsigned char value_mirrored = 0x00;

     for (i=0;i<=7;i++)
     {
        value_mirrored = value_mirrored | (((value>>i)&0x01)<<(7-i));
}
return (value_mirrored);
}
With the protocol sent, the DIR is changed from low to high (indicating now a READ transfer) because the DS1620 is ready to send out the 9-bit value. Note that RST-bar is still high. The SPI controller reads the first eight bits of the 9-bit value (LSB first). The software has to "mirror" the received byte. The 9th bit (followed by seven dummy bits) is pulled out by making another READ transfer and keeping DIR and RST-bar as they are. When the second byte is received, the software again mirrors it and pulls RST-bar low, terminating communication with the DS1620.

#define     RST_bit              0 /* PB0 */
#define     RST_port             PORTB
#define     DIR_bit              1 /* PB1 */
#define     DIR_port             PORTB
#define     READ_TEMP_CMD        0xAA

unsigned int read_temp(void)
{
     unsigned char temp_value_lo;
     unsigned char temp_value_hi;

     DIR_port = DIR_port & ~(1<<DIR_bit);         /* DIR = L WRITE mode */
     RST_port = RST_port | (1<<RST_bit);          /* RST = HI: DS1620 enabled */
     SPDR = mirror(READ_TEMP_CMD);                /* Send protocol to DS1620 */
     DIR_port = DIR_port | (1<<DIR_bit);          /* DIR = HI: READ mode */
     while ((SPSR & (1<<SPIF_bit)) == 0);         /* Wait for SPI flag = ready */
     temp_value_lo = mirror(SPDR);                /* Receive 8 lowest bits */
     temp_value_hi = mirror(SPDR);                /* Receive 8 highest bits */
     RST_port = RST_port & ~(1<<RST_bit);         /* RST = L Temp. reading done */
     return ((temp_value_hi<<8)+temp_value_lo);   /* Return the 9-bit value */
}

相關(guān)閱讀

發(fā)表評論
技術(shù)交流、積極發(fā)言! 發(fā)表評請遵守相關(guān)規(guī)定。

0 條評論

推薦閱讀

每月人物

正面迎戰(zhàn)智慧家庭:從稱體重到“稱”健康,芯海智慧測量全包了!

正面迎戰(zhàn)智慧家庭:從稱體重到“稱”健康,芯海智慧測量全包
隨著科技的發(fā)展,人們對生活質(zhì)量的追求越來越高,傳統(tǒng)的家庭生活方式已經(jīng)無法滿足現(xiàn)代人的家居生活,智慧家庭的新型生活理念成為很多人夢寐以求的...

依托AI平臺,涂鴉智能開啟全屋智能2.0時代!

依托AI平臺,涂鴉智能開啟全屋智能2.0時代!
隨著物聯(lián)網(wǎng)技術(shù)的突飛猛進,生活中越來越多的家庭設(shè)備將會聯(lián)上網(wǎng)絡(luò),變得“智慧”起來,智慧家庭的概念成了這幾年媒體、企業(yè)、用戶關(guān)注的焦點,而...

每周排行

  • 型 號
  • 產(chǎn)品描述
主站蜘蛛池模板: 在线成人精品国产区免费| 农民下乡在线观看3| 樱桃bt在线www| 日韩欧美一级| 久久精视频| 国产精品爽爽久久久久久竹菊| 中文无码不卡的岛国片国产片| 四库影院永久国产精品| 暖暖日本 在线 高清| 精品国产在天天线在线麻豆| 古代荡女丫鬟高H辣文纯肉| 91久久精一区二区三区大全| 亚洲精品久久午夜麻豆| 日日撸影院在线| 免费夜里18款禁用软粉色| 好妞操| 国产爱豆果冻传媒在线观看| a三级黄色片| 中国老太太xxx| 亚洲日韩一区精品射精| 我不卡影院手机在线观看 | 黄色网址在线看| 攻把受做哭边走边肉楼梯PLAY| 99热精品一区| 91九色视频无限观看免费| 中国成人在线视频| 亚洲在线成色综合网站| 亚洲国产AV精品一区二区蜜芽| 色偷偷影院| 日韩欧美一区二区三区免费看 | 亚洲欧美综合乱码精品成人网| 四虎影5151毛片在线看| 人妻系列合集| 人人干人人看| 日本不卡免免费观看| 日本枯瘦娇小| 色狠狠一区| 涩涩999| 无遮挡午夜男女XX00动态| 乌克兰女人与动ZOZO| 乡村教师电影版|