Está en la página 1de 62

1.

SEPTEMBER 2011

INTERCOMPONENT BUSSES
NAVN NAVNESEN TITLE

UNI VERSITy

MDL ETIADE 2012 9. OCTOBER 2012

SUBJECTS
SPI I2C I2C example: LM75 temperature sensor. 1-wire 1-wire example: DS1820 temperature sensor. I2S CodeVision setup

MDL ETIADE 2012 9. OCTOBER 2012

SPI (SERIAL PERIPHERAL INTERFACE)


Introduced by Motorola. Well suited for fast data rates (data streaming). Primitive (no error checks). Addressing multiple slaves extents HW. Commonly used intercomponent bus. Normally only one master. Multi-master possible, but troublesome. No speed limit is stated in the standard

MDL ETIADE 2012 9. OCTOBER 2012

SPI: SHIFT REGISTER BASED

MDL ETIADE 2012 9. OCTOBER 2012

SPI: MASTER AND SLAVE

CPOL=clock polarity CPHA=clock phase

MDL ETIADE 2012 9. OCTOBER 2012

SPI SLAVE
SS SCLK MOSI MISO

MDL ETIADE 2012 9. OCTOBER 2012

SLAVES IN PARALLEL CONFIGURATION

MDL ETIADE 2012 9. OCTOBER 2012

SLAVES IN SERIAL CONFIGURATION

MDL ETIADE 2012 9. OCTOBER 2012

SPI PRODUCTS

MDL ETIADE 2012 9. OCTOBER 2012

MEGA16: SPI INTERFACE


Mega16 has HARDWARE for SPI interface. Registers: SPI Control Register SPCR SPI Status Register SPSR SPI Data Register SPDR

MDL ETIADE 2012 9. OCTOBER 2012

I2C (IIC)
Inter IC bus (Introduced by Philips). Suited for medium data rates. Limited range (often locally at PCB). Inbuild addressing (minor HW demands). Simple protocol inbuild. Real time qualified (respons times can be calculated). Speed 100kbit/s (many devices support up to 400kbit/s)

MDL ETIADE 2012 9. OCTOBER 2012

I2C TOPOLOGY

Each node has its own unique address (or ID). By sending a START command, each node is able to become the bus master.

MDL ETIADE 2012 9. OCTOBER 2012

I2C MASTER: START + ADDRESS

All other nodes now enters a state of listening.

Then the master sends the address of the slave, it wants to communicate with:

The address is 7 bits. The last bit (R/W) informs the slave, whether the master wants to read or to write.
MDL ETIADE 2012 9. OCTOBER 2012

I2C SLAVE: ACK


After having received the START cammand and the address, all slaves compares the address with their own address: * If no address match, the STOP command is awaited. * If the address matches, the slave sends an ACK:
SDA SCL The slave holds SDA low and generates an SCL -pulse.

- Subsequently the master regains bus control MDL ETIADE 2012 9. OCTOBER 2012

I2C MASTER: SENDS / RECEIVES DATA


1. Master sends data:

2. Master receives data:

During reception (2) the slave controls SDA, but the master controls SCL. The slave is only allowed to change SDA while SCL is high.
MDL ETIADE 2012 9. OCTOBER 2012

I2C MASTER: ACK AFTER EACH BYTE RECEIVED


Following each byte received from a slave, the master MUST send an ACK (except after the last byte). Master sets SDA low and generates a clock pulse. Then the slave regains control over SDA.

SDA SCL

Following the last received byte, the master sends the STOP command (freeing the bus again).
MDL ETIADE 2012 9. OCTOBER 2012

MASTER: STOP

Sent by the master, when it has finished sending /receiving data. Received by all slaves, now knowing the bus is again free. STOP can be sent at any time (even in the middle of a data transmission). In all cases STOP means END of transmission.
MDL ETIADE 2012 9. OCTOBER 2012

I2C BUS HARDWARE


SCL and SDA are bi-directional. Open drain => External pull-up necessary!

MDL ETIADE 2012 9. OCTOBER 2012

RESERVED ADDRESSES

10-bit addressering is possible (new standard). In this case 2 bytes are sent as address: 11110AAx + AAAAAAAA. (8-bit nodes ignores 10-bit addressing).
MDL ETIADE 2012 9. OCTOBER 2012

I2C BUS ARBITRATION

If a master is unable to set an output high (it always test for this), it looses the bus control. If 2 masters start transmission simultaneously, the following happens:

Until the yellow marking, both masters think, they own the bus. Then CPU2 surrenders (until STOP).
MDL ETIADE 2012 9. OCTOBER 2012

I2C EXAMPLE: LM75

MDL ETIADE 2012 9. OCTOBER 2012

LM75: BLOCK DIAGRAM

MDL ETIADE 2012 9. OCTOBER 2012

LM75 ADDRESS

LM75 is always a slave (not capable of being a master). The address (7 bit) is composed of 4 constant bits and the external pin settings (A2-A0).

MDL ETIADE 2012 9. OCTOBER 2012

LM75: TEMPERATURE DATA FORMAT

2complement format. LSB = 0,5 deg. Celsius.

MDL ETIADE 2012 9. OCTOBER 2012

LM75: REGISTER STRUCTURE

MDL ETIADE 2012 9. OCTOBER 2012

LM75: POINTER REGISTER

MDL ETIADE 2012 9. OCTOBER 2012

LM75: TEMPERATURE REGISTERS

MDL ETIADE 2012 9. OCTOBER 2012

LM75: CONFIGURATION REGISTER

MDL ETIADE 2012 9. OCTOBER 2012

LM75: I2C TIMING, 2 BYTE READING

MDL ETIADE 2012 9. OCTOBER 2012

LM75: I2C TIMING, 1 BYTE READING

MDL ETIADE 2012 9. OCTOBER 2012

LM75: I2C TIMING

MDL ETIADE 2012 9. OCTOBER 2012

MEGA16: I2C INTERFACE


Mega16 has HARDWARE for I2C interface. This is called the Two Wire Serial Interface. Dedicated pins for SDA and SCL. Registers: TWI Bit Rate Register TWBR TWI Control Register TWCR TWI Status Register TWSR TWI Data Register TWDR TWI (Slave) Address Register TWAR

MDL ETIADE 2012 9. OCTOBER 2012

CODEVISION: I2C LIBRARY


CodeVision comes with a library for interfacing I2C devices (uses BIT BANGING). Any port pins can be used.

MDL ETIADE 2012 9. OCTOBER 2012

CODEVISION: I2C LIBRARY FUNCTIONS

MDL ETIADE 2012 9. OCTOBER 2012

CODEVISION: LM75 LIBRARY


CodeVision comes with a library for interfacing the I2C device LM75 (uses BIT BANGING). Any port pins can be used.

MDL ETIADE 2012 9. OCTOBER 2012

CODEVISION: LM75 LIBRARY FUNCTIONS

MDL ETIADE 2012 9. OCTOBER 2012

1-WIRE
Introduced by Dallas Semiconductor corp. Only 1 wire (+ground + optionally power). Cheaper than I2C. Only suited for low data rates. Limited range (often locally at the PCB). Inbuild addressing (all devices have a unique address). See good presentation at: http://www.maximintegrated.com/products/1wire/flash/overview/index.cfm
MDL ETIADE 2012 9. OCTOBER 2012

1 WIRE TOPOLOGY

Notice the inbuild capacitor (800pF).


Possibility of many slaves.

MDL ETIADE 2012 9. OCTOBER 2012

1-WIRE: SEQUENCE OF INITIALIZING

Master sends the RESET pulse. All slaves responds by sending a Presence Pulse. This tells the master, that at least one slave is present and ready to communicate. But the master will not know if several slaves are connected MDL ETIADE 2012
9. OCTOBER 2012

1-WIRE: WRITE
To write a 1, the master pulls the line low and releases it again. After 15s the slave will read the bus and see that it is high. To Write a 0, the master keeps the line low for 60s

MDL ETIADE 2012 9. OCTOBER 2012 40

1-WIRE: READ
To read a bit, the master pulls the line low and releases it. If the slave keeps it low after 15s it means 0, if the slave releases it, it means 1

MDL ETIADE 2012 9. OCTOBER 2012 41

1-WIRE: IN GENERAL
Normal sequence: 1. Master sends RESET and awaits Presence Pulse. 2. Master sends an 8-bit read command. 3. Master reads one or more bytes from the slave. 4. Often, the last byte will be CRC, only to be used if desirable.

Each slave has its own unique 64 bit address. This can be searched by the master (complex algorithm).

MDL ETIADE 2012 9. OCTOBER 2012

DS1820: 1-WIRE TEMPERATURE SENSOR

MDL ETIADE 2012 9. OCTOBER 2012

DS1820 TEMPERATURE REGISTER

MDL ETIADE 2012 9. OCTOBER 2012

DS1820: ALARM REGISTERS

MDL ETIADE 2012 9. OCTOBER 2012

DS1820: POWER

MDL ETIADE 2012 9. OCTOBER 2012

DS1820: ROM CODE

MDL ETIADE 2012 9. OCTOBER 2012

DS1820: MEMORY MAP

MDL ETIADE 2012 9. OCTOBER 2012

DS1820: SEQUENCE OF TRANSACTIONS

MDL ETIADE 2012 9. OCTOBER 2012

DS1820: COMMANDS
ROM Commands:
The bus master uses a ROM command to address the DS18S20 with which it wishes to communicate,

Function Commands:

MDL ETIADE 2012 9. OCTOBER 2012

MEGA16: 1-WIRE INTERFACE


Mega16 has NO HARDWARE for 1-wire interface. But CodeVision comes with has a 1-wire library. This library uses bit banging (any port pin can be used). Alternatively, one can write the 1-wire driver from scratch (many timing requirement to be met).

MDL ETIADE 2012 9. OCTOBER 2012

CODEVISION: 1-WIRE LIBRARY

MDL ETIADE 2012 9. OCTOBER 2012

CODEVISION: DS1820 LIBRARY


CodeVision comes with a library for interfacing the 1wire device DS1820 (uses BIT BANGING). Any port pin can be used.

MDL ETIADE 2012 9. OCTOBER 2012

CODEVISION: DS1820 LIBRARY FUNCTIONS

MDL ETIADE 2012 9. OCTOBER 2012

I2S
Inter-IC Sound Only used for digital audio streaming (as far as I know) Streaming from master to slave No feedback from slave to master at all
The master dont know if someone is actually listening

Multiple slaves can be connected in parallel and listen to the stream Supported by almost all audio ADC/DACs and most digital signal processors

MDL ETIADE 2012 9. OCTOBER 2012 55

I2S
I2S consists of three wires: - Word clock -Bit clock -Data Standard Word clock (=sample frquency) is 48kHz or 44.1kHz The bit clock is 64 times word clock Normally there are 24 or 32 bits per. channel and two channels per word.
MDL ETIADE 2012 9. OCTOBER 2012 56

I2S TIMING
From the ADMP441 datasheet

MDL ETIADE 2012 9. OCTOBER 2012 57

CODEVISION SETUP
Create a new project. Select No to the question about using the wizard and save the project

MDL ETIADE 2012 9. OCTOBER 2012 58

CODEVISION SETUP
Add your *.c files. If you have not written them yet, they can be created using file>new>source After you have closed this dialog

MDL ETIADE 2012 9. OCTOBER 2012 59

CODEVISION SETUP
Go to C compiler. Select your microcontroller (Mega16) and your clock (3,6864MHz for STK500)

MDL ETIADE 2012 9. OCTOBER 2012 60

CODEVISION SETUP
Go to After Build Select Program the Chip Press OK

MDL ETIADE 2012 9. OCTOBER 2012 61

CODEVISION SETUP
Press programmer settings and select your COM-port

MDL ETIADE 2012 9. OCTOBER 2012 62

También podría gustarte