Microprocesadores, Tema 8: Periféricos de Comunicación Síncronos Guillermo Carpintero Marta Ruiz Universidad Carlos III de Madrid
Standard de Comunicación Protocolos Standard de Comunicación Serie Síncrona Interfase Formato Num. 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
Características Básicas 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 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 1 2 3 n Dos papeles distintos para los dispositivos en el Bus Maestro / Esclavo Emisor / Receptor
Definiciones básicas Figura de The I2C-bus specification Phillips Semiconductor 2002
Conexión a nivel físico Bidireccional SDA (Serial DAta) es una línea bidireccional (SEMIDUPLEX) Líneas en colector abierto float high, driven low 2,2KΩ - 1KΩ Fast/HighSpeed 4,7KΩ Standard Figura de The I2C-bus specification Phillips Semiconductor 2002
Conexión a nivel lógico TRANSFERENCIAS INICIO / FIN START (S) STOP (P) Figura de The I2C-bus specification Phillips Semiconductor 2002
Conexión a nivel lógico TRANSFERENCIAS Nivel de Bit Figura de The I2C-bus specification Phillips Semiconductor 2002
Conexión a nivel lógico TRANSFERENCIAS Nivel de Byte Unidad mínima de información transferida: BYTE Que representa Dirección (del Esclavo) Datos (intercambio información) Código de Control (ordenar acción al esclavo) BYTE DATA TRANSFER
Conexión a nivel lógico TRANSFERENCIAS Acknowledge A cada transferencia de 8 bits, se le añade un último bit (bit 9) de ACK BYTE DATA TRANSFER 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 Figura del PIC18F2525/2620/4525/4620 Data Sheet Con permiso de MICROCHIP Direcciones de 10 bits Figura de The I2C-bus specification Phillips Semiconductor 2002
Dispositivo de Interfase I2C en el PIC18 Figura del PIC18F2525/2620/4525/4620 Data Sheet Con permiso de MICROCHIP 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 Los pines deben configurarse como ENTRADA Registros del Dispositivo:
Dispositivo de Interfase I2C en el PIC18 Figura del PIC18F2525/2620/4525/4620 Data Sheet Con permiso de MICROCHIP DATA INPUT OUTPUT ADDRESS
Dispositivo de Interfase I2C en el PIC18 Figura del PIC18F2525/2620/4525/4620 Data Sheet Con permiso de MICROCHIP SSPCON1 Error Bits Control Bits Master Slave
Dispositivo de Interfase I2C en el PIC18 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 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.
Dispositivo de Interfase I2C en el PIC18 Master Mode Transmit sequence would go as follows: S Addr Data P 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 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.
Dispositivo de Interfase I2C en el PIC18 Master Mode 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
Dispositivo de Interfase I2C en el PIC18 Figura del PIC18F2525/2620/4525/4620 Data Sheet Con permiso de MICROCHIP SSPCON2 Start Stop
Dispositivo de Interfase I2C en el PIC18 Figura del PIC18F2525/2620/4525/4620 Data Sheet Con permiso de MICROCHIP SSPSTAT
Conexión a nivel lógico Figura del PIC18F2525/2620/4525/4620 Data Sheet Con permiso de MICROCHIP CKP bit Clock Streching 0x18 = 0d24 10MHz/24 = 416KHz
Conexión a nivel lógico Figura del PIC18F2525/2620/4525/4620 Data Sheet Con permiso de MICROCHIP Clock Synch
Funciones en la Librería de C18 Figura del PIC18F2525/2620/4525/4620 Data Sheet Con permiso de MICROCHIP
Rutinas básicas Generar condición S, SSPCON2bits.SEN = 1; while(sspcon2bits.sen); Generar condición P, SSPCON2bits.PEN = 1; 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
Conexión a nivel lógico Figura del PIC18F2525/2620/4525/4620 Data Sheet Con permiso de MICROCHIP CKP bit Clock Streching Synchronization Acknowledge
Conexión a nivel lógico Figura del PIC18F2525/2620/4525/4620 Data Sheet Con permiso de MICROCHIP Bus Arbitration