Post on 08-Feb-2016
description
transcript
PIC Peripheral Interface Controllers
SPI protocol and RTC
DS1306 interface
Amit Kulkarni
Objectives
MSSP module
� Master synchronous module is a serial
interface.
Useful for communicating with other� Useful for communicating with other
peripheral or microcontroller devices.
� These peripheral devices may be serial
EEPROMs, shift registers, display drivers,
A/D converters, etc.
MSSP module
� The MSSP module can operate in one of two modes:
– Serial Peripheral Interface (SPI)
– Inter-Integrated Circuit (I2C)– Inter-Integrated Circuit (I2C)
� Full Master mode
� Slave mode (with general address call)
� The I2C interface supports the following modes in
hardware:
– Master mode
– Multi-Master mode
– Slave mode
Control registers
� The MSSP module has three associated
registers.
These include a status register (SSPSTAT)� These include a status register (SSPSTAT)
and two control registers (SSPCON1 and
SSPCON2).
� The use of these registers and their
individual configuration bits differ significantly
depending on whether the MSSP module is
operated in SPI or I2C mode.
SPI mode
� Originally started by Motorola Corp.
� Used in many devices such as ADC,DAC, EEPROM etc.
� The SPI mode allows 8 bits of data to be synchronouslyThe SPI mode allows 8 bits of data to be synchronouslytransmitted and received simultaneously.
� To accomplish communication, typically three pins are used:
• Serial Data Out (SDO) – RC5/SDO
• Serial Data In (SDI) – RC4/SDI/SDA
• Serial Clock (SCK) – RC3/SCK/SCL
SPI read write
� uC is used as master and SPI device is used
as slave.
uC generates the SCLK which is fed to the� uC generates the SCLK which is fed to the
SCLK pin of SPI device.
� This synchronizes the transfer operation one
bit at time.
� MSB goes first, CE remains HIGH.
SPI read write
� Information is transferred in groups of 8-bits.
� Address is immediately followed by the data.
� To distinguish between the read and write
operations:
– D7 bit of address byte is always HIGH (1) for write
– D7 bit of address byte is always LOW (0) for read
Steps for writing
Timing
Multi-byte burst write
Steps for reading data from SPI
Steps for reading data from SPI
DS1306 RTC interfacing
� Pin description
DS1306 Pin description
DS1306 Pin description
DS1306 Pin description
DS1306 Pin description
Control registers
Status register
RTC registers and address map
� It has total 128 bytes of RAM space.
RTC registers and address map
RTC registers and address map
Address locations for time and date
Power supply configurations
Power supply configurations
Power supply configurations
Interfacing using MSSP module
� The associated registers are
– SSPBUF: holds the byte to be transmitted or
received.received.
– SSP1CON: SPI mode selection of PIC18
– SSPSTAT: Status flags.
All are 8-bits wide.
SSPSTAT: MSSP STATUS REGISTER (SPI MODE)
SSPSTAT: MSSP STATUS REGISTER (SPI MODE)
SSPCON1: MSSP CONTROL REGISTER 1 (SPI MODE)
SSPCON1: MSSP CONTROL REGISTER 1 (SPI MODE)
Connections
Assignments: PIC18F4520
1. Develop the C program for interfacing
DS1306 RTC interfacing, and simulate
results on proteus.results on proteus.
2. Simulate the capture mode programming.
3. Simulate the compare mode programming.
4. Interface DC motor using PWM , for
different duty cycles.
5. Use the above code to implement a water
fountain.
Assignments: PIC18F4520
6. Implement up-down counter using RTC
DS1306 and LCD 16x2.
7. Implement stop-watch using RTC, LCD and 7. Implement stop-watch using RTC, LCD and
keys.
8. Study and implement ALARM features of
DS1306 in assembly and C.