Professional Documents
Culture Documents
net
EE6008-Microcontroller Based System Design Department Of EEE 2017-2018
www.AUNewsBlog.net
www.AUNewsBlog.net
EE6008-Microcontroller Based System Design Department Of EEE 2017-2018
7. Write a note on temperature sensor used for interfacing with I2C bus.
National Semiconductor’s LM 75 chip combines an analog temperature transducer, an analog-to-digital
convertor (9-bit), and an I2C bus interface, all in a tiny S)-8 surface mount package. The temperature range
covered is -25oC to +100oC with ±2oC accuracy. The two’s complement form of the temperature is available
from the 9-bit ADC. The resolution of the ADC is about 0.5oC.
15. What is the value to be loaded into SPBRG register if we want 19200 baud rate with 10MHZ clock
source. (Nov/Dec 2016)
01101010 is the value to be loaded into SPBRG register
www.AUNewsBlog.net
www.AUNewsBlog.net
EE6008-Microcontroller Based System Design Department Of EEE 2017-2018
PART – B
1. What is meant by I2C module? Explain how I2C is interfaced with PIC microcontroller. Nov/Dec 2016
The clock line, SCL, is driven by the PIC chip, which server as bus master. The open drain feature of every chip’s
bus driver can be used by the receiver to hold the clock line low, there by signalling the transmitter to pause until
the clock line is released by the receiver. The open drain feature is also needed if this PIC will ever become an
Dhanalakshmi college of Engineering 3
www.AUNewsBlog.net
www.AUNewsBlog.net
EE6008-Microcontroller Based System Design Department Of EEE 2017-2018
I2C slave to another PIC, in which it must relinquish control of the SCL line.
The previous figure illustrates that the first eight bits on the SDA line are sent by the transmitter whereas the
ninth bit is the acknowledgment bit which is sent by the receiver in response to the byte sent by the
transmitter. For instance, when the PIC sends out a chip address, it is the transmitter,
while every other chip on the I2C bus is a receiver. During the acknowledgment bit time, the addressed chip
is the only one that drives the SDA line, pulling it low in response to the masters pulse on SCL,
acknowledging the reception of its chip address.
When the data transfer direction is reversed that is form a peripheral chip to the PIC, which is the master ,
the peripheral chip drives the eight daa bits in response to the clock pulse from PIC. In this case, the
acknowledge bit is driven in a special way by the PIC, which is serving as receive but also as bus master. If
the peripheral chip is one that can send the contents of successive internal address back to the PIC, then
PIC completes the reception of each byte and signals a request for the next byte by pulling SDA line low in
acknowledgment. After any number of bytes have been received by the master from the peripheral, the PIC
can signal the peripheral to stop any further transfers by not pulling the SDA line low in acknowledgment.
SDA line should be stable during high period of the clock (SCL). When the slave peripheral is driving SDA
line , either as transmiter or acknowledge, it initiates the new bit in response to the falling edge of SCL, after
a specified time. It maintains that bit on SDA line until the next falling edge of SCL, again afte r a specified
hold time.
I2C bus transfers consist of a number of byte transfers framed between a START condition and either
another START condition or a STOP condition. Both SDA and SCL lines are released by all drives and float
high when bus transfers are not taking place. The PIC (I2C bus controller) initiates a transfer with a START
condition by first pulling SDA low and then pulling SCL as shown in the figure.
SDA
SDA
SCL
SCL
Similarly, the PIC terminates a multiple byte transfer with the STOP condition. With both SDA and SCL
initially low, it first releases SCL and then SDA. Both then occurrences are easily recognized by I 2C
hardware in each peripheral chip since they both consist of a chage in SDA line which SCL is high, a
condition that never happens in the middle of a byte transfer.
Data Communication protocol
In I2C communication standard, there is one bus master and several slaves. It can be assumed here
that the PIC microcontroller is the bus master and several peripheral devices connected to SDA and
SCL bus are slaves.
Following a start condition, the master sends a 7-bit address of the slave on SDA line. The MSB is sent
first. After sending 7 bit address of the slave peripheral a R/W bit (8th bit) is sent by the master. If R/W bit
is 0 the following byte (after the acknowledgment) is written by the master to the addressed slave
peripheral. If R/W bit is 1, the following byte after the acknowledgment bit has to be read from the slave
by the master. After sending the 7-bit address of the slave, the master sends the address of the internal
register of the salve where from the data has to be used or written to. The subsegment access is
automatically directed to the next address of the internal register.
The following diagrams give the general format to write and read from several peripheral internal
registers
Dhanalakshmi college of Engineering 4
www.AUNewsBlog.net
www.AUNewsBlog.net
EE6008-Microcontroller Based System Design Department Of EEE 2017-2018
.
START R/ W = 0
condition 7-bit address for write Internal address N, Data to be written
of peripheral chip in peripheral into address N
A A A
C C C
S WK K K
SDA
Data to be written Data to be written
STOP
into address N+1 into address N+2
condition
A A
C C
K K P
www.AUNewsBlog.net
www.AUNewsBlog.net
EE6008-Microcontroller Based System Design Department Of EEE 2017-2018
movwf FSR
START1:
bsf INDF, SDA ; SDA=1
bsf INDF , SCL ; SCL=1
call DELAY ; Generates a suitable delay
bcf INDF, SDA ; SDA=0
call DELAY ; Generate a suitable delay
bcf INDF, SCL ;SCL=0
return
STOP:
bcf INDF, SDA ;SDA=0
bsf INDF, SCL ; SCL=1
call DELAY ; Generate a suitable delay
bsf INDF, SDA ;SDA=1
return
The subroutine 'TRBYTE' send out the byte available in w. It returns with Z=1 if ACK occurs. It returns with Z=0 if NOACK occurs.
TRBUF is an 8-bit RAM variable used for temporary storage. The bits are shifted to carry flag (C) and the carry bit
transmitted successively. Data transfer is complete when all 8-bits are transmitted. Setting C = 1 initially sets an index for 8-bits
to be transferred. C is rotated through TRBUF. After transmitting C, C-bit is cleared. When TRBUF is completely cleared,
all 8-btis are transmitted.
TRBYTE:
movwf TRBUF
bsf STATUS,C
TR_1:
rlf TRBUF, F
movf RBUF,F
btfss STATUS, Z
call out_bit ; Send a bit available in C
btfss STATUS, Z
goto TR_1
call in_bit ; Get the ACK bit in RCBUF<0>
movlw 01H ;
andwf RCBUF, W ; Store the complement of ACK bit in Z flag
return
The RCVBYTE subroutine receives a byte from I2 C into W using a RAM variable RCBUF buffer.
Call RCVBYTE with bit 7 of TRBUF clear for ACK
Call RCVBYTE with bit 7 of TRBUF set for NOACK
RCBUF is an 8-bit RAM variable used for recieving the data. the bit is recieved in the RCBUF<0> and is rotated
successively through RCBUF as shown. The reception ends when all 8-bits are recieved.
RCVBYTE:
movlw 01H
movwf RCBUF ; Keep an index for 8-bits to be recieved.
rlf RCBUF, F
call In_bit
btfss STATUS, C
goto RCV_1
rlf TRBUF, F
call Out_bit
movf RCBUF,w
www.AUNewsBlog.net
www.AUNewsBlog.net
EE6008-Microcontroller Based System Design Department Of EEE 2017-2018
return
The out_bit subroutine transmits carry bit, then clears the carry bit.
Out_bit:
bcf INDF, SDA
btfsc STATUS, C
bsf INDF, SDA ; Send carry bit
bsf INDF, SCL
call DELAY
bcf INDF, SCL
bcf STATUS,C ; Clear carry bit
return
The in_bit subroutine receives one bit into bit-0 of RCBUF.
In_bit:
bsf INDF,SDA
bsf INDF, SCL
bcf RCBUF, 0
btfsc PORTC, SDA ; Check SDA line for data bit
bsf RCBUF, 0
bcf INDF, SCL
return
www.AUNewsBlog.net
www.AUNewsBlog.net
EE6008-Microcontroller Based System Design Department Of EEE 2017-2018
4. Explain with neat diagram interfacing of serial EEPROM using I2C bus.
5. Explain with neat diagram the use of UART to interface two PIC resources.
www.AUNewsBlog.net