Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
AVR / AVR318_1-WireMaster.pdf
Скачиваний:
50
Добавлен:
20.03.2015
Размер:
133.62 Кб
Скачать

AVR318

received value. Each of the bit-level functions calls OWI_TouchBit with the value that

 

will generate the correct waveform on the bus.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

The interface to these functions is the same as for the software only implementation.

 

The ‘pins’ argument is however not necessary in the polled UART driver. A set of

 

macros makes it possible to call these functions with or without the pins argument. If

 

the pins argument is included, it will be removed by the macros.

 

 

 

 

 

Higher level functions

Note that many functions in this layer accept an argument of type unsigned char

 

pointer. This pointer should point to an array of 8 bytes of memory that can be used

 

by the function. Allocation, and sometimes initialization, of these arrays must be done

 

by the caller. This document clearly states when the memory has to be initialized in a

 

special way before calling a function.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Byte transmission functions

Figure 14. Byte transmission functions

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

SendByte

 

 

 

 

 

 

 

 

 

 

 

 

ReceiveByte

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

temp = data &

 

 

 

 

 

 

 

 

 

 

 

 

Set data = 0

 

 

 

 

 

 

 

 

 

 

 

0x01

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Right shift data

 

 

 

 

 

 

 

 

 

 

 

Value of temp

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

0

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Yes

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

ReadBit

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

1

 

 

 

 

 

 

 

 

 

 

 

Yes

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

WriteBit1

 

 

 

WriteBit0

 

 

 

 

 

 

Result of

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

1

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

ReadBit

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Right shift data

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Set msb of data

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

0

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Bits left?

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Bits left?

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

No

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

No

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Return

 

 

 

 

 

 

 

 

 

 

 

 

Return data

 

 

 

 

 

ROM commands

All general ROM commands for standard speed communication are implemented.

 

The simplest ROM command is the SKIP ROM command. It simply calls the

 

SendByte function with the SKIP ROM command byte as argument.

 

 

 

 

 

Flowcharts for the READ ROM and MATCH ROM commands are shown in figure

Figure 15.

11

2579A-AVR-09/04

Figure 15. Read ROM flowchart

ReadRom

MatchRom

SendByte(READ ROM

Send MATCH ROM

command)

command

No

No

SendByte

ReceiveByte

 

Finished all 8

Finished all 8

bytes?

bytes?

Yes

Yes

Return

Return

The flowchart for the SEARCH ROM command is shown in Figure 16. This function will find one slave device for each time it is run, until there are no undiscovered slave devices on the bus. The last time it is run, it will return OWI_ROM_SEARCH_FINISHED. In addition to the the ‘pin’ parameter, used to select which bus to perform the search on, two parameters must be passed to this function: ‘lastDeviation’ and ‘bitPattern’. These parameters control the slave device search. Refer to Table 4 to understand how to use these parameters to complete a full search for all slave devices.

Table 4. bitPattern and lastDeviation usage

 

BitPattern

lastDeviation

First time

Zero filled 8 byte array

0

Consecutive runs

A copy of the 8 byte array

Value returned from

 

returned through bitPattern

SearchRom last run.

 

pointer last run.

 

The function is implemented in this way to give the caller maximum flexibility. The example software for the polled driver shows how it can be used to implement the full search.

12 AVR318

2579A-AVR-09/04

AVR318

Figure 16. Search ROM command

SearchRom

Set newDeviation to 0

Set bitIndex = 1

Send SEARCH

ROM command

 

Read bit twice

 

 

 

 

 

 

 

 

 

Error

 

Both bits = 1?

Yes

Error, set newDeviation to

 

ROM_SEARCH_FAILED

 

 

 

 

No

 

 

 

 

 

 

 

 

 

All slaves have the

 

bit1 ‡ bit2

Yes

 

Set

same bit at this position

 

bitPattern[bitIndex]

 

 

 

 

 

to first bit read

 

 

No

 

 

 

 

 

 

 

 

 

There are

 

bitIndex =

 

 

Set

both 0's

 

Yes

bitPattern[bitIndex]

and 1's at

 

lastDeviation?

 

 

 

to 1

this bit

 

 

 

 

 

 

 

 

 

position.

 

No

 

 

 

This is

 

 

 

 

where the

 

 

 

 

 

 

 

 

 

Set

actual

 

bitIndex >

 

 

search

 

lastDeviation?

Yes

bitPattern[bitIndex]

takes

 

 

 

 

to 0

place.

 

No

 

 

 

 

No

bitPattern[bitIndex] = 0?

 

Yes

Set newDeviation

 

 

to bitIndex

 

 

 

 

 

 

 

 

No

 

 

 

 

 

 

Send

 

 

 

 

 

bitPattern[bitIndex]

 

 

 

 

 

Increment bitIndex

 

 

 

 

 

bitIndex > 64?

 

 

 

 

 

Yes

 

 

 

 

 

Return

 

 

 

 

 

newDeviation

13

2579A-AVR-09/04

Соседние файлы в папке AVR