Você está na página 1de 57

Interface Solutions

I2C-bus

Bipolar junction transistor

PNP
NPN

Reduced models of the operation modes

Modes of Operation

Diode-Transistor Logic (DTL)

Diode-Transistor Logic (DTL)

NOR gate

NAND gate

Resistor-Transistor Logic (RTL)

Sinking vs. Sourcing

The current capacity of the PIC is of 25mA

'Sink' means that the chip 'sinks' current


down into itself.
'Source' is just the reverse, the I/O pin is the
actual source of the current.

Sinking Input

Sourcing Input

The LED will light


when the PIC pin is low.

Sinking Output

The LED will light


when the PIC pin is high.

Sourcing Output

TTL Logic
Open Collector Output

Totem Pole Output


An open collector may be used with higher
voltages

Sinking / Sourcing ???

A Basic Output

Open Collectors with


external pull-up.

NOT Gate 7404

NAND gate 7400


Sinking / Sourcing ???

Totem Pole Output ???

TTL logic

TTL logic NOT Gate

The Vcb-Ic Curves of an NPN transistor for different


values of Emitter Current (Common-Base Output
Characteristics)

NAND Output Current Sinking &


Sourcing

Sinking

Sourcing

11

Open Collector Output

Open Collectors with


external pull-up.

Tristate Gate
khi ENABLE=0 thi gate ko lam
viec
khi ENABLE=1, phu thuoc vao
input:
voi input= 0: thi Q3,Q4 dan.
voi input=1: Q2 dan

Current Controlled vs Voltage Controlled Devices

Types of FETs

JFET Junction Field Effect Transistor


MOSFET Metal Oxide Semiconductor Field Effect Transistor
D-MOSFET - Depletion Mode MOSFET
E- MOSFET - Enhancement Mode MOSFET

Types of Field Effect Transistors


(The Classification)

FET

JFET

n-Channel JFET
p-Channel JFET

MOSFET (IGFET)

Enhancement
MOSFET
n-Channel
EMOSFET

p-Channel
EMOSFET

Depletion
MOSFET
n-Channel
DMOSFET

p-Channel
DMOSFET

MOSFET circuit symbols

0V
VDD

CMOS Inverter
Sinking / Sourcing ???

Totem Pole Output ???

CMOS Inverter

AND gate

khi hai cai input =1 thi co tin hieu


output

Sinking / Sourcing ???

Totem Pole Output ???

OPEN-DRAIN (OPEN-COLLECTOR)
OUTPUTS

n
khi n ko dan thi lay +V ra Vout
khi n dan thi +V ve dat

TRISTATE OUTPUTS
MOSFET
p
p

n
n

Input/Output Voltage Designations

VOL the logic LOW output voltage.


VOH the logic HIGH output voltage.
VIL the logic LOW input voltage.
VIH the logic HIGH input voltage.

Input/Output Current Designations

IOL the logic LOW output current.


IOH the logic HIGH output current.
IIL the logic LOW input current.
IIH the logic HIGH input current.

TTL Gate Sinking the Input Current from Two Gate Inputs

TTL Gate Sourcing Current to Two Gate Inputs

Interfacing Logic Families


TTL to CMOS
Pull-up resistor
open collector la gi

two different power supplies

Xem chng 1

Interfacing Logic Families


CMOS to TTL
No problem with voltages
But concerns on currents

Interfacing Logic Families


CMOS to TTL

High Sink Current for Driving 2 TTL Loads

the negative value indicates current leaving the gate

Interface Solutions
I2C-bus

Wired AND connection using diodes and a resistor

ve 0

neu 1 con dan xuong 0 thi day


do xuong 0
neu thang nay ve 0 thi

15 dia chi dac biet cho I2C, ko dc dung toi

master giu nhip xung clock

4 so dau dac trung cho hang sx

MSB is fixed for all devices. For Ex 1010EPROM.

The addresses of most I2C devices are fixed and documented in the respective datasheet. Some I2C devices allow a few bits
out of the 7 or 10 address bits to be configured by hardware values on pins labeled A0, A1, and A2 for example.

Solving Address Conflict When Sharing I2C Bus


They generate up to 9 output
clocks from a single input
frequency. Each output can be
programmed in-system for any
clock frequency up to 230 MHz

Slave Address Conflict Solved With I2C Multiplexor


IC-bus repeater

Slave Address Conflict Solved With Bidirectional I2C Buffer

PCA9544A 4-CHANNEL I2C MULTIPLEXER

thang nhan(slave) co kha nang lam cham toc do truyen cua slave/master

uu tien thang co dia chi thap hon

cua master

Voltage Transition Time verse Load Capacitance

RC Time Constant

RC

(1

1
) *100% 39.3%
e0.5

I2C PC-interface
http://www.pvv.org/~asgaut/i2c/i2c.html

+5V must be supplied from an external power supply to the VDD line

i2c

pc

12.5V
xung clock vo day

=1 thi dan

con nay dan SCL len 1, con

Test circuit with I2C

24AA256/24LC256/24FC256

I2C test system

I2C functions
I2C SERIAL PORT
I2C START

i2c_start();

I2C WRITE

Issue start command in master


mode
Send a single byte

I2C READ

Read a received byte

inbyte = i2c_read();

I2C STOP

Issue a stop command in


master mode
Check to see if byte received

i2c_stop();

I2C POLL

i2c_write(outbyte);

sbit = i2c_poll();

#include "16F877A.h"
#use delay(clock=4000000)
#use i2c(MASTER,SCL=PIN_C3,SDA=PIN_C4)
/*
void main()
//Ghi 1 byte
{
int sendbyte, lowadd;
lowadd=0;
port_b_pullups(1);
sendbyte=(input_B());
i2c_start();
// start write cycle
i2c_write(0xA0);
// send control byte
i2c_write(0x00);
// send high address
i2c_write(lowadd); // send low address
i2c_write(sendbyte); // send data
i2c_stop();
delay_ms(5);
// wait for write
while(1)
{
}
}

#include "16F877A.h"
#use delay(clock=4000000)
#use i2c(MASTER,SCL=PIN_C3,SDA=PIN_C4)
void main()
//Ghi 5 bytes
{
int sendbyte, lowadd;
port_b_pullups(1);
sendbyte=(input_B());
for (lowadd=0; lowadd<5; lowadd++ )
{
i2c_start();
// start write cycle
i2c_write(0xA0);
// send control byte
i2c_write(0x00);
// send high address
i2c_write(lowadd); // send low address
i2c_write(sendbyte); // send data
i2c_stop();
delay_ms(5);
// wait for write
}
while(1)
{
}
}

#include "16F877A.h"
#use delay(clock=4000000)
#use i2c(MASTER,SCL=PIN_C3,SDA=PIN_C4)
void main()//Ghi ra 256bytes
{
int sendbyte, lowadd;
lowadd=0;
port_b_pullups(1);
sendbyte=(input_B());
while(1)
{
i2c_start();
// start write cycle
i2c_write(0xA0);
// send control byte
i2c_write(0x00);
// send high address
i2c_write(lowadd); // send low address
i2c_write(sendbyte); // send data
i2c_stop();
delay_ms(5);
lowadd++;
}
}

// wait for write


// inc address

Master Synchronous Serial Port (MSSP) module of 16F877


(I2C) bus operation
24LC16B EEPROM connection to PIC 16F877

EEPROM SPEC:
1.Microchip 24LC16B (16K Bits or 2KBytes)
2.8 Internal blocks (256 Bytes for each block)
I2C ADDRESS SPEC:
1. I2C Spec code for EEPROM SELECTION: 1010 must be the highest 4 Bits in the Higher Address
2. 3-bit Block Code (from 000 to 111) follows the EEPROM SELECTION bits
3. R/W bit follows to Complete the 8-bit Higher Address
4. Actual EEPROM address is selected by the 8-bit Lower Address

24LC16B 16K I2C Serial EEPROM

Master Synchronous Serial Port (MSSP) module of 16F877


(I2C) bus operation
baud100 EQU 0x31 ;100KHZ standard speed
org 0x0000
goto START

org 0x05; ???


START
;i2c operation INITIALIZATION
;PORTC setup - SDA and SCL both as inputs
The number 49.75 is approximated to 49, and its hexadecimal
movlw 0x18 ;0001 1000
equivalent is 0x31
Banksel TRISC
The following events will cause SSP Interrupt
movwf TRISC ;RC4 (SDA) and RC3(SCL) as inputs
Flag bit, SSPIF, to be set (SSP interrupt if
;MSSP Module Setup
enabled):
movlw baud100 ;100KHz speed
Start condition
banksel SSPADD
Stop condition
Data transfer byte transmitted/received
movwf SSPADD
Acknowledge transmit
;write baud rate
Repeated Start
movlw 0x80 ;1000 0000
Banksel SSPSTAT
movwf SSPSTAT ;100KHZ (no slew rate control)
;selection with I2C mode
movlw 0x28
;0010 1000 (SSPEN=1, SSPM3:0= 1000 ) master mode
Banksel SSPCON
movwf SSPCON

Master Synchronous Serial Port (MSSP) module of 16F877


(I2C) bus operation
;Flag Clear
banksel PIR1
bcf PIR1, SSPIF ;clear the SSP flag
;>S>> START
call i2cStart
;>C>> CONTROL
movlw 0xA0
call i2cSend ;block code write to 24LC16
;>A>> ADDRESS
movlw 0x00 ;address info
call i2cSend
;>D>> DATA
movlw 'm' ;1 byte data
call i2cSend
;>P>> STOP
call i2cStop
call delay10ms
;Give 24LC16B time to write the data

;subroutine I2CSTART
I2Cstart
banksel SSPCON2
bsf SSPCON2, SEN ;START
banksel PIR1
Swait
btfss PIR1, SSPIF
goto Swait
bcf PIR1, SSPIF
Return
;subroutine i2cblock for write
i2cSend
banksel SSPBUF
movwf SSPBUF
banksel PIR1
cwait
btfss PIR1, SSPIF
goto cwait
bcf PIR1, SSPIF
Return
;SUBROUTINE I2CSTOP
i2cStop
banksel SSPCON2
bsf SSPCON2, PEN
banksel PIR1
Pwait
btfss PIR1, SSPIF
goto Pwait
bcf PIR1, SSPIF
return

ACK???

Master Synchronous Serial Port (MSSP) module of 16F877


(I2C) bus operation
; 1 instruction cycle for 20MHz clock is 0.2 us
;100us delay needs 500 instruction cycles
; 500 =165*3 +5 ---->Kount=165=0xA5

Delay100us
banksel Kount100us
movlw HA5'
movwf Kount100us
R100us
decfsz Kount100us
goto R100us
return

CBLOCK 0x20
Kount100us
Kount10ms
ENDC

;10ms delay
; call 100 times of 100 us delay (with some time
discrepancy)
Delay10ms
banksel Kount10ms
movlw H'64' ;100
movwf Kount10ms
R10ms
call delay100us
decfsz Kount10ms
goto R10ms
return
;
END

Você também pode gostar