DOC PREVIEW
NMT EE 308 - The HCS12 Serial Peripheral Interface

This preview shows page 1-2-3-4-5 out of 15 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 15 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 15 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 15 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 15 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 15 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 15 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

EE 308 Mar. 26, 2003The HCS12 Serial Peripheral Interface (SPI)The HCS12 has a Synchronous Serial InterfaceOn the HCS12 it is called the Serial Peripheral Interface (SPI)If an HSC12 generates the clock used for the synchronous data transfer it isoperating in Master Mode.If an HCS12 uses and external clock used for the synchronous data transfer itis operating in Slave Mode.If two HCS12’s talk to each other using their SPI’s one must be set up as theMaster and the other as the Slave.The output of the Master SPI shift register is connected to the input of theSlave SPI shift register over the Master Out Slave In (MOSI) line.The input of the Master SPI shift register is connected to the output of theSlave SPI shift register over the Master In Slave Out (MISO) line.After 8 clock ticks, the data originally in the Master shift register has beentransferred to the slave, and the data in the Slave shift register has been trans-ferred to the Master.1EE 308 Mar. 26, 2003ClockMOSIMISOMasterSlaveClkSSMOSITV11010110TVClockTVMISO10100101Synchronous Serial CommunicationsSPI0DRSPI0DR2EE 308 Mar. 26, 2003Use of Slave Select with the HCS12 SPIA master HCS12 can talk with more than one slave HCS12’sA slave HCS12 uses its Slave Select (SS) line to determine if it is the one themaster is talking withThere can only be one master HCS12, because the master HCS12 is the devicewhich generates the serial clock signal.MasterSS SSMOSIMISOClockSlave 1 Slave 2Synchronous Serial CommunicationsWith select lines, one master can communicate with more than one slave3EE 308 Mar. 26, 2003Using the HCS12 SPI with other devicesThe HCS12 can communicate with many types of devices using its SPIFor example, consider a D/A (Digital-to-Analog) ConverterThe D/A converter has three digital lines connected to the HCS12:– Serial Data– Serial Clock– Chip SelectThe HCS12 can send a digital number to the D/A converter. The D/A con-verter will convert this digital number to a voltage.MasterSPI Communication with a D/A ConverterMOSIClockSSSDATASCLKCSD/A ChipVout4EE 308 Mar. 26, 2003Using the HCS12 SPI with other devicesAnother type of device the HCS12 can talk to is a Real Time Clock (RTC)An RTC keeps track of the time (year, month, day, hour, minute, second)An RTC can be programmed to generate an alarm (interrupt) at a particulartime (07:00), or can generate a periodic interrupt at a regular interval (once asecond, once an hour, etc.)The HCS12 initially tells the RTC what the correct time is.The RTC keeps track of time from then on.MasterSS CSSPI Communication with a Real Time ClockRTC ChipBattMOSIClock SCLKMISODoutDinIntINTIn a system, an HCS12 can communicate with many different devices over itsSPI interface.5EE 308 Mar. 26, 2003Using the HCS12 SPIIn synchronous serial communications, one device talks to another using aserial data line and a serial clock.There are a number of decisions to be made before communication can begin.For example– Is the HCS12 operating in master or slave mode?– Is the serial data sent out most significant bit (MSB) first, or least signifi-cant bit (LSB) first?– How many bits are sent in a single transfer cycle?– Is the data valid on the rising edge or the falling edge of the clock?– Is the data valid on the first edge or the second edge of the clock?– What is the speed of the data transfer (how many bits per second)?The HCS12 SPI is very versatile, and allows you to program all of theseparameters.The HCS12 SPI has 5 registers to set up and use the SPI system.0SPIESPE MSTR CPOL CPHASSOE0 0 0 SPC000SPR2 SPR1 SPR00 0 0SPIF MODFBit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0SPI0CR1SPI0CR2SPI0BRSPI0SRSPI0DR0x00D80x00D90x00DA0x00DB0x00DDSPTIELSBFE0MODFEN BIDIROE SPISWAISPPR2 SPPR1 SPPR00SPTEF6EE 308 Mar. 26, 2003Setting up the HCS12 SPI Clock ModeYou can program the SPI clock to determine the following things:Is the data valid on the first or the second edge of the clock (clock phase)?Is the clock idle high or idle low (clock polarity)?This setup is done in the SPI0CR1 register. Bit 0Bit 1Bit 2Bit 3Bit 4Bit 5Bit 6Bit 7Bit 0Bit 1Bit 2Bit 3Bit 4Bit 5Bit 6Bit 7Bit 0Bit 1Bit 2Bit 3Bit 4Bit 5Bit 6Bit 7CPOL = 0, CPHA = 1CPOL = 1, CPHA = 0CPOL = 0, CPHA = 0CPOL = 1, CPHA = 1Bit 0Bit 1Bit 2Bit 3Bit 4Bit 5Bit 6Bit 7CPOL = 0: SCK idle lowCPOL = 1: SCK idle highBit 3: CPOLCPHA = 0: Data valid on first clock edgeCPHA = 1: Data valid on second clock edgeBit 2: CPHASPI Clock Polarity and Phase (SPi0CR1 Bits 3 & 2)SPR2 − SPR0 −− SPI Baud Rate Selection BitsBaud Rate = Bus Clock / Baud Rate Divisor(SPR + 1)SCLK Speed (SPI0BR Bits 6,5,4, 2.1 & 0)SPPR2 − SPPR0 −− SPI Baud Rate Preselection BitsBaud Rate Divisor = (SPPR + 1) x 27EE 308 Mar. 26, 2003Setting up the HCS12 SPI Clock ModeThe speed of the HCS12 clock is set up in the SPI0BR register.The clock speed is set only if the HCS12 is being used as a master.The possible clock speeds (for an 24 MHz Bus clock) are shown below.SPPR2 SPPR1 SPPR0 SPR2 SPR1 SPR0 Bus Clock Frequency atDivisor Bus clock = 24 MHz0 0 0 0 0 0 2 12.0 MHz0 0 0 0 0 1 4 6.0 MHz0 0 0 0 1 0 8 3.0 MHz0 0 0 0 1 1 16 1.5 MHz0 0 0 1 0 0 32 750.0 kHz0 0 0 1 0 1 64 375.0 kHz0 0 0 1 1 0 128 187.5 kHz0 0 0 1 1 1 256 93.75 kHz0 0 1 0 0 0 4 6.0 MHz0 0 1 0 0 1 8 3.0 MHz0 0 1 0 1 0 16 1.5 MHz0 0 1 0 1 1 32 750.0 KHz0 0 1 1 0 0 64 375.0 KHz0 0 1 1 0 1 128 187.5 KHz0 0 1 1 1 0 256 93.75 KHz0 0 1 1 1 1 512 46.875 KHz0 1 0 0 0 0 6 4.0 MHz0 1 0 0 0 1 12 2.0 MHz0 1 0 0 1 0 24 1.0 MHz0 1 0 0 1 1 48 500 KHz0 1 0 1 0 0 96 250.0 KHz0 1 0 1 0 1 192 125.0 KHz0 1 0 1 1 0 384 62.5 KHz0 1 0 1 1 1 768 31.25 KHz8EE 308 Mar. 26, 2003SPPR2 SPPR1 SPPR0 SPR2 SPR1 SPR0 Bus Clock Frequency atDivisor Bus clock = 24 MHz0 1 1 0 0 0 8 3.0 MHz0 1 1 0 0 1 16 1.5 MHz0 1 1 0 1 0 32 750.0 KHz0 1 1 0 1 1 64 375.0 KHz0 1 1 1 0 0 128 187.5 KHz0 1 1 1 0 1 256 93.75 KHz0 1 1 1 1 0 512 46.875 KHz0 1 1 1 1 1 1024 23.438 KHz1 0 0 0 0 0 10 2.4 MHz1 0 0 0 0 1 20 1.2 MHz1 0 0 0 1 0 40 600.0 KHz1 0 0 0 1 1 80 300.0 KHz1 0 0 1 0 0 160 150.0 KHz1 0 0 1 0 1 320 75.0 KHz1 0 0 1 1 0 640 37.5 KHz1 0 0 1 1 1 1280 18.75 kHz1 0 1 0 0 0 12 2.0 MHz1 0 1 0 0 1 24 1.0 MHz1 0 1 0 1 0 48 500.0 KHz1 0 1 0 1 …


View Full Document

NMT EE 308 - The HCS12 Serial Peripheral Interface

Documents in this Course
Load more
Download The HCS12 Serial Peripheral Interface
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view The HCS12 Serial Peripheral Interface and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view The HCS12 Serial Peripheral Interface 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?