lect16_notes

lect16_notes - Foundations of Embedded Systems A Term Fall...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 4
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 6
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 8
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Foundations of Embedded Systems A Term Fall 2008 Lecture #16: Using SPI — The External Temperature Sensor & DAC Reading for Today: User's Manual Ch 15 and External Temp Sensor Reading for Next Class: Review All since Exam 1 HW #4 (on web): Due Monday 9/29/08 Lab #2 (on web): Due Tuesday 9/30/2008 (in class) Exam #2 — Tuesday 9/30/08 Last Class: >> Serial vs. Parallel interfaces >> USART are parallel-to-serial and serial-to-parallel converters >> Asynchronous UART mode Serial Peripheral Interface Bus (SPI) >> Used primarily for synchronous serial comms between a CPU and peripherals “within the box” = off—chip but on same PCB >> SP1 sends or receives data Most Significant Bit (MSB) first!! ——> Synchronous = shared clock (supplied by master) = High transfer speeds (~Mbps) _-U5Ua’\\k3 have Om eskdolts H 8.3 cum >> 3-4 wire connection SlMO = Slave In/Master Out data line SCLK = Serial Clock (UCLK in MSP430 USART) SOMI = Slave Out/Master In data line CS = Chip Select >> 3—4 wire connection SIMO = Slave In/Master Out data line SOMI = Slave Out/Master In data line SCLK = Serial Clock=(UCLK in MSP430 USART) CS = Chip Select KMWW.-M MsPI-rgo USART QM run Kn mstdnclrxronous “UH'RT” moée or m synchronous SPI moée >> To use SPI the programmer must... 1) Enable USART for SP1 mode 2) Select data format 3) Setup synchronous clock $14K?" P SPI void setupSPI(void) //‘1’\,\~\$ Cuflchofi 3343‘ up U ¢ 0" { MEl 1: USPIEO; // Enable USARTO SPI mode UOCTL &= ~SWRST; // Make sure SW RESET bit is off // Bits 3, 2 & 1 are used for SPI UCLK, SOMI and SIMO U) P3SEL |= BIT3|BIT2IBIT1; // set bits to Function mode:l L2} UOCTL |= CHAR + SYNC + MM; // USARTO module control // CHAR = 1 => 8—bit data // SYNC = 1 => SPI mode SQJQC" A44“ // M = 1 => master mode ‘FO’WVUi UOTCTL |= SSELO+SSEL1+STC+CKPL; // USARTO xmit control // SSELO = 1 & SSELl = 1 // (SMCLK for baud-rate gen.) 394's up // STC = 1 => 3—pin SPI mode 3 C5) // CKPL = Invert Clock 5"““0‘0005 UOBRO = Oxoz; // Divide SMCLK by 2 => SCLK CL L UOBRl = 0x00; W UOMCTL = 0x00; // Modulation control — not used. // Ensure all these bits are reset UOTXBUF = 0x00; //Clr transmit buffer Data (otter—SD“ if??? } L. N> Check SPQCS oi: STU: dewte to 3&6 / allowable. SCLK mules (52L, kbps (3 "reasonable" mic» (Lb Se/ec‘i fiérkphergj Lts‘mfi 14-5 Clfip Seipd (CS) First, what is the function of a CS? >> Likely to be multiple peripherals using SPI bus >> Only 1 Slave device and Master (MSP430) can use SPI bus at a time >> cs is typically ACTIVE LOW digital signal D ~. 51 4 a i gt CS : O = Device is Enabled (will read and write to SP1 data lines) CS = 1: Device is Disabled (outputs are high Z) ,,./ SlaveD I- S'w‘ I gm 3 DRAO‘Q 1/0 PMS 0‘“ usecl +0 fienemde E0) (31, C32 i0 5858Ci amoncfi 3 SP1 devices >> The MSP430 Interface Board has 2 peripherals that are SP1 devices — the external temperature sensor and the digital to analog converter. ~_._ . . M W “E Configuring the CS for the External Temperature Sensor >> Check schematic to see how the temperature sensor's CS is connected 3.3 U HSP438F449 // Configure a CS signal (active low) for temp sensor #define tempCS 0x10 // Temp sensor CS on Pin 4 z) (goal 0000 PlSEL &='*(tempCS); // Select Pl.4 digital IQ for TC77 cs PlDIR |= tempCS; // Set CS bit as an output PlOUT |= tempCS; // De—assert cs (set cs =1) Next program should... 5) Send or Receive data -- Poll transfer complete bits to determine when data transfer complete (interrupts not enabled here... they could be) N f3?j; flacthL ~‘5 ffiarrd MSB firs’} int getTemp( ) { // Get 13 bit two's complement temperature data from // Microchip TC77 Thermal Sensor via SPI bus unsigned int hi_byte, lo_byte; P10UT &= ~tempcs; // Assert temp cs = ACTIVE LOW ((5:03 UOTXaUF = 0x00; // "Send" all 0's to rc77 ’-\9> 1ZAX+\4;44 3 received(); // Wait until all 8 bits rcv'd +r 4: hi_byte = UORXBUF; // Store data in the hi-byte “"5 er hi_byte = hi_byte << 8; // Left—shift the hi—byte UOTXBUF = 0x00; // “Send” all 0's to TC77 received(); // Wait until all 8 bits rcv'd lo_byte = UORXBUF; // Store data in the lo-byte P10UT |= tmpCS; // De—assert CS = set HIGH temp = (hi_byte+lo_byte); return(temp); } void received( void) { char dmy; // Wait for receive buffer to fill // Bit URXIFGO = 1 when receive buffer UORXBUF has // received a complete byte, URXIFGO = 0 otherwise while ((IFGl & URXIFGO)==0) dmy=l; Finally, program needs to process received data... m >> From the data sheet -- 13 bit 2’s comp temperature data _ §§ “c, + o i Q 5 ° C -— Data bits are the high 13 bits! —— Bit 2 is the conversion complete bit (1 = complete) "0'06zscoperbit = Vii/C (can use right skufi [20+ 3 04160 4,8 9M? —- Max temperature reading is 125 C => What reading will that equal? Ob\ll \IOI oooowxx l W temp reading ~wo We? +0 rCéICUV‘VGHEL "(Qt/Mk4 If i—AAQ. VEOLEKACB 100W \QgCé,, QJVH ._ '256 ,= a000,,b1‘\s, 0,0635/C0 per ‘01,? aaoo : “63.071107; Equ \B bi¥ r reca‘weé \msk‘mé 7 7 ,, 7 , 7 WW 05+ Stfimlcl gut} , \01‘\3 7 ,, , , , 09 r 2 ,, f , \D «(fit ,flrmwafigpL7259HIA ,.:f_7fIf ' M: 30349, :1), _,©,Q\H\m\,w\_\_ow ,, ,flwflggufivxwxuwQHIWQQQQmg; Mi $hx$+ << 4 ‘ +07 mumplud * bye, Gangs Ox 0770‘ O; ,VOQQDOH} natvcgoor >> Temperature Sensor is example of device that reads from SPI Bus >> Digital-to—Analog Converter (DAC) is example of device that writes to SP1 Overview of a Digital-to-Analog Convert >> Converts integer value to a voltage >> MCP4921 is 12-bit DAC that outputs voltages “rail-to-rail” ( 0v +0 VCL\ a‘mWs Vou+ c (10ng 4‘ (V'efl NY“) Wylie Vulr: 20% V, 5.3 5 [MW Ho‘té >> DAC performs the inverse operation of an ADC >> To use SP1 to run the DAC the programmer must... 1) Enable USART for SP1 mode 2) Select data format 3) Setup synchronous clock Can we use the setup .p of SP1 on USARTO from before? -- \383' ‘rkxl KSWC iclécul How ever “Flee, C3 P‘ms wk“ C/lwuxfie.‘ ==> Wlus‘l' Con-C13qu 4) Select peripheral (CS) vllmose Then programmer must HSP43GF449 MCP4921 VOUTA DAC Output >> DAC actually uses 2 pins to enable serial data transfer —- first CS then LDAC - ‘_ ...
View Full Document

Page1 / 8

lect16_notes - Foundations of Embedded Systems A Term Fall...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online