View
2
Download
0
Category
Preview:
Citation preview
Microprocesadores, Tema 8:
Periféricos de Comunicación Síncronos
Guillermo Carpintero
Marta Ruiz
Universidad Carlos III de Madrid
Standard de Comunicación
Interfase FormatoNum.
Dispositivos
Separación
max.
Velocidad de Tx
(bits/seg)
SPI Serie Sinc. 8 3 m 2.1M
I2C Serie Sinc. 40 5.5 m 400k
Protocolos Standard de Comunicación Serie Síncrona
Desarrollado por Philips Semiconductor,
Version 1.0 1992 Standard (100-Kbps), Fast (400-Kbps)
Version 2.0 1998 High Speed (3.4-Mbps)
Orientado a comunicación de distintos integrados en una placa de circuito impreso
Características Básicas
Características
Serie Síncrono 2 hilos (SDA, SCL)
Maestro-Esclavo
Bidireccional float high, driven low
Esquema de Conexión
Interfase Serie Síncrono dos hilos SCL (Serial CLock)
SDA (Serial DAta)
Maestro Esclavos
(Cada uno se identifica por su dirección)
SCL
SDA
Dos papeles distintos para los dispositivos en el Bus
Maestro / Esclavo Emisor / Receptor
1 2 3 n
SDA
Definiciones básicas
Figura de “The I2C-bus specification”
Phillips Semiconductor 2002
float high, driven low
2,2KΩ - 1KΩ Fast/HighSpeed4,7KΩ Standard
Conexión a nivel físico
Bidireccional SDA (Serial DAta) es una línea bidireccional (SEMIDUPLEX)
Líneas en colector abierto
Figura de “The I2C-bus specification”
Phillips Semiconductor 2002
TRANSFERENCIAS – INICIO / FIN
START(S)
STOP(P)
Conexión a nivel lógico
Figura de “The I2C-bus specification”
Phillips Semiconductor 2002
TRANSFERENCIAS – Nivel de Bit
Conexión a nivel lógico
Figura de “The I2C-bus specification”
Phillips Semiconductor 2002
Dirección (del Esclavo)
Datos (intercambio información)
Código de Control (ordenar acción al esclavo)
TRANSFERENCIAS – Nivel de Byte
Conexión a nivel lógico
Unidad mínima de información transferida: BYTE
Que representa
BYTE DATA TRANSFER
TRANSFERENCIAS – Acknowledge
Conexión a nivel lógico
BYTE DATA TRANSFER ACK
A cada transferencia de 8 bits, se le añade un último bit (bit 9) de ACK
Formato de los mensajes
Direccionamiento de los Esclavos
Direcciones de 8 bits
SLAVE ADDRESS Byte
SLAVE ADDRESS
set by Hardware
Direccionamiento de los Esclavos
Direcciones de 10 bits
Figura del “PIC18F2525/2620/4525/4620 Data Sheet”
Con permiso de MICROCHIP
Figura de “The I2C-bus specification”
Phillips Semiconductor 2002
Dispositivo de Interfase I2C en el PIC18
Implementa las funciones de Maestro y Esclavo
Genera interrupciónes ante condiciones S y P en la línea
Da soporte a direccionamiento en 7 y 10 bits
Figura del “PIC18F2525/2620/4525/4620 Data Sheet”
Con permiso de MICROCHIP
Los pines deben configurarse como ENTRADA
Registros del Dispositivo:
INPUTOUTPUT
DATA
Dispositivo de Interfase I2C en el PIC18
Figura del “PIC18F2525/2620/4525/4620 Data Sheet”
Con permiso de MICROCHIP
OUTPUT
ADDRESS
SSPCON1
Dispositivo de Interfase I2C en el PIC18
Error Bits
Figura del “PIC18F2525/2620/4525/4620 Data Sheet”
Con permiso de MICROCHIP
Control Bits
Master
Slave
Slave Mode
MSSP module enabled
waits for a Start condition
Following Start, the 8 bits are shifted into the SSPSR register
SSPSR<7:1> is compared to the value of the SSPADD register
Dispositivo de Interfase I2C en el PIC18
If the addresses match:
1. The SSPSR register value is loaded into the SSPBUF register.
2. The Buffer Full bit, BF, is set.
3. An ACK pulse is generated.
4. MSSP Interrupt Flag bit, SSPIF (PIR1<3>), is set (interrupt is generated, if enabled)
on the falling edge of the ninth SCL pulse.
Transmit sequence would go as follows:
1. The user generates a Start condition by setting the Start Enable bit, SEN (SSPCON2<0>).
2. SSPIF is set. Wait the required start time before any other operation takes place.
3. The user loads the SSPBUF with the slave address to transmit.
4. Address is shifted out the SDA pin until all 8 bits are transmitted.
5. The MSSP module shifts in the ACK bit from the slave device and writes its value into the
Master Mode
Dispositivo de Interfase I2C en el PIC18
S
Addr
SSPCON2 register.
6. The MSSP module generates an interrupt at the end of the ninth clock cycle by setting the
SSPIF bit.
7. The user loads the SSPBUF with eight bits of data.
8. Data is shifted out the SDA pin until all 8 bits are transmitted.
9. The MSSP module shifts in the ACK bit from the slave device and writes its value into the
SSPCON2 register.
10. The MSSP module generates an interrupt at the end of the ninth clock cycle by setting
the SSPIF bit.
11. The user generates a Stop condition by setting the Stop Enable bit, PEN (SSPCON2<2>).
12. Interrupt is generated once the Stop condition is complete.
Data
P
Events that cause the SSP Interrupt Flag bit, SSPIF, to be set (SSP interrupt, if enabled):
• Start condition
• Stop condition
• Data transfer byte transmitted/received
• Acknowledge transmit
• Repeated Start
Master Mode
Dispositivo de Interfase I2C en el PIC18
SSPCON2
Dispositivo de Interfase I2C en el PIC18
Figura del “PIC18F2525/2620/4525/4620 Data Sheet”
Con permiso de MICROCHIP
Start
Stop
SSPSTAT
Dispositivo de Interfase I2C en el PIC18
Figura del “PIC18F2525/2620/4525/4620 Data Sheet”
Con permiso de MICROCHIP
CKP bit – Clock Streching
Conexión a nivel lógico
Figura del “PIC18F2525/2620/4525/4620 Data Sheet”
Con permiso de MICROCHIP
0x18 = 0d24 10MHz/24 = 416KHz
Clock Synch
Conexión a nivel lógico
Figura del “PIC18F2525/2620/4525/4620 Data Sheet”
Con permiso de MICROCHIP
Funciones en la Librería de C18
Figura del “PIC18F2525/2620/4525/4620 Data Sheet”
Con permiso de MICROCHIP
Generar condición S,
SSPCON2bits.SEN = 1;
while(SSPCON2bits.SEN);
Generar condición P,
SSPCON2bits.PEN = 1;
while(SSPCON2bits.PEN);
Rutinas básicas
while(SSPCON2bits.PEN);
Antes de transmitir (Is port Idle?)
void i2c_idle(void)
while( (SSPCON2 & 0x1F) | (SSPSTATbits.R_W) );
Buscar qué función de la librería realiza cada una de estas funciones
CKP bit – Clock Streching
Conexión a nivel lógico
Synchronization
Figura del “PIC18F2525/2620/4525/4620 Data Sheet”
Con permiso de MICROCHIP
Acknowledge
Bus Arbitration
Conexión a nivel lógico
Figura del “PIC18F2525/2620/4525/4620 Data Sheet”
Con permiso de MICROCHIP
Recommended