Part Number Hot Search : 
KE47A CS201212 XC9221 CR1005 IRH7250 CR1005 2D1K12 4066D
Product Description
Full Text Search
 

To Download C8051F974 Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  rev 1.0 5/14 copyright ? 2014 by silicon laboratories c8051f97x c8051f97x low power capacitive sensing mcu with up to 32 kb of flash low power consumption - 200 a/mhz in active mode (24.5 mhz clock) - 2 s wakeup time - 55 na sleep mode with brownout detector - 280 na sleep mode with lfo - 600 na sleep mode with external crystal capacitance sense interface - supports buttons, sliders, wheels, and proximity sensing - fast 40 s per channel conversion time - 16-bit resolution, up to 43 input channels - auto scan and wake-on-touch - auto-accumulate up to 64x samples 10-bit analog-to-digital converter - up to 43 external pin input channels, up to 300 ksps - internal vref or external vref supported clock sources - internal oscillators: 24.5 mhz, 2% accuracy supports uart operation; 20 mhz low power oscill ator requires very little bias current. - external oscillator: crystal, rc, c, or cmos clock - smartclock oscillator: 32 kh z crystal or internal lfo - can switch between clock sources on-the-fly; useful in imple- menting various power-saving modes on-chip debug - on-chip debug circuitry facilitate s full speed, non-intrusive in- system debug (no emulator required) - provides breakpoints, single st epping, inspect/modify memory and registers unique identifier - 128-bit unique key for each device high-speed cip-51 c core - efficient, pipelined instruction architecture - up to 25 mips throughput with 25 mhz clock - uses standard 8051 instruction set - expanded interrupt handler - 1-cycle 16 x 16 mac engine - 7-channel direct memory access (dma) module memory - up to 32 kb flash - flash is in-system programmable in 512-byte sectors - up to 8 kb ram general-purpose i/o - up to 43 pins with high sink current and programmable drive - crossbar-enabled timer/counters and pwm - 4 general purpose 16-bit timer/counters - 16-bit programmable counter array (pca) with three channels of pwm, capture/compare, or frequency output capability, and watchdog timer supply voltage: 1.8 to 3.6 v - built-in ldo regulator allows a high analog supply voltage and low digital core voltage - 2 supply monitors (brownout detector) for sleep and active modes package options - 24-pin qfn (4x4 mm) - 32-pin qfn (5x5 mm) - 48-pin qfn (6x6 mm) temperature ranges: ?40 to +85 c cip-51 (25 mhz) 16-32 kb flash 4-8 kb ram supply monitor core / memory / support c2 serial debug / programming core ldo clocking / oscillators smartclock with 16.4 khz lfo 24.5 mhz precision oscillator external oscillator clock selection analog peripherals sar adc (10-bit 300 ksps) temperature sensor digital peripherals uart 4 x 16-bit timers 3-channel pca / watchdog voltage reference flexible pin muxing priority crossbar encoder 43 multi-function i/o pins i2c / smbus spi 16-bit crc 20 mhz low power oscillator hs i2c slave capacitive sensing 16 x 16 mac 7 ch. dma
c8051f97x 2 rev 1.0 1. electrical characteristics . ................. ................ ................ ................. ................ ............... 1 0 1.1. electrical characteristics ......... ................ ................. .............. .............. .............. .......... 10 1.2. thermal conditions ........ ................ ................ ................. ................ ................. ............ 21 1.3. absolute maximum rating s.............. ................. ................ ................. ................ ..........21 2. system overview ............ ................ ................. ................ ................. ................ ................ .22 2.1. power ............... ................ ................ .............. .............. ............... .............. .............. ..... 24 2.1.1. voltage supply monito r (vmon0) ............ ................ ................. ................ .......... 24 2.1.2. device power modes............. ................ ................. ................ ................. ............ 24 2.1.3. suspend mode........... ................. ................ ................ ................. .............. .......... 25 2.1.4. sleep mode......... ................. .............. .............. .............. .............. .............. .......... 25 2.1.5. low power active mode ........ ................ ................. ................ ................. ............ 26 2.1.6. low power idle mode ... ................ ................ ................. .............. .............. ..........26 2.2. i/o.................. ................. ................ .............. .............. .............. .............. ............. ......... 26 2.2.1. general features....... ................. ................ ................ ................. .............. ..........26 2.2.2. crossbar ................ ................ ................ ................. ................ ................. ............ 26 2.3. clocking............ ................ ................ .............. .............. ............... .............. .............. ..... 27 2.4. counters/timers and pwm ............ ................ ................. ................ ................. ............27 2.4.1. programmable counter array (pca0) ............. .............. .............. .............. .......... 27 2.4.2. timers (timer 0, timer 1, timer 2, and timer 3). ............... .............. ........... ........ 27 2.5. communications and other digita l peripherals ............ ............... .............. ........... ........ 28 2.5.1. universal asynchronous rece iver/transmitter (uart0) ..... ............ ........... ........ 28 2.5.2. serial peripheral interface ( spi0) ............... ................ ................. .............. .......... 28 2.5.3. system management bu s / i2c (smbus0) ........ .............. .............. .............. ........ 28 2.5.4. high-speed i2c slave (i2cslave0)............... .............. .............. .............. .......... 29 2.5.5. 16/32-bit crc (crc0)... ................. ................. .............. .............. .............. .......... 29 2.6. analog peripherals ......... ................ ................ ................. ................ ................. ............ 29 2.6.1. 10-bit analog-to-digital conv erter (adc0) ............. ................ ................. ............ 29 2.7. digital peripherals ....... ................. ................ ................ ................. ................ ............... 30 2.7.1. direct memory access (dma0) ................ ................ ................. ................ .......... 30 2.7.2. multiply and accumulate (mac 0) ................. ................. .............. .............. .......... 30 2.8. reset sources............. ................. ................ ................ ................. ................ ............... 30 2.9. unique identifier ........ ................ ................. ................ ................. ................ ................ .30 2.10.on-chip debugging .... ................. .............. .............. .............. .............. .............. .......... 30 3. pin definitions............ ................. ................ ................ ................. ................ ................ ...... 31 3.1. c8051f970/3 qfn-48 pin de finitions............ ................. ................ ................. ............ 31 3.2. c8051f971/4 qfn-32 pin de finitions............ ................. ................ ................. ............ 35 3.3. c8051f972/5 qfn-24 pin de finitions............ ................. ................ ................. ............ 38 4. ordering information ........ ................. ................ ................ ................. ................ ............... 41 5. qfn-48 package specificatio ns ............... ................ ................. .............. .............. .......... 43 5.1. qfn-48 package marking............ .............. .............. .............. .............. .............. .......... 45 6. qfn-32 package specifications ....... .............. .............. .............. .............. .............. .......... 46 6.1. qfn-32 package marking............ .............. .............. .............. .............. .............. .......... 49 7. qfn-24 package specifications ....... .............. .............. .............. .............. .............. .......... 50 7.1. qfn-24 package marking............ .............. .............. .............. .............. .............. .......... 53 8. memory organization .......... ................ ................ ................. ................ ................. ............54 8.1. program memory............ ................ ................ ................. ................ ................. ............ 55
c8051f97x rev 1.0 3 8.1.1. movx instruction and program memory......... .............. .............. .............. .......... 55 8.2. data memory........ ................. ................ ................ .............. ............... .............. ............ 55 8.2.1. internal ram.......... ................ ................ ................. ................ ................. ............55 8.2.2. external ram......... ................ ................ ................. ................ ................. ............ 56 8.2.3. special function registers ..... ............... ................. ................ ................. ............ 56 9. special function register memory map............ ................. ................ ................. ............ 57 10. flash memory................ ................ ................ ................. ................ ................. .............. ..... 65 10.1.security options........ ................ ................. ................ ................. ................ ................ .65 10.2.programming the flash memory .... ................. ................ ................. ................ .......... 67 10.2.1.flash lock and key functions ... ................ ................ ................. .............. ..........67 10.2.2.flash erase procedure.......... ................ ................. ................ ................. ............ 67 10.2.3.flash write procedure......... .............. .............. .............. .............. .............. .......... 67 10.3.non-volatile data storage.............. ................ ................. ................ ................. ............ 68 10.4.flash write and erase guid elines ............... .............. .............. .............. .............. ........ 68 10.4.1.voltage supply maint enance and the suppl y monitor........ .............. ........... ........68 10.4.2.pswe maintenance ..... ................ ................ ................. .............. .............. .......... 68 10.4.3.system clock......... ................ ................ ................. ................ ................. ............ 69 10.5.flash control registers ............ ................. .............. .............. .............. .............. .......... 70 11. on-chip xram ......... ................ ................. .............. .............. .............. .............. .............. ... 74 11.1.accessing xram ............. ................ ................. ................ ................. ................ .......... 74 11.1.1.16-bit movx exam ple.................... ................. .............. .............. .............. .......... 74 11.1.2.8-bit movx example............... ................. ................ ................. ................ .......... 74 11.2.external memory interface regist ers................ ................ ................. ................ .......... 75 12. device identification and unique id entifier ............ ................ ................. .............. ..........76 12.1.device identification registers.. ................. .............. .............. .............. .............. .......... 77 13. interrupts .................. ................ ................. ................ ................ ................. .............. .......... 79 13.1.mcu interrupt sources and vectors ............ .............. .............. .............. .............. ........79 13.1.1.interrupt priorities .. ................ ................ ................. ................ ................. ............ 79 13.1.2.interrupt latency........ ................. ................ ................ ................. .............. .......... 79 13.2.interrupt control registers........ ................. .............. .............. .............. .............. .......... 82 14. external interrupts (int0 and int1). ................. .............. .............. .............. .............. ........ 91 14.1.external interrupt control registers............. .............. .............. .............. .............. ........ 92 15. voltage regulator (vreg0). ................ ................ ................. ................ ................. ............ 93 15.1.voltage regulator control register s .................. ................ ................. .............. .......... 93 16. power management .......... ................. ................ ................ ................. ................ ............... 9 4 16.1.normal active mode....... ................ ................ ................. ................ ................. ............ 95 16.2.idle mode ........... ................ ................. .............. .............. .............. .............. ............. .... 96 16.3.stop mode............... ................ ................ ................. ................ ................. ................ ... 97 16.4.suspend mode............... ................ ................ ................. ................ ................. ............ 9 7 16.5.sleep mode............... ................ ................. ................ ................. ................ ............... .. 97 16.6.low power active mode .............. .............. .............. .............. .............. .............. .......... 98 16.7.low power idle mode .... ................ ................ ................. ................ ................. ............ 98 16.8.configuring wakeup sources ........ ................ ................. ................ ................. ............ 99 16.9.determining the event that caused the last wak eup ................ .............. ........... ........ 99 16.10.power control registers ......... .............. .............. .............. ............... .............. .......... 100 17. analog-to-digital converter (adc0) ................... ................. ................ ................. .......... 104
c8051f97x 4 rev 1.0 17.1.adc0 analog mu ltiplexer................. ................. ................ ................. .............. .......... 105 17.2.output code formatting .. ................ ................. ................ ................. .............. .......... 106 17.3.modes of operation .... ................. ................ ................ ................. ................ ............. 107 17.3.1.starting a conver sion ................. ................ ................ ............... .............. ..........107 17.3.2.tracking modes ......... ................. ................ ................ ............... .............. .......... 108 17.3.3.burst mode ....... ................ .............. .............. .............. ............... .............. .......... 109 17.3.4.settling time requirements ................ ................ ................. ................ ............. 110 17.3.5.gain setting.... ................ ................ .............. .............. ............... .............. .......... 110 17.4.8-bit mode............... ................ ................ ................. ................ ................. ............... .. 110 17.5.low power mode ........... ................ ................ ................. ................ ................. .......... 111 17.6.window detector in single-en ded mode .............. .............. ............... .............. ..........111 17.7.voltage reference ......... ................ ................ ................. ................ ................. .......... 112 17.7.1.external voltage reference... ................ ................. ................ ................. .......... 112 17.7.2.internal voltage refe rence................ .............. .............. .............. .............. ........ 113 17.8.temperature sensor ...... ................ ................ ................. ................ ................. .......... 113 17.8.1.calibration ............. ................ ................ ................. ................ ................. .......... 113 17.9.adc control registers... ................ ................ ................. ................ ................. ..........114 17.10.voltage reference registers ....... ................ ................. ................ ................. .......... 127 17.11.temperature sensor regi sters................ .............. .............. .............. .............. ........ 128 18. capacitive sense (cs0) .... ................. ................ ................ ................. ................ ............. 130 18.1.configuring port pins as c apacitive sense inputs ................ .............. .............. ........ 131 18.2.initializing the capacitive s ensing peripheral ............ .............. .............. ............ ........131 18.3.capacitive sense start-of-conver sion sources.......... ................. ................ ............. 131 18.4.cs0 multiple channel enable ... .............. .............. .............. ............... .............. .......... 132 18.5.cs0 gain adjustment .... ................ ................ ................. ................ ................. .......... 132 18.6.wake from suspend ...... ................ ................ ................. ................ ................. .......... 132 18.7.using cs0 in applications t hat utilize sleep mode.... .............. .............. ............ ........ 132 18.8.automatic scanning (method 1? cs0smen = 0) .......... ................ ................. ..........132 18.9.automatic scanning (method 2? cs0smen = 1) .......... ................ ................. ..........134 18.10.cs0 comparator ............ ................ ................. ................ ................. .............. ..........134 18.11.cs0 conversion accumu lator............. ................ .............. ............... .............. .......... 135 18.12.cs0 pin monitor........... ................ ................ ................. ................ ................. .......... 136 18.13.adjusting cs0 for special situations .......... ................. ................ ................. .......... 137 18.13.1.adjusting the cs0 reset timi ng................. .............. ............... .............. .......... 137 18.13.2.adjusting primary reset ti ming: cs0dt ............. ................ ................. .......... 137 18.13.3.adjusting secondary reset timing: cs0dr ... .............. .............. ............ ........ 138 18.13.4.adjusting cs0 ramp timing : cs0ia ................. ................. ................ ............. 138 18.13.5.low-pass filter adju stments ............... ................. ................ ................. .......... 139 18.13.6.adjusting cs0 ramp timing : cs0rp .................. ................ ................. .......... 139 18.13.7.adjusting cs0lp for non- default cs0rp settings .......... ........... ............ ........ 139 18.13.8.other options for ad justing cs0lp............ .............. ............... .............. .......... 139 18.14.cs0 analog multiplexer ... ................. ................ ................ ............... .............. .......... 140 18.14.1.pin configuration for cs0 measurements method ........... ........... ............ ........ 142 18.15.capacitive sense registers....... ................ ................ ................. ................ ............. 143 19. analog multiplexer (amux0).......... .............. .............. .............. ............... .............. .......... 158 19.1.amux control registers........... .............. .............. .............. ............... .............. .......... 159
c8051f97x rev 1.0 5 20. cip-51 microcontroller core .......... .............. .............. .............. ............... .............. .......... 165 20.1.performance ............... ................. ................ ................ ................. ................ ............. 1 65 20.2.programming and debugging suppor t ................. .............. ............... .............. .......... 166 20.3.instruction set ......... ................ ................ ................. ................ ................. ................ .166 20.3.1.instruction and cpu timing.... ............... ................. ................ ................. .......... 166 20.4.sfr paging............... ................ ................. ................ ................. ................ ............... 171 20.5.cpu core registers ...... ................ ................ ................. ................ ................. .......... 178 21. direct memory access (dma0)...... .............. .............. .............. ............... .............. .......... 188 21.1.dma0 architecture...... ................. ................ ................ ................. ................ ............. 189 21.2.dma0 arbitration.. ................. ................ ................ .............. ............... .............. .......... 18 9 21.2.1.dma0 memory access arbitrat ion................ .............. ............... .............. .......... 189 21.2.2.dma0 channel arbitration ...... ................ ................. ................ ................. .......... 190 21.3.dma0 operation in low power modes............... ................ ............... .............. .......... 190 21.4.transfer configuration ... ................ ................ ................. ................ ................. ..........190 21.5.dma0 registers.......... ................. ................ ................ ................. ................ ............. 191 22. multiply and accumulate (mac0) .. .............. .............. .............. ............... .............. .......... 203 22.1.special function registers ....... .............. .............. .............. ............... .............. ..........204 22.2.integer and fractional math ...... .............. .............. .............. ............... .............. .......... 204 22.3.operating in multiply and accu mulate mode ............. .............. .............. ............ ........ 205 22.4.operating in multiply only mode ............. .............. .............. ............... .............. .......... 205 22.5.mcu mode operation......... ................. ................ ................ ............... .............. .......... 206 22.6.dma mode operation ......... ................. ................ ................ ............... .............. .......... 206 22.7. accumulator 1-bit shift operat ions............... ................. ................ ................. .......... 208 22.8.multi-bit shift accumulator oper ation ............... ................ ................. .............. .......... 209 22.9.accumulator alignm ent (right byte shift).... ................ ................. ................ ............. 210 22.10.rounding and saturation ............. ................ ................. ................ ................. .......... 210 22.11.usage examples.............. ................. ................ ................ ............... .............. ..........212 22.11.1.multiply and accumulate in fractional mode ................. .............. ............ ........ 212 22.11.2.multiply only in integer mode .......... .............. .............. .............. .............. ........212 22.11.3.initializing memory block using dma0 and mac0........... ........... ............ ........ 213 22.12.mac0 registers........... ................ ................ ................. ................ ................. .......... 214 23. cyclic redundancy check unit (crc0) ................ ................ ................. .............. .......... 233 23.1.crc algorithm ............ ................. ................ ................ ................. ................ ............. 23 3 23.2.preparing for a crc calc ulation............. .............. .............. ............... .............. .......... 235 23.3.performing a crc calculation..... ................ ................ ................. ................ ............. 235 23.4.accessing the crc0 result......... ................ ................ ................. ................ ............. 235 23.5.crc0 bit reverse feature ....... .............. .............. .............. ............... .............. ..........235 23.6.crc control registers ............. .............. .............. .............. ............... .............. .......... 236 24. clocking sources.............. ................. ................ ................ ................. .............. .............. .242 24.1.programmable precision internal oscillator............. .............. .............. .............. ........ 243 24.2.low power internal oscillator ... .............. .............. .............. ............... .............. .......... 243 24.3.external oscillator dr ive circuit .............. .............. .............. ............... .............. ..........243 24.3.1.external crystal mode ................ ................ ................ ............... .............. .......... 243 24.3.2.external rc mode ............ .............. .............. .............. ............... .............. .......... 244 24.3.3.external capacitor mode .............. ................ .............. ............... .............. .......... 246 24.3.4.external cmos clock mode.. ................ ................. ................ ................. .......... 246
c8051f97x 6 rev 1.0 24.4.special function registers for selecting and configuring t he system clock............ 247 24.5.clock selection control register s ............... ................ ................. ................ ............. 248 24.6.high frequency oscillator r egisters .................... .............. ............... .............. .......... 251 24.7.external oscillator r egisters............ ................. ................ ................. .............. .......... 253 25. smartclock (real time clock, rt c0) ................. ................ ................. .............. ..........254 25.1.smartclock interface..... ................ ................. ................ ................. .............. ..........255 25.1.1.using rtc0adr and rtc0dat to acce ss smartclock internal registers... 255 25.1.2.rtc0adr short strobe feature ........... ................. ................ ................. .......... 255 25.1.3.smartclock interface autor ead feature .............. ................ ................. .......... 256 25.1.4.rtc0adr autoincrement feat ure ............... .............. ............... .............. .......... 256 25.2.smartclock clocking sources..... ................ ................. ................ ................. ..........257 25.2.1.using the smartclock oscilla tor with a crystal.... ................ ................. .......... 257 25.2.2.using the smartclock osci llator in self-oscillate mode .. ........... ............ ........ 258 25.2.3.using the low freque ncy oscillator (lfo) .. .............. ............... .............. .......... 258 25.2.4.programmable load c apacitance ............ ................ ................. .............. .......... 259 25.2.5.automatic gain cont rol (crystal mode only) and smartclock bias doubling 260 25.2.6.missing smartclock detector... ................ ................ ............... .............. ..........262 25.2.7.smartclock oscillato r crystal valid detector .............. .............. .............. ........ 262 25.3.smartclock timer and alarm func tion .............. .............. ............... .............. ..........262 25.3.1.setting and reading the sm artclock timer value ............ ................ ............. 262 25.3.2.setting a smartclock alarm.. ................. ................ ................. .............. .......... 263 25.3.3.software considerations for using the smartclock ti mer and alarm ............ 264 25.4.rtc0 control registers. ................ ................ ................. ................ ................. .......... 265 26. port i/o (port 0, port 1, port 2, port 3, port 4, port 5, port 6, crossbar, and port match) 278 26.1.general port i/o initia lization ................ ................ .............. ............... .............. .......... 279 26.2.assigning port i/o pins to a nalog and digital functions ......... .............. ............ ........ 280 26.2.1.assigning port i/o pins to analog function s.............. ............... .............. ..........280 26.2.2.assigning port i/o pins to digital functions ............... ............... .............. .......... 281 26.2.3.assigning port i/o pins to fixed digital functions ..... ............... .............. .......... 281 26.3.priority crossbar decoder......... .............. .............. .............. ............... .............. .......... 282 26.4.port i/o modes of operation ..... .............. .............. .............. ............... .............. .......... 284 26.4.1.configuring port pi ns for analog modes ..... .............. ............... .............. .......... 284 26.4.2.configuring port pi ns for digital mode s .................... ............... .............. .......... 284 26.4.3.port drive strength ........... .............. .............. .............. ............... .............. .......... 284 26.5.port match.......... ................ ................. .............. .............. .............. .............. ............. .. 285 26.6.direct read/write acce ss to port i/o pins..... ................. ................ ................. .......... 285 26.7.port configuration registers..... .............. .............. .............. ............... .............. .......... 286 26.8.port i/o control registers....... ................ .............. .............. ............... .............. .......... 288 27. reset sources and supply monitor ... ................ ................. ................ ................. .......... 323 27.1.power-on reset ......... ................. ................ ................ ................. ................ ............. 324 27.2.power-fail reset / supply monito r .............. ................ ................. ................ ............. 325 27.3.enabling the vdd monitor . ................. ................ ................ ............... .............. .......... 326 27.4.external reset .......... ................ ................. ................ ................. ................ ............... 3 26 27.5.missing clock detector re set............... ................ .............. ............... .............. .......... 326 27.6.pca watchdog timer reset.......... ................ ................. ................ ................. .......... 326
c8051f97x rev 1.0 7 27.7.flash error reset........ ................. ................ ................ ................. ................ ............. 32 6 27.8.software reset ........... ................. ................ ................ ................. ................ ............. 32 6 27.9.reset sources control registers. ................ ................ ................. ................ ............. 327 27.10.supply monitor control registers ............ .............. .............. .............. .............. ........ 328 28. serial peripheral interface (spi0) .. .............. .............. .............. ............... .............. .......... 329 28.1.signal descriptions ........ ................ ................ ................. ................ ................. .......... 330 28.1.1.master out, slave in (mosi) ............... ................ ................. ................ ............. 330 28.1.2.master in, slave out (miso) .. ............... ................. ................ ................. .......... 330 28.1.3.serial clock (sck)..... ................. ................ ................ ............... .............. .......... 330 28.1.4.slave select (nss).... ................. ................ ................ ............... .............. .......... 330 28.2.spi0 master mode operation ... .............. .............. .............. ............... .............. .......... 331 28.3.spi0 slave mode operation ..... .............. .............. .............. ............... .............. .......... 333 28.4.spi0 interrupt sources ................. ................ ................ ................. ................ .............333 28.5.serial clock phase and polarity .............. .............. .............. ............... .............. ..........333 28.6.spi special function registers ... ................ ................ ................. ................ .............335 28.7.spi control registers .... ................ ................ ................. ................ ................. .......... 339 29. system management bus / i2c (s mbus0) .............. ................ ............... .............. .......... 343 29.1.supporting documents . ................... ................. ................ ................. .............. .......... 344 29.2.smbus configuration ..... ................ ................ ................. ................ ................. .......... 344 29.3.smbus operation.... ................ ................ .............. .............. ............... .............. .......... 344 29.3.1.transmitter vs. receiver...... ................ ................ ................. ................ ............. 345 29.3.2.arbitration ........... ................. ................ ................ ................. ................ ............. 345 29.3.3.clock low extension . ................. ................ ................ ............... .............. .......... 345 29.3.4.scl low timeout ...... ................. ................ ................ ............... .............. .......... 345 29.3.5.scl high (smbus free) timeout ................. .............. ............... .............. .......... 346 29.4.using the smbus ........... ................ ................ ................. ................ ................. .......... 346 29.4.1.smbus configuration register .............. ................. ................ ................. ..........346 29.4.2.smbus pin swap....... ................. ................ ................ ............... .............. ..........348 29.4.3.smbus timing control......... ................ ................ ................. ................ ............. 348 29.4.4.smb0cn control register..... ................ ................. ................ ................. ..........348 29.4.5.hardware slave address rec ognition................. ................. ................ ............. 350 29.4.6.data register.. ................ ................ .............. .............. ............... .............. .......... 350 29.5.smbus transfer modes ..... ................. ................ ................ ............... .............. .......... 351 29.5.1.write sequence (master)......... ................. ................ ................. .............. .......... 351 29.5.2.read sequence (master) . .............. .............. .............. ............... .............. .......... 352 29.5.3.write sequence (slave)......... ................ ................. ................ ................. .......... 353 29.5.4.read sequence (slave) ... .............. .............. .............. ............... .............. .......... 354 29.6.smbus status decoding .. ................ ................. ................ ................. .............. .......... 354 29.7.i2c / smbus control registers .... ................ ................ ................. ................ ............. 359 30. i2c slave ............ ................ ................. .............. .............. .............. .............. .............. ........365 30.1.supporting documents . ................... ................. ................ ................. .............. .......... 366 30.2.the i2c configuration.... ................ ................ ................. ................ ................. .......... 366 30.3.i2cslave0 operation ..... ................ ................. ................ ................. .............. ..........366 30.3.1.transmitter vs. receiver...... ................ ................ ................. ................ ............. 367 30.3.2.clock stretching ...... ................ ................. ................ ................. .............. .......... 367 30.3.3.scl low timeout ...... ................. ................ ................ ............... .............. .......... 368
c8051f97x 8 rev 1.0 30.3.4.hs-mode ................. ................ ................. ................ ................. .............. .......... 368 30.3.5.dma and cpu mode operations ................. .............. ............... .............. .......... 369 30.4.using the i2cslave0 module....... ................ ................. ................ ................. .......... 369 30.4.1.i2c0cntl control register.... ............... ................. ................ ................. .......... 369 30.4.2.i2c0stat status register .... ................ ................. ................ ................. .......... 369 30.4.3.i2c0slad slave address regi ster .............. .............. ............... .............. ..........370 30.4.4.i2c0din received data regist er................. .............. ............... .............. .......... 370 30.4.5.i2c0dout transmit data regi ster............ ................ ............... .............. ..........370 30.5.i2c transfer modes ....... ................ ................ ................. ................ ................. .......... 371 30.5.1.i2c write sequence (cpu m ode) ................ .............. ............... .............. .......... 371 30.5.2.i2c read sequence (cpu mode) .. .............. .............. ............... .............. .......... 372 30.5.3.i2c write sequence (dma mode ) ................ .............. ............... .............. .......... 372 30.5.4.i2c read sequence (dma mode).. .............. .............. ............... .............. .......... 374 30.6.i2cslave0 slave register s................. ................ .............. ............... .............. .......... 375 31. universal asynchronous receiver /transmitter (uart0) ............. ........... ............ ........ 381 31.1.enhanced baud rate generation ........... .............. .............. ............... .............. .......... 381 31.2.operational modes......... ................ ................ ................. ................ ................. .......... 383 31.2.1.8-bit uart ....... ................ .............. .............. .............. ............... .............. .......... 383 31.2.2.9-bit uart ....... ................ .............. .............. .............. ............... .............. .......... 384 31.3.multiprocessor communications.... ................ ................. ................ ................. .......... 385 31.4.uart control registers ........... .............. .............. .............. ............... .............. .......... 387 32. timers (timer0, timer1, timer2, and timer3) ............... .............. .............. ............ ........ 390 32.1.timer 0 and time r 1.................. .............. .............. .............. ............... .............. .......... 391 32.1.1.mode 0: 13-bit counter/timer.. ................. ................ ................. .............. .......... 392 32.1.2.mode 1: 16-bit counter/timer.. ................. ................ ................. .............. .......... 392 32.1.3.mode 2: 8-bit counter/timer with auto-reload ............... .............. ............ ........ 393 32.1.4.mode 3: two 8-bit counter/timers (timer 0 only) ........ .............. .............. ........ 394 32.2.timer 2............. ................ ................ .............. .............. ............... .............. ............. .... 395 32.3.timer 3............. ................ ................ .............. .............. ............... .............. ............. .... 398 32.4.timer control regi sters ............... ................ ................ ................. ................ ............. 401 32.5.timer 0/1 registers..... ................. ................ ................ ................. ................ ............. 405 32.6.timer 2 registers........ ................. ................ ................ ................. ................ ............. 40 9 32.7.timer 3 registers........ ................. ................ ................ ................. ................ ............. 41 5 33. programmable counter array (pca0) ................ ................. ................ ................. .......... 421 33.1.pca counter/timer. ................ ................ .............. .............. ............... .............. .......... 422 33.2.pca0 interrupt so urces ............... ................ ................ ................. ................ ............. 423 33.3.capture/compare modules............ ................ ................. ................ ................. ..........424 33.3.1.edge-triggered capture mode ............... ................. ................ ................. .......... 425 33.3.2.software timer (com pare) mode ................. .............. ............... .............. .......... 426 33.3.3.high-speed output mo de............. ................ .............. ............... .............. .......... 427 33.3.4.frequency output mode........ ................ ................. ................ ................. .......... 428 33.3.5. 8-bit, 9-bit, 10-bit and 11-bit pulse wi dth modulator modes....... .............. ........ 428 33.3.6. 8-bit pulse width modulator mode .............. .............. ............... .............. ..........429 33.3.7. 9/10/11-bit pulse width mo dulator mode ........... ................. ................ ............. 430 33.3.8. 16-bit pulse width modulator mode ................. .............. .............. ............ ........ 431 33.4.watchdog timer mode....... ................. ................ ................ ............... .............. ..........432
c8051f97x rev 1.0 9 33.4.1.watchdog timer operation ..... ................. ................ ................. .............. .......... 432 33.4.2.watchdog timer usage.. ................ .............. .............. ............... .............. .......... 433 33.5.pca0 control registers. ................ ................ ................. ................ ................. .......... 434 34. c2 interface ................ ................. ................ ................ ................. ................ .............. ...... 448 34.1.c2 pin sharing.......... ................ ................. ................ ................. ................ ............... 4 48 34.2.c2 interface registers ................. ................ ................ ................. ................ .............449 document change list ........ ................ .............. .............. .............. ............... .............. .......... 45 4 revision 0.1 to revision 1.0 .. ................. ................ ................ ................. ................ ............. 45 4 contact information ........... ................ ................ ................. ................ ................. ............... .. 455
c8051f97x 10 rev 1.0 electrical characteristics 1. electrical characteristics throughout the electrical characteristics chapter, ?v dd ? refers to the supply voltage. 1.1. electrical characteristics all electrical parameters in all tables ar e specified under the conditions listed in ta b l e 1.1 , unless stated otherwise. table 1.1. recommended operating conditions parameter symbol conditions min typ max units temperature range t a ?40 25 85 c supply voltage v dd 1.8 3 3.6 v *note: all minimum and maximum specifications are guaranteed and apply across the recommended operating conditions. typical values apply at nominal supply voltages and an operating temperature of 25 c unless otherwise noted. table 1.2. global electrical characteristics ?40 to +85 c, 25 mhz system clock unless otherwise specified. parameter conditions min typ max units supply voltage (v dd ) 1.8 3.0 3.6 v ram data retention voltage 1 ? 1.4 ? v sysclk (system clock) 2 0 ? 25 mhz t sysh (sysclk high time) 18 ? ? ns t sysl (sysclk low time) 18 ? ? ns specified operating temperature range ?40 ? +85 c notes: 1. based on device characterization data; not production tested. 2. sysclk must be at least 32 khz to enable debugging. 3. the values in this table are obtained with the cpu executing an ?sjm p $? loop, which is the compiled form of a while(1) loop in c. see the power measurement code examples for more information. 4. includes oscillator and regulator supply current.
c8051f97x rev 1.0 11 electrical characteristics digital supply current?cpu active (normal mode, fetching instructions from flash) i dd 3 , 4 v dd = 1.8?3.6 v, freq = 24.5 mhz (includes preci - sion oscillator current) ? 5 6 ma v dd = 1.8?3.6 v, freq = 20 mhz (includes low power oscillator current) ? 4 ? ma v dd = 1.8 v, freq = 1 mhz (includes external cmos oscillator / gpio current) ? 420 ? a v dd = 3.6 v, freq = 1 mhz (includes external cmos oscillator / gpio current) ? 440 ? a v dd = 1.8?3.6 v, freq = 32.768 khz (includes rtc current) ? 95 ? a i dd frequency sensitivity 1, 3, v dd = 1.8-3.6 v, t = 25 c, freq < 14 mhz (flash oneshot active) ? 230 ? a/mhz v dd = 1.8-3.6 v, t = 25 c, freq > 14 mhz (flash oneshot bypassed) ? 130 ? a/mhz table 1.2. global electrical characteristics (continued) ?40 to +85 c, 25 mhz system cl ock unless otherwise specified. parameter conditions min typ max units notes: 1. based on device characterization data; not production tested. 2. sysclk must be at least 32 khz to enable debugging. 3. the values in this table are obtained with the cpu executing an ?sjm p $? loop, which is the compiled form of a while(1) loop in c. see the power measurement code examples for more information. 4. includes oscillator and regulator supply current.
c8051f97x 12 rev 1.0 electrical characteristics digital supply current?cpu inactive (idle mode , not fetching instructions from flash) i dd 4 v dd = 1.8?3.6 v, freq = 24.5 mhz (includes preci - sion oscillator current) ? 3.3 4.5 ma v dd = 1.8?3.6 v, freq = 20 mhz (includes low power oscillator current) ? 2.5 ? ma v dd = 1.8?3.6 v, freq = 32.768 khz (includes rtc current) ? 90 ? a i dd frequency sensitivity 1 v dd = 1.8-3.6 v, t = 25 c ? 110 ? a/mhz table 1.2. global electrical characteristics (continued) ?40 to +85 c, 25 mhz system cl ock unless otherwise specified. parameter conditions min typ max units notes: 1. based on device characterization data; not production tested. 2. sysclk must be at least 32 khz to enable debugging. 3. the values in this table are obtained with the cpu executing an ?sjm p $? loop, which is the compiled form of a while(1) loop in c. see the power measurement code examples for more information. 4. includes oscillator and regulator supply current.
c8051f97x rev 1.0 13 electrical characteristics digital supply current?suspend and sleep mode digital supply current ? (suspend mode) v dd = 1.8?3.6 v ? 80 ? a digital supply current ? (sleep mode, rtc 32 khz crystal running, includes rtc and ? vddmon) v dd = 1.8 v, t = 25 c ? 0.6 ? a v dd = 3.3 v, t = 25 c ? 0.7 ? a v dd = 3.6 v, t = 25 c ? 0.8 ? a v dd = 1.8 v, t = 85 c ? 1 ? a v dd = 3.3 v, t = 85 c ? 1.3 ? a v dd = 3.6 v, t = 85 c ? 1.5 ? a digital supply current (sleep mode, rtc int lfo running, includes rtc and vddmon) v dd = 1.8 v, t = 25 c ? 0.28 ? a digital supply current ? (sleep mode, includes vddmon) v dd = 1.8 v, t = 25 c ? 0.05 ? a v dd = 3.3 v, t = 25 c ? 0.06 ? a v dd = 3.6 v, t = 25 c ? 0.11 ? a v dd = 1.8 v, t = 85 c ? 0.8 ? a v dd = 3.3 v, t = 85 c ? 0.9 ? a v dd = 3.6 v, t = 85 c ? 1.0 ? a table 1.2. global electrical characteristics (continued) ?40 to +85 c, 25 mhz system cl ock unless otherwise specified. parameter conditions min typ max units notes: 1. based on device characterization data; not production tested. 2. sysclk must be at least 32 khz to enable debugging. 3. the values in this table are obtained with the cpu executing an ?sjm p $? loop, which is the compiled form of a while(1) loop in c. see the power measurement code examples for more information. 4. includes oscillator and regulator supply current.
c8051f97x 14 rev 1.0 electrical characteristics table 1.3. port i/o dc electrical characteristics v dd = 1.8 to 3.6 v, ?40 to +85 c unless otherwise specified. parameter conditions min typ max units output high voltage ? (high drive strength, ? pndrv.n = 1) i oh = ?3 ma, port i/o push-pull v dd ? 0.7 ? ? v i oh = ?10 a v dd ? 0.1 ? ? v i oh = ?10 ma ? see chart ? output high voltage ? (low drive strength, ? pndrv.n = 0) i oh = ?1 ma v dd ? 0.7 ? ? v i oh = ?10 a v dd ? 0.1 ? ? v i oh = ?3 ma ? see chart ? v output low voltage ? (high drive strength, ? pndrv.n = 1) i ol = 8.5 ma ? ? 0.7 v i ol = 25 ma ? see chart ? v output low voltage ? (low drive strength, ? pndrv.n = 0) i ol = 1.4 ma ? ? 0.7 v i ol = 4 ma ? see chart ? v input high voltage v dd = 2.0 to 3.6 v v dd ? 0.6 ? ? v input low voltage v dd = 2.0 to 3.6 v ? ? 0.6 v input leakage current weak pull?up off ? ? 0.5 a weak pull-up on, v in =0 v, v dd = 1.8 v ? 4 ? a weak pull-up on, v in = 0 v, v dd = 3.6 v ? 23 ? a table 1.4. i 2 c slave electrical characteristics parameter condition min typ max units v dd range required to meet i 2 c spec 1.8 ? 3.6 v internal i 2 c pull-ups required to meet i 2 c spec ? 6 ? k ? note: stresses above those listed under ?absolute maximum ratings ? may cause permanent damage to the device. this is a stress rating only and functional operation of the devices at those or any other conditions above those indicated in the operation listings of this specification is not implied. exposure to maximum rati ng conditions for extended periods may affect device reliability.
c8051f97x rev 1.0 15 electrical characteristics figure 1.1. typical voh curves, 1.8?3.6 v
c8051f97x 16 rev 1.0 electrical characteristics figure 1.2. typical vol curves, 1.8?3.6 v
c8051f97x rev 1.0 17 electrical characteristics table 1.5. reset electrical characteristics v dd = 1.8 to 3.6 v, ?40 to +85 c unless otherwise specified. parameter conditions min typ max unit rst output low voltage i ol = 1.4 ma ? 0.1 ? v rst input high voltage v dd = 2.0 to 3.6 v v dd ? 0.6 ? ? v rst input low voltage v dd = 2.0 to 3.6 v ? ? 0.6 v rst input pull-up current rst = 0 v, v dd = 3.6 v ? 22 ? a vdd monitor threshold (v rst ) early warning ? 1.85 ? v vdd monitor threshold (v rst ) reset trigger (all modes ex. sleep) ? 1.75 ? v por monitor threshold (v por ) initial power-on ? 1.6 ? v por monitor threshold (v por ) brownout condition ? 1.6 ? v por monitor threshold (v por ) recovery from brownout ? 1.0 ? v missing clock detector ? timeout time from last system clock rising edge to reset initiation 100 650 1000 s minimum sys clock with missing clock detector enabled system clock frequency which triggers a missing clock detector timeout ? 7 ? khz reset time delay delay between release of any reset source and code execution at location 0x0000 ? ? 30 s minimum rst low time to gen - erate system reset ? 15 ? s vdd monitor turn-on time ? 300 ? ns vdd monitor supply current ? 20 ? a
c8051f97x 18 rev 1.0 electrical characteristics table 1.6. power management electrical specifications v dd = 1.8 to 3.6 v, ?40 to +85 c unless otherwise specified. parameter conditions min typ max units idle mode wake-up time 2 ? 3 sysclks suspend mode wake-up time low power oscillator ? 400 ? ns precision oscillator ? 1.3 ? s sleep mode wake-up time ? 2 ? s table 1.7. flash electrical characteristics v dd = 1.8 to 3.6 v, ?40 to +85 c unless otherwise specified. parameter conditions min typ max units flash size see ordering information for flash sizes of all c8051f97x devices 16384 ? 32768 bytes endurance 20k 100k ? erase cycle time 20 30 40 ms write cycle time 50 60 70 s table 1.8. internal precision oscillator electrical characteristics v dd = 1.8 to 3.6 v; t a = ?40 to +85 c unless otherwise specified; us ing factory-calibrated settings. parameter conditions min typ max units oscillator frequency ?40 to +85 c, v dd = 1.8?3.6 v 24 24.5 25 mhz oscillator supply current ? (from v dd ) 25 c; includes bias current of 90?100 a ?300? a table 1.9. internal low-power oscillator electrical characteristics v dd = 1.8 to 3.6 v; t a = ?40 to +85 c unless otherwise specified; us ing factory-calibrated settings. parameter conditions min typ max units oscillator frequency (low power oscillator) ?40 to +85 c, v dd = 1.8?3.6 v 18 20 22 mhz oscillator supply current ? (from v dd ) 25 c no separate bias current required ?100? a table 1.10. smartclock characteristics v dd = 1.8 to 3.6 v; t a = ?40 to +85 c unless otherwise specified; us ing factory-calibrated settings. parameter conditions min typ max units oscillator frequency (lfo) 11 16.4 22 khz
c8051f97x rev 1.0 19 electrical characteristics table 1.11. adc0 electrical characteristics v dd = 1.8 to 3.6 v v, vref = 1.65 v (refsl[1:0] = 11), ? 40 to +85 c unless otherwise specified. parameter conditions min typ max units dc accuracy resolution 10 bits integral nonlinearity ? 0.5 1 lsb differential nonlinearity (guaranteed monotonic) ? 0.5 1 lsb offset error ? <1 2 lsb full scale error ? 1 2.5 lsb dynamic performance (10 khz sine-wave single-ended input, 1 db below full scale, 300 ksps) signal-to-noise plus distortion 62 65 ? db signal-to-distortion ? 70 ? db spurious-free dynamic range ? 72 ? db conversion rate sar conversion clock ? ? 8.33 mhz conversion time in sar clocks 10-bit mode 8-bit mode 13 11 ? ? ? ? clocks track/hold acquisition time 1.5 ? ? s throughput rate ? ? 300 ksps analog inputs adc input voltage range single ended (ain+ ? gnd) 0 ? vref v absolute pin voltage with respect to gnd single ended 0 ? v dd v sampling capacitance 1x gain 0.5x gain ? ? 28 26 ? ? pf input multiplexer impedance ? 5 ? k ? power specifications power supply current ? (v dd supplied to adc0) conversion mode (300 ksps) tracking mode (0 ksps) ? ? 800 680 ? ? a power supply rejection external vref ? 76 ? db
c8051f97x 20 rev 1.0 electrical characteristics table 1.12. temperature electrical characteristics parameter condition min typ max units linearity ? + 1 ? c slope ? 3.4 ? mv/c slope error ? 40 ? v/c offset te m p = 2 5 c ? 1025 ? mv offset error te m p = 2 5 c ? 18 ? mv supply current ? 35 ? a table 1.13. voltage reference electrical characteristics v dd = 1.8 to 3.6 v, ? 40 to +85 c unless otherwise specified. parameter conditions min typ max units internal high-speed reference (refsl[1:0] = 11) output voltage ?40 to +85 c, v dd = 1.8?3.6 v 1.60 1.65 1.70 v supply current normal power mode low power mode ? ? 250 140 ? ? a external reference (ref sl[1:0] = 00, refoe = 0) input voltage range 0 ? v dd v input current fs = 300 ksps; vref = 3.0 v ? 5.25 ? a table 1.14. cs0 electrical characteristics v dd = 1.8 to 3.6 v; t a = ?40 to +85 c unless otherwise specified. parameter conditions min typ max units single conversion time * 12-bit mode 13-bit mode (default) 14-bit mode 16-bit mode 20 21 23 26 25 27 29 33 40 42.5 45 50 s power supply current ? 55 80 a *note: conversion time is specifi ed with the default configuration.
c8051f97x rev 1.0 21 electrical characteristics 1.2. thermal conditions 1.3. absolute maximum ratings stresses above t hose listed under table 1.16 may cause permanent damage to the device. this is a stress rating only and functional operation of the de vices at those or any other conditions above those indicated in the operation listings of this specification is not im plied. exposure to maximum rating condit ions for extended periods may affect device reliability. for more information on the available quality and reliability data, see the qua lity and reliability monitor report at http://www.silabs.com/suppor t/quality/pages/default.aspx . table 1.15. thermal characteristics parameter symbol conditions min typ max units thermal resistance ? junction to ambient ? ja still air, qfn 48 still air, qfn 32 still air, qfn 24 ? ? ? 82 40.4 59.5 ? ? ? c/w thermal resistance ? junction to case ? jc still air, qfn 48 still air, qfn 32 still air, qfn 24 ? ? ? 11.5 16.8 22.7 ? ? ? c/w table 1.16. absolute maximum limits parameter conditions min typ max units ambient temperature under bias ?55 ? 125 c storage temperature ?65 ? 150 c voltage on any port i/o pin or rst with respect to gnd ?0.3 ? v dd + 0.3 v voltage on v dd with respect to gnd ?0.3 ? 4.0 v maximum total current through v dd or gnd ?? 500ma maximum current through rst or any port pin ?? 100ma maximum total current through all port pins ?? 200ma note: exposure to maximum rating conditions for extended periods may affect device reliability.
c8051f97x 22 rev 1.0 system overview 2. system overview the c8051f97x device family are fully integrated, mixed-si gnal system-on-a-chip mcus. highlighted features are listed below. refer to table 4.1 for specific pr oduct feature selection and part ordering numbers. ?? core: ?? pipelined cip-51 core ?? fully compatible with standard 8051 instruction set ?? 70% of instructions execute in 1-2 clock cycles ?? 25 mhz maximum operating frequency ?? memory: ?? 16-32 kb flash; in-system programmable in 512-byte sectors ?? 4352-8448 bytes ram (including 256 bytes standard 8051 ram and 4-8 kb on-chip xram) ?? power: ?? ultra low power consumption in active and sleep modes. ?? power-on reset circuit and brownout detectors ?? capacitive sensing: ?? supports button and slider elements ?? 40 us/channel conversion time ?? 16-bit resolution ?? auto scan and wake-on-touch ?? auto-accumulate up to 64 samples ?? i/o: ?? up to 43 total multifunction i/o pins: ?? flexible peripheral crossbar for peripheral routing ?? clock sources: ?? precision internal oscillator: 24.5 mhz 2% ?? low power oscillator: 20 mhz 20% ?? low-frequency internal oscillator: 16.4 khz ?? external crystal, rc, c, and cmos options ?? timers/counters and pwm: ?? 3-channel programmable counter array (pca) supporting pwm, capture/compare, fr equency output modes, and watchdog timer function ?? 4x 16-bit general-purpose timers ?? communications and other digital peripherals: ?? uart ?? spi ? ?? i 2 c / smbus ? ?? high-speed i 2 c slave ?? 16-bit crc unit, supporting automatic crc of flash at 256-byte boundaries ?? analog: ?? 10-bit analog-to-digital c onverter (adc) (300 ksps) ?? digital: ?? 7-channel dma ?? 16 x 16 multiply and accumulate hardware ?? unique identifier: ?? 128-bit unique key for each device ?? on-chip debugging with on-chip power-on reset, voltage su pply monitor, watchdog timer, and cl ock oscillator, the c8051f97x devices are truly standalone system-on-a-chip solutions. the flas h memory is re-programmable in-circuit, providing non- volatile data storage and allowing field upgrades of the firmware.
c8051f97x rev 1.0 23 system overview the on-chip debugging interface (c2) allows non-intrus ive (uses no on-chip resources), full speed, in-circuit debugging using the production mcu installed in the final application. this debug logic supports inspection and modification of memory and registers, setting breakpoints, single stepping, and run and halt commands. all analog and digital peripherals are fully functional while debugging. each device is specified for 1.8 to 3. 6 v operation, and are available in 48-pin qfn, 32-pin qfn, or 24-pin qfn packages. all package options are lead-free and rohs co mpliant. the device is available in two temperature grades: -40 to +85 c. see table 4.1 for ordering info rmation. a block diagram is included in figure 2.1. figure 2.1. c8051f97x family block diagram (qfn-48 shown) port 1 drivers p1.0/xtal1 p1.1/xtal2 p1.2 p1.3 p1.4 p1.5 p1.6 p1.7 port 2 drivers port 3 drivers cip-51 8051 controller core vdd power on reset reset c2ck/rst gnd vreg analog power p2.0 p2.1 p2.2 p2.3 p2.4 p2.5 p2.6 p2.7 p3.0 p3.1 p3.2 p3.3 p3.4 p3.5 p3.6 p3.7 dma reset controller power management unit 16-32 kb isp flash program memory sfr bus port 4 drivers p4.0 p4.1 p4,2 p4.3 p4.4 p4.5 p4.6 p4.7 port 5 drivers p5.0 p5.1 p5.2 port 0 drivers p6.0/scl p6.1/sda p0.2 p0.3 p0.4 p0.5 p0.6/xtal3/cnvstr p0.7/xtal4 mac system clock configuration low-power 20 mhz oscillator precision 24.5 mhz oscillator external oscillator circuit smartclock clock gen ... sysclk pclk[0] pclk[1] pclk[2] pclk[n] debug/ programming hardware c2d digital power digital peripherals pca/wdt timers 0,1,2,3 spi i2c / smbus uart priority crossbar decoder high-speed i2c slave p0.0/vref p0.1 port 6 drivers crc engine 256 byte sram 4-8 kb xram crossbar control analog peripherals capacitance to digital converter 10-bit 300 ksps adc temp sensor vdd vdd vref gnd amux0
c8051f97x 24 rev 1.0 system overview 2.1. power 2.1.1. voltage supply monitor (vmon0) the c8051f97x devices include a voltage supply monitor which allows devices to function in known, safe operating condition without the need for external hardware. the supply monitor module includes the following features: ?? holds the device in reset if the main v dd supply drops below the vdd reset threshold. 2.1.2. device power modes the c8051f97x devices feature seven low power modes in addition to normal operating mode, allowing the designer to save power when the core is not in use. all power modes are detailed in table 2.1. table 2.1. power modes power mode description wake-up sources power and performance normal active device fully functional. n/a excellent mips/mw low power active device fully functional except peripherals whose clocks are intentionally disabled. n/a excellent. clocks only enabled for peripher - als that request for it. idle all peripherals fully functional. wake-up in 2 clock cycles. any interrupt good no code execution low power idle similar to idle mode, the cpu is halted. clocks of unused peripher - als can be intentionally gated. wake-up in 2 clock cycles. any interrupt very good no code execution. clocks only enabled for peripher - als that request for it. stop legacy 8051 low power mode. a reset is required to wake up. any reset good no code execution precision oscillator disabled suspend similar to stop mode, but very fast wake-up time and code resumes execution at the next instruction. cs0, smartclock, port match, i 2 c slave, rst pin very good no code execution all internal oscillators disabled system clock gated sleep ultra low power and flexible wake-up sources. code resumes execution at the ne xt instruction. smartclock, port match, i 2 c slave, rst pin excellent power supply gated all oscillators except smartclock disabled
c8051f97x rev 1.0 25 system overview 2.1.2.1. normal mode normal mode encompasses the typical fu ll-speed operation. the power consumpt ion of the device in this mode will vary depending on the system clock speed and any analog peripherals that are enabled. 2.1.2.2. idle mode setting the idle bit in pcon causes the hardware to hal t the cpu and enter idle mode as soon as the instruction that sets the bit completes execution. all internal regist ers and memory maintain their original data. all analog and digital peripherals can remain active during idle mode. idle mode is terminated when an enabled interrupt is asserted or a reset occurs. the assertion of an enabled interrupt will cause the idle bit to be cleared and the cpu to resume operation. the pending interrupt will be serviced and the next instruction to be executed after the retu rn from interrupt (reti) will be the instruction immediately following the one that set the idle mode select bit. if idle mode is terminated by an internal or external reset, the cip-51 performs a normal reset sequence and begins program execution at address 0x0000. 2.1.2.3. stop mode setting the stop mode select bit in the pcon register causes the core to enter stop mode as soon as the instruction that sets the bit complete s execution. in stop mode, the prec ision internal osc illator and cpu are stopped; the state of the low power os cillator and the exte rnal oscillator circuit is not affected. each analog peripheral (including the external oscillator circuit) may be shut down individually prio r to entering st op mode. stop mode can only be terminated by an internal or external reset. on reset, the cip-51 performs the normal reset sequence and begins program execution at address 0x0000. 2.1.3. suspend mode setting the suspend mode select bit in the pmu0cf regi ster causes the system clock to be gated off and all internal oscillators disabled. all digital logic (tim ers, communication peripherals, interrupts, cpu, etc.) stops functioning until one of the enabled wake-up sources occurs. the following wake-up sources can be configured to wake the device from suspend mode: ?? smartclock oscillator fail ?? smartclock alarm ?? port match event ?? i2c0 address match ?? cs0 end-of-conversion or end-of-scan 2.1.4. sleep mode setting the sleep mode select bit in the pmu0cf regist er turns off the internal 1.8 v regulator (vreg0) and switches the power supply of all on-chip ram to the v dd pin. power to most digi tal logic on the chip is disconnected; only pmu0 and the smartclock remain powered. all analog peripherals (adc0, external oscillator, etc.) should be disa bled prior to entering sleep mode. ram and sfr register contents are preserved in sleep mode as long as the voltage on vdd does not fall below vpor. the pc counter and all other volatile state inform ation is preserved allowing the device to resume code execution upon waking up from sleep mode. the following wake-up sources can be configured to wake the device from sleep mode: ?? smartclock oscillator fail ?? smartclock alarm ?? port match event ?? i2c0 address match
c8051f97x 26 rev 1.0 system overview 2.1.5. low power active mode running in normal active mode can waste a significant amo unt of amount of power by clocking unused peripherals. low power active mode in c8051f97x de vices allows control of clocking acti vity in the clock tree, which enables firmware to shut off clocking to unused peripherals and save power. the cpu and all the analog and digital peripherals remain active except those whose clocks are turned off by firmware. the cp u will not be able to access sfr of peripherals on inactive branches of the clock tree. low power active mode is terminated when the clkmode r egister is programmed to 0x00 or a reset occurs. systems that use all the peripherals and always stay in the active mode may not find improvement in power consumption in the low power active mode due overhead logic required for this implementation. 2.1.6. low power idle mode in this mode of operation, the cpu is halted and clocks supplied to unused peripherals can be shut down to save power. all internal registers and memory maintain their or iginal data. all the analog and digital peripherals remain active except those whose clocks are turned off by user. modules that are capable of requesting for clocks can do so at any time. low power idle mode is termin ated when an enabled interrupt is asserted or a reset occurs, but the interrupt only causes the device to switch from low power idle mode to low power active mode. to return to normal active mode, the clkmode register should be reset to 0x00. the pendi ng interrupt will be serviced and the next instruction to be executed after the return from interrupt (r eti) will be the instruction immediat ely following the one that set the idle mode select bit. if low power id le mode is terminated by an internal or external reset, the cip-51 performs a normal sequence and begins progra m execution at address 0x0000. 2.2. i/o 2.2.1. general features the c8051f97x ports have the following features: ?? push-pull or open-drain output modes and analog or digital modes. ?? port match allows the device to recognize a change on a port pin value and wake from idle mode or generate an interrupt. ?? internal pull-up resistors can be globally enabled or disabled. ?? two external interrupts provide unique interrup t vectors for monitoring time-critical events. 2.2.2. crossbar the c8051f97x devices have a digital peripheral crossbar with the following features: ?? flexible peripheral assignment to port pins. ?? pins can be individually skipped to move peripherals as needed for design or layout considerations. the crossbar has a fixed priority for each i/o function and assigns these functions to the port pins. when a digital resource is selected, the least-significant unassigned port pi n is assigned to that resource. if a port pin is assigned, the crossbar skips that pin wh en assigning the next select ed resource. additionally, th e crossbar will skip port pins whose associated bits in the pnskip regi sters are set. this provides some flexibility when designing a system: pins involved with sensitive analog measurements can be move d away from digital i/o and peripherals can be moved around the chip as needed to ease layout constraints.
c8051f97x rev 1.0 27 system overview 2.3. clocking the c8051f97x devices have th ree internal oscillators and the option to use an extern al crystal, rc, c, or cmos oscillator as the system clock. a prog rammable divider allows t he user to internally r un the system clock at a slower rate than the sele cted oscillator if desired. 2.4. counters/timers and pwm 2.4.1. programmable counter array (pca0) the c8051f97x devices include a three-channel, 16-bit programmable counter array with the following features: ?? 16-bit time base. ?? programmable clock divisor and clock source selection. ?? three independently-configurable channels. ?? 8, 9, 10, 11 and 16-bit pwm modes (edge-aligned operation). ?? output polarity control. ?? frequency output mode. ?? capture on rising, falling or any edge. ?? compare function for arbitrary waveform generation. ?? software timer (internal compare) mode. ?? module 2 acts as a watchdog timer. 2.4.2. timers (timer 0, ti mer 1, timer 2, and timer 3) timers include the following features: ?? timer 0 and timer 1 are standard 8051 timers, supp orting backwards-compati bility with firmware and hardware. ?? timer 2 and timer 3 can each operate as 16-bit auto-reload or two independent 8-bit auto-reload timers, and include comparator 0 or smartclock clo ck capture ca pabilities.
c8051f97x 28 rev 1.0 system overview 2.5. communications and other digital peripherals 2.5.1. universal asynchronous receiver/transmitter (uart0) the uart uses two signals (tx and rx) and a predet ermined fixed baud rate to provide asynchronous communications with other devices. the uart module provides the following features: ?? asynchronous transmissions and receptions. ?? baud rates up to sysclk / 2 (tra nsmit) or sysclk / 8 (receive). ?? 8 or 9 bit data. ?? automatic start and stop generation. 2.5.2. serial peripheral interface (spi0) spi is a 3- or 4-wire communication in terface that includes a clock, input da ta, output data, and an optional select signal. the spi module includes the following features: ?? supports 3- or 4-wire master or slave modes. ?? supports external clock fr equencies up to sysclk / 2 in master mode and sysclk / 10 in slave mode. ?? support for all clock phase and polarity modes. ?? 8-bit programmable clock rate. ?? support for multiple masters on the same data lines. 2.5.3. system management bus / i2c (smbus0) the smbus interface is a two-wire, bidi rectional serial bus compatible with both i2c and smbus protocols. the two clock and data signals operate in open-drain mode with external pull-ups to support automatic bus arbitration. reads and writes to the interface are byte oriented with the sm bus interface autonomously controlling the serial transfer of the data. data can be transferred at up to 1/ 8th of the system clock as a master or slave, which can be faster than allowed by the smbus / i2 c specification, dep ending on the clock source used. a method of extending the clock-low duration is available to accommodate devices with different speed capabilities on the same bus. the smbus interface may operate as a master and/or slave, and may function on a bus with multiple masters. the smbus provides control of sda (serial data), scl (serial clock) generation and synchronization, arbitration logic, and start/stop control and generation. the smbus module includes the following features: ?? standard (up to 100 kbps) and fast (400 kbps) transfer speeds. ?? support for master, slave, and multi-master modes. ?? hardware synchronization and arbitration for multi-master mode. ?? clock low extending (clock stretching) to interface with faster masters. ?? hardware support for 7-bit slave and general call address recognition. ?? firmware support for 10-bit slave address decoding. ?? ability to inhibit all slave states. ?? programmable data setup/hold times.
c8051f97x rev 1.0 29 system overview 2.5.4. high-speed i2c slave (i2cslave0) the i2c slave 0 interface is a 2-wire, bidirecti onal serial bus that is compatible with the i 2 c bus specification 3.0. it is capable of transferring in high-speed mode (hs-mode) at speeds of up to 3.4 mbps. either the cpu or the dma can write to the i 2 c interface, and the i 2 c interface can autonomous ly control the serial transfer of data. the interface also supports clock stretchi ng for cases where the cpu may be temporarily prohibited from transmitting a byte or processing a received byte during an i 2 c transaction. it can also operate in sleep mode without an active system clock and wake the cpu when a matching slave address is received. it operates only as an i 2 c slave device. the i2cslave0 peripheral pr ovides control of the scl (serial clock) synchronization, sda (serial data), scl clock stretching, i 2 c arbitration logic, and low power mode operation. the i2c slave 0 module includes the following features: ?? high-speed (up to 3.4 mbps), fast (400 kbps), and standard (up to 100 kbps) transfer speeds. ?? support for slave mode only. ?? clock low extending (clock stretching) to interface with faster masters. ?? hardware support for 7-bit slave and general call address recognition. ?? can operate in sleep mode without an active system clock and wake the cpu after receiving a matching slave address. ?? internal pull-up resistors. 2.5.5. 16/32-bit crc (crc0) the crc module is designed to provide hardware calculat ions for flash memory verification and communications protocols. the crc module supports the standard ccitt-16 16-bit polynomial (0x1021), and includes the following features: ?? support for four ccitt-16 polynomial. ?? byte-level bit reversal. ?? automatic crc of flash contents on one or more 256-byte blocks. ?? initial seed selection of 0x0000 or 0xffff. 2.6. analog peripherals 2.6.1. 10-bit analog-to-digital converter (adc0) the adc0 module on c8051f97x devices is a successiv e approximation register (sar) analog to digital converter (adc). the key features of the adc module are: ?? single-ended 10-bit mode. ?? supports an output update rate of 300 ksps samples per second. ?? selectable asynchronous hardware conversion trigger. ?? output data window comparator allows automatic range checking. ?? support for burst mode, which produces one set of accumulated data per conversion-start trigger with programmable power-on settling and tracking time. ?? conversion complete and window compare interrupts supported. ?? flexible output data formatting. ?? includes an internal 1.65 v fast-settling reference with two levels and support for an external reference.
c8051f97x 30 rev 1.0 system overview 2.7. digital peripherals 2.7.1. direct memory access (dma0) the dma0 module on c8051f97x devices enables autonomous data movement between xram and select peripherals. the key features of the dma module are: ?? supports 7 channels. ?? separate full-length and mid-point transfer interrupts for each channel. ?? options for big or little endian transfers. ?? directly supports the i2c slave 0 and mac0 modules. 2.7.2. multiply and accumulate (mac0) the c8051f97x devices include a multiply and accumulate engine which can be used to speed up many mathematical operations. the mac0 mo dule has the following key features: ?? single cycle operation. ?? multiply-accumulate or multiply only. ?? support for integer or fractional operations. ?? support for signed or unsigned operations. ?? rounding with saturation. ?? auto-increment or constant a and/or b registers. ?? logical 1-bit or multiple bit shif t of accumulator left or right. ?? negation of accumulator, a, and/or b registers. ?? dma support for repetitive operations on large arrays of data. ?? signed and unsigned alignment (right shift in bytes) of accumulator result. 2.8. reset sources reset circuitry allows the cont roller to be easily placed in a predefined default condition. on entry to this reset state, the following occur: ?? the core halts program execution. ?? module registers are initialized to their defined reset values unless the bits reset only with a power-on reset. ?? external port pins are forced to a known state. ?? interrupts and timers are disabled. all registers are reset to the predefined values noted in the register descriptions unless the bits only reset with a power-on reset. the contents of ram are unaffected during a reset; any previously stored data is preserved as long as power is not lost. the port i/o latches are reset to 1 in open-drain mode. weak pullups are enabled during and after the reset. for vdd supply monitor resets, the rst pin is driven low until the device exits the reset state. on exit from the reset state, the program counter (pc) is reset, the system clock defaults to the internal low-power oscillator, and the watchdog timer is enabled. program execution begin s at location 0x0000. 2.9. unique identifier each device contains a 128-bit unique identifier (uid) at the last 16 bytes of xram. this value is reloaded after each device reset, and firmware can overwrite the memory area during operation, if desired. 2.10. on-chip debugging the c8051f97x devices include an on-c hip silicon labs 2-wire (c2) debug interface to allow flash programming and in-system debugging with the production part installed in the end application. the c2 interface uses a clock signal (c2ck) and a bidirectional c2 data signal (c2d) to transfer information between the device and a host sys- tem. see the c2 interface specification for details on the c2 protocol.
c8051f97x rev 1.0 31 pin definitions 3. pin definitions 3.1. c8051f970/3 qf n-48 pin definitions figure 3.1. c8051f970/3-a-gm (qfn-48) pinout 48 pin qfn (top view) p0.5 p6.0 p6.1 p0.6 gnd 48 47 46 45 44 43 p1.0 p0.7 p0.3 p0.2 p0.1 p0.0 c2d / p5.2 p0.4 1 2 3 4 5 6 7 13 14 15 p4.4 p4.3 p4.2 p4.1 p2.0 p2.1 vdd gnd p2.2 p2.3 36 35 34 33 32 31 p2.4 30 42 p1.1 8 29 41 rst / c2ck p5.1 p1.7 p1.2 p5.0 p4.7 9 10 11 12 p4.6 p4.5 16 17 18 p3.7 p4.0 19 p3.6 20 p3.5 21 22 p3.3 p3.4 23 p3.2 24 p3.1 40 39 p1.4 p1.3 38 p1.5 37 p1.6 p2.5 p2.6 p2.7 28 27 p3.0 26 25
c8051f97x 32 rev 1.0 pin definitions table 3.1. pin definitions for c8051f970/3-a-gm (qfn-48) pin name type pin numbers crossbar capability additional digital functions analog functions gnd ground 32 vdd power 33 rst / c2ck active-low reset / c2 debug clock 7 p0.0 standard i/o 5 yes p0mat.0 int0.0 int1.0 adc0.0 cs0.0 vref p0.1 standard i/o 4 yes p0mat.1 int0.1 int1.1 adc0.1 cs0.1 p0.2 standard i/o 3 yes p0mat.2 int0.2 int1.2 adc0.2 cs0.2 p0.3 standard i/o 2 yes p0mat.3 int0.3 int1.3 adc0.3 cs0.3 p0.4 standard i/o 1 yes p0mat.4 int0.4 int1.4 adc0.4 cs0.4 p0.5 standard i/o 48 yes p0mat.5 int0.5 int1.5 adc0.5 cs0.5 p0.6 standard i/o smartclock input 45 yes p0mat.6 int0.6 int1.6 cnvstr adc0.6 cs0.6 xtal3 p0.7 standard i/o smartclock input 44 yes p0mat.7 int0.7 int1.7 adc0.7 cs0.7 xtal4 p1.0 standard i/o external oscillator input 43 yes p1mat.0 adc0.8 cs0.8 xtal1 p1.1 standard i/o external oscillator input 42 yes p1mat.1 adc0.9 cs0.9 xtal2
c8051f97x rev 1.0 33 pin definitions p1.2 standard i/o 41 yes p1mat.2 adc0.10 cs0.10 p1.3 standard i/o 40 yes p1mat.3 adc0.11 cs0.11 p1.4 standard i/o 39 yes p1mat.4 adc0.12 cs0.12 p1.5 standard i/o 38 yes p1mat.5 adc0.13 cs0.13 p1.6 standard i/o 37 yes p1mat.6 adc0.14 cs0.14 p1.7 standard i/o 36 yes p1mat.7 adc0.15 cs0.15 p2.0 standard i/o 35 yes p2mat.0 adc0.16 cs0.16 p2.1 standard i/o 34 yes p2mat.1 adc0.17 cs0.17 p2.2 standard i/o 31 yes p2mat.2 adc0.18 cs0.18 p2.3 standard i/o 30 yes p2mat.3 adc0.19 cs0.19 p2.4 standard i/o 29 yes p2mat.4 adc0.20 cs0.20 p2.5 standard i/o 28 yes p2mat.5 adc0.21 cs0.21 p2.6 standard i/o 27 yes p2mat.6 adc0.22 cs0.22 p2.7 standard i/o 26 yes p2mat.7 adc0.23 cs0.23 p3.0 standard i/o 25 adc0.24 cs0.24 p3.1 standard i/o 24 adc0.25 cs0.25 p3.2 standard i/o 23 adc0.26 cs0.26 table 3.1. pin definitions for c8051f970/3-a-gm (qfn-48) (continued) pin name type pin numbers crossbar capability additional digital functions analog functions
c8051f97x 34 rev 1.0 pin definitions p3.3 standard i/o 22 adc0.27 cs0.27 p3.4 standard i/o 21 adc0.28 cs0.28 p3.5 standard i/o 20 adc0.29 cs0.29 p3.6 standard i/o 19 adc0.30 cs0.30 p3.7 standard i/o 18 adc0.31 cs0.31 p4.0 standard i/o 17 adc0.32 cs0.32 p4.1 standard i/o 16 adc0.33 cs0.33 p4.2 standard i/o 15 adc0.34 cs0.34 p4.3 standard i/o 14 adc0.35 cs0.35 p4.4 standard i/o 13 adc0.36 cs0.36 p4.5 standard i/o 12 adc0.37 cs0.37 p4.6 standard i/o 11 adc0.38 cs0.38 p4.7 standard i/o 10 adc0.39 cs0.39 p5.0 standard i/o 9 adc0.40 cs0.40 p5.1 standard i/o 8 adc0.41 cs0.41 p5.2 / c2d standard i/o / c2 debug data 6 p6.0 standard i/o 47 i2cslave_scl p6.1 standard i/o 46 i2cslave_sda table 3.1. pin definitions for c8051f970/3-a-gm (qfn-48) (continued) pin name type pin numbers crossbar capability additional digital functions analog functions
c8051f97x rev 1.0 35 pin definitions 3.2. c8051f971/4 qf n-32 pin definitions figure 3.2. c8051f971/4-a-gm (qfn-32) pinout 32 pin qfn (top view) (with downbond) p0.2 p6.0 p6.1 p0.3 gnd 32 31 30 29 28 27 p0.5 p0.4 p0.0 c2d / p5.2 rst / c2ck p3.2 p3.1 p0.1 1 2 3 4 5 6 7 9 10 11 12 13 14 p2.6 p2.5 p2.4 p2.3 p2.1 p2.2 15 p2.0 p1.1 p1.2 vdd p1.3 p1.4 p1.5 24 23 22 21 20 19 p1.6 18 26 p0.6 8 16 17 25 p3.0 p2.7 p1.7 p1.0 p0.7
c8051f97x 36 rev 1.0 pin definitions table 3.2. pin definitions for c8051f971/4-a-gm (qfn-32) pin name type pin numbers crossbar capability additional digital functions analog functions gnd ground 32 vdd power 33 rst / c2ck active-low reset / c2 debug clock 7 p0.0 standard i/o 5 yes p0mat.0 int0.0 int1.0 adc0.0 cs0.0 vref p0.1 standard i/o 4 yes p0mat.1 int0.1 int1.1 adc0.1 cs0.1 p0.2 standard i/o 3 yes p0mat.2 int0.2 int1.2 adc0.2 cs0.2 p0.3 standard i/o 2 yes p0mat.3 int0.3 int1.3 adc0.3 cs0.3 p0.4 standard i/o 1 yes p0mat.4 int0.4 int1.4 adc0.4 cs0.4 p0.5 standard i/o 48 yes p0mat.5 int0.5 int1.5 adc0.5 cs0.5 p0.6 standard i/o smartclock input 45 yes p0mat.6 int0.6 int1.6 cnvstr adc0.6 cs0.6 xtal3 p0.7 standard i/o smartclock input 44 yes p0mat.7 int0.7 int1.7 adc0.7 cs0.7 xtal4 p1.0 standard i/o external oscillator input 43 yes p1mat.0 adc0.8 cs0.8 xtal1 p1.1 standard i/o external oscillator input 42 yes p1mat.1 adc0.9 cs0.9 xtal2 p1.2 standard i/o 41 yes p1mat.2 adc0.10 cs0.10
c8051f97x rev 1.0 37 pin definitions p1.3 standard i/o 40 yes p1mat.3 adc0.11 cs0.11 p1.4 standard i/o 39 yes p1mat.4 adc0.12 cs0.12 p1.5 standard i/o 38 yes p1mat.5 adc0.13 cs0.13 p1.6 standard i/o 37 yes p1mat.6 adc0.14 cs0.14 p1.7 standard i/o 36 yes p1mat.7 adc0.15 cs0.15 p2.0 standard i/o 35 yes p2mat.0 adc0.16 cs0.16 p2.1 standard i/o 34 yes p2mat.1 adc0.17 cs0.17 p2.2 standard i/o 31 yes p2mat.2 adc0.18 cs0.18 p2.3 standard i/o 30 yes p2mat.3 adc0.19 cs0.19 p2.4 standard i/o 29 yes p2mat.4 adc0.20 cs0.20 p2.5 standard i/o 28 yes p2mat.5 adc0.21 cs0.21 p2.6 standard i/o 27 yes p2mat.6 adc0.22 cs0.22 p2.7 standard i/o 26 yes p2mat.7 adc0.23 cs0.23 p3.0 standard i/o 25 adc0.24 cs0.24 p3.1 standard i/o 24 adc0.25 cs0.25 p3.2 standard i/o 23 adc0.26 cs0.26 p5.2 / c2d standard i/o / c2 debug data 6 p6.0 standard i/o 47 yes i2cslave_scl p6.1 standard i/o 46 yes i2cslave_sda table 3.2. pin definitions for c8051f971/4-a-gm (qfn-32) (continued) pin name type pin numbers crossbar capability additional digital functions analog functions
c8051f97x 38 rev 1.0 pin definitions 3.3. c8051f972/5 qf n-24 pin definitions figure 3.3. c8051f972/5-a-gm (qfn-24) pinout 24 pin qfn (top view) p0.0 c2d / p5.2 rst / c2ck p2.1 p2.0 p1.7 p1.6 p1.5 p1.4 p0.6 p0.7 vdd gnd p1.0 p1.1 p0.2 p6.0 p6.1 p0.3 gnd 1 2 3 4 5 6 7 8 9 10 11 12 18 17 16 15 14 13 24 23 22 21 20 19 p0.1 p0.5 p0.4 p1.2 p1.3
c8051f97x rev 1.0 39 pin definitions table 3.3. pin definitions for c8051f972/5-a-gm (qfn-24) pin name type pin numbers crossbar capability additional digital functions analog functions gnd ground 32 vdd power 33 rst / c2ck active-low reset / c2 debug clock 7 p0.0 standard i/o 5 yes p0mat.0 int0.0 int1.0 adc0.0 cs0.0 vref p0.1 standard i/o 4 yes p0mat.1 int0.1 int1.1 adc0.1 cs0.1 p0.2 standard i/o 3 yes p0mat.2 int0.2 int1.2 adc0.2 cs0.2 p0.3 standard i/o 2 yes p0mat.3 extclk int0.3 int1.3 adc0.3 cs0.3 p0.4 standard i/o 1 yes p0mat.4 int0.4 int1.4 adc0.4 cs0.4 p0.5 standard i/o 48 yes p0mat.5 int0.5 int1.5 adc0.5 cs0.5 p0.6 standard i/o 45 yes p0mat.6 int0.6 int1.6 cnvstr adc0.6 cs0.6 p0.7 standard i/o 44 yes p0mat.7 int0.7 int1.7 adc0.7 cs0.7 p1.0 standard i/o 43 yes p1mat.0 adc0.8 cs0.8 p1.1 standard i/o 42 yes p1mat.1 adc0.9 cs0.9
c8051f97x 40 rev 1.0 pin definitions p1.2 standard i/o 41 yes p1mat.2 adc0.10 cs0.10 p1.3 standard i/o 40 yes p1mat.3 adc0.11 cs0.11 p1.4 standard i/o 39 yes p1mat.4 adc0.12 cs0.12 p1.5 standard i/o 38 yes p1mat.5 adc0.13 cs0.13 p1.6 standard i/o 37 yes p1mat.6 adc0.14 cs0.14 p1.7 standard i/o 36 yes p1mat.7 adc0.15 cs0.15 p2.0 standard i/o 35 yes p2mat.0 adc0.16 cs0.16 p2.1 standard i/o 34 yes p2mat.1 adc0.17 cs0.17 p5.2 / c2d standard i/o / c2 debug data 6 p6.0 standard i/o 47 yes i2cslave_scl p6.1 standard i/o 46 yes i2cslave_sda table 3.3. pin definitions for c8051f972/5-a-gm (qfn-24) (continued) pin name type pin numbers crossbar capability additional digital functions analog functions
c8051f97x rev 1.0 41 ordering information 4. ordering information figure 4.1. c8051f97x part numbering all c8051f97x family members have the following features: ?? cip-51 core running up to 25 mhz ?? two internal oscillators (24.5 mhz and 80 khz) ?? i2c/smbus ?? spi ?? uart ?? 3-channel programmable counter array (pwm, clock generation, capture/compare) ?? 4 timers ?? capacitance-to-digital (cs0) module ?? real time clock ?? 16-bit crc unit in addition to these features, each part number in the c80 51f97x family has a set of features that vary across the product line. the product selection guide in table 4.1 shows the features available on each family member. c8051 f 970 ? a ? memory type ? f (flash) revision g m silicon labs 8051 family family and features ? 97x temperature grade g (-40 to +85) package type m (qfn)
c8051f97x 42 rev 1.0 ordering information table 4.1. product selection guide ordering part number flash memory (kb) ram (bytes) digital port i/os (total) number of adc0 channels pb-free (rohs compliant) temperature range package c8051f970-a-gm 32 8kb 43 43 ? ?40 to 85 c qfn-48 c8051f971-a-gm 32 8kb 28 28 ? ?40 to 85 c qfn-32 c8051f972-a-gm 32 8kb 19 19 ? ?40 to 85 c qfn-24 c8051f973-a-gm 16 4kb 43 43 ? ?40 to 85 c qfn-48 C8051F974-a-gm 16 4kb 28 28 ? ?40 to 85 c qfn-32 c8051f975-a-gm 16 4kb 19 19 ? ?40 to 85 c qfn-24
c8051f97x rev 1.0 43 qfn-48 packag e specifications 5. qfn-48 package specifications figure 5.1. qfn-48 package drawing (6x6 mm) table 5.1. qfn-48 package dimensions dimension min typ max dimension min typ max a 0.50 0.55 0.60 d2 3.35 3.50 3.65 a1 0.00 0.02 0.05 l 0.30 0.40 0.50 b 0.15 0.20 0.25 aaa 0.10 d 6.00 bsc bbb 0.07 d2 3.35 3.50 3.65 ccc 0.10 e 0.40 bsc ddd 0.05 e 6.00 bsc eee 0.08 notes: 1. all dimensions shown are in millim eters (mm) unless otherwise noted. 2. dimensioning and tolerancing per ansi y14.5m-1994. 3. this drawing conforms to jedec outline mo-220. 4. recommended card reflow profile is per the jede c/ipc j-std-020 specific ation for small body components.
c8051f97x 44 rev 1.0 qfn-48 package specifications figure 5.2. qfn-48 landing diagram table 5.2. qfn-48 landing diagram dimensions dimension max dimension max e 0.40 bsc x2 3.65 c1 5.90 y1 0.85 c2 5.90 y2 3.65 x1 0.20 notes: general 1. all dimensions shown are in millimeters (mm) unless otherwise noted. 2. dimension and tolerancing is per the ansi y14.5m-1994 specification. 3. this land pattern design is based on ipc-7351 guidelines. 4. all dimensions shown are at maximum material c ondition (mmc). least material condition (lmc) is calculated based on a fabricat ion allowance of 0.05 mm. solder mask design 5. all metal pads are to be non-solder mask defi ned (nsmd). clearance between the solder mask and the metal pad is to be 60 ? m minimum, all the way around the pad. stencil design 6. a stainless steel, laser-cut and electro-polished stenc il with trapezoidal walls should be used to assure good solder paste release. 7. the stencil thickness should be 0.125 mm (5 mils). 8. the ratio of stencil aperture to land pad size should be 1:1 for all perimeter pads. 9. a 3x3 array of 0.90 mm square openings on 1.15 mm pitch should be used for the center ground pad. card assembly 10. a no-clean, type-3 solder paste is recommended. 11. recommended card reflow profile is per the je dec/ipc j-std-020 specification for small body components.
c8051f97x rev 1.0 45 qfn-48 packag e specifications 5.1. qfn-48 package marking the first row of the package marking is the part number, including the revision. the second row is the 6-digit trace code indicating assembly information. the last row indicates year (two digits) and workweek (two digits) when the device was packaged. figure 5.3. qfn-48 package marking f970 a 000000 1410
c8051f97x 46 rev 1.0 qfn-32 package specifications 6. qfn-32 package specifications figure 6.1. qfn-32 package drawing table 6.1. qfn-32 package dimensions dimension min typ max dimension min typ max a 0.80 0.85 0.90 e2 3.20 3.30 3.40 a1 0.00 0.02 0.05 l 0.35 0.40 0.45 b 0.18 0.25 0.30 aaa ? ? 0.10 d 5.00 bsc bbb ? ? 0.10 d2 3.20 3.30 3.40 ddd ? ? 0.05 e 0.50 bsc eee ? ? 0.08 e5.00 bsc notes: 1. all dimensions shown are in mil limeters (mm) unless otherwise noted. 2. dimensioning and tolerancing per ansi y14.5m-1994. 3. this drawing conforms to the jedec solid state outline mo-220, variation vhhd except for custom features d2, e2, and l, wh ich are toleranced per supplier designation. 4. recommended card reflow profile is per the jedec/ipc j-std-020 s pecification for small body components.
c8051f97x rev 1.0 47 qfn-32 package specifications figure 6.2. typical qfn-32 landing diagram
c8051f97x 48 rev 1.0 qfn-32 package specifications table 6.2. qfn-32 pcb land pattern dimension min max c1 4.80 4.90 c2 4.80 4.90 e 0.50 bsc x1 0.20 0.30 x2 3.20 3.40 y1 0.75 0.85 y2 3.20 3.40 notes: general 1. all dimensions shown are in mil limeters (mm) unless otherwise noted. 2. this land pattern design is based on the ipc-7351 guidelines. solder mask design 3. all metal pads are to be non-solder mask defined (nsmd). clearance between the solder mask and the metal pad is to be 60 m minimum, all the way around the pad. stencil design 4. a stainless steel, laser-cut and electro-polis hed stencil with trapezoidal walls should be used to assure good solder paste release. 5. the stencil thickness should be 0.125mm (5 mils). 6. the ratio of stencil aperture to land pad size should be 1:1 for all perimeter pads. 7. a 3 x 3 array of 1.0 mm square openings on 1.2 mm pitch should be used for the center ground pad. card assembly 8. a no-clean, type-3 solder paste is recommended. 9. the recommended card reflow profile is per the jedec/ipc j-std-020 specification for small body components.
c8051f97x rev 1.0 49 qfn-32 package specifications 6.1. qfn-32 package marking the first row of the package marking is the part number, including the revision. the second row is the 6-digit trace code indicating assembly information. the last row indicates year (two digits) and workweek (two digits) when the device was packaged. figure 6.3. qfn-32 package marking f971 a 000000 1410
c8051f97x 50 rev 1.0 qfn-24 package specifications 7. qfn-24 package specifications figure 7.1. qfn-24 package drawing table 7.1. qfn-24 package dimensions dimension min typ max dimension min typ max a 0.70 0.75 0.80 l 0.30 0.40 0.50 a1 0.00 0.02 0.05 l1 0.00 ? 0.15 b 0.18 0.25 0.30 aaa ? ? 0.15 d 4.00 bsc bbb ? ? 0.10 d2 2.55 2.70 2.80 ddd ? ? 0.05 e 0.50 bsc eee ? ? 0.08 e 4.00 bsc z ? 0.24 ? e2 2.55 2.70 2.80 y ? 0.18 ? notes: 1. all dimensions shown are in millimeters (mm) unless otherwise noted. 2. dimensioning and tolerancing per ansi y14.5m-1994. 3. this drawing conforms to the jedec solid state outline mo-220, variation wggd except for custom features d2, e2, z, y, and l which are toleranced per supplier designation. 4. recommended card reflow profile is per the jedec/ipc j-std-020 specification for small body components. ?
c8051f97x rev 1.0 51 qfn-24 package specifications figure 7.2. typical qfn-24 landing diagram ?
c8051f97x 52 rev 1.0 qfn-24 package specifications table 7.2. qfn-24 pcb land pattern dimension min max c1 3.90 4.00 c2 3.90 4.00 e 0.50 bsc x1 0.20 0.30 x2 2.70 2.80 y1 0.65 0.75 y2 2.70 2.80 notes: general 1. all dimensions shown are in millimeters (mm) unless otherwise noted. 2. this land pattern design is based on the ipc-7351 guidelines. solder mask design 3. all metal pads are to be non-solder mask defined (nsmd). clearance between the solder mask and the metal pad is to be 60 m minimum, all the way around the pad. stencil design 4. a stainless steel, laser-cut and elec tro-polished stenc il with trapezoidal walls should be used to assure good solder paste release. 5. the stencil thickness should be 0.125 mm (5 mils). 6. the ratio of stencil aperture to land pad size should be 1:1 for all perimeter pads. 7. a 2x2 array of 1.10 mm x 1.10 mm openings on 1.30 mm pitch should be used for the center ground pad. card assembly 8. a no-clean, type-3 solder paste is recommended. 9. the recommended card reflow profile is per the jedec/ipc j-std-020 specification for small body components.
c8051f97x rev 1.0 53 qfn-24 package specifications 7.1. qfn-24 package marking the first row of the package marking is the part number, including the revision. the second row is the 6-digit trace code indicating assembly information. the last row indicates year (two digits) and workweek (two digits) when the device was packaged. figure 7.3. qfn-24 package marking f972 a 000000 1410
c8051f97x 54 rev 1.0 memory organization 8. memory organization the memory organization of the cip-51 system controlle r is similar to that of a standard 8051. there are two separate memory spaces: program memory and data memory. program and data memory share the same address space but are accessed via different instruction types. the memory organization of the c8051f97x device family is shown in figure 8.1. figure 8.1. c8051f97x memory map (32 kb flash version shown) program/data memory (flash) (direct and indirect addressing) 0x00 0x7f upper 128 ram (indirect addressing only) 0x80 0xff special function registers (direct addressing only) data memory (ram) 32 general purpose registers 0x1f 0x20 0x2f 32 bit-addressable bytes lower 128 ram (direct and indirect addressing) 0x30 internal data address space external data address space xram - 8192 bytes (accessible using movx instruction) 0x0000 0x1fff same 8192 bytes as 0x0000 to 0x1fff, wrapped on 8192-byte boundaries 0x2000 0xffff 32 kb flash (in-system programmable in 512 byte sectors) 0x0000 0x7fff lock byte 0x7ffe
c8051f97x rev 1.0 55 memory organization 8.1. program memory the cip-51 core has a 64 kb program memory space. the c8051f97x family implements 32 kb, or 16 kb of this program memory space as in-system, re-programmable flas h memory. the last address in the flash block (0x7fff on 32 kb devices and 0x3fff on 16 kb devices) serves as a security lock byte for the device, and provides read, write and erase protection. addresses above the lock byte within the 64 kb address space are reserved. figure 8.2. flash program memory map 8.1.1. movx instruction and program memory the movx instruction in an 8051 device is typically used to access external data memory. on the c8051f97x devices, the movx instruction is normally used to read and write on-chip xram, but can be re-configured to write and erase on-chip flash memory space. movc instructions are always used to read flash memory, while movx write instructions are used to erase and write flash. this flash access feature provides a mechanism for the c8051f97x to update program code and use the program memory space for non-volatile data storage. refer to section ?10. flash memory? on page 65 for further details. 8.2. data memory the c8051f97x device family includes up to 512 bytes of ram data memory. 256 bytes of this memory is mapped into the internal ram space of the 80 51. on devices with 512 bytes total ram, 256 additional bytes of memory are available as on-chip ?external? memory. the data memory map is shown in figure 8.1 for reference. 8.2.1. internal ram there are 256 bytes of internal ram mapped into the data memory space from 0x00 through 0xff. the lower 128 bytes of data memory are used for general purpose regi sters and scratch pad memory. either direct or indirect addressing may be used to access the lower 128 byte s of data memory. locations 0x00 through 0x1f are addressable as four banks of general purpose registers, each bank consisti ng of eight byte-wide registers. the next 16 bytes, locations 0x20 through 0x2f, may either be addressed as bytes or as 128 bit locations accessible with the direct addressing mode. the upper 128 bytes of data memory are accessible only by indirect addressing. this region occupies the same address space as the special function registers (sfr) bu t is physically separate from the sfr space. the addressing mode used by an instruction when accessin g locations above 0x7f determines whether the cpu accesses the upper 128 bytes of data me mory space or the sfrs. instructi ons that use direct addressing will access the sfr space. instructions using indirect add ressing above 0x7f access the upper 128 bytes of data memory. figure 8.1 illustrates the data me mory organization of the c8051f97x. flash memory organized in 512-byte pages lock byte 0x0000 0x3fff 0x3ffe 0x3e00 flash memory space lock byte 0x0000 0x7fff 0x7ffe 0x7e00 flash memory space c8051f970/1/2 c8051f973/4/5 lock byte page lock byte page
c8051f97x 56 rev 1.0 memory organization 8.2.1.1. general purpose registers the lower 32 bytes of data memory, locations 0x00 thro ugh 0x1f, may be addressed as four banks of general- purpose registers. each bank consists of eight byte-wide registers designated r0 through r7. only one of these banks may be enabled at a time. two bits in the progra m status word (psw) register, rs0 and rs1, select the active register bank. this allows fa st context switching when entering subr outines and interrupt service routines. indirect addressing modes use registers r0 and r1 as index registers. 8.2.1.2. bit addressable locations in addition to direct access to data memory organized as bytes, the sixteen data memory locations at 0x20 through 0x2f are also accessible as 128 individu ally addressable bits. each bit has a bit address from 0x00 to 0x7f. bit 0 of the byte at 0x20 has bit address 0x00 while bit7 of the by te at 0x20 has bit address 0x07. bit 7 of the byte at 0x2f has bit address 0x7f. a bit access is distinguished from a full byte access by the type of instruction used (bit source or destination operands as opposed to a byte source or destination). the mcs-51? assembly language allows an alternate notati on for bit addressing of the form xx.b where xx is the byte address and b is the bit position with in the byte. for example, the instruction: mov c, 22.3h moves the boolean value at 0x13 (bit 3 of the byte at location 0x22) into the carry flag. 8.2.1.3. stack a programmer's stack can be located anywhere in the 256 -byte data memory. the stack area is designated using the stack pointer (sp) sfr. the sp will point to the last location used. the next value pushed on the stack is placed at sp+1 and then sp is incremented. a reset initia lizes the stack pointer to location 0x07. therefore, the first value pushed on the stack is placed at location 0x08, wh ich is also the first register (r0) of register bank 1. thus, if more than one register bank is to be used, the sp should be initialized to a location in the data memory not being used for data storage. the stack depth can extend up to 256 bytes. 8.2.2. external ram c8051f97x devices have 4 kb or 8 kb of on-chip ram mapp ed into the external data memory space. all of these address locations may be accessed using the external mo ve instruction (movx) and the data pointer (dptr), or using movx indirect addressing mode. note: the 16-bit movx instruction is also used for writes to the flash memory. see section ?10. flash memory? on page 65 for details. the movx instruction accesses xram by default. for a 16-bit movx operation (@dptr), the upper 8 bits of the 16-bit external data memory address word are ?don't cares?. as a result, addresses 0x0000 through 0x00ff are mapped modulo style over the entire 64 k external data memory address range. for example, the xram byte at address 0x0000 is shadowed at addresses 0x0100, 0x0200, 0x0300, 0x0400, etc. the c8051f97x devices implement the upper four bytes of external ram as a 128-bit unique identifier. more information can be found in ?device identifi cation and unique identifier? on page 76. 8.2.3. special function registers the direct-access data memory locations from 0x80 to 0x ff constitute the special fu nction registers (sfrs). the sfrs provide control and data exchange with the cip-51's resources and peripherals. the cip-51 duplicates the sfrs found in a typical 8051 implementation as well as implementing additional sfrs used to configure and access the sub-systems unique to the mcu. this allo ws the addition of new fu nctionality while retaining compatibility with the mc s-51? instruction set. the sfr registers are accessed anytime the direct addres sing mode is used to access memory locations from 0x80 to 0xff. sfrs with addresses ending in 0x0 or 0x 8 (e.g. p0, tcon, scon0, ie, etc.) are bit-addressable as well as byte-addressable. all other sfrs are byte-address able only. unoccupied addresses in the sfr space are reserved for future use. accessing these areas will have an indeter minate effect and should be avoided.
c8051f97x rev 1.0 57 special function register memory map 9. special function register memory map this section details the specia l function register memory map for the c8051f97x devices. table 9.1. c8051f97x sfr memory map address page 0(8) 1(9) 2(a) 3(b) 4(c) 5(d) 6(e) 7(f) f8 spi0cn i2c0stat pca0l ? pca0h ? pca0cpl0 ? pca0cph0 ? cs0thl ? cs0thh ? vdm0cn p5mdout 0 f f0 b ? p4mdin ? p5mdin sfrnext smb0adr p0mat smb0adm p1mat pclken eip1 clkmode eip2 0 f e8 adc0cn dma0int pca0cpl1 ? pca0cph1 ? pca0cpl2 ? pca0cph2 p0mdin cs0dl p1mdin cs0dh p2mdin rstsrc p3mdin 0 f e0 acc p3 deviceid p4 revid p5 ? p6 ? flwr eie1 eie2 0 f d8 pca0cn dma0ncf pca0md p0mdout pca0cpm0 ? pca0cpm1 ? pca0cpm2 p1mdout cs0ss p3mdout cs0se it01cf pca0pwm p3mdout 0 f d0 psw ref0cn ? adc0l mac0acc0 adc0h mac0acc1 adc0mx mac0acc2 ? mac0acc3 ? mac0ovf ? mac0iter 0 f c8 tmr2cn reg0cn dma0nbal tmr2rll dma0nbah tmr2rlh dma0naol tmr2l dma0naoh tmr2h dma0nszl pmu0fl dma0nszh pmu0md mac0sta 0 f c0 smb0cn mac0cf0 smb0cf mac0inte smb0dat ? adc0gtl p4mdout adc0gth mac0cf1 adc0ltl mac0cf2 adc0lth p1skip ? p2skip 0 f b8 ip emi0cn p4drv adc0ac ? adc0pwr adc0tk cs0md1 ? cs0md2 ? cs0md3 ? 0 f b0 cs0cn ? oscxcn ? oscicn ? sfrlast ? pmu0cf ? flscl p0skip flkey 0 f a8 ie clksel cs0cf mac0al cs0mx mac0ah rtc0adr i2c0cn rtc0dat i2c0slad mac0bl oscicl mac0bh 0 f a0 p2 spi0cfg ? spi0ckr ? spi0dat ? amux0p3 i2c0dout amux0p4 i2c0din amux0p5 sfrpgcn sfrpage 0 f 98 scon0 sbuf0 p0drv amux0p0 p1drv amux0p1 p2drv amux0p2 p3drv crc0cnt p5drv crc0auto ? crc0flip ? 0 f 90 p1 tmr3cn dma0busy tmr3rll dma0en tmr3rlh ? tmr3l dma0sel tmr3h xbr0 cs0pm xbr1 adc0cf p6mdin 0 f 88 tcon dma0mint tmod ? tl0 ? tl1 p0mask th0 p1mask th1 toffl ckcon toffh psctl 0 f 80 p0 sp dpl dph crc0cn p2mask crc0in p2mat crc0dat ? pcon 0 f denotes bit-addressable sfrs, bold indicates sfrs on all pages
c8051f97x 58 rev 1.0 special function register memory map table 9.2. special function registers register address sfr page register description page acc 0xe0 all pages accumulator 181 adc0ac 0xba 0x0 adc0 accumulator configuration 116 adc0cf 0x97 0x0 adc0 configuration 115 adc0cn 0xe8 0x0 adc0 control 114 adc0gth 0xc4 0x0 adc0 greater-than high byte 121 adc0gtl 0xc3 0x0 adc0 greater-than low byte 122 adc0h 0xd3 0x0 adc0 data word high byte 119 adc0l 0xd2 0x0 adc0 data word low byte 120 adc0lth 0xc6 0x0 adc0 less-than high byte 123 adc0ltl 0xc5 0x0 adc0 less-than low byte 124 adc0mx 0xd4 0x0 adc0 multiplexer selection 125 adc0pwr 0xbb all pages adc0 power control 117 adc0tk 0xbc all pages adc0 burst mode track time 118 amux0p0 0x9a 0x0 port 0 analog mu ltiplexer control 159 amux0p1 0x9b 0x0 port 1 analog mu ltiplexer control 160 amux0p2 0x9c 0x0 port 2 analog mu ltiplexer control 161 amux0p3 0xa4 0x0 port 3 analog mu ltiplexer control 162 amux0p4 0xa5 0x0 port 4 analog mu ltiplexer control 163 amux0p5 0xa6 0x0 port 5 analog mu ltiplexer control 164 b 0xf0 0xf b register 182 ckcon 0x8e 0x0 clock control 401 clkmode 0xf7 0x0 clock mode 250 clksel 0xa9 0x0 clock select 248 crc0auto 0x9e 0x0 crc0 automatic control 239 crc0cn 0x84 0x0 crc0 control 236 crc0cnt 0x9d 0x0 crc0 automatic flash sector count 240 crc0dat 0x86 0x0 crc0 data output 238 crc0flip 0x9f 0x0 crc0 bit flip 241
c8051f97x rev 1.0 59 special function register memory map crc0in 0x85 0x0 crc0 data input 237 cs0cf 0xaa 0x0 capacitive sense 0 configuration 144 cs0cn 0xb0 0x0 capacitive sense 0 control 143 cs0dh 0xee 0x0 capacitive sense 0 data high byte 145 cs0dl 0xed 0x0 capacitive sense 0 data low byte 146 cs0md1 0xbd 0x0 capacitive sense 0 mode 1 151 cs0md2 0xbe 0x0 capacitive sense 0 mode 2 152 cs0md3 0xbf 0x0 capacitive sense 0 mode 3 153 cs0mx 0xab 0x0 capacitive sense 0 mux channel select 155 cs0pm 0x96 0x0 capacitive sense 0 pin monitor 154 cs0se 0xde 0x0 capacitive sense 0 auto scan end channel 148 cs0ss 0xdd 0x0 capacitive sense 0 auto scan start channel 147 cs0thh 0xfe 0x0 capacitive sense 0 comparator threshold high byte 149 cs0thl 0xfd 0x0 capacitive sense 0 comparator threshold low byte 150 deviceid 0xe1 0xf device identification 77 dma0busy 0x91 0xf dma0 busy 194 dma0en 0x92 0xf dma0 channel enable 191 dma0int 0xe8 0xf dma0 full-length interrupt flags 192 dma0mint 0x88 0xf dma0 mid-point interrupt flags 193 dma0naoh 0xcc 0xf memory address offset high 199 dma0naol 0xcb 0xf memory address offset low 200 dma0nbah 0xca 0xf memory base address high 197 dma0nbal 0xc9 0xf memory base address low 198 dma0ncf 0xd8 0xf dma0 channel configuration 196 dma0nszh 0xce 0xf memory transfer size high 201 dma0nszl 0xcd 0xf memory transfer size low 202 dma0sel 0x94 0xf dma0 channel select 195 dph 0x83 all pages data pointer high 179 dpl 0x82 all pages data pointer low 178 table 9.2. special function registers (continued) register address sfr page register description page
c8051f97x 60 rev 1.0 special function register memory map eie1 0xe6 all pages extended interrupt enable 1 85 eie2 0xe7 all pages extended interrupt enable 2 89 eip1 0xf6 0xf extended interrupt priority 1 87 eip2 0xf7 0xf extended interrupt priority 2 90 emi0cn 0xb9 0x0 external memory interface control 75 flkey 0xb7 all pages flash lock and key 71 flscl 0xb6 0x0 flash scale 72 flwr 0xe5 all pages flash write only 73 i2c0cn 0xac 0xf i2c0 control 380 i2c0din 0xa5 0xf i2c0 received data 375 i2c0dout 0xa4 0xf i2c0 transmit data 376 i2c0slad 0xad 0xf i2c0 slave address 377 i2c0stat 0xf8 0xf i2c0 status 378 ie 0xa8 all pages interrupt enable 82 ip 0xb8 all pages interrupt priority 84 it01cf 0xde 0xf int0 / int1 configuration 92 mac0acc0 0xd2 0xf accumulator byte 0 231 mac0acc1 0xd3 0xf accumulator byte 1 230 mac0acc2 0xd4 0xf accumulator byte 2 229 mac0acc3 0xd5 0xf accumulator byte 3 228 mac0ah 0xab 0xf operand a high byte 223 mac0al 0xaa 0xf operand a low byte 224 mac0bh 0xaf 0xf operand b high byte 225 mac0bl 0xae 0xf operand b low byte 226 mac0cf0 0xc0 0xf mac0 configuration 0 216 mac0cf1 0xc4 0xf mac0 configuration 1 218 mac0cf2 0xc5 0xf mac0 configuration 2 220 mac0inte 0xc1 0xf mac0 interrupt enable 222 mac0iter 0xd7 0xf iteration counter 232 table 9.2. special function registers (continued) register address sfr page register description page
c8051f97x rev 1.0 61 special function register memory map mac0ovf 0xd6 0xf accumulator overflow byte 227 mac0sta 0xcf 0xf mac0 status 214 oscicl 0xaf 0x0 high frequency oscillator calibration 251 oscicn 0xb2 0x0 high frequency oscillator control 252 oscxcn 0xb1 0x0 external oscillator control 253 p0 0x80 all pages port 0 pin latch 290 p0drv 0x99 0xf port 0 drive strength 294 p0mask 0x8b 0xf port 0 mask 288 p0mat 0xf4 0xf port 0 match 289 p0mdin 0xec 0xf port 0 input mode 291 p0mdout 0xd9 0xf port 0 output mode 292 p0skip 0xb6 0xf port 0 skip 293 p1 0x90 all pages port 1 pin latch 297 p1drv 0x9a 0xf port 1 drive strength 301 p1mask 0x8c 0xf port 1 mask 295 p1mat 0xf5 0xf port 1 match 296 p1mdin 0xed 0xf port 1 input mode 298 p1mdout 0xdc 0xf port 1 output mode 299 p1skip 0xc6 0xf port 1 skip 300 p2 0xa0 all pages port 2 pin latch 304 p2drv 0x9b 0xf port 2 drive strength 308 p2mask 0x84 0xf port 2 mask 302 p2mat 0x85 0xf port 2 match 303 p2mdin 0xee 0xf port 2 input mode 305 p2mdout 0xdd 0xf port 2 output mode 306 p2skip 0xc7 0xf port 2 skip 307 p3 0xe1 0x0 port 3 pin latch 309 p3drv 0x9c 0xf port 3 drive strength 312 p3mdin 0xef 0xf port 3 input mode 310 table 9.2. special function registers (continued) register address sfr page register description page
c8051f97x 62 rev 1.0 special function register memory map p3mdout 0xdf 0xf port 3 output mode 311 p4 0xe2 0x0 port 4 pin latch 313 p4drv 0xb9 0xf port 4 drive strength 316 p4mdin 0xf1 0xf port 4 input mode 314 p4mdout 0xc3 0xf port 4 output mode 315 p5 0xe3 0x0 port 5 pin latch 317 p5drv 0x9d 0xf port 5 drive strength 320 p5mdin 0xf2 0xf port 5 input mode 318 p5mdout 0xff 0xf port 5 output mode 319 p6 0xe4 0x0 port 6 pin latch 321 p6mdin 0x97 0xf port 6 input mode 321 pca0cn 0xd8 0x0 pca control 434 pca0cph0 0xfc 0x0 pca capture module high byte 0 441 pca0cph1 0xea 0x0 pca capture module high byte 1 444 pca0cph2 0xec 0x0 pca capture module high byte 2 447 pca0cpl0 0xfb 0x0 pca capture module low byte 0 440 pca0cpl1 0xe9 0x0 pca capture module low byte 1 443 pca0cpl2 0xeb 0x0 pca capture module low byte 2 446 pca0cpm0 0xda 0x0 pca capture/compare mode 0 439 pca0cpm1 0xdb 0x0 pca capture/compare mode 1 442 pca0cpm2 0xdc 0x0 pca capture/compare mode 1 445 pca0h 0xfa 0x0 pca counter/timer low byte 438 pca0l 0xf9 0x0 pca counter/timer high byte 437 pca0md 0xd9 0x0 pca mode 435 pca0pwm 0xdf 0x0 pca pwm configuration 436 pclken 0xf6 0x0 low power peripheral clock enable 249 pcon 0x87 all pages power control 100 pmu0cf 0xb5 0x0 power management unit configuration 101 pmu0fl 0xce 0x0 power management unit flag 102 table 9.2. special function registers (continued) register address sfr page register description page
c8051f97x rev 1.0 63 special function register memory map pmu0md 0xcf 0x0 power management unit mode 103 psctl 0x8f all pages program store control 70 psw 0xd0 all pages program status word 183 ref0cn 0xd1 0x0 voltage reference control 127 reg0cn 0xc9 0x0 voltage regulator control 93 revid 0xe2 0xf revision identification 78 rstsrc 0xef 0x0 reset source 327 rtc0adr 0xac 0x0 rtc address 265 rtc0dat 0xad 0x0 rtc data 266 sbuf0 0x99 0x0 uart0 serial port data buffer 389 scon0 0x98 all pages uart0 serial port control 387 sfrlast 0xb3 all pages sfr page last 187 sfrnext 0xf3 all pages sfr page next 186 sfrpage 0xa7 all pages sfr page 184 sfrpgcn 0xa6 0xf sfr page control 185 smb0adm 0xf5 0x0 smbus0 slave address mask 363 smb0adr 0xf4 0x0 smbus0 slave address 362 smb0cf 0xc1 0x0 smbus0 configuration 359 smb0cn 0xc0 0x0 smbus0 control 360 smb0dat 0xc2 0x0 smbus0 data 364 sp 0x81 all pages stack pointer 180 spi0cfg 0xa1 0x0 spi0 configuration 339 spi0ckr 0xa2 0x0 spi0 clock control 341 spi0cn 0xf8 0x0 spi0 control 340 spi0dat 0xa3 0x0 spi0 data 342 tcon 0x88 0x0 timer 0/1 control 403 th0 0x8c 0x0 timer 0 high byte 407 th1 0x8d 0x0 timer 1 high byte 408 tl0 0x8a 0x0 timer 0 low byte 405 table 9.2. special function registers (continued) register address sfr page register description page
c8051f97x 64 rev 1.0 special function register memory map tl1 0x8b 0x0 timer 1 low byte 406 tmod 0x89 0x0 timer 0/1 mode 404 tmr2cn 0xc8 all pages timer 2 control 409 tmr2h 0xcd 0x0 timer 2 high byte 414 tmr2l 0xcc 0x0 timer 2 low byte 413 tmr2rlh 0xcb 0x0 timer 2 reload high byte 412 tmr2rll 0xca 0x0 timer 2 reload low byte 411 tmr3cn 0x91 0x0 timer 3 control 415 tmr3h 0x95 0x0 timer 3 high byte 420 tmr3l 0x94 0x0 timer 3 low byte 419 tmr3rlh 0x93 0x0 timer 3 reload high byte 418 tmr3rll 0x92 0x0 timer 3 reload low byte 417 toffh 0x8e 0xf temperature sensor offset high 128 toffl 0x8d 0xf temperature sensor offset low 129 vdm0cn 0xff 0x0 supply monitor control 328 xbr0 0x95 0xf port i/o crossbar 0 286 xbr1 0x96 0xf port i/o crossbar 1 287 table 9.2. special function registers (continued) register address sfr page register description page
c8051f97x rev 1.0 65 flash memory 10. flash memory on-chip, re-programmable flash memory is included for program code and non-volatile data storage. the flash memory is organized in 512-byte pages. it can be erased and written through the c2 interface or from firmware by overloading the movx instruction. any individual byte in flash memory must only be written once between page erase operations. 10.1. security options the cip-51 provides security options to protect the flash me mory from inadvertent modification by software as well as to prevent the viewing of proprietary program code and constants. the program store write enable (bit pswe in register psctl) and the program store erase enable (bit psee in re gister psctl) bits protect the flash memory from accidental modification by software. pswe must be explicitly set to ?1? before software can modify the flash memory; both pswe and psee mu st be set to ?1? before software can erase flash memory. additional security features prevent proprietary program code and dat a constants from being read or altered across the c2 interface. a security lock byte located in flash user space offers pr otection of the flash program memory from access (reads, writes, or erases) by unprotected code or the c2 interface. see section ?8. memory organization? on page 54 for the location of the security byte. the flash security mechanism allows the user to lock n 512-byte flash pages, starting at page 0 (addresses 0x0000 to 0x01ff), where n is the 1?s complement number represented by the security lock byte. note that the page containing the flash security lock byte is unlocked when no other flash pages are locked (all bits of the lock byte are ?1?) and locked when any other flash pages are locked (any bit of the lock byte is ?0?). an example is shown in figure 10.1. figure 10.1. security byte decoding the level of flash security depends on the flash acce ss method. the three flash access methods that can be restricted are reads, writes, and erases from the c2 de bug interface, user firmware executing on unlocked pages, and user firmware executing on locked pages. table 10.1 su mmarizes the flash security features of the c8051f97x devices. security lock byte: 11111011b 1s complement: 00000100b flash pages locked: 5 (first four flash pages + lock byte page)
c8051f97x 66 rev 1.0 flash memory table 10.1. flash security summary action c2 debug interface user firmware executing from: unlocked page locked page read, write or erase unlocked pages (except page with lock byte) permitted permitted permitted read, write or erase locked pages (except page with lock byte) not permitted flash error reset permitted read or write page containing lock byte (if no pages are locked) permitted permitted n/a read or write page containing lock byte (if any page is locked) not permitted flash error reset permitted read contents of lock byte (if no pages are locked) permitted permitted n/a read contents of lock byte (if any page is locked) not permitted flash error reset permitted erase page containing lock byte (if no pages are locked) permitted permitted n/a erase page containing lock byte?unlock all pages (if any page is locked) c2 device erase only flash error reset flash error reset lock additional pages (change 1s to 0s in the lock byte) not permitted flash error reset flash error reset unlock individual pages (change 0s to 1s in the lock byte) not permitted flash error reset flash error reset read, write or erase reserved area not permitted flash error reset flash error reset notes: 1. c2 device erase erases all flash pages including the page containing the lock byte. 2. flash error reset is not permitted; causes flash error de vice reset (ferror bit in rs tsrc is ?1? after reset). 3. all prohibited operations that are performed via the c2 interface are ignored (do not cause device reset). 4. locking any flash page also locks the page containing the lock byte. 5. once written to, the lock byte cannot be modifi ed except by performing a c2 device erase. 6. if user code writes to the lock byte, the lock does not take effect until the next device reset.
c8051f97x rev 1.0 67 flash memory 10.2. programming the flash memory writes to flash memory clear bits from logic 1 to logic 0, and can be performed on single byte locations. flash erasures set bits back to logic 1, and occur only on full pages. the write and erase operations are automatically timed by hardware for proper executio n; data polling to determ ine the end of the write/ erase operation is not required. code execution is stalled during a flash write/erase operation. the simplest means of programming the flash memory is through the c2 interface using programming tools provided by silicon labs or a third party vendor. this is the only means for programmi ng a non-initialized device. to ensure the integrity of flash contents, it is strongly recommended that the on-chip supply monitor be enabled in any system that includes code that writes and/or erases flash me mory from software. 10.2.1. flash lock and key functions flash writes and erases by user so ftware are protected with a lock and key function. the flash lock and key register (flkey) must be written with the correct key codes, in sequence, before flash operations may be performed. the key codes are: 0xa5, 0xf1. the timing does not matter, but the codes mu st be written in order. if the key codes are written out of order, or the wrong codes ar e written, flash writes and er ases will be disabled until the next system reset. flas h writes and erases will also be disabled if a flash write or erase is attempted before the key codes have been written properly. the flash lock resets after each write or erase; the key codes must be written again before a following flash operation can be performed. 10.2.2. flash erase procedure the flash memory can be programmed by software usi ng the movx write instruction with the address and data byte to be programmed provided as normal operands. be fore writing to flash memory using movx, flash write operations must be enabled by: (1) setting the pswe program store write enable bit in the psctl register to logic 1 (this directs the movx writes to target flash memory ); and (2) writing the flash key codes in sequence to the flash lock register (flkey). the pswe bit remains set until cl eared by software. a write to flash memory can clear bits to logic 0 but cannot set them; only an erase operation can set bits to logic 1 in flash. a byte location to be programmed should be erased before a new value is written. erase operation applies to an entire page (setting all bytes in the page to 0xff). to erase an entire page, perform the following steps: 1. disable interrupts (recommended). 2. set the psee bit (register psctl). 3. set the pswe bit (register psctl). 4. write the first key code to flkey: 0xa5. 5. write the second key code to flkey: 0xf1. 6. using the movx instruction, write a data byte to any location within the page to be erased. 7. clear the pswe and psee bits. 10.2.3. flash write procedure flash bytes are programmed by software with the following sequence: 1. disable interrupts (recommended). 2. erase the flash page containing the tar get location, as descri bed in section 10.2.2. 3. set the pswe bit (register psctl). 4. clear the psee bit (register psctl). 5. write the first key code to flkey: 0xa5. 6. write the second key code to flkey: 0xf1. 7. using the movx instruct ion, write a single data byte to the desired location within the desired page. 8. clear the pswe bit. steps 5?7 must be repeated for each byte to be written. after flash writes are complete, pswe should be cleared so that movx instructions do not target program memory.
c8051f97x 68 rev 1.0 flash memory 10.3. non-volati le data storage the flash memory can be used for non-volatile data stor age as well as program code. this allows data such as calibration coefficients to be calculat ed and stored at run time. data is wri tten using the movx write instruction and read using the movc instruction. note: mo vx read instructions always target xram. 10.4. flash write and erase guidelines any system which contains routines which write or erase fl ash memory from software involves some risk that the write or erase routines will execute unin tentionally if the cpu is operating outside its spec ified operati ng range of supply voltage, system clock frequency or temperature. this accidental execution of flash modifying code can result in alteration of flash memory contents causing a sy stem failure that is only recoverable by re-flashing the code in the device. to help prevent the accidental modification of flash by fi rmware, hardware restricts flash writes and erasures when the supply monitor is not active and selected as a reset source. as the monitor is enabled and selected as a reset source by default, it is recommended that systems writ ing or erasing flash simply maintain the default state. the following guidelines are recommended for any system whic h contains routines which write or erase flash from code. 10.4.1. voltage supply maintenance and the supply monitor 1. if the system power supply is subject to voltage or current "spikes," add sufficient transient protection devices to the power supply to en sure that the supply voltages listed in the absolute maximum ratings table are not exceeded. 2. make certain that the minimum su pply rise time specification is met. if the system cannot meet this rise time specification, then add an exter nal supply brownout circuit to the rst pin of the device that holds the device in reset until the voltage supply reaches the lower limi t, and re-asserts rst if the supply drops below the low supply limit. 3. do not disable the supply monitor. if the supply mo nitor must be disabled in the system, firmware should be added to the startup routine to enable the on-chip su pply monitor and enable the supply monitor as a reset source as early in code as possible. this should be the first set of instructions executed after the reset vector. for c-based systems, this may involve modifying the startup code added by the c compiler. see your compiler documentation for more details. make certain that there are no delays in software between enabling the supply monitor and enabling the supply monitor as a reset source. code examples showing this can be found in ?an201: writi ng to flash from firmware", availabl e from the silicon laboratories web site. note that the supply monitor must be enabled and enabled as a reset source when writing or erasing flash memory. a flash error reset will occur if either condition is not met. 4. as an added precaution if the supply monitor is ever disabled, explicitly enable the supply monitor and enable the supply monitor as a reset source inside the functions that write and erase flash memory. the supply monitor enable instructions should be placed just after the instruction to set pswe to a 1, but before the flash write or erase operation instruction. 5. make certain that all writes to the rstsrc (reset sources) register use direct assignment operators and explicitly do not use the bit-wise operators (such as and or or). for example, "rstsrc = 0x02" is correct. "rstsrc |= 0x02" is incorrect. 6. make certain that all wr ites to the rstsrc register explicitly set the porsf bit to a '1'. areas to check are initialization code which enables ot her reset sources, such as the mi ssing clock detector or comparator, for example, and instructions which force a software reset. a global search on "rstsrc" can quickly verify this. 10.4.2. pswe maintenance 7. reduce the number of places in code where the pswe bit (in register psctl) is set to a 1. there should be exactly one routine in code that sets pswe to a '1' to write flash bytes and one routine in code that sets pswe and psee both to a '1' to erase flash pages. 8. minimize the number of variable accesses while pswe is set to a 1. handle pointer address updates and loop variable maintenance outside the "pswe = 1;... pswe = 0;" area. code examples showing this can
c8051f97x rev 1.0 69 flash memory be found in ?an201: writing to flas h from firmware", available from the silicon laboratories web site. 9. disable interrupts prio r to setting pswe to a '1' and leave them disabled until after pswe has been reset to 0. any interrupts posted during th e flash write or erase operation will be serviced in priority order after the flash operation has been completed and inte rrupts have been re-enabled by software. 10. make certain that the flash write and erase pointe r variables are not located in xram. see your compiler documentation for instructions regarding how to exp licitly locate variables in different memory areas. 11. add address bounds checking to the routines that write or erase flash memory to ensure that a routine called with an illegal address does not result in modification of the flash. 10.4.3. system clock 12. if operating from an external crystal-based source , be advised that crystal performance is susceptible to electrical interference and is sensitive to layout and to changes in temperature. if the system is operating in an electrically noisy environmen t, use the internal oscillator or use an external cmos clock. 13. if operating from the external oscillator, switch to the internal oscillator during flash write or erase operations. the external oscillator can continue to run, and the cpu can switch back to the external oscillator after the flash operation has completed. additional flash recommendations and example code can be found in ?an201: writing to flash from firmware", available from the silicon laboratories website.
c8051f97x 70 rev 1.0 flash memory 10.5. flash control registers register 10.1. psctl: program store control bit 7 6 5 4 3 2 1 0 name reserved psee pswe type r rw rw reset00000000 sfr page = all; sfr address: 0x8f table 10.2. psctl register bit descriptions bit name function 7:2 reserved must write reset value. 1 psee program store erase enable. setting this bit (in combination with pswe) allows an entire page of flash program mem - ory to be erased. if this bit is logic 1 and flash writes are enabled (pswe is logic 1), a write to flash memory using th e movx instruction will erase the entire page that contains the location addressed by the movx instructio n. the value of the data byte written does not matter. 0: flash program memory erasure disabled. 1: flash program memory erasure enabled. 0 pswe program store write enable. setting this bit allows writing a byte of dat a to the flash program memory using the movx write instruction. the flash location should be erased before writing data. 0: writes to flash program memory disabled. 1: writes to flash program memory enabled; the movx write instruction targets flash memory.
c8051f97x rev 1.0 71 flash memory register 10.2. flkey: flash lock and key bit 7 6 5 4 3 2 1 0 name flkey type rw reset00000000 sfr page = all; sfr address: 0xb7 table 10.3. flkey register bit descriptions bit name function 7:0 flkey flash lock and key register. write: this register provides a lock and key function for flash erasures and writes. flash writes and erases are enabled by writing 0xa5 followed by 0x f1 to the flkey register. flash writes and erases are automatically disabled af ter the next write or erase is complete. if any writes to flkey are performe d incorrectly, or if a flash write or erase operation is attempted while these operatio ns are disabled, the flash will be permanently locked from writes or erasures until the next device reset. if an applicatio n never writes to flash, it can intentionally lock the flash by writing a non-0xa5 value to flkey from firmware. read: when read, bits 1-0 indicate the current flash lock state. 00: flash is write/erase locked. 01: the first key code has been written (0xa5). 10: flash is unlocked (writes/erases allowed). 11: flash writes/erases are disabled until the next reset.
c8051f97x 72 rev 1.0 flash memory register 10.3. flscl: flash scale bit 7 6 5 4 3 2 1 0 name reserved bypass reserved type r rw r reset00000000 sfr page = 0x0; sfr address: 0xb6 table 10.4. flscl register bit descriptions bit name function 7 reserved must write reset value. 6 bypass flash read timing one-shot bypass. 0: the one-shot determines the flash read ti me. this setting should be used for operating frequencies less than 14 mhz. 1: the system clock determines the flash re ad time. this setting should be used for fre - quencies greater than 14 mhz. 5:0 reserved must write reset value. note: operations which clear the bypass bit do not need to be immediately followed by a benign 3-byte instruction. for code compatibility with c8051f930/31/20/ 21 devices, a benign 3-byte instruction whose third byte is a don't care should follow the clear operation. see the c8 051f93x-c8051f92x data sheet for more details.
c8051f97x rev 1.0 73 flash memory register 10.4. flwr: flash write only bit 7 6 5 4 3 2 1 0 name flwr type w reset00000000 sfr page = all; sfr address: 0xe5 table 10.5. flwr register bit descriptions bit name function 7:0 flwr flash write only. all writes to this register have no effect on system operation.
c8051f97x 74 rev 1.0 on-chip xram 11. on-chip xram the c8051f97x mcus include on-chip ram mapped into th e external data memory space (xram). the external memory space may be accessed using the external move in struction (movx) with the target address specified in either the data pointer (dptr), or with the target address low byte in r0 or r1. on c8051f97x devices, the target address high byte is a don?t care. when using the movx instruction to access on-chip ram, no additional initialization is required and the movx instruction execution time is as specified in the cip-51 chapter. important note : movx write operations can be configured to target flash memory, instead of xram. see section ?10. flash memory? on page 65 for more details. the movx instru ction accesses xram by default. 11.1. accessing xram the xram memory space is accessed using the movx inst ruction. the movx instruction has two forms, both of which use an indirect addressing method. the first meth od uses the data pointer, dptr, a 16-bit register which contains the effective address of the xram location to be read from or written to. the second method uses r0 or r1 in combination with the emi0cn register to generate the effective xram address. examples of both of these methods are given below. 11.1.1. 16-bit movx example the 16-bit form of the movx instruction accesses the memo ry location pointed to by the contents of the dptr register. the following series of instructions reads the va lue of the byte at address 0x1234 into the accumulator a: mov dptr, #1234h ; load dptr with 16-bit address to read (0x1234) movx a, @dptr ; load contents of 0x1234 into accumulator a ? the above example uses the 16-bit immediate mov instructio n to set the contents of dptr. alternately, the dptr can be accessed through the sfr regi sters dph, which contai ns the upper 8-bits of dptr, and dpl, which contains the lower 8-bits of dptr. 11.1.2. 8-bit movx example the 8-bit form of the movx instruction uses the contents of the emi0cn sfr to determine the upper 8-bits of the effective address to be accessed and the contents of r0 or r1 to determine the lower 8-bits of the effective address to be accessed. the following series of instructions read the contents of the byte at address 0x1234 into the accumulator a. mov emi0cn, #12h ; load high byte of address into emi0cn mov r0, #34h ; load low byte of address into r0 (or r1) movx a, @r0 ; load contents of 0x1234 into accumulator a
c8051f97x rev 1.0 75 on-chip xram 11.2. external memory interface registers f register 11.1. emi0cn: external memory interface control bit 7 6 5 4 3 2 1 0 name pgsel type rw reset 0 0 0 0 0 0 0 0 sfr page = 0x0; sfr address: 0xb9 bit name function 7:0 pgsel xram page select. the xram page select field provides the high byte of the 16-bit external data memory address when using an 8-bit movx command, effectively selecting a 256-byte page of ram. 0x00: 0x0000 to 0x00ff 0x01: 0x0100 to 0x01ff ... 0xfe: 0xfe00 to 0xfeff 0xff: 0xff00 to 0xffff
c8051f97x 76 rev 1.0 device identification and unique identifier 12. device identification and unique identifier the c8051f97x has sfrs that identify the device family , derivative, and revision. these sfrs can be read by firmware at runtime to determine the ca pabilities of the mcu that is executing code. this allows the same firmware image to run on mcus with different memory sizes and pe ripherals, and dynamically cha nge functionality to suit the capabilities of that mcu. in addition to the device iden tification registers, a 128-bit unique identi fier (uid) is preprogrammed into all devices. the uid resides in the last sixteen bytes of xram. the uid can be read by firmware using movx instructions and through the debug port. firmware can overwrite the ui d during normal operation, and the bytes in memory will be automa tically reinitialized with the uid value after any device reset. firmware using th is area of memory should always initialize the memory to a known value, as any previous data stored at th ese locations will be overwritten and not retained through a reset. table 12.1. uid implementation information device external memory (xram) addresses c8051f970 c8051f971 c8051f972 (msb) 0x1fff, 0x1ffe, 0x1ffd, 0x1ffc, 0x1ffb, 0x1ffa, 0x1ff9, 0x1ff8, 0x1ff7, 0x1ff6, 0x1ff5, 0x1ff4, 0x1ff3, 0x1ff2, 0x1ff1, 0x1ff0 (lsb) c8051f973 C8051F974 c8051f975 (msb) 0x0fff, 0x0ffe, 0x0ffd, 0x0ffc, 0x0ffb, 0x0ffa, 0x0ff9, 0x0ff8, 0x0ff7, 0x0ff6, 0x0ff5, 0x0ff4, 0x0ff3, 0x0ff2, 0x0ff1, 0x0ff0 (lsb)
c8051f97x rev 1.0 77 device identification and unique identifier 12.1. device identi fication registers register 12.1. deviceid: device identification bit 7 6 5 4 3 2 1 0 name deviceid type r reset00101001 sfr page = 0xf; sfr address: 0xe1 table 12.2. deviceid register bit descriptions bit name function 7:0 deviceid device id. this read-only register returns the 8-bit device id: 0x29 (c8051f97x).
c8051f97x 78 rev 1.0 device identification and unique identifier register 12.2. revid: revision identifcation bit 7 6 5 4 3 2 1 0 name revid type r resetxxxxxxxx sfr page = 0xf; sfr address: 0xe2 table 12.3. revid register bit descriptions bit name function 7:0 revid revision id. this read-only register returns the 8-bit revision id. 00000000: reserved. 00000001: revision a 00000010-11111111: reserved.
c8051f97x rev 1.0 79 interrupts 13. interrupts the c8051f97x includes an extended interrupt system supp orting multiple interrupt sources with two priority levels. the allocation of interrupt sources between on-chip peripherals and external input pins varies according to the specific version of the device. each interrupt source has one or more associated interrupt-pending flag(s) located in an sfr. when a peripheral or external source meets a valid interrupt condition, the associated interrupt- pending flag is set to logic 1. if interrupts are enabled for the source, an interrupt request is generated when the interr upt-pending flag is set. as soon as execution of the current instruction is complete , the cpu generates an lcall to a predetermined address to begin execution of an interrupt service routine (isr). each isr must end with an reti instruction, which returns program execution to the next instruction that would have been executed if the interrupt request had not occurred. if interrupts are not enabled, the interrupt-pending flag is ignored by the hardware and program execution continues as normal. the interrupt-pending flag is set to logic 1 regardless of the interrupt's enable/disable state. each interrupt source can be individually enabled or disa bled through the use of an associated interrupt enable bit in an sfr (ie and eie1). however, interrupts must first be gl obally enabled by setting the ea bit in the ie register to logic 1 before the individual interrupt enables are recogn ized. setting the ea bit to logic 0 disables all interrupt sources regardless of the individual interrupt-enable settings. some interrupt-pending flags are automatically cleare d by the hardware when the cpu vectors to the isr. however, most are not cleared by the hardware and must be cleared by software before returning from the isr. if an interrupt-pending flag remains set after the cpu comple tes the return-from-interrupt (reti) instruction, a new interrupt requ est will be generated i mmediately and the cpu will re-enter the isr after the completion of the next instruction. 13.1. mcu interrupt sources and vectors the c8051f97x mcus support interrupt sources for each peripheral on the device. software can simulate an interrupt by setting any interrupt-pending flag to logic 1. if interrupts are enabled for the flag, an interrupt request will be generated and th e cpu will vector to the isr address associ ated with the interrup t-pending flag. mcu interrupt sources, associated vector add resses, priority order and control bits are summarized in table 13.1. refer to the datasheet section associated with a particular on-chip peripheral for information regarding valid interrupt conditions for the peripheral and the behavior of its interrupt-pending flag(s). 13.1.1. interr upt priorities each interrupt source can be individually programmed to one of two priority levels: low or high. a low priority interrupt service routine can be preempted by a high pr iority interrupt. a high priority interrupt cannot be preempted. each interrupt has an associated interrupt pr iority bit in an sfr (ip or eip1) used to configure its priority level. low priority is the def ault. if two interrupts are recognized simultaneously, the interrupt with the higher priority is serviced first. if both interrupts have the same priority level, a fixed priority order is used to arbitrate, given in table 13.1. 13.1.2. interr upt latency interrupt response time depends on the state of the cpu when the interrupt occurs. pending interrupts are sampled and priority decoded each syste m clock cycle. therefore, the fastes t possible response time is 5 system clock cycles: 1 clock cycle to detect the interrupt and 4 cl ock cycles to complete the lcall to the isr. if an interrupt is pending when a reti is executed, a single inst ruction is executed before an lcall is made to service the pending interrupt. therefore, the maximum response time for an interrupt (when no other interrupt is currently being serviced or the new interrupt is of greater priority ) occurs when the cpu is perf orming an reti instruction followed by a div as the next instruction. in this case, the response time is 18 system clock cycles: 1 clock cycle to detect the interrupt, 5 clock cycles to execute the reti, 8 clock cycles to co mplete the div inst ruction and 4 clock cycles to execute the lcall to the isr. if the cpu is executing an isr for an interrupt with equal or higher priority, the new interrupt will not be serviced until the current isr completes, including the reti and following instruction. if more than one interrupt is pending when the cpu exits an isr, the cpu will service the next highest priority interrupt that is pending.
c8051f97x 80 rev 1.0 interrupts table 13.1. interrupt summary interrupt source interrupt vector priority order pending flag bit addressable? cleared by hw? enable flag priority control reset 0x0000 to p none n/a n/a always enabled always high - est external interrupt 0 (/int0) 0x0003 0 ie0 (tcon.1) y y ex0 (ie.0) px0 (ip.0) timer 0 overflow 0x000b 1 tf0 (tcon.5) y y et0 (ie.1) pt0 (ip.1) external interrupt 1 (/int1) 0x0013 2 ie1 (tcon.3) y y ex1 (ie.2) px1 (ip.2) timer 1 overflow 0x001b 3 tf1 (tcon.7) y y et1 (ie.3) pt1 (ip.3) uart0 0x0023 4 ri0 (scon0.0) ti0 (scon0.1) y n es0 (ie.4) ps0 (ip.4) timer 2 overflow 0x002b 5 tf2h (tmr2cn.7) tf2l (tmr2cn.6) y n et2 (ie.5) pt2 (ip.5) spi0 0x0033 6 spif (spi0cn.7) wcol (spi0cn.6) modf (spi0cn.5) rxovrn (spi0cn.4) y n espi0 (ie.6) pspi0 (ip.6) smb0 0x003b 7 si (smb0cn.0) y n esmb0 (eie1.0) psmb0 (eip1.0) smartclock alarm 0x0043 8 alrm (rtc0cn.2) * n n ertc0 (eie1.1) prtc0 (eip1.1) adc0 window comparator 0x004b 9 ad0wint (adc0cn.3) y n ewadc0 (eie1.2) pwadc0 (eip1.2) adc0 end of conversion 0x0053 10 ad0int (adc0cn.5) y n eadc0 (eie1.3) padc0 (eip1.3) programmable counter array 0x005b 11 cf (pca0cn.7) ccfn (pca0cn.n) y n epca0 (eie1.4) ppca0 (eie1.4) dma0 midpoint operation complete 0x0063 12 chn_mint (dma0mint.n) y n edma0m (eie1.5) pdma0m (eip1.5) dma0 endpoint operation complete 0x006b 13 chn_int (dma0int.n) y n edma0 (eie1.6) pdma0 (eip1.6) timer 3 overflow 0x0073 14 tf3h (tmr3cn.7) tf3l (tmr3cn.6) n n et3 (eie1.7) pt3 (eip1.7) port match 0x0083 16 none emat (eie2.1) pmat (eip2.1)
c8051f97x rev 1.0 81 interrupts smartclock oscillator fail 0x008b 17 oscfail (rtc0cn.5) * n n ertc0f (eie2.2) prtc0f (eip2.2) mac0 0x0093 18 mac0int (mac0sta.6) n n emac0 (eie2.3) pmac0 (eip2.3) cs0 conversion complete 0x009b 19 cs0int (cs0cn.5) y n ecscpt (eie2.4) pcscpt (eip2.4) cs0 digital com - parator 0x00a3 20 cs0cmpf (cs0cn.0) y n ecsdc (eie2.5) pcsdc (eip2.5) cs0 end of scan 0x00ab 21 cs0eos (cs0cn.6) y n ecseos (eie2.6) pcseos (eip2.6) i2c slave 0 0x00b3 22 i2c0int (i2c0stat.5) y n ei2c0 (eie2.7) pi2c0 (eip2.7) *note: indicates a register located in an indirect memory space. table 13.1. interrupt summary (continued) interrupt source interrupt vector priority order pending flag bit addressable? cleared by hw? enable flag priority control
c8051f97x 82 rev 1.0 interrupts 13.2. interrupt control registers register 13.1. ie: interrupt enable bit 7 6 5 4 3 2 1 0 name ea espi0 et2 es0 et1 ex1 et0 ex0 type rw rw rw rw rw rw rw rw reset00000000 sfr page = all; sfr address: 0xa8 (bit-addressable) table 13.2. ie register bit descriptions bit name function 7 ea all interrupts enable. globally enables/disables all interrupts and overrides individual interrupt mask settings. 0: disable all in terrupt sources. 1: enable each interr upt according to its individual mask setting. 6 espi0 spi0 interrupt enable. this bit sets the masking of the spi0 interrupts. 0: disable all spi0 interrupts. 1: enable interrupt requests generated by spi0. 5 et2 timer 2 interr upt enable. this bit sets the masking of the timer 2 interrupt. 0: disable timer 2 interrupt. 1: enable interrupt requests generated by the tf2l or tf2h flags. 4 es0 uart0 interrupt enable. this bit sets the masking of the uart0 interrupt. 0: disable uart0 interrupt. 1: enable ua rt0 interrupt. 3 et1 timer 1 interr upt enable. this bit sets the masking of the timer 1 interrupt. 0: disable all ti mer 1 interrupt. 1: enable interrupt requests generated by the tf1 flag. 2 ex1 external interrupt 1 enable. this bit sets the masking of external interrupt 1. 0: disable external interrupt 1. 1: enable interrupt requests generated by the int1 input. 1 et0 timer 0 interr upt enable. this bit sets the masking of the timer 0 interrupt. 0: disable all ti mer 0 interrupt. 1: enable interrupt requests generated by the tf0 flag.
c8051f97x rev 1.0 83 interrupts 0 ex0 external interrupt 0 enable. this bit sets the masking of external interrupt 0. 0: disable external interrupt 0. 1: enable interrupt requests generated by the int0 input. table 13.2. ie register bit descriptions bit name function
c8051f97x 84 rev 1.0 interrupts register 13.2. ip: interrupt priority bit 7 6 5 4 3 2 1 0 name reserved pspi0 pt2 ps0 pt1 px1 pt0 px0 typer rwrwrwrwrwrwrw reset10000000 sfr page = all; sfr address: 0xb8 (bit-addressable) table 13.3. ip register bit descriptions bit name function 7 reserved must write reset value. 6 pspi0 serial peripheral interface (spi 0) interrupt priority control. this bit sets the priority of the spi0 interrupt. 0: spi0 interrupt set to low priority level. 1: spi0 interrupt set to high priority level. 5 pt2 timer 2 interrupt priority control. this bit sets the priority of the timer 2 interrupt. 0: timer 2 interrupt set to low priority level. 1: timer 2 interrupt set to high priority level. 4 ps0 uart0 interrupt priority control. this bit sets the priority of the uart0 interrupt. 0: uart0 interrupt set to low priority level. 1: uart0 interrupt set to high priority level. 3 pt1 timer 1 interrupt priority control. this bit sets the priority of the timer 1 interrupt. 0: timer 1 interrupt set to low priority level. 1: timer 1 interrupt set to high priority level. 2 px1 external interrupt 1 priority control. this bit sets the priority of th e external interr upt 1 interrupt. 0: external interrupt 1 set to low priority level. 1: external interrupt 1 set to high priority level. 1 pt0 timer 0 interrupt priority control. this bit sets the priority of the timer 0 interrupt. 0: timer 0 interrupt set to low priority level. 1: timer 0 interrupt set to high priority level. 0 px0 external interrupt 0 priority control. this bit sets the priority of th e external interr upt 0 interrupt. 0: external interrupt 0 set to low priority level. 1: external interrupt 0 set to high priority level.
c8051f97x rev 1.0 85 interrupts register 13.3. eie1: extended interrupt enable 1 bit 7 6 5 4 3 2 1 0 name et3 edma0 edma0m epca0 eadc0 ewadc0 ertc0a esmb0 type rw rw rw rw rw rw rw rw reset00000000 sfr page = all; sfr address: 0xe6 table 13.4. eie1 register bit descriptions bit name function 7 et3 timer 3 interr upt enable. this bit sets the masking of the timer 3 interrupt. 0: disable timer 3 interrupts. 1: enable interrupt requests generated by the tf3l or tf3h flags. 6 edma0 dma0 interrupt enable. this bit sets the masking of the dma0 interrupt. 0: disable dma0 interrupts. 1: enable interrupt requests generated by dma0. 5 edma0m dma0 mid-point interrupt enable. this bit sets the masking of the dma0 mid-point interrupt. 0: disable dma0m interrupts. 1: enable interrupt requests generated by the dma0m flags. 4 epca0 programmable counter array (pca0) interrupt enable. this bit sets the masking of the pca0 interrupts. 0: disable all pc a0 interrupts. 1: enable interrupt requests generated by pca0. 3 eadc0 adc0 conversion complete interrupt enable. this bit sets the masking of the adc0 conversion complete interrupt. 0: disable adc0 conversi on complete interrupt. 1: enable interrupt requests generated by the adint flag. 2 ewadc0 window comparison adc0 interrupt enable. this bit sets the masking of adc0 window comparison interrupt. 0: disable adc0 window comparison interrupt. 1: enable interrupt requests generated by adc0 window compare flag (adwint). 1 ertc0a rtc alarm interrupts enable. this bit sets the masking of the rtc alarm interrupt. 0: disable rtc alarm interrupts. 1: enable interrupt requests generated by a rtc alarm.
c8051f97x 86 rev 1.0 interrupts 0 esmb0 smbus (smb0) in terrupt enable. this bit sets the masking of the smb0 interrupt. 0: disable all sm b0 interrupts. 1: enable interrupt requests generated by smb0. table 13.4. eie1 register bit descriptions bit name function
c8051f97x rev 1.0 87 interrupts register 13.4. eip1: extended interrupt priority 1 bit 7 6 5 4 3 2 1 0 name pt3 pdma0 pdma0m ppca0 padc0 pwadc0 prtc0a psmb0 type rw rw rw rw rw rw rw rw reset00000000 sfr page = 0xf; sfr address: 0xf6 table 13.5. eip1 register bit descriptions bit name function 7 pt3 timer 3 interrupt priority control. this bit sets the priority of the timer 3 interrupt. 0: timer 3 interrupts set to low priority level. 1: timer 3 interrupts set to high priority level. 6 pdma0 dma0 interrupt priority control. this bit sets the priority of the dma0 interrupt. 0: dma0 interrupts set to low priority level. 1: dma0 interrupts set to high priority level. 5 pdma0m dma0 mid-point interrupt priority control. this bit sets the masking of the dma0 mid-point interrupt. 0: mid-point dma0 interrupts set to low priority level. 1: mid-point dma0 interrupts set to high priority level. 4 ppca0 programmable counter array (pca0) interrupt priority control. this bit sets the priority of the pca0 interrupt. 0: pca0 interrupt set to low priority level. 1: pca0 interrupt set to high priority level. 3 padc0 adc0 conversion complete interrupt priority control. this bit sets the priority of the adc0 conversion complete interrupt. 0: adc0 conversion complete inte rrupt set to low priority level. 1: adc0 conversion complete interrupt set to high priority level. 2 pwadc0 adc0 window comparator interrupt priority control. this bit sets the priority of the adc0 window interrupt. 0: adc0 window interrupt set to low priority level. 1: adc0 window interrupt se t to high priority level. 1 prtc0a rtc alarm interrupt priority control. this bit sets the priority of the rtc alarm interrupt. 0: rtc alarm interrupt se t to low priority level. 1: rtc alarm interrupt set to high priority level.
c8051f97x 88 rev 1.0 interrupts 0 psmb0 smbus (smb0) interrupt priority control. this bit sets the priority of the smb0 interrupt. 0: smb0 interrupt set to low priority level. 1: smb0 interrupt set to high priority level. table 13.5. eip1 register bit descriptions bit name function
c8051f97x rev 1.0 89 interrupts register 13.5. eie2: extended interrupt enable 2 bit 7 6 5 4 3 2 1 0 name ei2c0 ecseos ecsdc ecscpt emac0 ertc0f emat reserved type rw rw rw rw rw rw rw rw reset00000000 sfr page = all; sfr address: 0xe7 table 13.6. eie2 register bit descriptions bit name function 7 ei2c0 i2c0 slave interrupt enable. 0: disable i2c0 slave event interrupt. 1: enable interrupt requests generated by the i2c0 slave. 6 ecseos capacitive sense end of scan interrupt enable. this bit sets the masking of the capa citive sense end of scan interrupt. 0: disable capacitive sense end of scan interrupt. 1: enable interrupt requests generated by the capacitive sense end of scan. 5 ecsdc capacitive sense digital comparator interrupt enable. this bit sets the masking of the capacitive sense digital comparator interrupt. 0: disable capacitive sense digital comparator interrupt. 1: enable interrupt requests generated by the capacitive sense digital comparator. 4 ecscpt capacitive sense conversion complete interrupt enable. this bit sets the masking of the capaciti ve sense conversion complete interrupt. 0: disable capacitive sense co nversion comple te interrupt. 1: enable interrupt requests generated by cs0int. 3 emac0 mac0 interrupt enable. 0: disable mac0 event interrupt. 1: enable interrupt requests generated by mac0. 2 ertc0f rtc oscillator fail interrupt enable. this bit sets the masking of the rtc alarm interrupt. 0: disable rtc alarm interrupts. 1: enable interrupt requests generated by the rtc alarm. 1 emat port match interrupts enable. this bit sets the masking of the port match event interrupt. 0: disable all port match interrupts. 1: enable interrupt requests generated by a port match. 0 reserved must write reset value.
c8051f97x 90 rev 1.0 interrupts register 13.6. eip2: extended interrupt priority 1 bit 7 6 5 4 3 2 1 0 name pi2c0 pcseos pcsdc pcscpt pmac0 prtc0f pmat reserved type rw rw rw rw rw rw rw rw reset00000000 sfr page = 0xf; sfr address: 0xf7 table 13.7. eip2 register bit descriptions bit name function 7 pi2c0 i2c0 slave interrupt priority control. 0: i2c0 slave interrupts set to low priority level. 1: i2c0 slave interrupts se t to high priority level. 6 pcseos capacitive sense end of scan interrupt priority control. this bit sets the priority of the capacitive sense end of scan interrupt. 0: capacitive sense end of scan in terrupt set to lo w priority level. 1: capacitive sense end of scan in terrupt set to high priority level. 5 pcsdc capacitive sense digital comparator interrupt priority control. this bit sets the priority of the capacitive sense digital comparator interrupt. 0: capacitive sense digital comparator interrupt set to low priority level. 1: capacitive sense digital comparator interrupt set to high priority level. 4 pcscpt capacitive sense conversion complete interrupt priority control. this bit sets the priority of the capaci tive sense conversion complete interrupt. 0: capacitive sense conversion complete interrupt set to low priority level. 1: capacitive sense conversion complete interrupt set to high priority level. 3 pmac0 mac0 interrupt priority control. 0: mac0 interrupts set to low priority level. 1: mac0 interrupts set to high priority level. 2 prtc0f rtc oscillator fail interr upt priority control. this bit sets the priority of the rtc alarm interrupt. 0: rtc alarm interrupt se t to low priority level. 1: rtc alarm interrupt set to high priority level. 1 pmat port match interrupt priority control. this bit sets the priority of the port match event interrupt. 0: port match interrupt se t to low priority level. 1: port match interrupt se t to high priority level. 0 reserved must write reset value.
c8051f97x rev 1.0 91 external interrupt s (int0 and int1) 14. external interrupts ( int0 and int1) the c8051f97x device family includes two external digital interrupt sources (int0 and int1 ), with dedicated interrupt sources (up to 16 additional i/o interrupts are available through the port match function). as is the case on a standard 8051 architecture, certain controls for these two interrupt sources are available in the timer0/1 registers. extensions to these controls which provide additional functionality on c8051f97x devices are available in the it01cf register. int0 and int1 are configurable as active high or low, edge or level sensitive. the in0pl and in1pl bits in the it01cf register select active high or active low; the it0 and it1 bi ts in tcon select level or edge sensitive. the table below lis ts the possible configurations. int0 and int1 are assigned to port pins as defined in the it01cf register. note that int0 and int1 port pin assignments are independent of any crossbar assignments. int0 and int1 will monitor their assigned port pins without disturbing the peripheral that wa s assigned the port pin via the crossbar. to assign a port pin only to int0 and/or int1 , configure the crossbar to skip the selected pin(s). ie0 and ie1 in the tcon register serve as the interrupt-pendin g flags for the int0 and int1 external interrupts, respectively. if an int0 or int1 external interrupt is configured as e dge-sensitive, the corresponding interrupt- pending flag is automatically cleared by the hardware when the cpu vectors to the isr. when configured as level sensitive, the interrupt-pending flag remains logic 1 while the input is active as defined by the corresponding polarity bit (in0pl or in1pl); the flag remains logic 0 while the input is inactive. the ex ternal interrup t source must hold the input active until the interrupt request is recogni zed. it must then deactivate the interrupt request before execution of the isr completes or anot her interrupt request will be generated. it0 in0pl int0 interrupt it1 in1pl int1 interrupt 1 0 active low, edge sensitive 1 0 active low, edge sensitive 1 1 active high, edge sensitive 1 1 active high, edge sensitive 0 0 active low, level sensitive 0 0 active low, level sensitive 0 1 active high, level sensitive 0 1 active high, level sensitive
c8051f97x 92 rev 1.0 external interrupts (int0 and int1) 14.1. external interrupt control registers register 14.1. it01cf: int0 / int1 configuration bit 7 6 5 4 3 2 1 0 name in1pl in1sl in0pl in0sl type rw rw rw rw reset00000001 sfr page = 0xf; sfr address: 0xde table 14.1. it01cf register bit descriptions bit name function 7 in1pl int1 polarity. 0: int1 input is active low. 1: int1 input is active high. 6:4 in1sl int1 port pin selection. these bits select which port pin is assigned to int1 . this pin assignment is independent of the crossbar; int1 will monitor the assigned port pin without disturbing the peripheral that has been assigned the port pin via t he crossbar. the crossbar will not assign the port pin to a peripheral if it is c onfigured to skip the selected pin. 000: select p0.0. 001: select p0.1. 010: select p0.2. 011: select p0.3. 100: select p0.4. 101: select p0.5. 110: select p0.6. 111: select p0.7. 3 in0pl int0 polarity. 0: int0 input is active low. 1: int0 input is active high. 2:0 in0sl int0 port pin selection. these bits select which port pin is assigned to int0 . this pin assignment is independent of the crossbar; int0 will monitor the assigned port pin without disturbing the peripheral that has been assigned the port pin via t he crossbar. the crossbar will not assign the port pin to a peripheral if it is c onfigured to skip the selected pin. 000: select p0.0. 001: select p0.1. 010: select p0.2. 011: select p0.3. 100: select p0.4. 101: select p0.5. 110: select p0.6. 111: select p0.7.
c8051f97x rev 1.0 93 voltage regulator (vreg0) 15. voltage regulator (vreg0) c8051f97x devices include an internal voltage regulator (v reg0) to regulate the internal core supply to 1.8 v from a vdd supply of 1.8 to 3.6 v. electrical characteristics for the on-chi p regulator are specifi ed in the electrical specifications chapter. the reg0cn register allows the precision oscillator bias to be disabled, r educing supply current in all non-sleep power modes. this bias should only be disabled when the precision osc illator is not being used. the internal regulator (vreg0) is disabled when the device enters sleep mode and remains enabled when the device enters suspend mode. see section ?16. power management? on page 94 for complete de tails about low power modes. 15.1. voltage regulator control registers register 15.1. reg0cn: voltage regulator control bit 7 6 5 4 3 2 1 0 name reserved oscbias reserved type r rw r reset 0 0 0 0 0 0 0 0 sfr page = 0x0; sfr address: 0xc9 bit name function 7:5 reserved must write reset value. 4 oscbias high frequency oscillator bias. when set to 1, the bias used by the precisio n high frequency oscillator is forced on. if the precision oscillator is not being used, this bit may be cleared to 0 to reduce supply current in all non-sleep power modes. 3:0 reserved must write reset value.
c8051f97x 94 rev 1.0 power management 16. power management c8051f97x devices support seven power modes: normal active, low power active, idle, low power idle, stop, suspend, and sleep. the power management unit (pmu0) allows the device to enter and wake-up from the available power modes. a brief description of each power mode is provided in ta b l e 16.1 . detailed descriptions of each mode can be found in the following sections. in battery powered systems, the system should spend as much time as possible in sleep mode in order to preserve battery life. when a task with a fixed number of clock cycl es needs to be performed, th e device should switch to normal active mode or low power active mode, finish the task as quickly as possible, and return to sleep mode. idle mode, low power idle mode and suspend mode provide a very fast wake-up time; however, the power savings in these modes will not be as much as in sleep mode. stop mode is included for legacy reas ons; the system will be more power efficient and easier to wake up when idle, suspend, or sleep modes are used. although switching power modes is an integral part of power management, clock gating and enabling/disabling individual peripherals as needed will help lower power c onsumption in all power mode s. each analog peripheral can be disabled when not in use or placed in a low power mode. digital peripherals such as timers or serial buses draw little power whenever they are not in use. digital peripherals draw no power in sleep mode. table 16.1. power modes power mode description wake-up sources power and performance normal active device fully functional. n/a excellent mips/mw low power active device fully functional except peripherals whose clocks are intentionally disabled. n/a excellent. clocks only enabled for peripher - als that request for it. idle all peripherals fully functional. wake-up in 2 clock cycles. any interrupt good no code execution low power idle similar to idle mode, the cpu is halted. clocks of unused peripher - als can be intentionally gated. wake-up in 2 clock cycles. any interrupt very good no code execution. clocks only enabled for peripher - als that request for it. stop legacy 8051 low power mode. a reset is required to wake up. any reset good no code execution precision oscillator disabled suspend similar to stop mode, but very fast wake-up time and code resumes execution at the next instruction. cs0 comparator threshold event, smartclock, port match, i 2 c slave, rst pin very good no code execution all internal oscillators disabled system clock gated sleep ultra low power and flexible wake-up sources. code resumes execution at the next instruction. smartclock, port match, i 2 c slave, rst pin excellent power supply gated all oscillators except smartclock disabled
c8051f97x rev 1.0 95 power management in low power modes (low power active mode and low power idle mode) there are two mechanisms to provide clocks to peripherals: ?? cpu turns on the clocks of peripher als through sfr registers. examples of such peripherals are timers, pca0, adc0, etc. ?? peripherals with clock request capability can reques t for the clocks when ne eded. examples of such peripherals are dma0, i2c slave, etc. figure 16.1. c8051f97x module clocking in low power modes modules that are capable of requesti ng for clocks can do so at any ti me. these modules will use the requested clock to synchronize with outgoing dma request or interrupt requ est. on the other hand, modules with no capability of requesting for clocks will always receive clock from cl ock generation module if their clock sources are enabled through t he pclken register. 16.1. normal active mode the mcu is fully functional in normal active mode. figure 16.2 shows the on-chip power distribution to various peripherals. there are two supply voltages powering various sections of the chip: v dd and the 1.8 v internal core supply. all analog peripherals are directly powered from the v dd pin. all digital peripherals and the cip-51 core are powered from the 1.8 v internal core supply. ram, pmu0 and the smartclock are always powered directly from the v dd pin in sleep mode and powered from the core supply in all other power modes. clock generator interrupt module dma cpu modules with clock requesting capability (i2c slave, etc.) modules without clock requesting capability (timers, pca0, etc.) int req int int int clk int clk req int req int cpu idle cpu clk dma clk dma clk req dma req pclk pclk req
c8051f97x 96 rev 1.0 power management figure 16.2. c8051f97x power distribution 16.2. idle mode setting the idle mode select bit (pcon.0) causes the cip- 51 to halt the cpu and enter idle mode as soon as the instruction that sets the bit completes execution. all internal registers and me mory maintain their original data. all analog and digital peripherals can remain active during idle mode. note: to ensure the mcu enters a low power st ate upon entry into idle mode, the one-shot circuit should be enabled by clearing the bypass bit (flscl.6). idle mode is terminated when an enabled interrupt is asserted or a reset occurs. the assertion of an enabled interrupt will cause the idle mode sele ction bit (pcon.0) to be cleared an d the cpu to resume operation. the pending interrupt will be servic ed and the next instruction to be executed after the return from interrupt (reti) will be the instruction immediately following the one that set the idle mode select bit. if idle mode is terminated by an internal or external reset, the cip-51 performs a normal reset sequence and begins program execution at address 0x0000 if enabled, the watchdog timer (wdt) will eventually cause an internal watchdog rese t and thereby terminate the idle mode. this feature protects the system from an uni ntended permanent shutdown in the event of an inadvertent write to the pcon register. if this behavior is not desire d, the wdt may be disabled by software prior to entering the idle mode if the wdt was initially configured to allow this operation. this provides the opportunity for additional power savings, allowing the system to rema in in the idle mode indefinitely, wait ing for an external stimulus to wake up the system. refer to "27.6. pca watchdog timer reset" on page 326 for more information on the use and configuration of the wdt. c8051f97x device vdd vreg0 p0.2 p0.1 p0.0 p6.1 p0.3 analog peripherals vref cs0 adc0 temp sensor amux0 digital peripherals cip-51 core flash timers uart pmu0 smartclock ram 1.8 v to 3.6 v 1.8 v active idle stop suspend sleep gpio
c8051f97x rev 1.0 97 power management 16.3. stop mode setting the stop mode select bit (pcon.1) causes the cip- 51 to enter stop mode as soon as the instruction that sets the bit completes execution. in st op mode the precision inte rnal oscillator and cpu ar e stopped; the state of the low power oscillator and the external oscillator circuit is not affected. each analog periphe ral (including the external oscillator circuit) may be shut down individually prior to en tering stop mode. stop mode can only be terminated by an internal or external reset. on reset, the cip-51 performs the normal reset sequence and begins program execution at address 0x0000. if enabled, the missing clock detector will cause an intern al reset and thereby term inate the stop mode. the missing clock detector should be disabled if the cpu is to be put to in stop mode for longer than the mcd timeout. stop mode is a legacy 8051 power mode; it will not result in optimal power savings. sleep or suspend mode will provide more power savings if the mcu needs to be inactive for a long period of time. note: to ensure the mcu enters a low power stat e upon entry into stop mode, the one- shot circuit should be enabled by clearing the bypass bit (flscl.6). 16.4. suspend mode setting the suspend mode select bit (pmu0cf.6) causes the system clock to be gated off and all internal oscillators disabled. all digital logic (timers, communication peri pherals, interrupts, cpu, etc.) stops functioning until one of the enabled wake-up sources occurs. the following wake-up sources can be configured to wake the device from suspend mode: ?? smartclock oscillator fail ?? smartclock alarm ?? port match event ?? i2c0 address match ?? cs0 comparator threshold event note: upon wake-up from suspend mode, pmu0 requires two system clocks in order to update the pmu0cf wake-up flags. all flags will read back a value of '0' during the first two system clocks fo llowing a wake-up from suspend mode. ? the state of the wake-up source 's interrupt indicator bit is not valid until 6 clock cycles after the device returns from suspend mode. if firmware needs to check a wake-up source's inte rrupt flag, firmware should insert instructions to wait 6 clock cycles between the call to enter suspend mode and the instruction that polls the interrupt flag. in addition, a noise glitch on rst that is not long en ough to reset the device will cause the device to exit suspend. in order for the mcu to respond to the pin reset event, so ftware must not place the device back into suspend mode for a period of 15 s. the pmu0cf regi ster may be checked to determine if the wake-up was due to a falling edge on the rst pin. if the wake-up source is not due to a falling edge on rst , there is no time restriction on how soon software may place the device back into suspend mode. a 4.7 k ? pullup resistor to v dd is recommend for rst to prevent noise glitches from waking the device. 16.5. sleep mode setting the sleep mode select bit (pmu0cf.6) turns off the internal 1.8 v regulator (vreg0) and switches the power supply of all on-chip ram to the v dd pin (see figure 16.2 ). power to most digital logic on the chip is disconnected; only pmu0 and the smartclock remain powered. all analog peripherals (adc0, external oscillator, etc.) should be disa bled prior to entering sleep mode. gpio pins configured as digital outputs will retain their output state during sl eep mode. they will maintain the same current drive capability in sleep mode as they ha ve in normal active mode. gpio pins configured as digital inputs can be used duri ng sleep mode as wakeup sources using the port match feature. they will maintain the same input level specifications in sleep mo de as they have in normal active mode. c8051f97x devices support a wakeup request for external devices. upon exit from sleep mode, the wake-up request signal is driven low, allowing other devices in the system to wake up from their low power modes. the wakeup request signal is low when the mcu is awake and high when the mcu is asleep.
c8051f97x 98 rev 1.0 power management ram and sfr register contents are preserved in sleep mode as long as the voltage on v dd does not fall below vpor. the pc counter and all other volatile state inform ation is preserved allowing the device to resume code execution upon waking up from sleep mode. the following wake-up sources can be configured to wake the device from sleep mode: ?? smartclock oscillator fail ?? smartclock alarm ?? port match event ?? i2c0 address match the v dd supply monitor can be disabled to save power by writing 1 to the mondis (pmu0md.5) bit. when the v dd supply monitor is disabled, all reset sour ces will trigger a full por and will re-enable the v dd supply monitor. in addition, any falling edge on rst (due to a pin reset or a noise glitch) will cause the device to exit sleep mode. in order for the mcu to respond to the pin reset event, so ftware must not place the device back into sleep mode for a period of 15 s. the pmu0cf register may be checked to determ ine if the wake-up was due to a falling edge on the rst pin. if the wake-up source is not due to a falling edge on rst , there is no time restriction on how soon software may place the device back into sleep mode. a 4.7 k ? pullup resistor to v dd is recommend for rst to prevent noise glitches from waking the device. 16.6. low power active mode running in normal active mode can waste a significant amo unt of amount of power by clocking unused peripherals. low power active mode in c8051f97x de vices allows control of clocking acti vity in the clock tree, which enables firmware to shut off clocking to unused peripherals and save power. setting bit 1 and 2 of clkmode register causes the cip- 51 to enter low power active mode as soon as the instruction that sets the bits complete s execution. cpu, all the analog and di gital peripherals remain active except those whose clocks are turned off by user. the cpu will not be able to access sfr of peripherals on inactive branches of the clock tree . refer to figure 16.1 for more information on how modules receive or request for clocks in low power modes. it is important that firmware configures bit 4 to 7 of pclken register on page 249 to ensure desired clock gating of peripherals during low power active mode . for example, if uart is supposed to be active during low power active mode, according to the pclken register description bit 4 should be set. however, that is no t sufficient in this case because timer 1 is needed for uart baud rate generation. as a consequence, bit 7 should be set as well for proper uart operation. low power active mode is terminated when the clkmode r egister is programmed to 0x00 or a reset occurs. systems that use all the peripherals and always stay in the active mode may not find improvement in power consumption in the low power active mode due overhead logic required for this implementation. 16.7. low power idle mode in this mode of operation, the cpu is halted and clocks supplied to unused peripherals can be shut down to save power. clocks of these peripherals can be enabled or disa bled by programming bits 0 to 3 of pclken register accordingly on page 249 . the device should be put to low power mode by setting bits 1 and 2 of clkmode register. the last step necessary to put device in low power idle mode is to se t the idle mode select bit (pcon.0) to 1. the cpu will be halted and the de vice will enter low-power idle mode as soon as the in struction that sets the idle mode select bit completes execution. as a result, configuration of peripherals clock gating through pclken register and clkmode register should be properly prepar ed before the idle mode select bit in pcon is set. all internal registers and memory maintain their original da ta. all the analog and digital peripherals remain active except those whose clocks are turned off by user. modules t hat are capable of requesting for clocks can do so at any time. refer to figure 16.1 for more information on how modules re ceive or request for clocks in low power modes. note: to ensure the mcu enters a low power st ate upon entry into low power idle mode, the one-shot circuit should be enabled by clearing the bypass bit (flscl.6).
c8051f97x rev 1.0 99 power management low power idle mode is terminated when an enabled interrupt is asserted or a reset occurs. the assertion of an enabled interrupt will cause the idle mode selection bit (pcon. 0) to be cleared. but the interrupt only causes the device to switch from low power idle mode to low power active mode. to return to normal active mode, the clkmode register should be reset to 0x 00. the pending interrupt will be serv iced and the next instruction to be executed after the return from interrupt (reti) will be the instruction immediat ely following the one that set the idle mode select bit. if low power idle mode is terminated by an internal or extern al reset, the cip-51 performs a normal sequence and begins program execution at address 0x0000. if enabled, the watchdog timer (wdt) will eventually cause an internal watchdog rese t and thereby terminate the low power idle mode. this feature prot ects the system from an unintended permanent shutdown in the event of an inadvertent write to the pcon register. if this behavior is not desired, the wdt may be disabled by software prior to entering the low power idle mode if th e wdt was initially confi gured to allow this operation. this provides the opportunity for additional power saving s, allowing the system to remain in the low power idle mode indefinitely, waiting for an external stimulus to wake up the system. refer to "27.6. pca watchdog timer reset" on page 326 for more information on the use and configuration of the wdt. 16.8. configuring wakeup sources before placing the device in a low power mode, one or mo re wakeup sources should be enabled so that the device does not remain in the low power mode indefinitely. for idle and low power idle modes, this includes enabling any interrupt. for stop mode, this includes e nabling any reset source or relying on the rst pin to reset the device. no wake-up source is needed for low power active mode. firmware needs to set the clkmode register to 0x00 to return to normal active mode wake-up sources for suspend and sleep modes are configured through the pmu0cf register. wake-up sources are enabled by writing 1 to the corresponding wake-up source enable bit. wake-up sources must be re-enabled each time the device is placed in suspend or sleep mode, in the same write that places the device in the low power mode. the reset pin is always enabled as a wake-up source. on the falling edge of rst the device will be awaken from sleep mode. the device must remain awake for more than 15 s in order for the reset to take place. 16.9. determining the event that caused the last wakeup when waking from idle or low power idle mode, the cpu will vector to the interrupt wh ich caused it to wake up. when waking from stop mode, the rstsrc register may be read to determine the cause of the last reset. upon exit from suspend or sleep mode, the wake-up flag s in the pmu0cf and pmu0fl registers can be read to determine the event which caused the device to wake up. after waking up, the wakeup flags will continue to be updated if any of the wake-up events occur. wakeup flags are always updated, even if they are not enabled as wake-up sources. all wakeup flags enabled as wakeup sources in pmu0cf and pmu0fl must be cleared before the device can enter suspend or sleep mode. after clearing the wakeup flags, each of the enabled wakeup events should be checked in the individual peripherals to ensure that a wakeup event did not occur while the wakeup flags were being cleared.
c8051f97x 100 rev 1.0 power management 16.10. power control registers register 16.1. pcon: power control bit 7 6 5 4 3 2 1 0 name gf5 gf4 gf3 gf2 gf1 gf0 stop idle type rw rw rw rw rw rw rw rw reset 0 0 0 0 0 0 0 0 sfr page = all; sfr address: 0x87 bit name function 7 gf5 general purpose flag 5. this flag is a general purpose flag for use under firmware control. 6 gf4 general purpose flag 4. this flag is a general purpose flag for use under firmware control. 5 gf3 general purpose flag 3. this flag is a general purpose flag for use under firmware control. 4 gf2 general purpose flag 2. this flag is a general purpose flag for use under firmware control. 3 gf1 general purpose flag 1. this flag is a general purpose flag for use under firmware control. 2 gf0 general purpose flag 0. this flag is a general purpose flag for use under firmware control. 1 stop stop mode select. setting this bit will place the cip-51 in stop mode. this bit will always be read as 0. 0 idle idle mode select. setting this bit will place the cip-51 in idle mode. this bit will always be read as 0.
c8051f97x rev 1.0 101 power management register 16.2. pmu0cf: power management unit configuration bit 7 6 5 4 3 2 1 0 name sleep suspend clear rstwk rtcfwk rtcawk pmatwk reserved type rw rw rw rw rw rw rw rw reset 0 0 0 0 0 0 0 0 sfr page = 0x0; sfr address: 0xb5 bit name function 7 sleep sleep mode select. writing a 1 to this bit places the device in sleep mode. 6 suspend suspend mode select. writing a 1 to this bit places the device in suspend mode. 5 clear wake-up flag clear. writing a 1 to this bit clears all wake-up flags. 4 rstwk reset pin wake-up flag. this bit is set to 1 if a glitch has been detected on rst . 3 rtcfwk rtc oscillator fail wake-up source enable and flag. read: hardware sets this bit to 1 if the rtc oscillator failed. write: write this bit to 1 to enabl e wake-up on an rtc oscillator failure. 2 rtcawk rtc alarm wake-up source enable and flag. read: hardware sets this bit to 1 if the rtc alarm occured. write: write this bit to 1 to enable wake-up on an rtc alarm. 1 pmatwk port match wake-up source enable and flag. read: hardware sets this bit to 1 if port match event occured. write: write this bit to 1 to enable wake-up on a port match event. 0 reserved must write reset value. notes: 1. read-modify-write operations (orl, anl, etc.) should not be used on this register. wake-up sources must be re- enabled each time the sleep or suspend bits are written to 1. 2. the low power internal oscillator cannot be disabled and t he mcu cannot be placed in suspend or sleep mode if any wake-up flags are set to 1. software should clear all wa ke-up sources after each reset and after each wake-up from suspend or sleep modes. 3. pmu0 requires two system clocks to update the wake-up so urce flags after waking from suspend mode. the wake-up source flags will read 0 during the first two system clocks following the wake from suspend mode.
c8051f97x 102 rev 1.0 power management register 16.3. pmu0fl: power management unit flag bit 7 6 5 4 3 2 1 0 name reserved i2cwk cs0wk type rw rw rw reset 0 0 0 0 0 0 x 0 sfr page = 0x0; sfr address: 0xce bit name function 7:2 reserved must write reset value. 1 i2cwk i2c0 slave wake-up source enable and flag. read: hardware sets this bit to 1 if an i2c0 slave event occured. write: write this bit to 1 to enable wake-up on an i2c0 slave event. 0 cs0wk cs0 wake-up source enable and flag. read: hardware sets this bit to 1 if a capacitive sensing comparator threshold event occured. write: write this bit to 1 to enable wake-up on a capacitive sensing comparator thresh - old event. notes: 1. the low power internal oscillator cannot be disabled and t he mcu cannot be placed in suspend or sleep mode if any wake-up flags are set to 1. software should clear all wa ke-up sources after each reset and after each wake-up from suspend or sleep modes. 2. pmu0 requires two system clocks to update the wake-up so urce flags after waking from suspend mode. the wake-up source flags will read 0 during the first two system clocks following the wake from suspend mode.
c8051f97x rev 1.0 103 power management register 16.4. pmu0md: power management unit mode bit 7 6 5 4 3 2 1 0 name rtcoe wakeoe reserved type rw rw rw reset 0 0 0 0 0 0 0 0 sfr page = 0x0; sfr address: 0xcf bit name function 7 rtcoe buffered rtc ou tput enable. enables the buffered rtc o scillator output on p0.2. 0: disable the buffered rtc output. 1: enable the buffered rtc output. 6 wakeoe wakeup request output enable. enables the sleep mode wake-up request signal on p0.3. 0: disable the wake-up request signal. 1: enable the wake-up request signal. 5:0 reserved must write reset value.
c8051f97x 104 rev 1.0 analog-to-digital converter (adc0) 17. analog-to-digital converter (adc0) the adc0 module on c8051f97x devices is a 300 ksps, 10-bit successive-approximation-register (sar) adc with integrated track-and-hold and programmable window detector. adc0 also has an autonomous low power burst mode which can automatically enable adc0, capture and a ccumulate samples, then pl ace adc0 in a low power shutdown mode without cpu intervention. it also has a 16 -bit accumulator that can au tomatically oversample and average the adc results. the adc is fully configurable under soft ware control via special function regi sters. the adc0 operates in single- ended mode and may be configured to measure various different signals using the analog multiplexer described in ?19. analog multiplexer (amux0)? on page 158. the adc includes a temperature sensor described in ?17.8. temperature sensor? on page 113, and the voltage reference for the adc is described in ?17.7. voltage reference? on page 112. important note: the cs0 module and the adc0 module cannot bot h be enabled at the same time. even if one module is enabled and not running, the other module must not be enabled. figure 17.1. adc0 functional block diagram adc0 sar analog to digital converter accumulator window compare sysclk clock divider less than greater than 0.5x ? 1x gain control / configuration adc0 vdd vref internal ldo 1.65 v reference trigger selection adwint (window interrupt) sar clock temp sensor vdd gnd internal ldo input selection adbusy (on demand) timer 0 overflow timer 2 overflow timer 3 overflow cnvstr (external pin) adint (interrupt flag) amux0
c8051f97x rev 1.0 105 analog-to-digital converter (adc0) 17.1. adc0 analog multiplexer the adc0 module has an analog multiplexer that selects th e positive inputs to the single-ended adc0. any of the following may be selected as the positive input: pins from the analog pad selector (amux0), the on-chip temperature sensor, internal regulated digital supply vo ltage (output of vreg0), vdd, or gnd. the adc0 input channels are selected in the adc0mx register. if any of the internal signals are selected as the adc0 input channel, the amux0 registers must not select an external pin and all be cleared to 0. important note about adc0 input configuration : a port pin selected as adc0 input should be configured as follows: 1. set to analog mode input by clearing to 0 the corresponding bit in register pnmdin. 2. force the priority crossbar decoder to skip the pin by setting 1 to the corresponding bit in register pnskip. 3. disable the auto-ground for the pin by setting 1 to the corresponding bit in the port latch (pn). 4. enable the analog pad selection for the pin by setting 1 to the corresponding bit in the amux0pn register. see ?26. port i/o (port 0, port 1, port 2, port 3, port 4, port 5, port 6, crossbar, and port match)? on page 278 for more port i/o configuration details. table 17.1. adc0 input multiplexer channels adc0mx setting signal name qfn-48 pin name qfn-32 pin name qfn-24 pin name 00000 ? 11010 adc0.0 ? adc0.26 amux input selector 11011 temp temperature sensor output 11100 vdd vdd supply voltage 11101 ldo internal ldo regulator output 11110 reserved reserved 11111 gnd ground
c8051f97x 106 rev 1.0 analog-to-digital converter (adc0) 17.2. output code formatting the registers adc0h and adc0l contain the high and low by tes of the output conversion code from the adc at the completion of each conversion. data can be right-just ified or left-justified, depending on the setting of the ad0sjst[2:0]. when the repeat count is set to 1, conver sion codes are represented as 10-bit unsigned integers. inputs are measured from 0 to vref x 1023/1024. example codes are shown bel ow for both right-justified and left- justified data. unused bits in the a dc0h and adc0l registers are set to 0. when the repeat count is greater than 1, the output conversion code repr esents the accumulated result of the conversions performed and is updated after the last conversion in the series is finished. sets of 4, 8, 16, 32, or 64 consecutive samples can be accumulated and represented in unsigned integer format. the repeat count can be selected using the ad0rpt bits in the adc0ac register . when a repeat count higher than 1, the adc output must be right-justified (ad0sjst = 0xx); unused bits in the adc0h and adc0l registers are set to 0. the example below shows the right-justified result for various input voltages and repeat counts. notice that accumulating 2 n samples is equivalent to left-shifting by n bit positions when all samples returned from the adc have the same value. the ad0sjst bits can be used to format the contents of the 16-bit accumulator. the accumulated result can be shifted right by 1, 2, or 3 bit positions. based on the principles of oversampling and averaging, the effective adc resolution increases by 1 bit each time the oversampling ra te is increased by a factor of 4. the example below shows how to increase the effective adc resolution by 1, 2, and 3 bits to obtain an effective adc resolution of 11- bit, 12-bit, or 13-bit respecti vely without cp u intervention. input voltage right-j ustified adc0h:adc0l (ad0sjst = 000) left-justified adc0h:adc0l (ad0sjst = 100) vref x 1023/1024 0x03ff 0xffc0 vref x 512/1024 0x0200 0x8000 vref x 256/1024 0x0100 0x4000 0 0x0000 0x0000 input voltage repeat count = 4 repeat count = 16 repeat count = 64 v ref x 1023/1024 0x0ffc 0x3ff0 0xffc0 v ref x 512/1024 0x0800 0x2000 0x8000 v ref x 511/1024 0x07fc 0x1ff0 0x7fc0 0 0x0000 0x0000 0x0000 input voltage repeat count = 4 shift right = 1 11-bit result repeat count = 16 shift right = 2 12-bit result repeat count = 64 shift right = 3 13-bit result v ref x 1023/1024 0x07f7 0x0ffc 0x1ff8 v ref x 512/1024 0x0400 0x0800 0x1000 v ref x 511/1024 0x03fe 0x04fc 0x0ff8 0 0x0000 0x0000 0x0000
c8051f97x rev 1.0 107 analog-to-digital converter (adc0) 17.3. modes of operation adc0 has a maximum conversion speed of 300 ksps. the adc0 conversion clock (sarclk) is a divided version of the system clock when burst mode is disabled (bursten = 0), or a divide d version of the low power oscillator when burst mode is enabled (bursen = 1). the clock divide value is determined by the ad0sc bits in the adc0cf register. 17.3.1. starting a conversion a conversion can be initiated in one of five ways, de pending on the programmed stat es of the adc0 start of conversion mode bits (ad0cm2 ? 0) in register adc0cn. conversions may be initiated by on e of the following: 1. writing a 1 to the ad0busy bit of register adc0cn 2. a timer 0 overflow (i.e., timed continuous conversions) 3. a timer 2 overflow 4. a timer 3 overflow 5. a rising edge on the cnvstr input signal (pin p0.6) writing a 1 to ad0busy provides software control of adc0 whereby conversions are performed ?on-demand?. during conversion, the ad0busy bit is set to logic 1 and reset to logic 0 when the conversion is complete. the falling edge of ad0busy triggers an in terrupt (when enabled) and sets the adc0 interrupt flag (ad0int). when polling for adc conversion comp letions, the adc0 in terrupt flag (ad0int) should be used. conver ted data is available in the adc0 data registers, ad c0h:adc0l, when bit ad0int is logic 1. when timer 2 or timer 3 overflows are used as the conversion source , low byte overflows are used if timer 2/3 is in 8-bit mode; high byte overflows are used if timer 2/3 is in 16-bit mode. see ?32. timers (timer0, timer1, timer2, and timer3)? on page 390 for timer configuration. important note about using cnvstr: the cnvstr input pin also functions as port pin p0.6. when the cnvstr input is used as the adc0 conversion source, port pin p0.6 should be skipped by the digital crossbar. to configure the crossbar to skip p0.6, set to 1 bit 6 in register p0skip. see ?26. port i/o (port 0, port 1, port 2, port 3, port 4, port 5, port 6, cro ssbar, and port match)? on page 278 for details on port i/o configuration.
c8051f97x 108 rev 1.0 analog-to-digital converter (adc0) 17.3.2. tracking modes each adc0 conversion must be preceded by a minimum tracking time in order for the converted result to be accurate. the minimum tracking time is given in ta b l e 1.11 . the ad0tm bit in register adc0cn controls the adc0 track-and-hold mode. in its default state when burst mode is disabled, the adc0 inpu t is continuously tracked, except when a conversion is in progress. when the ad0tm bit is logic 1, adc0 operates in low-power track-and- hold mode. in this mode, each conversion is preceded by a tracking period of 3 sar clocks (after the start-of- conversion signal). when the cnvstr signal is used to initiate conversions in low-power tracking mode, adc0 tracks only when cnvstr is low; conversion begins on the rising edge of cnvstr (see figure 17.2 ). tracking can also be disabled (shutdown) when the device is in low power standby or sleep modes. low-power track-and- hold mode is also useful when amux settings are fre quently changed, due to the settling time requirements described in ?17.3.4. settling time requirements? on page 110 . figure 17.2. 10-bit adc track and conversion example timing (bursten = 0) write '1' to ad0busy, timer 0, timer 2, timer 1, timer 3 overflow (ad0cm[2:0]=000, 001,010 011, 101) ad0tm=1 track convert low power mode ad0tm=0 track or convert convert track low power or convert sar clocks sar clocks b. adc0 timing for internal trigger source 123456789 cnvstr (ad0cm[2:0]=100) ad0tm=1 a. adc0 timing for external trigger source sar clocks track or convert convert track ad0tm=0 track convert low power mode low power or convert 10 11 12 13 14 123456789 10 11 12 13 14 123456789 10 11 12 13 14 15 16 17
c8051f97x rev 1.0 109 analog-to-digital converter (adc0) 17.3.3. burst mode burst mode is a power saving feature that allows adc0 to remain in a low power state between conversions. when burst mode is enabled, adc0 wakes from a low power state, accumulates 1, 4, 8, 16, 32, or 64 using an internal burst mode clock (approximately 20 mhz), then re-enters a low power st ate. since the burst mode clock is independent of the system clock, adc0 can perform mult iple conversions then enter a low power state within a single system clock cycle, even if the system clock is slow (e.g. 32.768 khz), or suspended. burst mode is enabled by setting bursten to logic 1. when in burst mode, ad0en controls the adc0 idle power state (i.e., the state adc0 enters when not tracking or performing conversions). if ad0en is set to logic 0, adc0 is powered down after each burst. if ad0en is set to logic 1, adc0 remains enabled after each burst. on each convert start signal, adc0 is awakened from its idle powe r state. if adc0 is powered down, it will automatically power up and wait the prog rammable power-up time controlled by th e ad0pwr bits. otherwise, adc0 will start tracking and converting immediately. figure 17.3 shows an example of burst mode operation with a slow system clock and a repeat count of 4. when burst mode is enabled, a single convert start will initiate a number of conversions equa l to the repeat count. when burst mode is disabled, a convert start is required to initiate each conversion. in both modes, the adc0 end of conversion interrupt flag (ad0in t) will be set after ?repeat count? conversions have bee n accumulated. similarly, the window comparator will not compare the result to the greater- than and less-than registers until ?repeat count? conversions have been accumulated. in burst mode, tracking is determined by the settings in ad0pwr and ad0tk. the default settings for these registers will work in most applicat ions without modification; however, settling time requir ements may need adjustment in some applications. refer to ?17.3.4. settling time requirements? on page 110 for more details. notes: ? setting ad0tm to 1 will insert an addit ional 3 sar clocks of tracking before each conversion, r egardless of the settings of ad0pwr and ad0tk. ? when using burst mode, care must be taken to issue a convert start signal no faster than once every four sysclk periods. this includes external convert start signals. burst mode must not be enabled together with the capacitive sense (cs0) module. figure 17.3. burst mode tracking example with repeat count set to 4 convert start ad0tm = 1 ad0en = 0 powered down powered down system clock t 3 c power-up and track t c t c t c power-up and track t c.. ad0tm = 0 ad0en = 0 powered down powered down c power-up and track t c t c t c power-up and track t c.. ad0pwr t = tracking set by ad0tk t3 = tracking set by ad0tm (3 sar clocks) c = converting ad0tk t 3 t 3 t 3
c8051f97x 110 rev 1.0 analog-to-digital converter (adc0) 17.3.4. settling time requirements a minimum amount of tracking time is required before ea ch conversion can be performed, to allow the sampling capacitor voltage to settle. this tracking time is determined by the amux0 resistance, the adc0 sampling capacitance, any external source resist ance, and the accuracy required for the conversion. note that in low-power tracking mode, three sar clocks are used for tracking at the start of every conver sion. for many applications, these three sar clocks will meet the minimum tracking time re quirements, and hi gher values fo r the external source impedance will increase the required tracking time. figure 17.4 shows the equivalent adc0 input circuit. the required adc0 settling time for a given settling accuracy (sa) may be approximated by equation 17.1 . when measuring the temperature sensor output or v dd with respect to gnd, r total reduces to r mux . see table 1.11 for adc0 minimum settling time requirements as well as the mux impedance and sampling capacitor values. equation 17.1. adc0 settling time requirements figure 17.4. adc0 equivalent input circuits 17.3.5. gain setting the adc has gain settings of 1x and 0.5x . in 1x mode, the full scale reading of the adc is determined directly by v ref . in 0.5x mode, the full-scale reading of the adc occurs when the input voltage is v ref x 2. the 0.5x gain setting can be useful to obtain a higher input voltage range when using a small v ref voltage, or to measure input voltages that are between v ref and v dd . gain settings for the adc are contro lled by the amp0gn bit in register adc0cf. 17.4. 8-bit mode setting the adc08be bit in register adc0cf to 1 will put the adc in 8-bi t mode. in 8-bit mode, only the 8 msbs of data are converted, allowing the conversion to be completed in two fewer sar clock cycles than a 10-bit conversion. this can result in an ov erall lower power consumption since the system can spend more time in a low power mode. the two lsbs of a conversi on are always 00 in this mode, and the adc0l register will always read back 0x00. t 2 n sa ------ - ?? ?? r total c sample ? ln = where sa is the settling accuracy, give n as a fraction of an lsb (e.g., 0.25 to settle within 1/4 lsb) t is the required settl ing time in seconds r total is the sum of the amux0 resistance and any external source resistance. n is the adc resolution in bits (10) r mux c sample rc input = r mux * c sample mux select p0.x note: the value of csample depends on the pg a gain. see table 1.11 for details.
c8051f97x rev 1.0 111 analog-to-digital converter (adc0) 17.5. low power mode the sar converter provides a low power mode that allo ws a significant reduction in operating current when operating at low sar clock frequencies. low power mode is enabled by setting the ad0lpm bit (adc0pwr.7) to 1. in general, low power mode is recommended when operating with sar conversion clock frequency at 4 mhz or less. see ?1. electrical characteristics? on page 10 for details on power consumption and the maximum clock frequencies allowed in each mode. setting the low power mode bit reduces the bias currents in both the sar converter and in the high-speed voltage reference. 17.6. window detector in single-ended mode figure 17.5 shows two example window comparisons for right-justified data, with adc0lth:adc0ltl = 0x0080 (128d) and adc0gth:adc0gtl = 0x0040 (64d). the input voltage can range from 0 to vref x (1023/1024) with respect to gnd, and is represented by a 10-bit unsigned in teger value. in the left example, an ad0wint interrupt will be generated if the adc0 co nversion word (adc0h:adc0l) is within the range defined by adc0gth:adc0gtl and adc0lth:adc0ltl (if 0x0040 < adc0h:adc0l < 0x0080). in the right example, and ad0wint interrupt will be gener ated if the adc0 conversion word is outsi de of the ra nge defined by the adc0gt and adc0lt registers (if adc0h:adc0l < 0x0040 or adc0h:adc0l > 0x0080). figure 17.6 shows an example using left-justified data with the same comparison values. figure 17.5. adc window compare example: right-justified single-ended data figure 17.6. adc window compare exampl e: left-justified single-ended data 0x03ff 0x0081 0x0080 0x007f 0x0041 0x0040 0x003f 0x0000 0 input voltage (px.x - gnd) vref x (1023/ 1024) vref x (128/1024) vref x (64/1024) ad0wint=1 ad0wint not affected ad0wint not affected adc0lth:adc0ltl adc0gth:adc0gtl 0x03ff 0x0081 0x0080 0x007f 0x0041 0x0040 0x003f 0x0000 0 input voltage (px.x - gnd) vref x (1023/ 1024) vref x (128/1024) vref x (64/1024) ad0wint not affected ad0wint=1 ad0wint=1 adc0h:adc0l adc0h:adc0l adc0gth:adc0gtl adc0lth:adc0ltl 0xffc0 0x2040 0x2000 0x1fc0 0x1040 0x1000 0x0fc0 0x0000 0 input voltage (px.x - gnd) vref x (1023/ 1024) vref x (128/1024) vref x (64/1024) ad0wint=1 ad0wint not affected ad0wint not affected adc0lth:adc0ltl adc0gth:adc0gtl 0xffc0 0x2040 0x2000 0x1fc0 0x1040 0x1000 0x0fc0 0x0000 0 input voltage (px.x - gnd) vref x (1023/ 1024) vref x (128/1024) vref x (64/1024) ad0wint not affected ad0wint=1 ad0wint=1 adc0h:adc0l adc0h:adc0l adc0lth:adc0ltl adc0gth:adc0gtl
c8051f97x 112 rev 1.0 analog-to-digital converter (adc0) 17.7. voltage reference the voltage reference mux is configurable to use an exte rnally connected voltage reference, the internal voltage reference, or one of two power supply voltages (see figure 17.7 ). the voltage reference mux is configured using the ref0cn register. electrical specifications are can be found in the electrical specifications chapter. important note about the vref input: port pin p0.0 is used as the external vref input. when using an external voltage reference, p0.0/vref should be configured as an analog input and skipped by the priority crossbar decoder. refer to ?26. port i/o (port 0, port 1, port 2, port 3, port 4, port 5, port 6, crossbar, and port match)? on page 278 for complete port i/o configuration details. the ex ternal reference voltage must be within the range 0 < vref < vdd. figure 17.7. voltage reference functional block diagram 17.7.1. external voltage reference to use an external voltage reference, refsl[1:0] should be set to 00. by pass capacitors should be added as recommended by the manufacturer of the external vo ltage reference. if the manufacturer does not provide recommendations, a 4.7 f in parallel with a 0.1 f capacitor is recommended. p0.0/vref r1 vdd external voltage reference circuit gnd 00 01 10 11 ref0cn refsl0 tempe refsl1 recommended bypass capacitors + 4.7 ? f0.1 ? f internal 1.8v regulated digital supply v dd internal 1.65v high speed reference to amux0 temp sensor en vref (to adc)
c8051f97x rev 1.0 113 analog-to-digital converter (adc0) 17.7.2. internal voltage reference for applications requiring the maximum number of port i/o pins, or very short vref turn-on time, the 1.65 v high- speed reference will be the best internal reference option to choose. the high-speed internal reference is selected by setting refsl to 11b. when selected, the high-speed internal reference will be automatically enabled/disabled on an as-needed basis by adc0. for applications with a non-varying power supply voltag e, using the power supply as the voltage reference can provide adc0 with added dynamic range at the cost of re duced power supply noise rejection. to use the 1.8 to 3.6 v power supply voltage (vdd) or the 1.8 v regulated digital supply voltage as the reference source, refsl should be set to 01b or 10b, respectively. 17.8. temperature sensor an on-chip temperature sensor is included, which can be di rectly accessed via the adc multiplexer in single-ended configuration. to use the adc to measure the temperature sensor, the adc mux channel should select the temperature sensor. the temperature sensor transfer fu nction is shown in figure 17.8. the output voltage (v temp ) is the positive adc input when the a dc multiplexer is set correctly. the tempe bit in register ref0cn enables/ disables the temperature sensor. while disabled, the temp erature sensor defaults to a high impedance state and any adc measurements performed on the sensor will result in meaningle ss data. refer to the electrical specification tables for the slope and offset parameters of the temperature sensor. figure 17.8. temperature sensor transfer function 17.8.1. calibration the uncalibrated temperature sensor output is extr emely linear and suitable for relative temperature measurements. for absolute temperature measurements, of fset and/or gain calibration is recommended. typically a 1-point (offset) calibration includes the following steps: 1. control/measure the ambient temperat ure (this temperature must be known). 2. power the device, and delay for a few seconds to allo w for self-heating. 3. perform an adc conversion with the te mperature sensor selected as the adc input. 4. calculate the offset characteri stics, and store this value in non-v olatile memory for use with subsequent temperature sensor measurements. temperature voltage v temp = ( slope x temp c ) + offset offset (v at 0 celsius) slope (v / deg c) temp c = (v temp - offset ) / slope
c8051f97x 114 rev 1.0 analog-to-digital converter (adc0) 17.9. adc control registers register 17.1. adc0cn: adc0 control bit 7 6 5 4 3 2 1 0 name aden adbmen adint adbusy adwint adcm type rw rw rw rw rw rw reset00000000 sfr page = 0x0; sfr address: 0xe8 (bit-addressable) table 17.2. adc0cn register bit descriptions bit name function 7 aden adc enable. 0: disable adc0 (low-power shutdown). 1: enable adc0 (active and ready for data conversions). 6 adbmen burst mode enable. important note: burst mode must be disabled if cs0 is active. this is true regardless of the adc0mx configuration. 0: adc0 burst mode disabled. 1: adc0 burst mode enabled. 5 adint conversion complete interrupt flag. set by hardware upon completion of a data conversion (adbmen=0), or a burst of con - versions (adbmen=1). can trigger an interrupt. must be cleared by firmware. 4 adbusy adc busy. writing 1 to this bit initiates an adc conver sion when adcm = 000. this bit should not be polled to indicate when a conversion is complete. instead, the adint bit should be used when polling for conversion completion. 3 adwint window compare interrupt flag. set by hardware when the contents of adc0 h:adc0l fall within the window specified by adc0gth:adc0gtl and adc0lth:adc0ltl. can trigge r an interrupt. must be cleared by firmware. 2:0 adcm start of conversion mode select. specifies the adc0 start of conversion so urce. all remaining bit combinations are reserved. 000: adc0 conversion initiat ed on write of 1 to adbusy. 001: adc0 conversion initiated on overflow of timer 0. 010: adc0 conversion initiated on overflow of timer 2. 011: adc0 conversion initiated on overflow of timer 3. 100: adc0 conversion initiated on rising edge of cnvstr. 101-111: reserved.
c8051f97x rev 1.0 115 analog-to-digital converter (adc0) register 17.2. adc0cf: adc0 configuration bit 7 6 5 4 3 2 1 0 name adsc ad8be adtm adgn type rw rw rw rw reset00000000 sfr page = 0x0; sfr address: 0x97 table 17.3. adc0cf register bit descriptions bit name function 7:3 adsc sar clock divider. this field sets the adc clock divider value. it should be configured to be as close to the maximum sar clock speed as the datasheet will allow. the sar clock frequency is given by the following equation: f adcclk is equal to the selected sysclk when adbmen is 0 and the high-frequency oscillator when adbmen is 1. 2 ad8be 8-bit mode enable. 0: adc0 operates in 10-bit mode (normal operation). 1: adc0 operates in 8-bit mode. 1 adtm track mode. selects between normal or delayed tracking modes. 0: normal track mode. when adc0 is enabled, conversion begins immediately following the start-of-conversion signal. 1: delayed track mode. when adc0 is enab led, conversion begins 3 sar clock cycles following the start-of-conversion signal. the adc is allowed to track during this time. 0 adgn gain control. 0: the on-chip pga gain is 0.5. 1: the on-chip pga gain is 1. f clksar f adcclk adsc 1 + ------------------------ - =
c8051f97x 116 rev 1.0 analog-to-digital converter (adc0) register 17.3. adc0ac: adc0 accumulator configuration bit 7 6 5 4 3 2 1 0 name reserved adae adsjst adrpt type rw w rw rw reset00000000 sfr page = 0x0; sfr address: 0xba table 17.4. adc0ac register bit descriptions bit name function 7 reserved must write reset value. 6 adae accumulate enable. enables multiple conversions to be accumulat ed when burst mode is disabled. this bit is write-only and always reads as zero. 0: adc0h:adc0l contain the result of the latest conversion when burst mode is dis - abled. 1: adc0h:adc0l contain the accumulated conv ersion results when burst mode is dis - abled. firmware must write 0x0000 to adc0h:adc0l to clear the accumulated result. 5:3 adsjst accumulator shift and justify. specifies the format of data read from adc0h:adc0l. all remaining bit combinations are reserved. 000: right justified. no shifting applied. 001: right justified. shifted right by 1 bit. 010: right justified. shifted right by 2 bits. 011: right justified. shifted right by 3 bits. 100: left justified. no shifting applied. 101-111: reserved. 2:0 adrpt repeat count. selects the number of conversions to perform and accumulate in burst mode. this bit field must be set to 000 if burst mode is disabled. 000: perform and accumulate 1 conversion. 001: perform and accumulate 4 conversions. 010: perform and accumulate 8 conversions. 011: perform and accumulate 16 conversions. 100: perform and accumulate 32 conversions. 101: perform and accumulate 64 conversions. 110-111: reserved.
c8051f97x rev 1.0 117 analog-to-digital converter (adc0) register 17.4. adc0pwr: adc0 power control bit 7 6 5 4 3 2 1 0 name adlpm reserved adpwr type rw rw rw reset00001111 sfr page = all; sfr address: 0xbb table 17.5. adc0pwr register bit descriptions bit name function 7 adlpm low power mode enable. this bit can be used to reduce power to the adc's internal common mode buffer. it can be set to 1 to reduce power when tracking times in the application are longer (slower sample rates). 0: disable low power mode. 1: enable low power mode (requires extended tracking time). 6:4 reserved must write reset value. 3:0 adpwr burst mode power up time. this field sets the time delay allowed for t he adc to power up from a low power state. when adtm is set, an additional 3 sarclks are added to this time. t pwrtime 8adpwr ? f hfosc ------------------------------ =
c8051f97x 118 rev 1.0 analog-to-digital converter (adc0) register 17.5. adc0tk: adc0 burst mode track time bit 7 6 5 4 3 2 1 0 name reserved adtk type r rw reset00011110 sfr page = all; sfr address: 0xbc table 17.6. adc0tk register bit descriptions bit name function 7:6 reserved must write reset value. 5:0 adtk burst mode tracking time. this field sets the time delay between co nsecutive conversions performed in burst mode. when adtm is set, an additio nal 3 sarclks are added to this time. the burst mode track delay is not inserted prior to the first conversion. the required tracking time for the first conversion should be defined with the adpwr field. t bmtk 64 adtk ? f hfosc ---------------------------- =
c8051f97x rev 1.0 119 analog-to-digital converter (adc0) register 17.6. adc0h: adc0 data word high byte bit 7 6 5 4 3 2 1 0 name adc0h type rw reset00000000 sfr page = 0x0; sfr address: 0xd3 table 17.7. adc0h register bit descriptions bit name function 7:0 adc0h data word high byte. when read, this register returns the most significant byte of the 16-bit adc0 accumula - tor, formatted according to the settings in adsjst. the re gister may also be written, to set the upper byte of the 16-bit adc0 accumulator. note: if accumulator shifting is enabled, the most si gnificant bits of the value read will be zeros.
c8051f97x 120 rev 1.0 analog-to-digital converter (adc0) register 17.7. adc0l: adc0 data word low byte bit 7 6 5 4 3 2 1 0 name adc0l type rw reset00000000 sfr page = 0x0; sfr address: 0xd2 table 17.8. adc0l register bit descriptions bit name function 7:0 adc0l data word low byte. when read, this register returns the least significant byte of the 16-bit adc0 accumula - tor, formatted according to the settings in adsjst. the re gister may also be written, to set the lower byte of the 16-bit adc0 accumulator. note: if accumulator shifting is enabled, the most si gnificant bits of the value read will be zeros.
c8051f97x rev 1.0 121 analog-to-digital converter (adc0) register 17.8. adc0gth: adc0 greater-than high byte bit 7 6 5 4 3 2 1 0 name adc0gth type rw reset11111111 sfr page = 0x0; sfr address: 0xc4 table 17.9. adc0gth register bit descriptions bit name function 7:0 adc0gth greater-than high byte. most significant byte of the 16-bit greater-than window compare register.
c8051f97x 122 rev 1.0 analog-to-digital converter (adc0) register 17.9. adc0gtl: adc0 greater-than low byte bit 7 6 5 4 3 2 1 0 name adc0gtl type rw reset11111111 sfr page = 0x0; sfr address: 0xc3 table 17.10. adc0gtl register bit descriptions bit name function 7:0 adc0gtl greater-than low byte. least significant byte of the 16-bit greater-than window compare register. note: in 8-bit mode, this register should be set to 0x00.
c8051f97x rev 1.0 123 analog-to-digital converter (adc0) register 17.10. adc0lth: adc0 less-than high byte bit 7 6 5 4 3 2 1 0 name adc0lth type rw reset00000000 sfr page = 0x0; sfr address: 0xc6 table 17.11. adc0lth register bit descriptions bit name function 7:0 adc0lth less-than high byte. most significant byte of the 16-bit less-than window compare register.
c8051f97x 124 rev 1.0 analog-to-digital converter (adc0) register 17.11. adc0ltl: adc0 less-than low byte bit 7 6 5 4 3 2 1 0 name adc0ltl type rw reset00000000 sfr page = 0x0; sfr address: 0xc5 table 17.12. adc0ltl register bit descriptions bit name function 7:0 adc0ltl less-than low byte. least significant byte of the 16-bit less-than window compare register. note: in 8-bit mode, this register should be set to 0x00.
c8051f97x rev 1.0 125 analog-to-digital converter (adc0) register 17.12. adc0mx: adc0 multiplexer selection bit 7 6 5 4 3 2 1 0 name reserved adc0mx type r rw reset00011111 sfr page = 0x0; sfr address: 0xd4 table 17.13. adc0mx register bit descriptions bit name function 7:5 reserved must write reset value. note: if any of the internal signals are sele cted as the adc0 input channel, the amux0 registers must not select an external pin and all be cleared to 0.
c8051f97x 126 rev 1.0 analog-to-digital converter (adc0) 4:0 adc0mx amux0 positive input selection. selects the positive input channel for adc0. for reserved bit comb inations, no input is selected. 00000: select channel adc0.0. 00001: select channel adc0.1. 00010: select channel adc0.2. 00011: select channel adc0.3. 00100: select channel adc0.4. 00101: select channel adc0.5. 00110: select channel adc0.6. 00111: select channel adc0.7. 01000: select channel adc0.8. 01001: select channel adc0.9. 01010: select channel adc0.10. 01011: select channel adc0.11. 01100: select channel adc0.12. 01101: select channel adc0.13. 01110: select channel adc0.14. 01111: select channel adc0.15. 10000: select channel adc0.16. 10001: select channel adc0.17. 10010: select channel adc0.18. 10011: select channel adc0.19. 10100: select channel adc0.20. 10101: select channel adc0.21. 10110: select channel adc0.22. 10111: select channel adc0.23. 11000: select channel adc0.24. 11001: select channel adc0.25. 11010: select channel adc0.26. 11011: temperature sensor. 11100: vdd supply voltage. 11101: internal ldo regulator output. 11110: reserved. 11111: ground. table 17.13. adc0mx register bit descriptions bit name function note: if any of the internal signals are sele cted as the adc0 input channel, the amux0 registers must not select an external pin and all be cleared to 0.
c8051f97x rev 1.0 127 analog-to-digital converter (adc0) 17.10. voltage reference registers register 17.13. ref0cn: voltage reference control bit 7 6 5 4 3 2 1 0 name reserved refsl tempe reserved type rw rw rw rw reset00000000 sfr page = 0x0; sfr address: 0xd1 table 17.14. ref0cn register bit descriptions bit name function 7:5 reserved must write reset value. 4:3 refsl voltage reference select. selects the adc0 voltage reference. 00: the adc0 voltage reference is the p0.0/vref pin. 01: the adc0 voltage reference is the vdd pin. 10: the adc0 voltage reference is the internal 1.8 v digital supply voltage. 11: the adc0 voltage reference is the internal 1.65 v high speed voltage reference. 2 tempe temperature sensor enable. enables/disables the internal temperature sensor. 0: disable the temperature sensor. 1: enable the temperature sensor. 1:0 reserved must write reset value.
c8051f97x 128 rev 1.0 analog-to-digital converter (adc0) 17.11. temperature sensor registers register 17.14. toffh: temperature sensor offset high bit 7 6 5 4 3 2 1 0 name toff type r resetxxxxxxxx sfr page = 0xf; sfr address: 0x8e table 17.15. toffh register bit descriptions bit name function 7:0 toff temperature sensor offset high. most significant bits of the 10-bit temperature sensor offset measurement.
c8051f97x rev 1.0 129 analog-to-digital converter (adc0) register 17.15. toffl: temperature sensor offset low bit 7 6 5 4 3 2 1 0 name toff reserved type r r resetxx000000 sfr page = 0xf; sfr address: 0x8d table 17.16. toffl register bit descriptions bit name function 7:6 toff temperature sensor offset low. least significant bits of the 10-bit temperature sensor offset measurement. 5:0 reserved must write reset value.
c8051f97x 130 rev 1.0 capacitive sense (cs0) 18. capacitive sense (cs0) the capacitive sense subsystem uses a capacitance-to-digit al circuit to determine the capacitance on a port pin. the module can take measurements from different port pins using the module?s analog multiplexer. the module is enabled only when the cs0int bit (cs0cn) is set to 1. otherwise the module is in a low-power shutdown state. the module can be configured to take measurements on on e port pin or a group of po rt pins, using auto-scan. a selectable gain circuit allows the desi gner to adjust the maximum allowable capacitance. an accumulator is also included, which can be configured to average multiple conversions on an input channel. interrupts can be generated when cs0 completes a conversion or when the measured value crosses a threshold defined in cs0thh:l. important note : the cs0 module and the adc0 module cannot both be enabled at the same time. even if one module is enabled and not running, the other module must not be enabled. figure 18.1. cs0 block diagram capacitance to digital converter timer 0 overflow timer 2 overflow timer 1 overflow start conversion 000 cs0busy (w) cs0cmpf 001 010 011 100 timer 3 overflow greater than compare logic 101 initiated continuously cs0thh:l cs0dh:l auto-scan logic cs0ss cs0se 22-bit accumulator 110 111 initiated continuously when auto-scan enabled reserved cs0cn cs0cmpf cs0pme cs0cmpen cs0busy cs0int cs0eos cs0en cs0cf cs0acu0 cs0acu1 cs0acu2 cs0mcen cs0cm0 cs0cm1 cs0cm2 cs0smen cs0mux . . . 1x-8x cs0md1 cs0cg0 cs0cg1 cs0cg2 cs0woi cs0dr0 cs0dr1 cs0pol cs0md2 cs0ia0 cs0ia1 cs0ia2 cs0dt0 cs0dt1 cs0dt2 cs0cr0 cs0cr1 cs0md3 cs0lp0 cs0lp1 cs0lp2 cs0rp0 cs0rp1 cs0pm cspmmd0 cspmmd1 i2c0pm piopm pcapm smbpm spipm uapm pin monitor port i/o and peripherals 12, 13, 14, or 16 bits from am0 pad selector cs0cmpen cs0smen cs0mcen cs0pol cs0woi wake up event logic cs0woi cs0eos wake-up signal
c8051f97x rev 1.0 131 capacitive sense (cs0) 18.1. configuring port pins as capacitive sense inputs in order for a port pin to be measured by cs0, that port pin must be configured as an analog input (see ?26. port i/ o (port 0, port 1, port 2, port 3, port 4, port 5, port 6, crossbar, and port match)? ). configuring the input multiplexer to a port pin not configured as an analog inpu t will cause the capacitive se nse comparator to output incorrect measurements. 18.2. initializing the ca pacitive sensing peripheral the following procedure is recommended for properly initializing the cs0 peripheral: 1. enable the cs0 block (cs0int = 1) before performing any other initializations. 2. initialize the start of conversion mode sele ct bits (cs0cm[2:0]) to the desired mode. 3. continue initializing all remaining cs0 registers. 18.3. capacitive sense start-of-conversion sources a capacitive sense conversion can be initiated in one of seven ways, depending on the programmed state of the cs0 start of conversion bits (cs0cf6:4). conver sions may be initiated by one of the following: 1. writing a 1 to the cs0busy bit of register cs0cn 2. timer 0 overflow 3. timer 2 overflow 4. timer 1 overflow 5. timer 3 overflow 6. convert continuously 7. convert continuously with auto-scan enabled conversions can be configured to be initiated continuousl y through one of two methods. cs0 can be configured to convert at a single channel continuously or it can be c onfigured to convert continuously with auto-scan enabled. when configured to convert co ntinuously, conversions will b egin after the cs0busy bit in cs0cf has been set. an interrupt will be gener ated if cs0 conversion comple te interrupts are e nabled by setting the ecscpt bit (eie2.0). the cs0 module uses a method of successive approximatio n to determine the value of an external capacitance. the number of bits the cs0 module converts is adjustabl e using the cs0cr bits in register cs0md2. conversions are 13 bits long by default, but they can be adjusted to 12, 13, 14, or 16 bits depending on the needs of the application. unconverted bits will be se t to 0. shorter conversion lengths produce faster co nversion rates, and vice- versa. applications can take advantage of faster conver sion rates when the unconverted bits fall below the noise floor. note: cs0 conversion complete interrupt behavior depends on the sett ings of the cs0 accumulator. if cs0 is configured to accumulate multiple conversions on an input channel, a cs0 conversion complete interrupt will be generated only after the last conver sion completes. ?
c8051f97x 132 rev 1.0 capacitive sense (cs0) 18.4. cs0 multiple channel enable cs0 has the capability of measuring the total capacitance of multiple channels using a si ngle conversion. when the multiple channel feature is enabled (cs0mcen = 1), channels selected by amux0pn are internally shorted together and the combined node is selected as the cs0 input. this mode can be used to detect a capacitance change on multiple channels using a single conversion and is useful for im plementing ?wake-on-multiple channels?. 18.5. cs0 gain adjustment the gain of the cs0 circuit can be adjusted in integer incr ements from 1x to 8x (8x is the default). high gain gives the best sensitivity and resolution for small capacitors, such as those typica lly implemented as touch-sensitive pcb features. to measure larger capacitance values, the gain should be lowered accordingly. the bits cs0cg[2:0] in register cs0md set the gain value. 18.6. wake from suspend cs0 has the capability of waking the device from a low power suspend mode upon detection of a ?touch? using the digital comparator. this threshold comp arator event can also be used as an end-of-conversion wake by setting the threshold registers to all zeros. 18.7. using cs0 in applicat ions that utilize sleep mode to achieve maximum power efficiency, cs0 should be enabled only when taking a conversion and disabled at all other times. cs0 must be disabled by software prior to entering sleep mode. 18.8. automatic scanni ng (method 1?cs0smen = 0) cs0 can be configured to automatically scan a sequence of contiguous cs0 input channels by configuring and enabling auto-scan. using auto-scan with the cs0 compar ator interrupt enabled allows a system to detect a change in measured capacitance without requir ing any additional dedicated mcu resources. auto-scan is enabled by setting the cs0 start-of-conversio n bits (cs0cf6:4) to 111b. after enabling auto-scan, the starting and ending channels should be set to appropriate values in cs0ss and cs0se, respectively. writing to cs0ss when auto-scan is enabled will ca use the value written to cs0ss to be copied into cs0mx. after being enabled, writing a 1 to cs0busy will start auto-scan conversions. when auto-scan completes the number of conversions defined in the cs0 accumulator bits (cs0cf1: 0), auto-scan configures cs0mx to the next sequential port pin configured as an analog input and begins a conv ersion on that channel. all ot her pins between cs0ss and cs0se which are set as analog inputs are grounded during the conversion. this scan sequence continues until cs0mx reaches the ending input channel value defined in cs0se. after one or more conversions have been taken at this channel, auto-scan configures cs0mx back to the starting input channel. for an example system configured to use auto-scan, please see figure ?18.2 auto-scan example? on page 133 . note: auto-scan attempts one conversion on a cs0mx channel regardless of whether that channel?s port pin has been configured as an analog input. auto-scan will also complete the current rotation when the device is halted for debugging. if auto-scan is enabled when the device enters suspend mode, auto-s can will remain enabled and running. this feature allows the device to wake from suspend throug h cs0 greater-than comparator event on any configured capacitive sense input included in the auto-scan sequence of inputs.
c8051f97x rev 1.0 133 capacitive sense (cs0) figure 18.2. auto-scan example sfr configuration: a d a a d d d d d a a a a a a a p2.0 . . . pxmdin bit port pin 0 cs0mx channel p2.1 1 p2.2 2 p2.3 3 p2.4 4 p2.5 5 p2.6 6 p2.7 7 p3.0 8 p3.1 9 p3.2 10 p3.3 11 p3.4 12 p3.5 13 p3.6 14 p3.7 15 cs0ss = 0x02 cs0se = 0x0d p2mdin = 0xf2 p3mdin = 0x04 cs0cf = 0x70 cs0cn = 0x80 enables cs0 enables auto-scan as start-of- conversion source sets p2.2 as auto- scan starting channel sets p3.5 as auto- scan ending channel configures p2.3, p2.2, p2.0 as analog inputs configures p3.0-p3.1 and p3.3-p3.7 as analog inputs scans on channels not configured as analog inputs result in indeterminate values that cannot trigger a cs0 greater than interrupt event
c8051f97x 134 rev 1.0 capacitive sense (cs0) 18.9. automatic scanni ng (method 2?cs0smen = 1) when cs0smen is enabled, cs0 uses an alternate autoscanning method that uses the contents of amux0pn to determine which channels to include in the scan. this maximizes flex ibility for application development and can result in more power efficient scanning. the following procedure can be used to configure the device for automatic scanning with cs0smen = 1. 1. set the cs0smen bit to 1. 2. select the start of conversion mode (cs0cm[2:0]) if not already configured. mode 101b is the mode of choice for most systems. 3. configure the amux0pn registers to enable channels in the scan. 4. configure the cs0thh:cs0thl digi tal comparator threshold and polarity. 5. enable wake from suspend on end of scan (cs0woi = 1) if this functionality is desired. 6. set cs0ss to point to the firs t channel in the scan. note: cs0ss uses the same bit mapping as the cs0mx register. 7. issue a start of conversion (busy = 1). 8. enable the cs0 wakeup source and place the device in suspend mode (optional). if using mode 101b, scanning will stop on ce a ?touch? has been detected usin g the digital comparator. the cs0mx register will contain the channel mux value of the channel that caused the inte rrupt. setting the busy bit when servicing the interrupt will cause the sca n to continue where it left off. sc anning will also stop after all channels have been sampled and no ?t ouches? have been detected. if the cs0woi bit is set, a wake from suspend event will be generated. note: when automatic sc anning is enabled, the contents of the cs0mx register are only valid when the digital comparator interrupt is set and busy = 0. 18.10. cs0 comparator the cs0 comparator compares the latest capacitive sense conversion result with the value stored in cs0thh:cs0thl. if the result is less than or equal to the stored value, the cs 0cmpf bit(cs0cn:0) is set to 0. if the result is greater th an the stored value, cs0cmpf is set to 1. if the cs0 conversion accumulator is configured to accumulate multiple conversions, a comparison will not be made until the last conversion has been accumulated. an interrupt will be generated if cs0 greater-than comparat or interrupts are enabled by setting the ecsgrt bit (eie2.1) when the comparator sets cs0cmpf to 1. if auto-scan is running when the comp arator sets the cs0cmpf bit, no furthe r auto-scan initia ted conversions will start until firmware sets cs0busy to 1. a cs0 greater-than comparator event ca n wake a device from suspend mode. th is feature is useful in systems configured to continuously samp le one or more capacitive sense channe ls. the device will remain in the low-power suspend state until the captured value of one of the scanned channels causes a cs0 greater-than comparator event to occur. it is not necessary to have cs0 comparator interrupts enabled in order to wake a device from suspend with a greater-than event. for a summary of behavior with differ ent cs0 comparator, auto-scan, and auto accumulator settings, please see ta b l e 18.1 .
c8051f97x rev 1.0 135 capacitive sense (cs0) 18.11. cs0 conversion accumulator cs0 can be configured to accumulate multiple conversions on an input channel. the number of samples to be accumulated is configured using the cs0acu2:0 bits (cs0 cf2:0). the accumulator can accumulate 1, 4, 8, 16, 32, or 64 samples. after the defined number of samples have been accumulated, the result is divided by either 1, 4, 8, 16, 32, or 64 (depending on the cs0acu[2:0] setting) and copied to the cs0dh:cs0dl sfrs. table 18.1. operation with auto-scan and accumulate auto-scan enabled accumulator enabled cs0 conversion complete interrupt behavior cs0 greater than interrupt behavior cs0mx behavior n n cs0int interrupt serviced after 1 con - version completes interrupt serviced after 1 conver - sion completes if value in cs0dh:cs0dl is greater than cs0thh:cs0thl cs0mx unchanged. n y cs0int interrupt serviced after m conversions com - plete interrupt serviced after m conver - sions complete if value in cs0dh:cs0dl (post accumu - late and divide) is greater than cs0thh:cs0thl cs0mx unchanged. y n cs0int interrupt serviced after 1 con - version completes interrupt serviced after conver - sion completes if value in cs0dh:cs0dl is greater than cs0thh:cs0thl; auto-scan stopped if greater-than comparator detects conversion value is greater than cs0thh:cs0thl, cs0mx is left unchanged; otherwise, cs0mx updates to the next channel (cs0mx + 1) and wraps back to cs0ss after passing cs0se. y y cs0int interrupt serviced after m conversions com - plete interrupt serviced after m conver - sions complete if value in cs0dh:cs0dl (post accumu - late and divide) is greater than cs0thh:cs0thl; auto-scan stopped if greater-than comparator detects conversion value is greater than cs0thh:cs0thl, cs0mx is left unchanged; otherwise, cs0mx updates to the next channel (cs0mx + 1) and wraps back to cs0ss after passing cs0se. note: m = accumulator setting (1x, 4x, 8x, 16x, 32x, 64x).
c8051f97x 136 rev 1.0 capacitive sense (cs0) 18.12. cs0 pin monitor the cs0 module provides accurate conversions in all operating modes of the cpu, peripherals and i/o ports. pin monitoring circuits are provided to eliminate possible inte rference from high-current output pin switching. the cs0 pin monitor register (cs0pm) controls the operation of these pin monitors. conversions in the cs0 module are immune to any change on digital inputs and immune to most output switching. even high-speed serial da ta transmission will not affect cs0 operation as long as the output load is limited. output changes that switch large loads such as leds and hea vily-loaded communications lines can affect conversion accuracy. for this reason, the cs0 module includes pin monitoring circuits that will, if enabled, automatically adjust conversion timing if necessary to eliminate any effect from high-current output pin switching. the pin monitor enable bit should be set for any outp ut signal that is expected to drive a large load. example: the smbus in a system is heavily loaded with mu ltiple slaves and a long pcb route. set the smbus pin monitor enable, smbpm = 1. example: timer2 controls an led on port 1, pin 3 to provide variable dimming. set the port sfr write monitor enable, piopm = 1. example: the spi bus is used to communicate to a nearby host. the pin monitor is not needed because the output is not heavily loaded, spipm remains = 0, the default reset state. pin monitors should not be enabled unless they are requir ed. the pin monitor works by repeating any portion of a conversion that may have b een corrupted by a change on an output pin. setting pin monitor enables bits will slow cs0 conversions. the frequency of cs0 retry operations can be limited by se tting the cspmmd bits. in th e default (reset) state, all converter retry requests will be perform ed. this is the recomme nded setting for all applic ations. the number of retries per conversion can be limited to either two or fo ur retries by changing cspmmd. limiting the number of retries per conversion ensures that ev en in circumstances where extremely frequent high-power output switching occurs, conversions will be completed, though there may be some loss of accuracy due to switching noise. activity of the pin monitor circuit can be detected by reading the pin monitor event bit, cs0pme, in register cs0cn. this bit will be set if any cs0 c onverter retries have occurred. it remain s set until cleared by software or a device reset. notes on pin monitor operation: ?? when the system clock is active in the system, the pin monitor feature r equires a system clock frequency of 5.5 mhz or higher to function correctly. ?? when using cs0 as a wake-up source with pin monito ring enabled, the minimum active mode system clock frequency that can be used is 1.8 mhz. a cs0 wake-up event in a system with an active mode clock frequency below 1.8 mhz will cause cs0 to start another conver sion instead of remaining stopped when the system wakes from its low power state.
c8051f97x rev 1.0 137 capacitive sense (cs0) 18.13. adjusting cs0 for special situations there are several configuration options in the cs0 modul e designed to modify the operation of the circuit and address special situations. in particular, any circuit with more than 500 ? of series impedance between the sensor and the device pin may require the adjustments detaile d in this section for optimal performance. typical applications which may require adjustments include the following: ?? touch panel sensors fabricated using a resistive conductor such as indium-tin-oxide (ito). ?? circuits using a high-value series resistor to isol ate the sensor element for high esd protection. capacitive sensors created using pcb traces should gene rally require no fine tuning, and the default settings for cs0dt, cs0dr, cs0ia, cs0rp and cs0lp should be used. 18.13.1. adjusting the cs0 reset timing the cs0 module determines capacitance by discharging an external capacitor and then measuring how quickly that capacitor charge s. in order to do this, the external capacitor must be fully discharged before every test. there are two timers inside the cs0 module which determi ne the timing for the reset (discharge) operation. cs0 performs a two-stage discharge (double reset) of the ex ternal capacitor at the start of every bit conversion to improve performance in high-noise environments. in this me thod, most of the charge in the external capacitor is removed in a first reset stage through a low-resistance swit ch to ground. a second reset is then performed using a high-resistance switch to ground. this second reset removes any ambient noise energy that might have been captured in the external capacitor at the end of the first reset stage. the lengths of both reset periods are independently adjustable. longer periods are used when the external capacitor is separated from the cs0 modu le by a large resistor (more than 500 ? ) because that series resistor would slow the rate of discharge. determining the appropriate settings fo r cs0dt (the primary reset) and cs0dr (the secondary reset) are two of a series of related adjustments which must be made when us ing cs0 to measure capacitive loads in the presence of high resistance. 18.13.2. adjusting primary reset timing: cs0dt primary reset timing adjustment is performed to provide peak sensitivity for highly-resisti ve loads and peak linearity for capacitive loads linked thorough a distributed resistanc e (such as an ito touch panel) while minimizing the required conversion time. the adjustment for cs0dt should be performed while cs0dr and cs0ia bits are set at their maximum values (cs0dr = 11b, cs0ia = 001b). 1. begin the adjustment with cs0dt set to maximu m delay (cs0dt = 111b). measure the untouched average cs0 result for the channel under test. note: when calibrating cs0 for use with an ito panel, consider the use of an artificial finger: a small (?? o.d.) washer (#2 regular, #4 narrow) wired through a 1000 pf capacitor to ground. select a touch point at the on the farthest end of the longest row. find the point where maximum response is returned from the cs0 conversion. 2. record the average touched cs0 value with cs0dt = 111b. the touched value should be higher than the untouched value. the magnitude of the difference between the touched and untouched average cs0 values is the figure of me rit for touch sensitivity. 3. decrease the primary reset time cs0dt by one and repeat the touched and untouched cs0 measurements. repeat this step until values have b een recorded for all eight cs0dt settings. as the cs0dt setting decreases, the averag e sensitivity of the cs0 value ma y begin to decrease significantly. 4. cs0dt should be set high enough that there is not a significant decrease in sens itivity due to resistance. select the cs0dt setting that occurred prior to the observed drop in cs0 touch sensitivity.
c8051f97x 138 rev 1.0 capacitive sense (cs0) 18.13.3. adjusting secondary reset timing: cs0dr adjustments for cs0ia and cs0dt should be set to their maximum value (cs0ia = 001b, cs0dt = 111b) while the cs0dr adjustments are being performed. because the only function of dr is to reduce the ef fect of environmental noise, establishing the proper dr adjustment can only be performed in a test environmen t with the highest expected level of ambient noise while connected to the sensor which is sp ecific to the int ended application. increasing the cs0dr adjustment does not increase the level of possible noise rejection, it only changes the amount of time that the cs0 module will wait for the secon dary reset circuit to finish its noise-reduction operation. resistive sensors require longer cs 0dr operating periods, and their cs0 dr settings will be necessarily higher. higher settings for cs0dr cause the cs0 conversion proc ess to slow substantially. the adjustment method is intended to find the lowest (fastest) cs 0dr setting that delivers full function. 1. begin the adjustment with cs0dr set to maximum delay (cs0dr = 11b). record a series of cs0 output values for the sensor when it is being touched. note: if an ito touch panel is being tested, th is sensor touch should be performed at th e sensor location at the end of the longest ito trace. the series of cs0 output values should be large enough that a reliably repeatable determination of standard deviation can be made, a hundred samples or greater (but typically less than 10,000 samples). 2. for this test, the standard deviation of data in the seri es is the figure of merit used to define the level of noise received by the cs0 converter. the secondary re set circuit reduces noise. an increase in standard deviation indicates that the secondary reset circuit is no longer working opti mally. the best adjustment point for cs0dr is the lowest setting for which there is an acceptably-low standard deviation. 3. decrease the value of the cs0dr setting by one (from 11b to 10b). record a new data set and determine its standard deviation. repeat this process for cs0dr settings 01b and 00b. compare the standard deviations calculated for the four cs0dr settings. sele ct the lowest cs0dr settin g for which there is not a significant increase in standard deviation. 18.13.4. adjusting cs0 ramp timing: cs0ia in the presence of larger series resistors between the devi ce pin and the capacitive sens or, it is necessary to also adjust the ramp time for the cs0 conversion. this is done by using cs0ia to modify the source current used to charge up the capacitive sens or. if this source current and the series impedance are both hi gh, the cs0 module will ?see? less of the capacitor on the other side of the impeda nce. reducing the current allows the pin voltage to more directly reflect the voltage at the capacitive sensor. the adjustment for cs0ia should be performed while cs 0dr and cs0dt bits are set at their maximum values (cs0dr = 11b, cs0dt = 111b). 1. begin the adjustment with cs0ia set to minimum current (cs0ia = 001b). measure the untouched average cs0 result for the channel under test. note: when calibrating cs0 for use with an ito panel, consider the use of an artificial finger: a small (?? o.d.) washer (#2 regular, #4 narrow) wired through a 1000pf capacitor to ground. select a touch point at the on the farthest end of the longest row. find the point where maximum response is returned from the cs0 conversion. 2. record the average touched cs0 value with cs0ia = 001b. the touched value should be higher than the untouched value. the magnitude of the difference between the touched and untouched average cs0 values is the figure of me rit for touch sensitivity. 3. increase the current control cs0ia by one and repeat the touched and un touched cs0 measurements. repeat this step until values have been recorded fo r all eight cs0ia settings (including cs0ia = 000b, which is the highest current setting). as cs0ia is changed, the average sensitivity of the cs0 value may begin to decrease significantly. 4. cs0ia should be chosen such that there is not a sign ificant decrease in sensitivit y due to resistance. select the cs0ia setting that occurred prior to the observed drop in cs0 touch sensitivity.
c8051f97x rev 1.0 139 capacitive sense (cs0) 18.13.5. low-pass filter adjustments a programmable active low-pass filter is pr ovided to limit external noise interference in cs0 operation. the filter is programmable in two ways. the filter can be tailored for opt imal performance with slow-r ising signals by adjusting the low-pass filter ramping control, cs 0rp. another control, cs0lp, allows th e user to adjust the filter?s corner frequency. for most applications, the default settings for the filter controls (cs0lp = 000b, cs0rp = 00b) should be used. 18.13.6. adjusting cs0 ramp timing: cs0rp determining the appropriate setting for cs0rp is one of the last in a series of related adjustments to be made for high-resistance loads. it requires that the adjustments for gain (cs0cg), output current (cs0ia), and the reset timing (cs0dt and cs0dr) have already been made. the adjustment values determined for those settings should be programmed into the cs0 module when performing the cs0rp adjustment. configure the cs0 module to perform continuously repeated capacitance sensing operations. using an oscilloscope, measure the maximu m rise time seen on the cs0 sensor pin. subtract 200 ns. this is the cs0 ramp time for this channel. 18.13.7. adjusting cs0lp fo r non-default cs0rp settings the default setting for the low-pass filter corner frequenc y (cs0lp = 000b) gives the best sensing response for all applications using default ramp timing (cs0rp = 00b). for applications with slower ramp timing, the corner frequency should always be modified to match the edge-ra te of the input ramp. for all non-default settings of cs0rp (cs0rp = 01b, 10b or 11b), set cs0lp = 001b. 18.13.8. other options for adjusting cs0lp in some circumstances, it may be preferable to trade cs0 sensitivity for increased nois e filtering. decreasing the filter?s corner frequency below the na tural ramp rate of the converter will c ause a lower capacitance value to be reported. the change in capacitance du e to a touch event will also be attenuated. as a resu lt, lowering the corner frequency will not necessarily incr ease the signal-to-noise ratio for capacitive touch events. although signal-to-noise is the figure of merit for this adjustment, there may be acceptable trade-offs in the adjustment of cs0lp which re sult in an overall lower snr but better operation over a wide range of environmental conditions. some applications may call for adaptive changes to the corner frequency based on measurements of input noise, trading sensitivity for nois e rejection only when necessary. becaus e this optional adjustment requires a subjective trade-off between noise rejection and sensitivity, the ultimate determination of acceptable results for this adjustment will be determined by the end application. when performing these tests, all other cs0 configuration registers should be properly adjusted for the channel under test. cs0lp operation can only be analyzed when the cs0 is otherwise optimally adjusted. cs0lp adjustments should only be performed during performance tuning for a specific application in a well-defined noise environment. cs0lp settings adjust the cs0 response to environmental noise. as in the adjustment of cs0dr settings, cs0lp adjustment can only be performed in a test environmen t with the highest expected level of ambient noise while connected to the sensor which is sp ecific to the int ended application. higher settings for cs0lp cause the lo w-pass filter corner frequ ency to drop. noise will be reduced and reported capacitance will be reduced. th is adjustment process increm entally increases cs0lp sett ings to dete rmine which, if any, of the settings provide a hi gher snr. for this test, the optimum se tting for cs0lp will provide higher snr results for the system in this high-interference environmen t, although the same setting is likely to reduce snr for the same system in a low- interference environment. 1. begin the adjustment with cs0lp set to maximum corner frequency (cs0lp = 000b). record a series of cs0 output values for the sensor when it is untouched and record another series of cs0 output values from the sensor when it is being touched. if an ito touc h panel is being tested, this sensor touch should be performed at a sensor location on the shortest ito tr ace at a location closest to the panel connector. calculation of snr may be performed as described in application note an367, ?understanding capacitive sensing signal to noise ratios and setting reliable thresholds?. 2. increase the value of the cs0lp setting by one (from 000b to 001b). record a new data set and determine its snr. repeat this process fo r all remaining cs0lp settings.
c8051f97x 140 rev 1.0 capacitive sense (cs0) 3. this series of tests can be repeated in a variety of noise environments. comparison of the resulting snr tables can then be used to determine how cs0lp adjustments might be used to improve capacitive sensing in high-interference environments. 18.14. cs0 analog multiplexer the cs0 input multiplexer can be controlled through two methods. the cs0mx register can be written to through firmware, or the register can be configured automatically using the auto-scan functionality (see section ?18.8. automatic scanning (method 1?cs0smen = 0)? on page 132 ). table 18.2. adc0 input multiplexer channels adc0mx setting signal name qfn-48 pin name qfn-32 pin name qfn-24 pin name 000000 cs0.0 p0.0 p0.0 p0.0 000001 cs0.1 p0.1 p0.1 p0.1 000010 cs0.2 p0.2 p0.2 p0.2 000011 cs0.3 p0.3 p0.3 p0.3 000100 cs0.4 p0.4 p0.4 p0.4 000101 cs0.5 p0.5 p0.5 p0.5 000110 cs0.6 p0.6 p0.6 p0.6 000111 cs0.7 p0.7 p0.7 p0.7 001000 cs0.8 p1.0 p1.0 p1.0 001001 cs0.9 p1.1 p1.1 p1.1 001010 cs0.10 p1.2 p1.2 p1.2 001011 cs0.11 p1.3 p1.3 p1.3 001100 cs0.12 p1.4 p1.4 p1.4 001101 cs0.13 p1.5 p1.5 p1.5 001110 cs0.14 p1.6 p1.6 p1.6 001111 cs0.15 p1.7 p1.7 p1.7 010000 cs0.16 p2.0 p2.0 p2.0 010001 cs0.17 p2.1 p2.1 p2.1 010010 cs0.18 p2.2 p2.2 reserved 010011 cs0.19 p2.3 p2.3 reserved 010100 cs0.20 p2.4 p2.4 reserved 010101 cs0.21 p2.5 p2.5 reserved
c8051f97x rev 1.0 141 capacitive sense (cs0) 010110 cs0.22 p2.6 p2.6 reserved 010111 cs0.23 p2.7 p2.7 reserved 011000 cs0.24 p3.0 p3.0 reserved 011001 cs0.25 p3.1 p3.1 reserved 011010 cs0.26 p3.2 p3.2 reserved 011011 cs0.27 p3.3 reserved reserved 011100 cs0.28 p3.4 reserved reserved 011101 cs0.29 p3.5 reserved reserved 011110 cs0.30 p3.6 reserved reserved 011111 cs0.31 p3.7 reserved reserved 100000 cs0.32 p4.0 reserved reserved 100001 cs0.33 p4.1 reserved reserved 100010 cs0.34 p4.2 reserved reserved 100011 cs0.35 p4.3 reserved reserved 100100 cs0.36 p4.4 reserved reserved 100101 cs0.37 p4.5 reserved reserved 100110 cs0.38 p4.6 reserved reserved 100111 cs0.39 p4.7 reserved reserved 101000 cs0.40 p5.0 reserved reserved 101001 cs0.41 p5.1 reserved reserved 101010 cs0.42 p5.2 p5.2 p5.2 101011-111111 reserved reserved table 18.2. adc0 input multiplexer channels (continued) adc0mx setting signal name qfn-48 pin name qfn-32 pin name qfn-24 pin name
c8051f97x 142 rev 1.0 capacitive sense (cs0) 18.14.1. pin configuration for cs0 measurements method a port pin selected as cs0 input should be configured as follows: 1. set to analog mode input by clearing to 0 the corresponding bit in register pnmdin. 2. force the priority crossbar decoder to skip the pin by setting 1 to the corresponding bit in register pnskip. 3. enable or disable the auto-ground for the pin by clearing 0 or setting 1 to the corresponding bit in the port latch (pn), respectively. auto-grounding means that the pin will be grounded when cs0 meas urement is not being performed on the pin. 4. set to 1 the corresponding bits in amux0p n that cs0 will be taking measurements on. 5. if only a single channel is to be sensed, setup the cs0 multiplexer to select the appropriate pin for measurement. if automatic scanning is used, setup cs0ss and cs0se registers. if multiple channels are to be binded, the cs0mc important notes : ? when cs0 is active, adc0 must not be enabled ev en if adc0 is not going to perform an operation. ? similarly, when adc0 is acti ve, cs0 should not be enabled. see section ?26. port i/o (port 0, port 1, port 2, port 3, port 4, port 5, port 6, crossbar, and port match)? on page 278 for more port i/o configuration details.
c8051f97x rev 1.0 143 capacitive sense (cs0) 18.15. capacitive sense register register 18.1. cs0cn: capacitive sense 0 control bit 7 6 5 4 3 2 1 0 name csen cseos csint csbusy cscmpen reserved cspme cscmpf type rw r rw rw rw r r r reset 0 0 0 0 0 0 0 0 sfr page = 0x0; sfr address: 0xb0 (bit-addressable) bit name function 7 csen cs0 enable. 0: cs0 disabled and in low-power mode. 1: cs0 enabled and ready to convert. 6 cseos cs0 end of scan interrupt flag. this bit must be cleared by firmware. 0: cs0 has not completed a scan since the last time cs0eos was cleared. 1: cs0 has completed a scan. 5 csint cs0 interrupt flag. this bit must be cleared by firmware. 0: cs0 has not completed a data conversion since the last time cs0int was cleared. 1: cs0 has completed a data conversion. 4 csbusy cs0 busy. read: a 1 indicates a cs0 conversion is in progress. write: writing a 1 to this bi t initiates a cs0 conversion if cs0cm[2:0] = 000b, 110b, or 111b. 3 cscmpen cs0 digital comparator enable. enables the digital comparator, which compares accumulated cs0 conversion output to the value stored in cs0thh:cs0thl. 0: disable cs0 digital comparator. 1: enable cs0 digital comparator. 2 reserved must write reset value. 1 cspme cs0 pin monitor event. set if any converter re-tries have occurred due to a pin monitor event. this bit must be cleared by firmware. 0 cscmpf cs0 digital comparator interrupt flag. 0: cs0 result is sma ller than the value set by cs0thh and cs0thl since the last time cs0cmpf was cleared. 1: cs0 result is greater than the value se t by cs0thh and cs0thl since the last time cs0cmpf was cleared.
c8051f97x 144 rev 1.0 capacitive sense (cs0) register 18.2. cs0cf: capacitive sense 0 configuration bit 7 6 5 4 3 2 1 0 name cs0smen cs0cm cs0mcen cs0acu type rw rw r rw reset 0 0 0 0 0 0 0 0 sfr page = 0x0; sfr address: 0xaa bit name function 7 cs0smen cs0 channel scan masking enable. 0: the amux0 register contents are ignored. 1: the amux0 registers dete rmine which channels will be included in the scan. 6:4 cs0cm cs0 start of conversion mode select. 000: conversion initiated on every write of 1 to cs0busy. 001: conversion initiated on overflow of timer 0. 010: conversion initiated on overflow of timer 2. 011: conversion initiated on overflow of timer 1. 100: conversion initiated on overflow of timer 3. 101: when cs0smen is set to 1, the converter completes a single scan of the channels selected by the amux0 registers. this settin g is invalid when cs0s men is cleared to 0. 110: conversion initiated continuously on the channel selected by cs0mx after writing 1 to cs0busy. 111: when cs0smen is set to 1, the converte r enters auto scan mode and continuously scans the channels selected by the amux0 re gisters. when cs0smen is cleared to 0, the converter scans continuously on channels from cs0ss to cs0se after firmware writes 1 to cs0busy. 3 cs0mcen cs0 multiple channel enable. 0: multiple channel feature is disabled. 1: channels selected by the amux0 registers are internally shorted together and the combined node is selected as the cs0 input. this mode can be used to detect a capaci - tance change on multiple channe ls using a single conversion. 2:0 cs0acu cs0 accumulator mode select. 000: accumula te 1 sample. 001: accumula te 4 samples. 010: accumula te 8 samples. 011: accumulate 16 samples 100: accumulate 32 samples. 101: accumulate 64 samples. 110-111: reserved.
c8051f97x rev 1.0 145 capacitive sense (cs0) register 18.3. cs0dh: capacitive sense 0 data high byte bit 7 6 5 4 3 2 1 0 name cs0dh type r reset 0 0 0 0 0 0 0 0 sfr page = 0x0; sf r address: 0xee bit name function 7:0 cs0dh cs0 data high byte. stores the high byte of the last comp leted 16-bit capacitive sense conversion.
c8051f97x 146 rev 1.0 capacitive sense (cs0) register 18.4. cs0dl: capacitive sense 0 data low byte bit 7 6 5 4 3 2 1 0 name cs0dl type r reset 0 0 0 0 0 0 0 0 sfr page = 0x0; sf r address: 0xed bit name function 7:0 cs0dl cs0 data low byte. stores the low byte of the last comple ted 16-bit capacitive sense conversion.
c8051f97x rev 1.0 147 capacitive sense (cs0) register 18.5. cs0ss: capacitive sense 0 auto scan start channel bit 7 6 5 4 3 2 1 0 name reserved cs0ss type r rw reset 0 0 0 0 0 0 0 0 sfr page = 0x0; sfr address: 0xdd bit name function 7:6 reserved must write reset value. 5:0 cs0ss starting channel for auto scan. sets the first cs0 channel to be selected by the mux for capacitive sense conversion when auto scan is enabled and active. all channels detailed in cs0mx are possible choices for this register. when auto scan is enabled, a write to cs0ss will also update cs0mx.
c8051f97x 148 rev 1.0 capacitive sense (cs0) register 18.6. cs0se: capacitive sense 0 auto scan end channel bit 7 6 5 4 3 2 1 0 name reserved cs0se type r rw reset 0 0 0 0 0 0 0 0 sfr page = 0x0; sfr address: 0xde bit name function 7:6 reserved must write reset value. 5:0 cs0se ending channel for auto scan. sets the last cs0 channel to be selected by the mux for capacitive sense conversion when auto scan is enabled and active. all channels detailed in cs0mx are possible choices for this register.
c8051f97x rev 1.0 149 capacitive sense (cs0) register 18.7. cs0thh: capacitive sense 0 comparator threshold high byte bit 7 6 5 4 3 2 1 0 name cs0thh type rw reset x x x x x x x x sfr page = 0x0; sfr address: 0xfe bit name function 7:0 cs0thh cs0 comparator threshold high byte. high byte of the 16-bit value compared to the capacitive sense conversion result.
c8051f97x 150 rev 1.0 capacitive sense (cs0) register 18.8. cs0thl: capacitive sense 0 comparator threshold low byte bit 7 6 5 4 3 2 1 0 name cs0thl type rw reset x x x x x x x x sfr page = 0x0; sfr address: 0xfd bit name function 7:0 cs0thl cs0 comparator threshold low byte. low byte of the 16-bit value compared to the capacitive sense conversion result.
c8051f97x rev 1.0 151 capacitive sense (cs0) register 18.9. cs0md1: capacitive sense 0 mode 1 bit 7 6 5 4 3 2 1 0 name reserved cs0pol cs0dr cs0woi cs0cg type rw r r r rw reset 0 0 0 0 0 1 1 1 sfr page = 0x0; sfr address: 0xbd bit name function 7 reserved must write reset value. 6 cs0pol cs0 digital comparator polarity select. 0: the digital comparator generates an interr upt if the conversion is greater than the threshold. 1: the digital comparator generates an interrupt if the conversion is less than or equal to the threshold. 5:4 cs0dr cs0 double reset select. these bits adjust the secondary cs0 reset ti me. for most touch-se nsitive switches, the default (fastest) value is sufficient. 00: no additional time is used for secondary reset. 01: an additional 0.75 us is used for secondary reset. 10: an additional 1.5 us is used for secondary reset. 11: an additional 2.25 us is used for secondary reset. 3 cs0woi cs0 wake on interrupt configuration. 0: wake-up event generated on digital comparator interrupt only. 1: wake-up event generated on end of scan or digital comparator interrupt. 2:0 cs0cg cs0 capacitance gain select. these bits select the gain applied to the capacitance measurement. lower gain values increase the size of the capacitance that can be measured with the cs0 module. the capacitance gain is equiva lent to cs0cg[2:0] + 1. 000: gain = 1x 001: gain = 2x 010: gain = 3x 011: gain = 4x 100: gain = 5x 101: gain = 6x 110: gain = 7x 111: gain = 8x
c8051f97x 152 rev 1.0 capacitive sense (cs0) register 18.10. cs0md2: capacitive sense 0 mode 2 bit 7 6 5 4 3 2 1 0 name cs0cr cs0dt cs0ia type rw rw rw reset 0 1 0 0 0 0 0 0 sfr page = 0x0; sfr address: 0xbe bit name function 7:6 cs0cr cs0 conversion rate. these bits control the conversion rate of the cs0 module. 00: conversions last 12 internal cs 0 clocks and are 12 bits in length. 01: conversions last 13 internal cs 0 clocks and are 13 bits in length. 10: conversions last 14 internal cs 0 clocks and are 14 bits in length. 11: conversions last 16 internal cs0 clocks.and are 16 bits in length. 5:3 cs0dt cs0 discharge time. these bits adjust the primary cs0 reset time . for most touch-sensitive switches, the default (fastest) value is sufficient. 000: discharge time is 0.75 us (recommended for most switches). 001: discharge time is 1.0 us. 010: discharge time is 1.2 us. 011: discharge time is 1.5 us. 100: discharge time is 2 us. 101: discharge time is 3 us. 110: discharge time is 6 us. 111: discharge time is 12 us. 2:0 cs0ia cs0 output current adjustment. these bits adjust the output cu rrent used to charge up the capacitive sensor element. for most touch-sensitive s witches, the default (highest ) current is sufficient. 000: full current. 001: 1/8 current. 010: 1/4 current. 011: 3/8 current. 100: 1/2 current. 101: 5/8 current. 110: 3/4 current. 111: 7/8 current.
c8051f97x rev 1.0 153 capacitive sense (cs0) register 18.11. cs0md3: capacitive sense 0 mode 3 bit 7 6 5 4 3 2 1 0 name reserved cs0rp cs0lp type rw rw rw reset 0 0 0 0 0 0 0 0 sfr page = 0x0; sfr address: 0xbf bit name function 7:5 reserved must write reset value. 4:3 cs0rp cs0 ramp selection. these bits are used to compensate cs0 conver sions for circuits requiring slower ramp times. for most touc h-sensitive switches, the default (fastest) value is sufficient. 00: ramp time is less than 1.5 us. 01: ramp time is between 1.5 us and 3 us. 10: ramp time is between 3 us and 6 us. 11: ramp time is greater than 6 us. 2:0 cs0lp cs0 low pass filter selection. these bits set the internal corner frequency of the cs0 low-pass filter. higher values of cs0lp result in a lower internal corner frequency. for most touch-sensitive swit ches, the default setting of 000b should be used. if the cs0rp bits are adjusted from their default value, the cs0lp bits should normally be set to 001b. settings higher than 001b will result in attenuated readings from the cs0 mod - ule and should be used only under special circumstances.
c8051f97x 154 rev 1.0 capacitive sense (cs0) register 18.12. cs0pm: capacitive sense 0 pin monitor bit 7 6 5 4 3 2 1 0 name uapm spipm smbpm pcapm piopm i2c0pm cspmmd type rw rw rw rw rw rw rw reset 0 0 0 0 0 0 0 0 sfr page = 0x0; sfr address: 0x96 bit name function 7 uapm uart pin monitor enable. enables monitoring of the uart tx pin. 6 spipm spi pin monitor enable. enables monitoring spi output pins. 5 smbpm smbus pin monitor enable. enables monitoring of the smbus pins. 4 pcapm pca pin monitor enable. enables monitoring of pca output pins. 3 piopm port i/o pin monitor enable. enables monitoring of writes to the port latch registers. 2 i2c0pm i2c slave pin monitor enable. enables monitoring of the i2c slave output pin. 1:0 cspmmd cs0 pin monitor mode. selects the operation to take when a monitored signal changes state. 00: always retry bit cycles on a pin state change. 01: retry up to twice on consecutive bit cycles. 10: retry up to four times on consecutive bit cycles. 11: reserved.
c8051f97x rev 1.0 155 capacitive sense (cs0) register 18.13. cs0mx: capacitive sense 0 mux channel select bit 7 6 5 4 3 2 1 0 name cs0uc reserved cs0mx type rw rw rw reset 1 0 0 0 0 0 0 0 sfr page = 0x0; sfr address: 0xab bit name function 7 cs0uc cs0 connect. disconnects cs0 from all port pins, regardless of the selected channel. 0: cs0 connected to port pins. 1: cs0 disconnected from port pins. 6 reserved must write reset value.
c8051f97x 156 rev 1.0 capacitive sense (cs0) 5:0 cs0mx cs0 mux channel select. selects a single input channel for capacitive sense conversion. 000000: select cs0.0. 000001: select cs0.1. 000010: select cs0.2. 000011: select cs0.3. 000100: select cs0.4. 000101: select cs0.5. 000110: select cs0.6. 000111: select cs0.7. 001000: select cs0.8. 001001: select cs0.9. 001010: select cs0.10. 001011: select cs0.11. 001100: select cs0.12. 001101: select cs0.13. 001110: select cs0.14. 001111: select cs0.15. 010000: select cs0.16. 010001: select cs0.17. 010010: select cs0.18. 010011: select cs0.19. 010100: select cs0.20. 010101: select cs0.21. 010110: select cs0.22. 010111: select cs0.23. 011000: select cs0.24. 011001: select cs0.25. 011010: select cs0.26. 011011: select cs0.27. 011100: select cs0.28. 011101: select cs0.29. 011110: select cs0.30. 011111: select cs0.31. 100000: select cs0.32. 100001: select cs0.33. 100010: select cs0.34. 100011: select cs0.35. 100100: select cs0.36. 100101: select cs0.37. 100110: select cs0.38. 100111: select cs0.39. 101000: select cs0.40. 101001: select cs0.41. 101010: select cs0.42. 101011-111111: reserved. bit name function
c8051f97x 158 rev 1.0 analog multiplexer (amux0) 19. analog multiplexer (amux0) the analog multiplexer (amux0) module c onnects physical device pins with an alog peripherals, like the adc and capacitive sensing modules. for the adc, the amux0 module se lects the single channel for adc measurement. see ?analog-to-digital converter (adc0)? on page 104 for more information on configuring pins for use with the adc. for the cs0 module, the amux0 module selects all channel s that should be measured together using channel binding or scanned individually using single- or auto-sca n modes. see ?capacitive sense (cs0)? on page 130 for more information on configuring pins for use with the cs0 module. figure 19.1. amux0 block diagram amux0 p0 pins (8) p1 pins (8) adc0 cs0 p2 pins (8) p4 pins (8) p3 pins (8) p5 pins (3)
c8051f97x rev 1.0 159 analog multiplexer (amux0) 19.1. amux control registers register 19.1. amux0p0: port 0 analog multiplexer control bit 7 6 5 4 3 2 1 0 name b7 b6 b5 b4 b3 b2 b1 b0 type rw rw rw rw rw rw rw rw reset00000000 sfr page = 0x0; sfr address: 0x9a table 19.1. amux0p0 register bit descriptions bit name function 7 b7 port 0 bit 7 analog multiplexor control. 0: p0.7 pin is not connected by the analog multiplexer for cs0 or adc0 measurements. 1: p0.7 pin is connected by the analog multiplexer for cs0 or adc0 measurements. 6 b6 port 0 bit 6 analog multiplexor control. 0: p0.6 pin is not connected by the analog multiplexer for cs0 or adc0 measurements. 1: p0.6 pin is connected by the analog multiplexer for cs0 or adc0 measurements. 5 b5 port 0 bit 5 analog multiplexor control. 0: p0.5 pin is not connected by the analog multiplexer for cs0 or adc0 measurements. 1: p0.5 pin is connected by the analog multiplexer for cs0 or adc0 measurements. 4 b4 port 0 bit 4 analog multiplexor control. 0: p0.4 pin is not connected by the analog multiplexer for cs0 or adc0 measurements. 1: p0.4 pin is connected by the analog multiplexer for cs0 or adc0 measurements. 3 b3 port 0 bit 3 analog multiplexor control. 0: p0.3 pin is not connected by the analog multiplexer for cs0 or adc0 measurements. 1: p0.3 pin is connected by the analog multiplexer for cs0 or adc0 measurements. 2 b2 port 0 bit 2 analog multiplexor control. 0: p0.2 pin is not connected by the analog multiplexer for cs0 or adc0 measurements. 1: p0.2 pin is connected by the analog multiplexer for cs0 or adc0 measurements. 1 b1 port 0 bit 1 analog multiplexor control. 0: p0.1 pin is not connected by the analog multiplexer for cs0 or adc0 measurements. 1: p0.1 pin is connected by the analog multiplexer for cs0 or adc0 measurements. 0 b0 port 0 bit 0 analog multiplexor control. 0: p0.0 pin is not connected by the analog multiplexer for cs0 or adc0 measurements. 1: p0.0 pin is connected by the analog multiplexer for cs0 or adc0 measurements. note: if any of the internal signals are sele cted as the adc0 input channel, the amux0 registers must not select an external pin and all be cleared to 0.
c8051f97x 160 rev 1.0 analog multiplexer (amux0) register 19.2. amux0p1: port 1 analog multiplexer control bit 7 6 5 4 3 2 1 0 name b7 b6 b5 b4 b3 b2 b1 b0 type rw rw rw rw rw rw rw rw reset00000000 sfr page = 0x0; sfr address: 0x9b table 19.2. amux0p1 register bit descriptions bit name function 7 b7 port 1 bit 7 analog multiplexor control. 0: p1.7 pin is not connected by the analog multiplexer for cs0 or adc0 measurements. 1: p1.7 pin is connected by the analog multiplexer for cs0 or adc0 measurements. 6 b6 port 1 bit 6 analog multiplexor control. 0: p1.6 pin is not connected by the analog multiplexer for cs0 or adc0 measurements. 1: p1.6 pin is connected by the analog multiplexer for cs0 or adc0 measurements. 5 b5 port 1 bit 5 analog multiplexor control. 0: p1.5 pin is not connected by the analog multiplexer for cs0 or adc0 measurements. 1: p1.5 pin is connected by the analog multiplexer for cs0 or adc0 measurements. 4 b4 port 1 bit 4 analog multiplexor control. 0: p1.4 pin is not connected by the analog multiplexer for cs0 or adc0 measurements. 1: p1.4 pin is connected by the analog multiplexer for cs0 or adc0 measurements. 3 b3 port 1 bit 3 analog multiplexor control. 0: p1.3 pin is not connected by the analog multiplexer for cs0 or adc0 measurements. 1: p1.3 pin is connected by the analog multiplexer for cs0 or adc0 measurements. 2 b2 port 1 bit 2 analog multiplexor control. 0: p1.2 pin is not connected by the analog multiplexer for cs0 or adc0 measurements. 1: p1.2 pin is connected by the analog multiplexer for cs0 or adc0 measurements. 1 b1 port 1 bit 1 analog multiplexor control. 0: p1.1 pin is not connected by the analog multiplexer for cs0 or adc0 measurements. 1: p1.1 pin is connected by the analog multiplexer for cs0 or adc0 measurements. 0 b0 port 1 bit 0 analog multiplexor control. 0: p1.0 pin is not connected by the analog multiplexer for cs0 or adc0 measurements. 1: p1.0 pin is connected by the analog multiplexer for cs0 or adc0 measurements. note: if any of the internal signals are sele cted as the adc0 input channel, the amux0 registers must not select an external pin and all be cleared to 0.
c8051f97x rev 1.0 161 analog multiplexer (amux0) register 19.3. amux0p2: port 2 analog multiplexer control bit 7 6 5 4 3 2 1 0 name b7 b6 b5 b4 b3 b2 b1 b0 type rw rw rw rw rw rw rw rw reset00000000 sfr page = 0x0; sfr address: 0x9c table 19.3. amux0p2 register bit descriptions bit name function 7 b7 port 2 bit 7 analog multiplexor control. 0: p2.7 pin is not connected by the analog multiplexer for cs0 or adc0 measurements. 1: p2.7 pin is connected by the analog multiplexer for cs0 or adc0 measurements. 6 b6 port 2 bit 6 analog multiplexor control. 0: p2.6 pin is not connected by the analog multiplexer for cs0 or adc0 measurements. 1: p2.6 pin is connected by the analog multiplexer for cs0 or adc0 measurements. 5 b5 port 2 bit 5 analog multiplexor control. 0: p2.5 pin is not connected by the analog multiplexer for cs0 or adc0 measurements. 1: p2.5 pin is connected by the analog multiplexer for cs0 or adc0 measurements. 4 b4 port 2 bit 4 analog multiplexor control. 0: p2.4 pin is not connected by the analog multiplexer for cs0 or adc0 measurements. 1: p2.4 pin is connected by the analog multiplexer for cs0 or adc0 measurements. 3 b3 port 2 bit 3 analog multiplexor control. 0: p2.3 pin is not connected by the analog multiplexer for cs0 or adc0 measurements. 1: p2.3 pin is connected by the analog multiplexer for cs0 or adc0 measurements. 2 b2 port 2 bit 2 analog multiplexor control. 0: p2.2 pin is not connected by the analog multiplexer for cs0 or adc0 measurements. 1: p2.2 pin is connected by the analog multiplexer for cs0 or adc0 measurements. 1 b1 port 2 bit 1 analog multiplexor control. 0: p2.1 pin is not connected by the analog multiplexer for cs0 or adc0 measurements. 1: p2.1 pin is connected by the analog multiplexer for cs0 or adc0 measurements. 0 b0 port 2 bit 0 analog multiplexor control. 0: p2.0 pin is not connected by the analog multiplexer for cs0 or adc0 measurements. 1: p2.0 pin is connected by the analog multiplexer for cs0 or adc0 measurements. note: if any of the internal signals are sele cted as the adc0 input channel, the amux0 registers must not select an external pin and all be cleared to 0.
c8051f97x 162 rev 1.0 analog multiplexer (amux0) register 19.4. amux0p3: port 3 analog multiplexer control bit 7 6 5 4 3 2 1 0 name b7 b6 b5 b4 b3 b2 b1 b0 type rw rw rw rw rw rw rw rw reset00000000 sfr page = 0x0; sfr address: 0xa4 table 19.4. amux0p3 register bit descriptions bit name function 7 b7 port 3 bit 7 analog multiplexor control. 0: p3.7 pin is not connected by the analog multiplexer for cs0 or adc0 measurements. 1: p3.7 pin is connected by the analog multiplexer for cs0 or adc0 measurements. 6 b6 port 3 bit 6 analog multiplexor control. 0: p3.6 pin is not connected by the analog multiplexer for cs0 or adc0 measurements. 1: p3.6 pin is connected by the analog multiplexer for cs0 or adc0 measurements. 5 b5 port 3 bit 5 analog multiplexor control. 0: p3.5 pin is not connected by the analog multiplexer for cs0 or adc0 measurements. 1: p3.5 pin is connected by the analog multiplexer for cs0 or adc0 measurements. 4 b4 port 3 bit 4 analog multiplexor control. 0: p3.4 pin is not connected by the analog multiplexer for cs0 or adc0 measurements. 1: p3.4 pin is connected by the analog multiplexer for cs0 or adc0 measurements. 3 b3 port 3 bit 3 analog multiplexor control. 0: p3.3 pin is not connected by the analog multiplexer for cs0 or adc0 measurements. 1: p3.3 pin is connected by the analog multiplexer for cs0 or adc0 measurements. 2 b2 port 3 bit 2 analog multiplexor control. 0: p3.2 pin is not connected by the analog multiplexer for cs0 or adc0 measurements. 1: p3.2 pin is connected by the analog multiplexer for cs0 or adc0 measurements. 1 b1 port 3 bit 1 analog multiplexor control. 0: p3.1 pin is not connected by the analog multiplexer for cs0 or adc0 measurements. 1: p3.1 pin is connected by the analog multiplexer for cs0 or adc0 measurements. 0 b0 port 3 bit 0 analog multiplexor control. 0: p3.0 pin is not connected by the analog multiplexer for cs0 or adc0 measurements. 1: p3.0 pin is connected by the analog multiplexer for cs0 or adc0 measurements. note: if any of the internal signals are sele cted as the adc0 input channel, the amux0 registers must not select an external pin and all be cleared to 0.
c8051f97x rev 1.0 163 analog multiplexer (amux0) register 19.5. amux0p4: port 4 analog multiplexer control bit 7 6 5 4 3 2 1 0 name b7 b6 b5 b4 b3 b2 b1 b0 type rw rw rw rw rw rw rw rw reset00000000 sfr page = 0x0; sfr address: 0xa5 table 19.5. amux0p4 register bit descriptions bit name function 7 b7 port 4 bit 7 analog multiplexor control. 0: p4.7 pin is not connected by the analog multiplexer for cs0 or adc0 measurements. 1: p4.7 pin is connected by the analog multiplexer for cs0 or adc0 measurements. 6 b6 port 4 bit 6 analog multiplexor control. 0: p4.6 pin is not connected by the analog multiplexer for cs0 or adc0 measurements. 1: p4.6 pin is connected by the analog multiplexer for cs0 or adc0 measurements. 5 b5 port 4 bit 5 analog multiplexor control. 0: p4.5 pin is not connected by the analog multiplexer for cs0 or adc0 measurements. 1: p4.5 pin is connected by the analog multiplexer for cs0 or adc0 measurements. 4 b4 port 4 bit 4 analog multiplexor control. 0: p4.4 pin is not connected by the analog multiplexer for cs0 or adc0 measurements. 1: p4.4 pin is connected by the analog multiplexer for cs0 or adc0 measurements. 3 b3 port 4 bit 3 analog multiplexor control. 0: p4.3 pin is not connected by the analog multiplexer for cs0 or adc0 measurements. 1: p4.3 pin is connected by the analog multiplexer for cs0 or adc0 measurements. 2 b2 port 4 bit 2 analog multiplexor control. 0: p4.2 pin is not connected by the analog multiplexer for cs0 or adc0 measurements. 1: p4.2 pin is connected by the analog multiplexer for cs0 or adc0 measurements. 1 b1 port 4 bit 1 analog multiplexor control. 0: p4.1 pin is not connected by the analog multiplexer for cs0 or adc0 measurements. 1: p4.1 pin is connected by the analog multiplexer for cs0 or adc0 measurements. 0 b0 port 4 bit 0 analog multiplexor control. 0: p4.0 pin is not connected by the analog multiplexer for cs0 or adc0 measurements. 1: p4.0 pin is connected by the analog multiplexer for cs0 or adc0 measurements. note: if any of the internal signals are sele cted as the adc0 input channel, the amux0 registers must not select an external pin and all be cleared to 0.
c8051f97x 164 rev 1.0 analog multiplexer (amux0) register 19.6. amux0p5: port 5 analog multiplexer control bit 7 6 5 4 3 2 1 0 name reserved b2 b1 b0 type rw rw rw rw reset00000000 sfr page = 0x0; sfr address: 0xa6 table 19.6. amux0p5 register bit descriptions bit name function 7:3 reserved must write reset value. 2 b2 port 5 bit 2 analog multiplexor control. 0: p5.2 pin is not connected by the analog multiplexer for cs0 or adc0 measurements. 1: p5.2 pin is connected by the analog multiplexer for cs0 or adc0 measurements. 1 b1 port 5 bit 1 analog multiplexor control. 0: p5.1 pin is not connected by the analog multiplexer for cs0 or adc0 measurements. 1: p5.1 pin is connected by the analog multiplexer for cs0 or adc0 measurements. 0 b0 port 5 bit 0 analog multiplexor control. 0: p5.0 pin is not connected by the analog multiplexer for cs0 or adc0 measurements. 1: p5.0 pin is connected by the analog multiplexer for cs0 or adc0 measurements. note: if any of the internal signals are sele cted as the adc0 input channel, the amux0 registers must not select an external pin and all be cleared to 0.
c8051f97x rev 1.0 165 cip-51 microcontroller core 20. cip-51 microcontroller core the c8051f97x uses the cip-51 microcontroller. the cip-51 is fully compatible with the mcs-51? instruction set; standard 803x/805x assemblers and compilers can be used to develop software. the mcu family has a superset of all the peripherals included with a standard 8051. the cip-51 also includes on-chip debug hardware and interfaces directly with the analog a nd digital subsystems providing a comple te data acquisition or control-system solution in a single integrated circuit. the cip-51 microcontroller core implements the standard 8051 organization and peripherals as well as additional custom peripherals and functions to extend its capability (see figure 20 .1 for a block diagram). the cip-51 includes the following features: 20.1. performance the cip-51 employs a pipelined architecture that greatl y increases its instruction throughput over the standard 8051 architecture. the cip-51 core ex ecutes 70% of its instructions in on e or two system clock cycles, with no instructions taking more than eight system clock cycles. figure 20.1. cip-51 block diagram with the cip-51's maximum system clock at 25 mhz, it has a peak throughput of 25 mips. the cip-51 has a total of 109 instructions. the table below shows the total numb er of instructions that re quire each execution time. clocks to execute 1 2 2/3 3 3/4 4 4/5 5 8 number of instructions 26 50 5 14 7 3 1 2 1 ?? fully compatible with mc s-51 instruction set ?? 25 mips peak throughput with 25 mhz clock ?? 0 to 25 mhz clock frequency ?? extended interrupt handler ?? reset input ?? power management modes ?? on-chip debug logic ?? program and data memory security data bus tmp1 tmp2 prgm. address reg. pc incrementer alu psw data bus data bus memory interface mem_address d8 pipeline buffer data pointer interrupt interface system_irqs emulation_irq mem_control control logic a16 program counter (pc) stop clock reset idle power control register data bus sfr bus interface sfr_address sfr_control sfr_write_data sfr_read_data d8 d8 b register d8 d8 accumulator d8 d8 d8 d8 d8 d8 d8 d8 mem_write_data mem_read_data d8 sram address register sram d8 stack pointer d8
c8051f97x 166 rev 1.0 cip-51 microcontroller core 20.2. programming and debugging support in-system programming of the flash program memory an d communication with on-chip debug support logic is accomplished via the silicon labs 2- wire development interface (c2). the on-chip debug s upport logic facilitates full spe ed in-circuit debugg ing, allowing the se tting of hardware breakpoints, starting, stopping and single stepping through program exec ution (including interrupt service routines), examination of the program's call stack, and reading/writing the contents of registers and memory. this method of on-chip debugging is completely non-intrusiv e, requiring no ram, stack, timers, or other on-chip resources. the cip-51 is supported by de velopment tools from silicon labs and third party vendors. silicon labs provides an integrated development environment (ide ) including editor, debugger and programmer. the ide's debugger and programmer interface to the cip-51 via the c2 interface to prov ide fast and efficient in -system device programming and debugging. third party macro assemblers and c compilers are also available. 20.3. instruction set the instruction set of the cip-51 syst em controller is fully compatible with the standard mcs-51? instruction set. standard 8051 development tools can be used to develop software for the cip-51. all cip-51 instructions are the binary and functional equivalent of their mcs-51? counter parts, including opcodes, addressing modes and effect on psw flags. however, instruction timing is different than that of the standard 8051. 20.3.1. instruction and cpu timing in many 8051 implementations, a distinction is made between machine cycles and clock cycles, with machine cycles varying from 2 to 12 clock cycles in length. howe ver, the cip-51 implementation is based solely on clock cycle timing. all instruction timings ar e specified in terms of clock cycles. due to the pipelined architecture of the cip-51, most inst ructions execute in the same number of clock cycles as there are program bytes in the instruct ion. conditional branch instructions ta ke one less clock cycle to complete when the branch is not taken as opposed to when the bran ch is taken. table 20.1 is the cip-51 instruction set summary, which includes the mnemonic, number of byte s, and number of clock cycles for each instruction.
c8051f97x rev 1.0 167 cip-51 microcontroller core table 20.1. cip-51 instruction set summary mnemonic description bytes clock cycles arithmetic operations add a, rn add register to a 1 1 add a, direct add direct byte to a 2 2 add a, @ri add indirect ram to a 1 2 add a, #data add immediate to a 2 2 addc a, rn add register to a with carry 1 1 addc a, direct add direct byte to a with carry 2 2 addc a, @ri add indirect ram to a with carry 1 2 addc a, #data add immediate to a with carry 2 2 subb a, rn subtract register from a with borrow 1 1 subb a, direct subtract direct byte from a with borrow 2 2 subb a, @ri subtract indirect ram from a with borrow 1 2 subb a, #data subtract immediate from a with borrow 2 2 inc a increment a 1 1 inc rn increment register 1 1 inc direct increment direct byte 2 2 inc @ri increment indirect ram 1 2 dec a decrement a 1 1 dec rn decrement register 1 1 dec direct decrement direct byte 2 2 dec @ri decrement indirect ram 1 2 inc dptr increment data pointer 1 1 mul ab multiply a and b 1 4 div ab divide a by b 1 8 da a decimal adjust a 1 1 logical operations anl a, rn and register to a 1 1 anl a, direct and direct byte to a 2 2 anl a, @ri and indirect ram to a 1 2 anl a, #data and immediate to a 2 2 anl direct, a and a to direct byte 2 2 anl direct, #data and immediate to direct byte 3 3 orl a, rn or register to a 1 1 orl a, direct or direct byte to a 2 2 orl a, @ri or indirect ram to a 1 2 orl a, #data or immediate to a 2 2 orl direct, a or a to direct byte 2 2 orl direct, #data or immediate to direct byte 3 3 xrl a, rn exclusive-or register to a 1 1
c8051f97x 168 rev 1.0 cip-51 microcontroller core xrl a, direct exclusive-or direct byte to a 2 2 xrl a, @ri exclusive-or indirect ram to a 1 2 xrl a, #data exclusive-or immediate to a 2 2 xrl direct, a exclusive-or a to direct byte 2 2 xrl direct, #data exclusive-or immediate to direct byte 3 3 clr a clear a 1 1 cpl a complement a 1 1 rl a rotate a left 1 1 rlc a rotate a left through carry 1 1 rr a rotate a right 1 1 rrc a rotate a right through carry 1 1 swap a swap nibbles of a 1 1 data transfer mov a, rn move register to a 1 1 mov a, direct move direct byte to a 2 2 mov a, @ri move indirect ram to a 1 2 mov a, #data move immediate to a 2 2 mov rn, a move a to register 1 1 mov rn, direct move direct byte to register 2 2 mov rn, #data move immediate to register 2 2 mov direct, a move a to direct byte 2 2 mov direct, rn move register to direct byte 2 2 mov direct, direct move direct byte to direct byte 3 3 mov direct, @ri move indirect ram to direct byte 2 2 mov direct, #data move immediate to direct byte 3 3 mov @ri, a move a to indirect ram 1 2 mov @ri, direct move direct byte to indirect ram 2 2 mov @ri, #data move immediate to indirect ram 2 2 mov dptr, #data16 load dptr with 16-bit constant 3 3 movc a, @a+dptr move code byte relative dptr to a 1 3 movc a, @a+pc move code byte relative pc to a 1 3 movx a, @ri move external data (8-bit address) to a 1 3 movx @ri, a move a to external data (8-bit address) 1 3 movx a, @dptr move external data (16-bit address) to a 1 3 movx @dptr, a move a to external data (16-bit address) 1 3 push direct push direct byte onto stack 2 2 pop direct pop direct byte from stack 2 2 xch a, rn exchange register with a 1 1 xch a, direct exchange direct byte with a 2 2 xch a, @ri exchange indirect ram with a 1 2 table 20.1. cip-51 instruction set summary mnemonic description bytes clock cycles
c8051f97x rev 1.0 169 cip-51 microcontroller core xchd a, @ri exchange low nibble of indirect ram with a 1 2 boolean manipulation clr c clear carry 1 1 clr bit clear direct bit 2 2 setb c set carry 1 1 setb bit set direct bit 2 2 cpl c complement carry 1 1 cpl bit complement direct bit 2 2 anl c, bit and direct bit to carry 2 2 anl c, /bit and complement of direct bit to carry 2 2 orl c, bit or direct bit to carry 2 2 orl c, /bit or complement of direct bit to carry 2 2 mov c, bit move direct bit to carry 2 2 mov bit, c move carry to direct bit 2 2 jc rel jump if carry is set 2 2/3 jnc rel jump if carry is not set 2 2/3 jb bit, rel jump if direct bit is set 3 3/4 jnb bit, rel jump if direct bit is not set 3 3/4 jbc bit, rel jump if direct bit is set and clear bit 3 3/4 program branching acall addr11 absolute subroutine call 2 3 lcall addr16 long subroutine call 3 4 ret return from subroutine 1 5 reti return from interrupt 1 5 ajmp addr11 absolute jump 2 3 ljmp addr16 long jump 3 4 sjmp rel short jump (relative address) 2 3 jmp @a+dptr jump indirect relative to dptr 1 3 jz rel jump if a equals zero 2 2/3 jnz rel jump if a does not equal zero 2 2/3 cjne a, direct, rel compare direct byte to a and jump if not equal 3 3/4 cjne a, #data, rel compare immediate to a and jump if not equal 3 3/4 cjne rn, #data, rel compare immediate to register and jump if not equal 3 3/4 cjne @ri, #data, rel compare immediate to indirect and jump if not equal 3 4/5 djnz rn, rel decrement register and jump if not zero 2 2/3 djnz direct, rel decrement direct byte and jump if not zero 3 3/4 nop no operation 1 1 table 20.1. cip-51 instruction set summary mnemonic description bytes clock cycles
c8051f97x 170 rev 1.0 cip-51 microcontroller core notes on registers, operands and addressing modes: rn ?register r0?r7 of the currently selected register bank. @ri ?data ram location addressed indirectly through r0 or r1. rel ?8-bit, signed (twos complement) offset relative to the first byte of the following in struction. used by sjmp and all conditional jumps. direct ?8-bit internal data location?s address. this could be a direct-access data ram location (0x00?0x7f) or an sfr (0x80?0xff). #data ?8-bit constant #data16 ?16-bit constant bit ?direct-accessed bit in data ram or sfr addr11 ?11-bit destination address used by acall and ajmp . the destination must be within the same 2 kb page of program memory as the first byte of the following instruction. addr16 ?16-bit destination address used by lcall and lj mp. the destination may be anywhere within the 8 kb program memory space. there is one unused opcode (0xa5) that performs the same function as nop. all mnemonics copyrighted ? intel corporation 1980.
c8051f97x rev 1.0 171 cip-51 microcontroller core 20.4. sfr paging the cip-51 features sfr paging, allowing the device to map many sfrs into the 0x80 to 0xff memory address space. the sfr memory space has 256 pages. in this way, each memory location from 0x80 to 0xff can access up to 256 sfrs. the c80 51f97x family of devices utilizes two sf r pages: 0x00 and 0x0f. sfr pages are selected using the special function register page regi ster, sfrpage. the procedure for reading and writing an sfr is as follows: 1. select the appropriate sfr page number using the sfrpage register. 2. use direct accessing mode to read or writ e the special function register (mov instruction). 20.5. interrupts and sfr paging when an interrupt occurs, the sfr page register will automatically switch to the sfr page containing the flag bit that caused the interrupt. the automatic sfr page switch function conveniently removes the burden of switching sfr pages from the interrupt service routine. upon execution of the reti instruction, the sfr page is automati - cally restored to the sfr page in use prior to the interrupt. this is accomplished via a three-byte sfr page stack. the top byte of the stack is sfrpage, the current sf r page. the second byte of the sfr page stack is sfrnext. the third or bottom byte of the sfr page stac k is sfrlast. upon entering an interrupt service routine, the current sfrpage value is pushed to the sfrnext by te, and the value of sfrnext is pushed to sfrlast. hardware then loads sfrpage with the sfr page containing the flag bit associated with the interrupt. on a return from interrupt, the sfr page stack is popped resulting in the value of sfrnext returning to the sfrpage regis - ter, thereby restoring the sfr page context without softwa re intervention. the value in sfrlast (0x00 if there is no sfr page value in the bottom of the stack) of the st ack is placed in sfrnext register. if desired, the values stored in sfrnext and sfrlast may be modified during an interrupt, enabling the cpu to return to a different sfr page upon execution of the reti instruction (on inte rrupt exit). modifying registers in the sfr page stack does not cause a push or pop of the stack. only in terrupt calls and returns will caus e push/pop opera tions on the sfr page stack.
c8051f97x 172 rev 1.0 cip-51 microcontroller core figure 20.2. sfr page stack automatic hardware switching of the sfr page on interrupts may be enabled or disabled as desired using the sfr automatic page control enable bit located in the sfr page co ntrol register (sfrpgcn). th is function defaults to ?enabled? upon reset. in this way, the auto-switching function will be en abled unless disabled in software. a summary of the sfr locations (address and sfr page) are provided in ta b l e 9.1 on page 57 and table 9.2 on page 58 . each memory location in the map has an sfr page row, denoting the page in which that sfr resides. certain sfrs are accessible from all sfr pages. for exam ple, the port i/o registers p0, p1, p2, and p3 are avail - able on all pages regardless of the sfrpage register value. cip-51 interrupt logic sfrpage sfrlast sfrlast sfrpgen bit
c8051f97x rev 1.0 173 cip-51 microcontroller core 20.6. sfr page stack example this example demonstrates the operation of the sfr page stack during interrupts. in this example, the sfr control register is left in the default enabled state (i.e., sfrpgen = 1), and the cip-51 is executing in-line code that is writ - ing values to i2c0stat i2c slave 0 status register (loc ated at address 0xf8 on sfr p age 0x0f). the device is also using the spi peripheral (spi0) and the programmabl e counter array (pca0) peripheral to generate a pwm output. the pca is timing a critical control function in its interrupt service routine, and so its associated isr is set to high priority. at this point, the sfr page is set to access the i2c0stat sf r (sfrpage = 0x0f). see figure 20.3 . figure 20.3. sfr page stack while using sfr page 0x0f to access i2c0stat 0x0f (i2c0stat) sfrpage sfrnext sfrlast sfr page stack sfrs
c8051f97x 174 rev 1.0 cip-51 microcontroller core while cip-51 executes in-line code (reading a value from i2c0stat in this example), the spi0 interrupt occurs. the cip-51 vectors to the spi0 isr and pushes the current sfr page value (sfr page 0x0f) into sfrnext in the sfr page stack. the sfr page needed to access spi0 's sfrs is then automatically placed in the sfrpage register (sfr page 0x00). sfrpage is considered the to p of the sfr page stack. firmware can now access the spi0 sfrs. software may switch to any sfr page by writ ing a new value to the sfrpage register at any time during the spi0 isr to access sfrs t hat are not on sfr page 0x00. see figure 20.4 . figure 20.4. sfr page stack after spi0 interrupt occurs 0x00 (spi0) 0x0f (i2c0stat) sfrpage sfrnext sfrlast sfr page stack sfrs sfr page 0x00 automatically pushed on stack in sfrpage on spi0 interrupt sfrpage pushed to sfrnext
c8051f97x rev 1.0 175 cip-51 microcontroller core while in the spi0 isr, a pca interrupt occurs. recall the pc a interrupt is configured as a high priority interrupt, while the spi0 interrupt is configured as a low priority interrupt. thus, the cip-51 will now vector to the high priority pca isr. upon doing so, the cip-51 will automatically place the sfr page needed to access the pca?s special function registers into the sfrpage register, sfr page 0x00. the value that was in the sfrpage register before the pca interrupt (sfr page 0x00 for spi0) is pushed down the stack into sfrnext. li kewise, the value that was in the sfrnext register before the pca interrupt (in this case sfr page 0x0f for i2c0stat) is pushed down to the sfrlast register, the bottom of the stack. note that a value stored in sfrlast (via a previous software write to the sfrlast register) will be overwritten. see figure 20.5 . figure 20.5. sfr page stack upon pca interrupt occurring during a spi0 isr 0x00 (pca0) 0x0f (i2c0stat) 0x00 (spi0) sfrpage sfrnext sfrlast sfr page stack sfrs sfr page 0x00 automatically pushed on stack in sfrpage on pca interrupt sfrpage pushed to sfrnext sfrnext pushed to sfrlast
c8051f97x 176 rev 1.0 cip-51 microcontroller core on exit from the pca interr upt service routine, the cip- 51 will return to the spi0 isr. on execution of the reti instruction, sfr page 0x00 used to access the pca re gisters will be automatically popped off of the sfr page stack, and the contents of the sfrnext register will be moved to the sfrpage regi ster. firmware in the spi0 isr can continue to access sfrs as it did prior to the pca interrupt. likewise, the contents of sfrlast are moved to the sfrnext register. recall this was the sfr page value 0x0f being used to access i2c0stat before the spi0 interrupt occurred. see figure 20.6 . figure 20.6. sfr page stack upon return from pca interrupt 0x00 (spi0) 0x0f (i2c0stat) sfrpage sfrnext sfrlast sfr page stack sfrs sfr page 0x00 automatically popped off of the stack on return from interrupt sfrnext popped to sfrpage sfrlast popped to sfrnext
c8051f97x rev 1.0 177 cip-51 microcontroller core on the execution of the reti instruct ion in the spi0 isr, the value in sfrp age register is overwritten with the contents of sfrnext. the cip-51 may now access the i2c0st at register as it did prior to the interrupts occur - ring. see figure 20.7 . figure 20.7. sfr page stack upon return from spi0 interrupt in the example above, all three bytes in the sfr page stack are accessible via the sfrpage, sfrnext, and sfrlast special function registers. if the stack is altered wh ile servicing an inte rrupt, it is possib le to return to a different sfr page upon interrupt exit than selected prior to the interrupt call. direct access to the sfr page stack can be useful to enable real-time op erating systems to control and manage context switching between multiple tasks. push operations on the sfr page stack only occur on interrupt service, and pop operations only occur on interrupt exit (execution on the reti instruct ion). the automatic switching of the sf rpage and operation of the sfr page stack as described above can be disabled in software by clearing the sfr automatic page enable bit (sfrpgen) in the sfr page control register (sfrpgcn). 0x0f (i2c0stat) sfrpage sfrnext sfrlast sfr page stack sfrs sfr page 0x00 automatically popped off of the stack on return from interrupt sfrnext popped to sfrpage
c8051f97x 178 rev 1.0 cip-51 microcontroller core 20.7. cpu core registers register 20.1. dpl: data pointer low bit 7 6 5 4 3 2 1 0 name dpl type rw reset00000000 sfr page = all; sfr address: 0x82 table 20.2. dpl register bit descriptions bit name function 7:0 dpl data pointer low. the dpl register is the low byte of the 16-b it dptr. dptr is used to access indirectly addressed flash memory or xram.
c8051f97x rev 1.0 179 cip-51 microcontroller core register 20.2. dph: data pointer high bit 7 6 5 4 3 2 1 0 name dph type rw reset00000000 sfr page = all; sfr address: 0x83 table 20.3. dph register bit descriptions bit name function 7:0 dph data pointer high. the dph register is the high byte of the 16-b it dptr. dptr is used to access indirectly addressed flash memory or xram.
c8051f97x 180 rev 1.0 cip-51 microcontroller core register 20.3. sp: stack pointer bit 7 6 5 4 3 2 1 0 name sp type rw reset00000111 sfr page = all; sfr address: 0x81 table 20.4. sp register bit descriptions bit name function 7:0 sp stack pointer. the stack pointer holds the location of the to p of the stack. the stack pointer is incre - mented before every push operation. the sp register defaults to 0x07 after reset.
c8051f97x rev 1.0 181 cip-51 microcontroller core register 20.4. acc: accumulator bit 7 6 5 4 3 2 1 0 name acc type rw reset00000000 sfr page = all; sfr address: 0xe0 (bit-addressable) table 20.5. acc register bit descriptions bit name function 7:0 acc accumulator. this register is the accumulator for arithmetic operations.
c8051f97x 182 rev 1.0 cip-51 microcontroller core register 20.5. b: b register bit 7 6 5 4 3 2 1 0 name b type rw reset00000000 sfr page = 0xf; sfr address: 0xf0 (bit-addressable) table 20.6. b register bit descriptions bit name function 7:0 b b register. this register serves as a second accumu lator for certain arithmetic operations.
c8051f97x rev 1.0 183 cip-51 microcontroller core register 20.6. psw: program status word bit 7 6 5 4 3 2 1 0 name cy ac f0 rs ov f1 parity type rw rw rw rw rw rw r reset00000000 sfr page = all; sfr address: 0xd0 (bit-addressable) table 20.7. psw register bit descriptions bit name function 7 cy carry flag. this bit is set when the last arithmetic operatio n resulted in a carry (addition) or a borrow (subtraction). it is cleared to logic 0 by all other arithmetic operations. 6 ac auxiliary carry flag. this bit is set when the last arithmetic operation resulted in a carry into (addition) or a borrow from (subtraction) the high order nibble. it is cleared to logic 0 by all other arith - metic operations. 5 f0 user flag 0. this is a bit-addressable, general pur pose flag for use under firmware control. 4:3 rs register bank select. these bits select which register ban k is used during register accesses. 00: bank 0, addresses 0x00-0x07 01: bank 1, addresses 0x08-0x0f 10: bank 2, addresses 0x10-0x17 11: bank 3, addresses 0x18-0x1f 2 ov overflow flag. this bit is set to 1 under the following circumstances: 1. an add, addc, or subb instruct ion causes a sign-change overflow. 2. a mul instruction results in an overflow (result is greater than 255). 3. a div instruction causes a divide-by-zero condition. the ov bit is cleared to 0 by the add, addc, subb, mul, and div instructions in all other cases. 1 f1 user flag 1. this is a bit-addressable, general pur pose flag for use under firmware control. 0 parity parity flag. this bit is set to logic 1 if the sum of the ei ght bits in the accumulator is odd and cleared if the sum is even.
c8051f97x 184 rev 1.0 cip-51 microcontroller core register 20.7. sfrpage: sfr page bit 7 6 5 4 3 2 1 0 name sfrpage type rw reset00000000 sfr page = all; sfr address: 0xa7 table 20.8. sfrpage register bit descriptions bit name function 7:0 sfrpage sfr page. specifies the sfr page used when reading, writing, or modifying special function regis - ters.
c8051f97x rev 1.0 185 cip-51 microcontroller core register 20.8. sfrpgcn: sfr page control bit 7 6 5 4 3 2 1 0 name reserved sfrpgen type r rw reset00000001 sfr page = 0xf; sfr address: 0xa6 table 20.9. sfrpgcn register bit descriptions bit name function 7:1 reserved must write reset value. 0 sfrpgen sfr automatic page control enable. upon interrupt, the c8051 core will vector to the specified interr upt service routine and automatically switch the sfr page to the co rresponding peripheral or function's sfr page. this bit is used to control this autopaging function. 0: disable sfr automatic paging. the c8051 core will not automati cally change to the appropriate sfr page (i.e., the sfr page that contains the sfrs for the peripheral/func - tion that was the source of the interrupt). 1: enable sfr automatic paging. upon interrup t, the c8051 will switch the sfr page to the page that contains the sfrs for the peripheral or function that is the source of the interrupt.
c8051f97x 186 rev 1.0 cip-51 microcontroller core register 20.9. sfrnext: sfr page next bit 7 6 5 4 3 2 1 0 name sfrnext type rw reset00000000 sfr page = all; sfr address: 0xf3 table 20.10. sfrnext register bit descriptions bit name function 7:0 sfrnext sfr page next. this is the value that will go to the sfr pa ge register upon a re turn from interrupt. write: sets the sfr page contained in the se cond byte of the sfr stack. this will cause the sfrpage sfr to have this sfr page value upon a retu rn from interrupt. read: returns the value of the sfr page contained in the second byte of the sfr stack. sfr page context is retained upon interrupts/return from interrupts in a 3-byte sfr page stack: sfrpage is the first entry, sfrnext is the second, and sfrlast is the third entry. the sfr stack bytes may be used alter the context in the sfr page stack, and will not cause the stack to push or pop. only interrupts and return fr om interrupts cause pushes and pops of the sfr page stack.
c8051f97x rev 1.0 187 cip-51 microcontroller core register 20.10. sfrlast: sfr page last bit 7 6 5 4 3 2 1 0 name sfrlast type rw reset00000000 sfr page = all; sfr address: 0xb3 table 20.11. sfrlast register bit descriptions bit name function 7:0 sfrlast sfr page last. this is the value that will go to the sfrnext register upon a re turn from interrupt. write: sets the sfr page in the last entry of the sfr stack. this will cause the sfrnext sfr to have this sfr page va lue upon a return from interrupt. read: returns the value of the sfr page contained in the last entry of the sfr stack. sfr page context is retained upon interrupts/return from interrupts in a 3-byte sfr page stack: sfrpage is the first entry, sfrnext is the second, and sfrlast is the third entry. the sfr stack bytes may be used alter the context in the sfr page stack, and will not cause the stack to push or pop. only interrupts and return fr om interrupts cause pushes and pops of the sfr page stack.
c8051f97x 188 rev 1.0 direct memory access (dma0) 21. direct memo ry access (dma0) an on-chip direct memory access (dma0) is includ ed on the c8051f97x devices. the dma0 subsystem allows unattended variable-length data transfers between xram and peripheral sfr registers without cpu intervention. during dma0 operation, the cpu is free to perform so me other tasks. in order to save total system power consumption, the cpu and flash can be powered down. dma0 improves th e system performance and efficiency with high data throughput peripherals. dma0 contains seven independent channels, co mmon control registers, and a dma0 engine (see figure 21.1 ). each channel includes a register that assigns a peripheral to the channel, a channel co ntrol register, and a set of sfrs that include xram address information and sfr address information used by the channel during a data transfer. the dma0 architectu re is described in detail in ?21.1. dma0 architecture? . the dma0 in c8051f97x devices suppo rts two peripherals: mac0 and i2c0 . peripherals with dma0 capability should be configured to work with the dma0 through their own registers. the dma0 provides up to seven channels, and each channel can be configured for one of eight possible data transfer functions: ?? xram to mac a registers (mac0ah, mac0al). ?? xram to mac b registers (mac0bh, mac0bl). ?? xram to mac accumulator registers (mac0accn). ?? mac accumulator registers (mac0accn) to xram. ?? i2c slave 0 received data register (i2c0din) to xram. ?? xram to i2c slave 0 transmit data register (i2c0dout). functions 5 and 6 are mutually exclusive. the dma0 subsystem signals the mcu through a set of in terrupt service routine flags. interrupts can be generated when the dma0 transfers half of the data length or full data length on any channel. figure 21.1. dma0 block diagram mac a request internal dma bus control mac b request mac c input request mac c output request i2c transmit request i2c receive request channel memory interface config channel control channel 0 channel 1 channel 6 ... peripheral assignment - dma0ncf[2:0] dma0en dma0int dma0mint dma0busy dma0sel dma0sel[0] ch0_en ch1_en ch2_en ch3_en ch4_en ch5_en ch6_en ch0_int ch1_int ch2_int ch3_int ch4_int ch5_int ch6_int ch0_mint ch1_mint ch2_mint ch3_mint ch4_mint ch5_mint ch6_mint ch0_busy ch1_busy ch2_busy ch3_busy ch4_busy ch5_busy ch6_busy dma0sel[0] dma0sel[1] dma0sel[2] common control/ status dma engine minten stall inten endian periph2 dma0ncf periph0 periph1 dma0nbah dma0nbal dma0naoh dma0naol dma0nszh dma0nszl
c8051f97x rev 1.0 189 direct memory access (dma0) 21.1. dma0 architecture the first step in configuring a dma0 channel is to select the desired channel for data transfer using dma0sel[2:0] bits (dma0sel). after setting the dma0 channel, firm ware can address channel-specific registers such as dma0ncf, dma0nbah/l, dma0naoh/l, an d dma0nszh/l. once firmware selects a channel, the subsequent sfr configuration applies to the dma0 transfer of that selected channel. each dma0 channel consists of an sfr assigning the channel to a peripheral, a channel control register and a set of sfrs that describe xram and sfr addresses to be used during data transfer ( figure 21.1 ). the peripheral assignment bits of dma0ncf select one of the eight data transfer functions. the selected channel can choose the desired function by writing to the per iph field in the dma0ncf register. the control register dma0ncf of each channel configures the endianness of the data in xram, stall enable, full- length interrupt enable and mid-point interrupt enable. when a channel is stalled by setting the stall bit (dma0ncf.5), dma0 transfers in prog ress will not be ab orted, but new dma0 transf ers will be blocked until the stall status of the channel is reset. after the stall bit is set, software s hould poll the corresponding chnbusy bit to verify that there are no more dma transfers for that channel. the memory interface configuration sfrs of a channel defi ne the linear region of xram involved in the transfer through a 12-bit base address register dma0nbah:l, a 10 -bit address offset register dma0naoh/l and a 10-bit data transfer size dma0nszh:l. the effective memory address is the address involved in the current dma0 transaction. effective memory address = base address + address offset the address offset serves as byte counter. the address offs et should be always less than data transfer length. the address offset increments by one after each byte tran sferred. for dma0 configuration of any channel, address offsets of active channels should be reset to 0 before dma0 transfers occur. data transfer size dma0nszh:l defines the maximum nu mber of bytes for the dma0 transfer of the selected channel. if the address offset reaches data transfer size , the full-length in terrupt flag bit chni (dma0int) of the selected channel will be asserted . similarly, the mid-point inte rrupt flag bit chnmi is set when the address offset is equal to half of data transfer size if the transfer size is an even number or when the address offset is equal to half of the transfer size plus one if the tr ansfer size is an odd number. interrupt flags must be cleared by software so that the next dma0 data transfer can proceed. the dma0 subsystem permits data transfer between sfr registers and xram. the dma0 subsystem executes its task based on settings of a channel?s control and memory interface configuration sfrs. when data is copied from xram to sfr registers, it takes two cy cles for dma0 to read from xram and the sfr write occurs in the second cycle. if more than one byte is involved, a pipeline is us ed. when data is copied from sfr registers to xram, the dma0 only requires one cycle for one byte transaction. the selected dma0 channel for a peripheral should be enabled through the enable bits chnen (dma0en.n) to allow the dma0 to transfer the data. when the dma0 is tran sferring data on a channel, the busy status bit of the channel chnbusy (dma0busy.n) is se t. during the transaction, writes to dma0nszh:l, dma0nbah:l, and dma0naoh:l are disabled. besides reporting transaction status of a channel, dma0bu sy can be used to force a dma0 transfer on an already configured channel by setting the chnbusy bit (dma0busy.n) . this is useful for communication peripherals such as the i2c0. for example, after the i2c0 acknowledges the received slave address from i2c master during a read transaction, a byte of data s hould be written to th e i2c0dout register that will be transmitte d to the i2c master during the next i2c data transfer. writing 1 to the chn_busy bit (dma0busy.n) of an enabled dma0 channel forces a data transfer fr om the xram to i2c0dout. 21.2. dma0 arbitration 21.2.1. dma0 memory access arbitration if both dma0 and cpu attempt to access sfr register or xram at the same time, the cpu preempts the dma0 module. dma0 will be stalled until cpu completes its bus activity.
c8051f97x 190 rev 1.0 direct memory access (dma0) 21.2.2. dma0 chan nel arbitration multiple dma0 channels can request transfer simultaneo usly, but only one dma0 c hannel will be granted the bus to transfer the data. channel 0 has the highest priority . dma0 channels are serviced based on their priority. a higher priority channel is serviced first. channel arbitrat ion occurs at the end of the data transfer granularity (transaction boundary) of the dma. when there is a dma0 re quest at the transaction boundary from higher priority channel, lower priority ones will be st alled until the highest prio rity one completes its tr ansaction. so, for 16-bit transfers like mac0ah:l, the transact ion boundary is at every 2 bytes. 21.3. dma0 operation in low power modes dma0 remains functional in normal ac tive, low power active, idle, low powe r idle modes but not in sleep or suspend mode. cpu will wait for dma0 to complete all pending requests befo re it enters sleep mode. when the system wakes up from suspend or sleep mode to normal active mode, p ending dma0 interrup ts will be serviced according to priority of channels. dma0 stalls when cpu is in debug mode. 21.4. transfer configuration the following steps are required to configure one of the dma0 channels for operation: 1. select the channel to be configured by writing dma0sel. 2. specify the data transfer function by writing dma0 ncf. this register also specifies the endianness of the data in xram and enables full or mid-point interrupts. 3. specify the base address in xram for the transfer by writing dma0nbah:l. 4. specify the size of the transfer in bytes by writing dma0nszh:l. 5. reset the address offset counter by writing 0 to dma0naoh:l. 6. enable the dma0 channel by writing 1 to the appropriate bit in dma0en.
c8051f97x rev 1.0 191 direct memory access (dma0) 21.5. dma0 registers register 21.1. dma0en: dma0 channel enable bit 7 6 5 4 3 2 1 0 name reserved ch6en ch5en ch4en ch3en ch2en ch1en ch0en type r rw rw rw rw rw rw rw reset 0 0 0 0 0 0 0 0 sfr page = 0xf; sfr address: 0x92 bit name function 7 reserved must write reset value. 6 ch6en channel 6 enable. 0: disable dma0 channel 6. 1: enable dma0 channel 6. 5 ch5en channel 5 enable. 0: disable dma0 channel 5. 1: enable dma0 channel 5. 4 ch4en channel 4 enable. 0: disable dma0 channel 4. 1: enable dma0 channel 4. 3 ch3en channel 3 enable. 0: disable dma0 channel 3. 1: enable dma0 channel 3. 2 ch2en channel 2 enable. 0: disable dma0 channel 2. 1: enable dma0 channel 2. 1 ch1en channel 1 enable. 0: disable dma0 channel 1. 1: enable dma0 channel 1. 0 ch0en channel 0 enable. 0: disable dma0 channel 0. 1: enable dma0 channel 0.
c8051f97x 192 rev 1.0 direct memory access (dma0) register 21.2. dma0int: dma0 full-length interrupt flags bit 7 6 5 4 3 2 1 0 name reserved ch6i ch5i ch4i ch3i ch2i ch1i ch0i type r rw rw rw rw rw rw rw reset 0 0 0 0 0 0 0 0 sfr page = 0xf; sfr address: 0xe8 (bit-addressable) bit name function 7 reserved must write reset value. 6 ch6i channel 6 full-length interrupt flag. 0: no interrupt generated. 1: full-length interrupt generated in channel 6. 5 ch5i channel 5 full-length interrupt flag. 0: no interrupt generated. 1: full-length interrupt generated in channel 5. 4 ch4i channel 4 full-length interrupt flag. 0: no interrupt generated. 1: full-length interrupt generated in channel 4. 3 ch3i channel 3 full-length interrupt flag. 0: no interrupt generated. 1: full-length interrupt generated in channel 3. 2 ch2i channel 2 full-length interrupt flag. 0: no interrupt generated. 1: full-length interrupt generated in channel 2. 1 ch1i channel 1 full-length interrupt flag. 0: no interrupt generated. 1: full-length interrupt generated in channel 1. 0 ch0i channel 0 full-length interrupt flag. 0: no interrupt generated. 1: full-length interrupt generated in channel 0. note: channel full-length interrupt flags are set when the offset address dma0naoh/l equals to data transfer size dma0nszh/l minus 1 for the channel. firmware must clear this flag. the full-length interrupt is enabled by setting the ien bit in the dma0ncf register with dma0sel configured for the corresponding channel.
c8051f97x rev 1.0 193 direct memory access (dma0) register 21.3. dma0mint: dma0 mid-point interrupt flags bit 7 6 5 4 3 2 1 0 name reserved ch6mi ch5mi ch4mi ch3mi ch2mi ch1mi ch0mi type r rw rw rw rw rw rw rw reset 0 0 0 0 0 0 0 0 sfr page = 0xf; sfr address: 0x88 (bit-addressable) bit name function 7 reserved must write reset value. 6 ch6mi channel 6 mid-point interrupt flag. 0: no mid-point interrupt generated. 1: mid-point interrupt generated in channel 6. 5 ch5mi channel 5 mid-point interrupt flag. 0: no mid-point interrupt generated. 1: mid-point interrupt generated in channel 5. 4 ch4mi channel 4 mid-point interrupt flag. 0: no mid-point interrupt generated. 1: mid-point interrupt generated in channel 4. 3 ch3mi channel 3 mid-point interrupt flag. 0: no mid-point interrupt generated. 1: mid-point interrupt generated in channel 3. 2 ch2mi channel 2 mid-point interrupt flag. 0: no mid-point interrupt generated. 1: mid-point interrupt generated in channel 2. 1 ch1mi channel 1 mid-point interrupt flag. 0: no mid-point interrupt generated. 1: mid-point interrupt generated in channel 1. 0 ch0mi channel 0 mid-point interrupt flag. 0: no mid-point interrupt generated. 1: mid-point interrupt generated in channel 0. note: mid-point interrupt flag is set when the offset address dm a0naoh/l equals to half of data transfer size dma0nszh/l if the transfer size is an even number or half of data trans fer size dma0nszh/l plus one if the transfer size is an odd number. firmware must clear this flag. the mid-point inte rrupt is enabled by setting the mien bit in the dma0ncf register with dma0sel configur ed for the corresponding channel.
c8051f97x 194 rev 1.0 direct memory access (dma0) register 21.4. dma0busy: dma0 busy bit 7 6 5 4 3 2 1 0 name reserved ch6busy ch5busy ch4busy ch3busy ch2busy ch1busy ch0busy type r rw rw rw rw rw rw rw reset 0 0 0 0 0 0 0 0 sfr page = 0xf; sfr address: 0x91 bit name function 7 reserved must write reset value. 6 ch6busy channel 6 busy. this bit is set to 1 by hardware when a dma0 transfer is in progress on channel 6. writ - ing this bit to 1 forces a dma0 transfer to start on channel 6. 5 ch5busy channel 5 busy. this bit is set to 1 by hardware when a dma0 transfer is in progress on channel 5. writ - ing this bit to 1 forces a dma0 transfer to start on channel 5. 4 ch4busy channel 4 busy. this bit is set to 1 by hardware when a dma0 transfer is in progress on channel 4. writ - ing this bit to 1 forces a dma0 transfer to start on channel 4. 3 ch3busy channel 3 busy. this bit is set to 1 by hardware when a dma0 transfer is in progress on channel 3. writ - ing this bit to 1 forces a dma0 transfer to start on channel 3. 2 ch2busy channel 2 busy. this bit is set to 1 by hardware when a dma0 transfer is in progress on channel 2. writ - ing this bit to 1 forces a dma0 transfer to start on channel2. 1 ch1busy channel 1 busy. this bit is set to 1 by hardware when a dma0 transfer is in progress on channel 1. writ - ing this bit to 1 forces a dma0 transfer to start on channel 1. 0 ch0busy channel 0 busy. this bit is set to 1 by hardware when a dma0 transfer is in progress on channel 0. writ - ing this bit to 1 forces a dma0 transfer to start on channel 0.
c8051f97x rev 1.0 195 direct memory access (dma0) register 21.5. dma0sel: dma0 channel select bit 7 6 5 4 3 2 1 0 name reserved select type r rw rw reset 0 0 0 0 0 0 0 0 sfr page = 0xf; sfr address: 0x94 bit name function 7:3 reserved must write reset value. 2:0 select channel select. this field selects the channel and provides access to the channel's dma0ncf, dma0nbal/h, dma0naol/h, dma0nszl/h registers. 000: select channel 0. 001: select channel 1. 010: select channel 2. 011: select channel 3. 100: select channel 4. 101: select channel 5. 110: select channel 6. 111: reserved.
c8051f97x 196 rev 1.0 direct memory access (dma0) register 21.6. dma0ncf: dma0 channel configuration bit 7 6 5 4 3 2 1 0 name ien mien stall endian reserved periph type rw rw rw rw r rw reset 0 0 0 0 0 0 0 0 sfr page = 0xf; sfr address: 0xd8 (bit-addressable) bit name function 7 ien full-length interrupt enable. this bit enables dma0 full- length interrupt requests for the selected channel. 0: disable the dma0 full-length interrupt request of the selected channel. 1: enable the dma0 full- length interrupt request of the selected channel. 6 mien mid-point interrupt enable. this bit enables dma0 mid-point interrupt requests for the selected channel. 0: disable the dma0 mid-point interrupt request of the selected channel. 1: enable the dma0 mid-point interrupt request of the selected channel. 5 stall channel stall. setting this bit stalls the dma transfer on the selected channel. a stalled channel cannot initiate new dma transfers. t he dma0 transfer of the stalled channel resumes where it was only when this bit is cleared by firmware. 0: the dma transfer of the selected channel is not stalled. 1: the dma transfer of the selected channel is stalled. 4 endian data transfer endianness. this bit sets the byte order of the xram data. 0: data is written to and read from xram in little endian order. 1: data is written to and read from xram in big endian order. 3 reserved must write reset value. 2:0 periph peripheral transfer select. this field selects the dma0 transfer function for the selected channel. 000-001: reserved. 010: the dma channel transfers from xram to the mac a register. 011: the dma channel transfers from xram to the mac b register. 100: the dma channel transfers from xram to the mac accumulator registers. 101: the dma channel transfers from th e mac accumulator re gisters to xram. 110: the dma channel transfers from the i2c slave data register to xram. 111: the dma channel transfers from xram to the i2c slave data register. note: this register is a dma channel indirect register. sele ct the desired channel first using the dma0sel register.
c8051f97x rev 1.0 197 direct memory access (dma0) register 21.7. dma0nbah: memory base address high bit 7 6 5 4 3 2 1 0 name reserved nbah type r rw reset 0 0 0 0 0 0 0 0 sfr page = 0xf; sfr address: 0xca bit name function 7:4 reserved must write reset value. 3:0 nbah memory base address high. this field sets high byte of the channel memo ry base address. this base address is the starting channel xram address if the channel's address offset dma0nao is reset to 0. note: this register is a dma channel indirect register. sele ct the desired channel first using the dma0sel register.
c8051f97x 198 rev 1.0 direct memory access (dma0) register 21.8. dma0nbal: memory base address low bit 7 6 5 4 3 2 1 0 name nbal type rw reset 0 0 0 0 0 0 0 0 sfr page = 0xf; sfr address: 0xc9 bit name function 7:0 nbal memory base address low. this field sets low byte of the channel memo ry base address. this base address is the starting channel xram address if the channel's address offset dma0nao is reset to 0. note: this register is a dma channel indirect register. sele ct the desired channel first using the dma0sel register.
c8051f97x rev 1.0 199 direct memory access (dma0) register 21.9. dma0naoh: memory address offset high bit 7 6 5 4 3 2 1 0 name reserved naoh type r rw reset 0 0 0 0 0 0 0 0 sfr page = 0xf; sfr address: 0xcc bit name function 7:2 reserved must write reset value. 1:0 naoh memory address offset high. this field is the high byte of the channel offset address. the base address added to the offset address creates the current channel xram address. the address offset auto- increments by one after one byte is transferred. when configuring a channel for a dma transfer, the address offset should be reset to 0. note: this register is a dma channel indirect register. sele ct the desired channel first using the dma0sel register.
c8051f97x 200 rev 1.0 direct memory access (dma0) register 21.10. dma0naol: memory address offset low bit 7 6 5 4 3 2 1 0 name naol type rw reset 0 0 0 0 0 0 0 0 sfr page = 0xf; sfr address: 0xcb bit name function 7:0 naol memory address offset low. this field is the high byte of the channel offset address. the base address added to the offset address creates the current channel xram address. the address offset auto- increments by one after one byte is transferred. when configuring a channel for a dma transfer, the address offset should be reset to 0. note: this register is a dma channel indirect register. sele ct the desired channel first using the dma0sel register.
c8051f97x rev 1.0 201 direct memory access (dma0) register 21.11. dma0nszh: memory transfer size high bit 7 6 5 4 3 2 1 0 name reserved nszh type r rw reset 0 0 0 0 0 0 0 0 sfr page = 0xf; sfr address: 0xce bit name function 7:2 reserved must write reset value. 1:0 nszh memory transfer size high. this field sets the upper two bits of the number of dma transfers for the selected chan - nel. note: this register is a dma channel indirect register. sele ct the desired channel first using the dma0sel register.
c8051f97x 202 rev 1.0 direct memory access (dma0) register 21.12. dma0nszl: memory transfer size low bit 7 6 5 4 3 2 1 0 name nszl type rw reset 0 0 0 0 0 0 0 0 sfr page = 0xf; sfr address: 0xcd bit name function 7:0 nszl memory transfer size low. this field sets the low byte of the number of dma transfers for the selected channel. note: this register is a dma channel indirect register. sele ct the desired channel first using the dma0sel register.
c8051f97x rev 1.0 203 multiply and accumulate (mac0) 22. multiply and accumulate (mac0) the c8051f97x devices include a multiply and accumulate engine which can be used to speed up many mathematical operations. mac0 contains a 16-by-16 bit multiplier and a 40-bit adder, which can perform integer or fractional multiply-accumulate and multiply operations in a single sysclk cycle. figure 22.1 shows a block diagram of the mac0 subsystem and its associated sfrs. figure 22.1. mac0 block diagram mac0 a regi st er mac0 b register 16 x 16 multiply adder 1 0 accmd 0 flags logic rounding dma control signals negate accnegate busy mac0 data transfer logic admasrc bdmasrc signeden apostinc bpostinc data bus 0 1 41-bit accumulator mac0 accumul at or 1 bit shift alignment saturate dma control signals accalign 1 0 round signeden signeden mbshift shiftdir mac0acc1 mac0acc0 mac0acc2 mac0acc3 mac0ovr mac0ah mac0al mac0bh mac0bl
c8051f97x 204 rev 1.0 multiply and accumulate (mac0) the module provides the following capabilities: ?? single cycle operation ?? multiply-accumulate or multiply only ?? support for integer or fractional operations ?? support for signed or unsigned operations ?? rounding with saturation ?? auto-increment or constant a and/or b registers ?? logical 1-bit or multiple bit shif t of accumulator left or right ?? negation of accumulator, a, and/or b registers ?? dma support for repetitive operations on large arrays of data. ?? signed and unsigned alignment (right shift in bytes) of accumulator result 22.1. special func tion registers there are fifteen special function regi ster (sfr) locations associated with ma c0. six of these registers are related to configuration and operation, while the other nine are us ed to store multi-byte input and output data for mac0. the configuration registers mac0cf0, mac0cf1, mac0cf2 are used to configure and control mac0. the status register mac0sta contains flags to indicate overflow an d interrupt conditions, mac operation completion, as well as zero result. the 16-bit mac0a (mac0ah:mac0al ) and mac0b (mac0bh:mac0bl) registers are used as inputs to the multiplier. figure 22.1 shows a 41-bit accumulator?but only 40 bits can be read by the mcu or dma via the mac0 accumulator. the mac0 accumulator cons ists of five sfrs: mac0ovf, mac0acc3, mac0acc2, mac0acc1, and mac0acc0. the primary re sult of a mac0 operation is available from the accumulator registers after the appropriate rounding, saturation or byte-realignment has been performed. 22.2. integer and fractional math mac0 can perform math operations in unsigned or sig ned mode?this is controlled by the signeden signed mode selection bit. mac0 is capable of interpreting the 16-bit inputs stored in mac0a and mac0b as integers or as fractional numbers. when the fracmd bit (mac0cf0.4) is cleared to 0, the inputs are treated as 16-bit integer values. after a mac operation, the internal 41-bit ac cumulator will contain the integer result. figure 22.2 shows how integers are stored in the sfrs. figure 22.2. integer mode data representation high  byte  low  byte  s*2 15  2 14  2 13  2 12  2 11  2 10  2 9  2 8  2 7  2 6  2 5  2 4  2 3  2 2  2 1  2 0  if  (mac0sn  ==  1),  s= r 1,  otherwise  s=1  mac0  accumulator  bit  weighting  mac0ovr  mac0acc3  :  mac0acc2  :  mac0acc1  :  mac0acc0  s*2 39  2 38   2 32  2 31  2 30  2 29  2 28   2 4  2 3  2 2  2 1  2 0  s  =  sign  of  result  (1  or r 1)  mac0a and
c8051f97x rev 1.0 205 multiply and accumulate (mac0) when the fracmd bit is set to 1, the inputs are treated at 16-bit fractional values. the decimal point is located between bits 15 and 14 of the data word. after the operati on, the accumulator will contain a 40-bit fractional value, with the decimal point located between bits 31 and 30. figure 22.3 shows how fractional numbers are stored in the sfrs. figure 22.3. fractional mode data representation 22.3. operating in mult iply and accumulate mode mac0 operates in multiply and accumu late (mac) mode when the accmd bit (mac0cf0.3) is cleared to 0. when operating in mac mode, mac0 performs a 16-by-16 bi t multiply on the contents of the mac0a and mac0b registers and adds the result to the contents of th e 41-bit accumulator. a mac o peration takes 1 sysclk cycle to complete. a rounded (and optionally , saturated) resu lt is available when the mac0rnd bit is set. if the clracc bit (mac0cf0.5) is set to 1, the accumulator and all mac0sta flags will be cleare d during the next sysclk cycle. the clracc bit will clear itself to 0 when the clear op eration has completed. 22.4. operating in multiply only mode mac0 operates in multiply only mode when the accmd bit (mac0cf0.5) is set to 1. multiply only mode is identical to multiply and accu mulate mode, except that the multiplication result is added with a value of zero before being stored in the 41-bit accumulator (i.e. it overwrites the current accumu lator contents). as in mac mode, the rounded result can be read if the round bit is set. note t hat in multiply only mode, the hovf flag is not affected. mac0a  and  mac0b  bit  weighting  high  byte  low  byte  s*1  2 r 1  2 r 2  2 r 3  2 r 4  2 r 5  2 r 6  2 r 7  2 r 8  2 r 9  2 r 10  2 r 11  2 r 12  2 r 13  2 r 14  2 r 15  if  (mac0sn  ==  1),  s= r 1,  otherwise  s=1  mac0  accumulator  bit  weighting  (no  rounding)  mac0ovr  mac0acc3  :  mac0acc2  :  mac0acc1  :  mac0acc0  s*2 8  2 7   2 1  2 0  2 r 1  2 r 2  2 r 3   2 r 27  2 r 28  2 r 29  2 r 30  2 r 31  s  =  sign  of  result  (1  or r 1)  mac0  accumulator  rounded  result  (mac0rnd=1)  bit  weighting  mac0acc1  mac0acc0  s*1  2 r 1  2 r 2  2 r 3  2 r 4  2 r 5  2 r 6  2 r 7  2 r 8  2 r 9  2 r 10  2 r 11  2 r 12  2 r 13  2 r 14  2 r 15  s  =  sign  of  result  (1  or r 1) 
c8051f97x 206 rev 1.0 multiply and accumulate (mac0) 22.5. mcu mode operation mcu mode operation for the mac is enabled when there is no dma channel enabled for transferring data to or from any mac0 register. when mcu mode operation is acti ve, the mac inputs and results are transferred to or from xram via software ac cess to the sfrs. during mcu mode operation, a mac operation is triggered by software writing 1 to the busy bit in the mac0sta register. when the mac operation has completed, hardware clears the busy bit to 0. the typical seque nce of mcu mode operations is as follows: 1. firmware disables all mac-specific dma channels. 2. firmware initializes the cont rol registers (mac0cf0, mac0cf1, mac0cf2, mac0iter) appropriately. 3. firmware writes all the operand values: ?? update mac0a, mac0b ?? setup accumulator either by clearing it (via setting th e clracc bit) or writing directly to mac0acc0-3 and mac0ovr 4. firmware writes 1 to the busy bit. 5. mac0 completes the mac operati on in 1 sysclk cycle, clears busy bit to 0, and sets both the macint and accrdy bits to 1. 22.6. dma mode operation dma mode operation is a powerful mode that can be used process large array of data using the mac0 module. alternatively, it can be used to implement digital filter s efficiently. dma mode operation for the mac0 is enabled when there is at least one dma channel enabled for transferring data to or from any mac0 register. during dma mode operation, the busy bit must be set to 1 to generate dma requests. the complete flowchart of dma mode operation is given in figure 22.4 .
c8051f97x rev 1.0 207 multiply and accumulate (mac0) figure 22.4. dma mode operation flow chart busy = 1 firmware triggers dma-enabled mac operation after setting up other mac0 configuration bits and dma channels opctr = 0 opctr keeps track of number of mac operations before requesting for dma transfer from/to mac0 accumulator mac0a updated? x y n mac0 performs mac operation opctr = opctr + 1 mac0 accumulator updated? x n y x n mac0b updated? y opctr=mac0iter? n y mac0 accumulator transferred out? x n y busy = 0 exit dma mode operation mac0 accumulator updated is true when one of following conditions are met (higher priority first): 1. accmd == 0 2. dma is enabled and dma transferred of n bytes from xram; where n = accdmain 3. dma was not enabled ? re-use existing value in accumulator mac0a updated is true when one of following conditions are met (higher priority first): 1. apostinc == 1: increments mac0a if true 2. admasrc == 1 3. dma enabled and dma transferred 2 bytes from xram to mac0a mac0b updated is true when one of following conditions are met (higher priority first): 1. bpostinc == 1: increments mac0b if true 2. bdmasrc == 1 3. dma enabled and dma transferred 2 bytes from xram to mac0b mac0 accumulator transferred out is true when dma is enabled and dma transferred n bytes from xram where n = accdmaout
c8051f97x 208 rev 1.0 multiply and accumulate (mac0) a few important points to note for dma mode operation: ?? partial dma transfers will terminate dma mode operation. for example, a mac0a dma transaction requires 2 bytes, but if the dma has only 1 byte left to transfer, the dma mode operation will te rminate after the single byte is tr ansferred into mac0a. ?? even if dma transfers are enabl ed for mac0a, no dma request will be generated for mac0a if either apostinc or admasrc bit is set to 1. ?? if the accdmain field specifies a transf er length of less than 5 bytes, onl y the least significant bytes of the accumulator will receive data from the dma. the upper byte s will be sign-extended in a way that is compatible with the signeden setting as shown in figure 22.5 . the example below shows the result of the 41-bit accumulator after a transfer of a 16-bit number d[0:15] by dma. figure 22.5. dma transfer into accumulator in sign and unsigned modes 22.7. accumulator 1-bit shift operations mac0 contains a 1-bit arithmetic shift function which can be used to shift the contents of the 41-bit accumulator left or right by one bit. the accumulator shift is initiated by writing a 1 to the shiften bit and takes one sysclk cycle to complete. in mcu mode, se tting shiften bit will immediately shift one bi t of the accumulator at the next system clock regardless of whether the mac ha s finished the operation or not. in dma mode, setting the shiften bit will shift the accumulator after the completion of the mac oper ation. hardware automatically clears the shiften bit to 0 after the shift has completed. the direction of the arit hmetic shift is controlled by the shiftdir bit. a 1-bit arithmetic shift does not affect any flag in the mac0sta register. the 1-bit shift examples for signed (signeden = 1) and unsigned (signeden = 0) modes are shown in figure 22.6 . unsigned  dma  transfer  of  2  bytes  (b[0:15]  into  41 r bit  accumulator  (mac0accin_dma  =  1)  bit  position  40  39  38  37  17  16  15  14  13  2  1  0   0  0  0  0  0  0  d15  d14  d13  d3  d1  d0   signed  dma  transfer  of  2  bytes  (b[0:15]  into  41 r bit  accumulator  (mac0accin_dma  =  1)  bit  position  40  39  38  37  17  16  15  14  13  2  1  0   d15  d15  d15  d15  d15  d15  d15  d14  d13  d3  d1  d0 
c8051f97x rev 1.0 209 multiply and accumulate (mac0) figure 22.6. 1-bit shift of 41-bit accumulator in signed and unsigned modes 22.8. multi-bit shift accumulator operation the mac0 also includes a multi-bit arit hmetic shift (up to 4 bits) function t hat can operate in dma mode only. the shift operation is only performed at the end of a mac operati on. the shiftdir bit controls the direction of shift. to enable multi-bit shifting on the accu mulator, the shiften bit must be set. ?? mbshift = 0x00 : 1-bit shift ?? mbshift = 0x01 : 2-bit shift ?? mbshift = 0x02 : 3-bit shift ?? mbshift = 0x03 : 4-bit shift original  41 r bit  accumulator  data  (before  shifting)  bit  position:  40  39  38  37  7  6  5  4  3  2  1  0   d40  d39  d38  d37  d7  d6  d5  d4  d3  d2  d1  d0   signed  mode  1 r bit  shift  left  result  bit  position  40  39  38  37  7  6  5  4  3  2  1  0   d40  d38  d37  d36  d6  d5  d4  d3  d2  d1  d0  0   signed  mode  1 r bit  shift  right  result  bit  position  40  39  38  37  7  6  5  4  3  2  1  0   d40  d40  d39  d38  d8  d7  d6  d5  d4  d3  d2  d1   unsigned  mode  1 r bit  shift  left  result  bit  position  40  39  38  37  7  6  5  4  3  2  1  0   d39  d38  d37  d36  d6  d5  d4  d3  d2  d1  d0  0   unsigned  mode  1 r bit  shift  right  result  bit  position  40  39  38  37  7  6  5  4  3  2  1  0   0  d40  d39  d38  d8  d7  d6  d5  d4  d3  d2  d1  
c8051f97x 210 rev 1.0 multiply and accumulate (mac0) 22.9. accumulator alignment (right byte shift) accumulator alignment (or right byte shifting) is one of two methods for dma or mcu to access the 41-bit accumulator in different ways without changing the contents of the 41-bit accumulator. on power-up reset, this is the default option by which data is read from the mac0 accumulator. the other method of access is the rounding and saturation logic described on page 210 mac0 provides 4 different byte alignment options: ?? no align (no shifting)?this is the default on reset. ?? sr1 (1 byte right shift) ?? sr3 (3 byte right shift) ?? sr4 (4 byte right shift) ? the alignment is performed with the appropriate sign extension depending on the setting of signeden. the examples in ta b l e 22.1 and ta b l e 22.2 show what the mcu or dma would r ead from mac0 accumulator with the sr3 setting. accumulator alignment does not affect any flag in the mac0sta. 22.10. rounding and saturation rounding is another method for the mac0 to access the 41-bit accumulator without changing its contents. a rounding engine is included, which can be used to provide a rounded result when operating on fractional numbers. mac0 uses an unbiased rounding algorithm to round the data stored in bits 31?16 of the 41-bit accumulator, as shown in ta b l e 22.3 . the 41-bit accumulator is not affected by the rounding engine. although rounding is primarily used for fractional data, it can be used in integer mode to obtain a 2-byte right-shifted rounded result. the upper 3 bytes are stuffed with the appropriate bits depending on the signeden setting, just like in the accumulator alignment option. the rounding and saturation logic d oes not affect any flag in the mac0sta register. ta b l e 22.3 and ta b l e 22.4 show the results for the signed and unsigned rounding. table 22.1. unsigned mode (signeden = 0) byte position 41-bit accumulator value mac0 accumulator value acc0 x0 x3 acc1 x1 x4 acc2 x2 0 acc3 x3 0 accovf x4 0 table 22.2. signed mode (signeden = 1) byte position 41-bit accumulator value mac0 accumulator value (bit 40 of 41-bit acc = 0) mac0 accumulator value (bit 40 of 41-bit acc = 1) acc0 x0 x3 x3 acc1 x1 x4 x4 acc2 x2 0 0xff acc3 x3 0 0xff accovf x4 0 0xff
c8051f97x rev 1.0 211 multiply and accumulate (mac0) when saturation bit saturate is set to 1, table 22.5 and table 22.6 show the saturation results. table 22.3. mac0 unsigned rounding without saturation ( signeden ? = ? 0, ? saturate= ? 0 ) 41-bit acc bits 15?0 (acc41[15:0]) 41-bit acc bits 31?16 (acc41[31:16]) lower 16 bits of mac0 accumulator upper 24 bits of mac0 accumulator >0x8000 any value acc41[31:16] + 1 all bits = 0 <0x8000 any value acc41[31:16] all bits = 0 == 0x8000 odd (lsb == 1) acc41[31:16] + 1 all bits = 0 == 0x8000 even (lsb == 0) acc41[31:16] all bits = 0 table 22.4. mac0 signed rounding without saturation (signeden = 1, saturate = 0, let x41 = [acc41 + 0x8000]) 41-bit acc bits 15?0 (acc41[15:0]) 41-bit acc bits 31?16 (acc41[31:16]) lower 15 bits of mac0 accumulator upper 25 bits of mac0 accumulator >0x8000 any value x41[30:16] all bits = x41[39] <0x8000 any value x41[30:16] all bits = x41[39] == 0x8000 odd (lsb == 1) x41[30:16] all bits = x41[39] == 0x8000 even (lsb == 0) x41[30:16] - 1 all bits = x41[39] table 22.5. signeden = 0, saturate = 1, y40 = unsaturated rounded result (sovf | hovf) value mac0 accumulator 0 y40 1 0x000000ffff table 22.6. signeden = 1, saturate = 1, z40 = unsaturated rounded result (sovf | hovf | (acc41[31]^z40[15])) value mac0 accumulator 0 z40 1, acc41[39] = 0 0x0000007fff 1, acc41[39] = 1 0xffffff8000
c8051f97x 212 rev 1.0 multiply and accumulate (mac0) 22.11. usage examples this section details some software examples for using mac0. 22.11.1. multiply and accumulate in fractional mode the example below implements the equation: (0.5 x 0.25) + (0.5 x -0.25) = 0.125 ? 0.125 = 0.0 sfrpage = mac0_page; // change page register to mac0 page mac0cf0 = 0x30; // clear accumulator, select fractional mode // multiply and accumulate mode mac0cf1 = 0x10; // select signed mode mac0cf2 = 0x00; // disable rounding, saturation and alignment logic mac0a = 0x4000; // load mac0a with 0.5 decimal mac0b = 0x2000; // load mac0b with 0.25 decimal mac0iter = 1; // set to 1 iteration mac0sta = 1; // set busy to start first mac operation nop(); // nop to allow mac0 to complete operation mac0cf0 |= 0x02; // negate mac0b mac0sta = 1; // set busy to start second mac operation nop(); // after this, mac0 accumulator should be zero and // zerof flag should be set 22.11.2. multiply on ly in integer mode the example below implements the equation: 4660 x -292 = -1360720 sfrpage = mac0_page; // change page register to mac0 page mac0cf0 = 0x2a; // clear accumulator, multiply only mode // negate b mac0cf1 = 0x10; // select signed mode mac0cf2 = 0x00; // disable rounding, saturation and alignment logic mac0a = 4660; // load mac0a with 4660 decimal mac0b = 292; // load mac0b with 292 decimal (will be negated) mac0iter = 1; // set to 1 iteration mac0sta = 1; // set busy to start mac operation nop(); // nop to allow mac0 to complete operation // mac0 accumulator should contain 0xffffeb3cb0
c8051f97x rev 1.0 213 multiply and accumulate (mac0) 22.11.3. initializing memory block using dma0 and mac0 this example demonstrates a sophistica ted example of initializing a block of memory in xram with value 0x55. // memory block to initialize volatile segment_variable(memblock[500], u8, seg_xdata); sfrpage = dma0_page; // change page register to dma0 page dma0sel = 0; // select dma channel 0 dma0en &= ~0x01; // disable dma channel 0 dma0int &= ~0x01; // clear interrupt bit for channel 0 dma0ncf = 0x05; // select mac0 accumulator to xram transfer dma0ncf |= (lsb << 4); // use lsb to spec endian bit for compiler independence dma0nba = (u16)&memblock[0]; // xram base address dma0nao = 0; // xram offset dma0nsz = 500; // transfer 500 bytes dma0en |= 0x01; // enable dma channel 0 // no need to change page register as mac0 and dma0 registers are in same page. mac0cf0 = 0x28; // clear accumulator, multiply only mode mac0cf1 = 0x0a; // select unsigned mode, constant a and constant b mac0cf2 = 0x04; // disable rounding, saturation and alignment logic // 2-byte dma transaction from mac0 accumulator to xram mac0a = 1; // load mac0a with 1 decimal mac0b = 0x5555; // load mac0b with 0x5555 hexadecimal mac0ict = 1; // set to 1 iteration mac0sta = 1; // set busy to start mac operation while (!(dma0int & 1)); // poll for dma channel 0 completion interrupt // all 500 bytes in memblock[] will be initialized to 0x55
c8051f97x 214 rev 1.0 multiply and accumulate (mac0) 22.12. mac0 registers register 22.1. mac0sta: mac0 status bit 7 6 5 4 3 2 1 0 name reserved macint schange accrdy hovf zerof sovf busy type rw rw rw rw rw rw rw rw reset 0 0 0 0 0 0 0 0 sfr page = 0xf; sfr address: 0xcf bit name function 7 reserved must write reset value. 6 macint interrupt flag. this flag is set when at least one of the following conditions are met: - hardware overflow bit (hovf) is set. - soft overflow bit (sovf) is set and the sovfien bit is set. - the accrdy bit is set when the mac operates in mcu mode. firmware must clear this bit. 5 schange sign change event. hardware sets this bit when operating in signed mode (signeden = 1) and the sign bit of the mac0 accumulator re sult is opposite of the expected sign (signexp) bit. firmware must clear this bit. this bit also clears automatically if firmware clears the accu - mulator by setting the clracc bit in the mac0cf0 register. 4 accrdy acc ready status flag. this bit is set only when the mac operates in mcu mode and a mac operation com - pletes. this bit must be cleared by firmware. 3 hovf hard overflow flag. this bit is set to 1 when the a mac operation results in a hardware overflow. hardware overflow for a signed operation (signeden = 1) occurs when a mac opera - tion causes mac0ovf to change from 0x7f to 0x80 or 0x80 to 0x7f. hardware overflow for an unsigned operation (signeden = 0) occurs when a mac operation causes mac0ovf to change from 0xff to 0x00. firmware must clear this bit. this bit also clears automatically if firmware clears the accu - mulator by setting the clracc bit in the mac0cf0 register. 2 zerof zero flag. this bit is set to 1 if a mac operation re sults in a mac accumulator value of zero. firmware must clear this bit. this bit also clears automatically if firmware clears the accu - mulator by setting the clracc bit in the mac0cf0 register.
c8051f97x rev 1.0 215 multiply and accumulate (mac0) 1 sovf soft overflow flag. hardware sets this bit to 1 when a signed ma c operation causes an overflow into the sign bit (bit 31) of the accumulator or when an unsigned mac operation causes an over - flow into the mac0ovf register. firmware must clear this bit. this bit also clears automatically if firmware clears the accu - mulator by setting the clracc bit in the mac0cf0 register. 0 busy busy flag. firmware can set this bit to trigger the mac0 peripheral to start an operation in both mcu mode and dma mode. in mcu mode, the mac0 module will perform a single mac oper ation using data that is already present in the registers. hardware cl ears this bit when the operation completes. in dma mode, the mac0 module will perform the required num ber of mac operations as defined by the dma registers, fetching the da ta into and out of the mac0 registers via dma transfers. hardware automa tically clears this bit when when all of the dma opera - tions complete. bit name function
c8051f97x 216 rev 1.0 multiply and accumulate (mac0) register 22.2. mac0cf0: mac0 configuration 0 bit 7 6 5 4 3 2 1 0 name shiften shiftdir clracc fracmd accmd accne - gate bnegate anegate type w rw w rw rw rw rw rw reset 0 0 0 0 0 0 0 0 sfr page = 0xf; sfr address: 0xc0 (bit-addressable) bit name function 7 shiften accumulator shift control. when this bit is set, hardware shifts the 40-bit mac0 accumulator by 1 bit. this bit also enables multi-bit shifts in dma mode. 0: do not shift the accumulator by one bit in the shiftdir direction. 1: shift the accumulator by one bit in the shiftdir direction. 6 shiftdir accumulator shift direction. this bit controls the direction of the accu mulator shift activated by the shiften bit. 0: the mac0 accumulator will be shifted left. 1: the mac0 accumulator will be shifted right. 5 clracc clear accumulator. this bit works only in mcu mode only and is used to reset the accumulator before the next operation. when this bi t is set, the mac0 accumulato r will be cleared to zero. in addition, all bits in the mac0sta register except mac0int and accrdy are cleared. hardware will automatically clear this bit w hen the operation comp letes. firmware will always read this bit as 0. 4 fracmd fractional mode. 0: mac0 operates in integer mode. 1: mac0 operates in fractional mode. 3 accmd accumulate mode. 0: select multiply-and -accumulate (mac) mode. 1: select multiply-only mode. 2 accne - gate negate accumulator input. this bit controls whether hardware negates the accumulator before it is added with the multiplication result of a and b. if this bit is set to 1, the signeden bit must also be set to 1, enabling signed arithmetic. 0: no change is applied to the accumulator befo re it is added to t he multiplication result of a and b. 1: hardware negates the accumulator before it is added to the multiplication result of a and b.
c8051f97x rev 1.0 217 multiply and accumulate (mac0) 1 bnegate negate mac0 b input. this bit controls whether hardware negates the mac0 b input befo re the multiplication operation with the mac0 a input. the contents of the mac0 b register do not change if the input is negated. 0: no change is applied to the mac0 b input before the multiply operation. 1: hardware negates the mac0 b input before the multiply operation. 0 anegate negate mac0 a input. this bit controls whether hardware negates the mac0 a input befo re the multiplication operation with the mac0 b input. the contents of the mac0 a register do not change if the input is negated. 0: no change is applied to the mac0 a input before the multiply operation. 1: hardware negates the mac0 a input before the multiply operation. bit name function
c8051f97x 218 rev 1.0 multiply and accumulate (mac0) register 22.3. mac0cf1: mac0 configuration 1 bit 7 6 5 4 3 2 1 0 name mbshift signexp signede n mac0bc bpostinc admasrc apostinc type rw rw rw rw rw rw rw reset 0 0 0 0 0 0 0 0 sfr page = 0xf; sfr address: 0xc4 bit name function 7:6 mbshift multi-bit accumulator shift. this field sets the number of bits hardware shifts the accumulator at the end of a mac operation in dma mode if shiften is set to 1. the direction of the shift is determined by the shiftdir bit. 00: shift the accumulator 1 bit. 01: shift the accumulator by 2 bits. 10: shift the accumulator by 3 bits. 11: shift the accumulator by 4 bits. 5 signexp expected accumulator sign. this bit sets the expected sign of the accumulator after an operation. a signed operation that does not match the signe xp bit will set the schange bit. this bit can only be used with signed arithmetic (signeden = 1). 0: set the expected sign to zero. 1: set the expected sign to one. 4 signeden signed mode enable. 0: mac operations use unsigned arithmetic. 1: mac operations use signed arithmetic. 3 mac0bc b dma data source selection. this bit controls the source of data for the mac0 b register when operating in dma mode. this bit is ignored when the mac0 module operates in mcu mode. 0: each mac0 operation will request the dm a fetch data from xr am for the mac0 b register. 1: each mac0 operation will use ex isting data in mac0 b register. 2 bpostinc b post-increment enable. this bit controls whether the mac0 b regist er value is incremented after a mac0 opera - tion. this bit can be used in both mcu and dma modes. 0: do not change the mac0 b register after a mac0 operation. 1: increment the mac0 b register after a mac0 operation.
c8051f97x rev 1.0 219 multiply and accumulate (mac0) 1 admasrc a dma data source selection. this bit controls the source of data for the mac0 a register when operating in dma mode. this bit is ignored when the mac0 module operates in mcu mode. 0: each mac0 operation will request the dm a fetch data from xr am for the mac0 a register. 1: each mac0 operation will use ex isting data in mac0 a register. 0 apostinc a post-increment enable. this bit controls whether the mac0 a regist er value is incremented after a mac0 opera - tion. this bit can be used in both mcu and dma modes. 0: do not change the mac0 a register after a mac0 operation. 1: increment the mac0 a register after a mac0 operation. bit name function
c8051f97x 220 rev 1.0 multiply and accumulate (mac0) register 22.4. mac0cf2: mac0 configuration 2 bit 7 6 5 4 3 2 1 0 name round satu - rate accalign accdmaout accdmain type rw rw rw rw rw reset 0 0 0 0 0 0 0 0 sfr page = 0xf; sfr address: 0xc5 bit name function 7 round rounding enable. this bit controls whether the mcu or dma reads a rounded result from the mac0 accu - mulator. 0: mac0 accumulator does not contain a 16-bit rounded result. 1: mac0 accumulator contains a 16-bit rounded result. 6 saturate saturation enable. if round is set to 1, this bit controls whet her the rounded mac0 accumulator result will saturate. the details of the saturation logic is defined in the section on rounding and saturation. 0: rounded result will not saturate. 1: rounded resu lt will saturate. 5:4 accalign accumulator alignment. this field controls how many bytes the hardware shifts the mac0 accumulator result to the right after an operation. this setting can be used in both mcu and dma modes. 00: do not shift the accumulator output. 01: shift the accumulator output right by 1 byte. 10: shift the accumulator output right by 3 bytes. 11: shift the accumulator output right by 4 bytes. 3:2 accd - maout accumulator dma input count. this field only effects dma mode operations. this field specifies t he number of bytes the mac0 will request the dma to tr ansfer from the mac0 accumu lator to xram after each operation, starting from the least significant byte. 00: request the dma move 1 byte from the accumulator to xram. 01: request the dma move 2 bytes from the accumulator to xram. 10: request the dma move 4 bytes from the accumulator to xram. 11: request the dma move 5 bytes from the accumulator to xram.
c8051f97x rev 1.0 221 multiply and accumulate (mac0) 1:0 accdmain accumulator dma input count. this field only effects dma mode operations. this field specifies t he number of bytes the mac0 will request the dma to transfer from xram to the mac0 a ccumulator before each operation, starting from the least significant byte. 00: request the dma move 1 byte from xram to the accumulator. 01: request the dma move 2 bytes from xram to the accumulator. 10: request the dma move 4 bytes from xram to the accumulator. 11: request the dma move 5 bytes from xram to the accumulator. bit name function
c8051f97x 222 rev 1.0 multiply and accumulate (mac0) register 22.5. mac0inte: mac0 interrupt enable bit 7 6 5 4 3 2 1 0 name reserved schange ien zerofien sovfien type rw rw rw rw reset 0 0 0 0 0 0 0 0 sfr page = 0xf; sfr address: 0xc1 bit name function 7:3 reserved must write reset value. 2 schangei en sign change event interrupt enable. enables mac0 interrupts if a sign change event (schange) occurs. 1 zerofien zero flag interrupt enable. enables mac0 interr upts if the zero flag (zerof) is set. 0 sovfien soft overflow interrupt enable. enables mac0 interrupts if the soft overflow (sovf) flag is set.
c8051f97x rev 1.0 223 multiply and accumulate (mac0) register 22.6. mac0ah: operand a high byte bit 7 6 5 4 3 2 1 0 name mac0ah type rw reset 0 0 0 0 0 0 0 0 sfr page = 0xf; sfr address: 0xab bit name function 7:0 mac0ah mac0 a high byte. this field is the upper 8 bits of the mac0 a input.
c8051f97x 224 rev 1.0 multiply and accumulate (mac0) register 22.7. mac0al: operand a low byte bit 7 6 5 4 3 2 1 0 name mac0al type rw reset 0 0 0 0 0 0 0 0 sfr page = 0xf; sfr address: 0xaa bit name function 7:0 mac0al mac0 a low byte. this field is the lower 8 bits of the mac0 a input.
c8051f97x rev 1.0 225 multiply and accumulate (mac0) register 22.8. mac0bh: operand b high byte bit 7 6 5 4 3 2 1 0 name mac0bh type rw reset 0 0 0 0 0 0 0 0 sfr page = 0xf; sfr address: 0xaf bit name function 7:0 mac0bh mac0 b high byte. this field is the upper 8 bits of the mac0 b input.
c8051f97x 226 rev 1.0 multiply and accumulate (mac0) register 22.9. mac0bl: operand b low byte bit 7 6 5 4 3 2 1 0 name mac0bl type rw reset 0 0 0 0 0 0 0 0 sfr page = 0xf; sfr address: 0xae bit name function 7:0 mac0bl mac0 b low byte. this field is the lower 8 bits of the mac0 b input.
c8051f97x rev 1.0 227 multiply and accumulate (mac0) register 22.10. mac0ovf: accumulator overflow byte bit 7 6 5 4 3 2 1 0 name mac0ovf type rw reset 0 0 0 0 0 0 0 0 sfr page = 0xf; sfr address: 0xd6 bit name function 7:0 mac0ovf mac0 accumulator overflow byte. this field is the accumulator overflow byte, or bits [39:32] of the mac0 operation accu - mulated result.
c8051f97x 228 rev 1.0 multiply and accumulate (mac0) register 22.11. mac0acc3: accumulator byte 3 bit 7 6 5 4 3 2 1 0 name mac0acc3 type rw reset 0 0 0 0 0 0 0 0 sfr page = 0xf; sfr address: 0xd5 bit name function 7:0 mac0acc3 mac0 accumulator byte 3. this field is byte 3 of the accumulator, or bits [31:24] of the mac0 operation accumulated result.
c8051f97x rev 1.0 229 multiply and accumulate (mac0) register 22.12. mac0acc2: accumulator byte 2 bit 7 6 5 4 3 2 1 0 name mac0acc2 type rw reset 0 0 0 0 0 0 0 0 sfr page = 0xf; sfr address: 0xd4 bit name function 7:0 mac0acc2 mac0 accumulator byte 2. this field is byte 2 of the accumulator, or bits [23:16] of the mac0 operation accumulated result.
c8051f97x 230 rev 1.0 multiply and accumulate (mac0) register 22.13. mac0acc1: accumulator byte 1 bit 7 6 5 4 3 2 1 0 name mac0acc1 type rw reset 0 0 0 0 0 0 0 0 sfr page = 0xf; sfr address: 0xd3 bit name function 7:0 mac0acc1 mac0 accumulator byte 1. this field is byte 1 of the accumulator, or bits [15:8] of the mac0 operation accumulated result.
c8051f97x rev 1.0 231 multiply and accumulate (mac0) register 22.14. mac0acc0: accumulator byte 0 bit 7 6 5 4 3 2 1 0 name mac0acc0 type rw reset 0 0 0 0 0 0 0 0 sfr page = 0xf; sfr address: 0xd2 bit name function 7:0 mac0acc0 mac0 accumulator byte 0. this field is byte 0 of the accumulator, or bits [7:0] of the mac0 operation accumulated result.
c8051f97x 232 rev 1.0 multiply and accumulate (mac0) register 22.15. mac0iter: iteration counter bit 7 6 5 4 3 2 1 0 name mac0iter type rw reset 0 0 0 0 0 0 0 0 sfr page = 0xf; sfr address: 0xd7 bit name function 7:0 mac0iter iteration counter. this field specifies the number of mac0 op erations before requesting a dma transfer from xram into the accumulator and from the accumulator into xram. a value of 0 in this field requests 256 iterations.
c8051f97x rev 1.0 233 cyclic redundancy check unit (crc0) 23. cyclic redundancy check unit (crc0) c8051f97x devices include a cyclic redundancy check unit (crc0) that can perform a crc using a 16-bit polynomial. crc0 accepts a stream of 8-bi t data written to the crc0in register . crc0 posts the 16-bit result to an internal register. the internal resu lt register may be accessed indirect ly using the crcpnt bits and crc0dat register, as shown in figure 23.1. crc0 also has a bit reverse register fo r quick data manipulation. figure 23.1. crc0 block diagram 23.1. crc algorithm the crc unit generates a crc result equivalent to the following algorithm: 1. xor the input with the most-signifi cant bits of the current crc result. if this is the first iteration of the crc unit, the current crc result wi ll be the set initial value ? (0x0000 or 0xffff). 2a. if the msb of the crc result is set, shift the crc result and xor th e result with the selected polynomial. 2b. if the msb of the crc result is not set, shift the crc result. ? repeat steps 2a/2b for the number of input bits (8). the algorithm is also described in the following example. ? crc0 crc0dat crc0in byte-level bit reversal hardware crc calculation unit seed (0x0000 or 0xffff) automatic flash read control 8 8 8 8 8 flash memory crc0flip 8
c8051f97x 234 rev 1.0 cyclic redundancy check unit (crc0) the 16-bit crc algorithm can be described by the following code: unsigned short updatecrc (unsigned short crc_acc, unsigned char crc_input) { unsigned char i; // loop counter #define poly 0x1021 // create the crc "dividend" for polynomial arithmetic (binary arithmetic // with no carries) crc_acc = crc_acc ^ (crc_input << 8); // "divide" the poly into the dividend using crc xor subtraction // crc_acc holds the "remainder" of each divide // // only complete this division for 8 bits since input is 1 byte for (i = 0; i < 8; i++) { // check if the msb is set (if msb is 1, then the poly can "divide" // into the "dividend") if ((crc_acc & 0x8000) == 0x8000) { // if so, shift the crc value, and xor "subtract" the poly crc_acc = crc_acc << 1; crc_acc ^= poly; } else { // if not, just shift the crc value crc_acc = crc_acc << 1; } } // return the final remainder (crc value) return crc_acc; } ? table 23.1 lists several input values and the a ssociated outputs using the 16-bit crc algorithm: table 23.1. example 16-bit crc outputs input output 0x63 0xbd35 0x8c 0xb1f4 0x7d 0x4eca 0xaa, 0xbb, 0xcc 0x6cf6 0x00, 0x00, 0xaa, 0xbb, 0xcc 0xb166
c8051f97x rev 1.0 235 cyclic redundancy check unit (crc0) 23.2. preparing fo r a crc calculation to prepare crc0 for a crc calculation, software should set the initial value of the resu lt. the polynomial used for the crc computation is 0x1021. the c rc0 result may be initialized to one of two values: 0x0000 or 0xffff. the following steps can be us ed to initialize crc0. 1. select the initial result value (set crcval to 0 for 0x0000 or 1 for 0xffff). 2. set the result to its initial value (write 1 to crcinit). 23.3. performing a crc calculation once crc0 is initialized, the input da ta stream is sequentially written to crc0in, one byte at a time. the crc0 result is automatically updated after eac h byte is written. the crc engine ma y also be configured to automatically perform a crc on one or more 256 byte blocks read from flash. the following steps can be used to automatically perform a crc on flash memory. 1. prepare crc0 for a crc calculation as shown above. 2. write the index of th e starting page to crc0auto. 3. set the autoen bit to 1 in crc0auto. 4. write the number of 256 byte blocks to perform in the crc calculation to crccnt. 5. write any value to crc0 cn (or or its contents with 0x00) to initiate the crc calculation. the cpu will not execute code any additional code until the crc operation completes. se e the note in the crc0cn register definition for more information on how to properly initiate a crc calculation. 6. clear the autoen bit in crc0auto. 7. read the crc result. 23.4. accessing th e crc0 result the internal crc0 result is 16 bits. the crcpnt bits sele ct the byte that is targeted by read and write operations on crc0dat and increment after each r ead or write. the calculation result will remain in the in ternal cr0 result register until it is set, ov erwritten, or additional data is written to crc0in. 23.5. crc0 bit reverse feature crc0 includes hardware to reverse the bit order of each bit in a byte as shown in figure 23.2. each byte of data written to crc0flip is read back bit reversed. for example, if 0xc0 is written to crc0flip, the data read back is 0x03. bit reversal is a useful mathematical f unction used in algorithms such as the fft. figure 23.2. bit reversal crc0flip (write) crc0flip (read)
c8051f97x 236 rev 1.0 cyclic redundancy check unit (crc0) 23.6. crc control registers register 23.1. crc0cn: crc0 control bit 7 6 5 4 3 2 1 0 name reserved crcinit crcval reserved crcpnt type r rw rw r rw reset00010000 sfr page = 0x0; sfr address: 0x84 table 23.2. crc0cn register bit descriptions bit name function 7:4 reserved must write reset value. 3 crcinit crc initialization enable. writing a 1 to this bit initializes th e entire crc result based on crcval. 2 crcval crc initialization value. this bit selects the set value of the crc result. 0: crc result is set to 0x0000 on write of 1 to crcinit. 1: crc result is set to 0xfff f on write of 1 to crcinit. 1 reserved must write reset value. 0 crcpnt crc result pointer. specifies the byte of the crc result to be read/written on the ne xt access to crc0dat. this bit will automatically togg le upon each read or write. 0: crc0dat accesses bits 7- 0 of the 16-bit crc result. 1: crc0dat accesses bits 15-8 of the 16-bit crc result. note: upon initiation of an auto matic crc calculation, the th ree cycles following a write to crc0cn that initiate a crc operation must only co ntain instructions which execute in the same number of cycles as the number of bytes in the instruction. an example of such an in struction is a 3-byte mov that targets the crc0flip register. when programming in c, the dummy value written to crc0flip should be a non -zero value to prevent the co mpiler from generating a 2- byte mov instruction.
c8051f97x rev 1.0 237 cyclic redundancy check unit (crc0) register 23.2. crc0in: crc0 data input bit 7 6 5 4 3 2 1 0 name crc0in type rw reset00000000 sfr page = 0x0; sfr address: 0x85 table 23.3. crc0in register bit descriptions bit name function 7:0 crc0in crc data input. each write to crc0in results in the written data being co mputed into the existing crc result according to the crc algorithm.
c8051f97x 238 rev 1.0 cyclic redundancy check unit (crc0) register 23.3. crc0dat: crc0 data output bit 7 6 5 4 3 2 1 0 name crc0dat type rw reset00000000 sfr page = 0x0; sfr address: 0x86 table 23.4. crc0dat register bit descriptions bit name function 7:0 crc0dat crc data output. each read or write performed on crc0dat targ ets the crc result bits pointed to by the crc0 result pointer (crcpnt bits in crc0cn). note: crc0dat may not be valid for one cycle after setting the crci nit bit in the crc0cn register to 1. any time crcinit is written to 1 by firmware, at least one inst ruction should be performed before reading crc0dat.
c8051f97x rev 1.0 239 cyclic redundancy check unit (crc0) register 23.4. crc0auto: crc0 automatic control bit 7 6 5 4 3 2 1 0 name autoen crcst type rw rw reset00000000 sfr page = 0x0; sfr address: 0x9e table 23.5. crc0auto register bit descriptions bit name function 7 autoen automatic crc calc ulation enable. when autoen is set to 1, any write to c rc0cn will initiate an automatic crc starting at flash sector crcst and continuing for crccnt sectors. 6:0 crcst automatic crc ca lculation starting block. these bits specify the flash block to star t the automatic crc calc ulation. the starting address of the first flash bl ock included in the automa tic crc calculation is crcst x block_size, where block_size is 256 bytes.
c8051f97x 240 rev 1.0 cyclic redundancy check unit (crc0) register 23.5. crc0cnt: crc0 automatic flash sector count bit 7 6 5 4 3 2 1 0 name crcdn crccnt type rw rw reset00000000 sfr page = 0x0; sfr address: 0x9d table 23.6. crc0cnt register bit descriptions bit name function 7 crcdn automatic crc calcul ation complete. set to 0 when a crc calculation is in progre ss. code execution is stopped during a crc calculation; therefore, reads fr om firmware will always return 1. 6:0 crccnt automatic crc calcul ation block count. these bits specify the number of flash blocks to include in an automatic crc calculation. the last address of the last flash block in cluded in the automatic crc calculation is (crcst+crccnt) x block size - 1. the block size is 256 bytes.
c8051f97x rev 1.0 241 cyclic redundancy check unit (crc0) register 23.6. crc0flip: crc0 bit flip bit 7 6 5 4 3 2 1 0 name crc0flip type rw reset00000000 sfr page = 0x0; sfr address: 0x9f table 23.7. crc0flip register bit descriptions bit name function 7:0 crc0flip crc0 bit flip. any byte written to crc0flip is read back in a bit-reversed order, i.e., the written lsb becomes the msb. for example: if 0xc0 is written to crc0flip, the data read back will be 0x03. if 0x05 is written to crc0flip, the data read back will be 0xa0.
c8051f97x 242 rev 1.0 clocking sources 24. clocking sources the c8051f97x devices ca n be clocked from the internal low-power 24.5 mhz oscillato r, the internal low-power 20 mhz oscillator, the smartclock real time clock oscillator, or externally by an external oscillator (not supported on devices in the qfn-24 package). an adjustable clock di vider allows the selected clock source to be post-scaled by powers of 2, up to a factor of 128. by default, the system cl ock comes up as the 24.5 mhz oscillator divided by 8. figure 24.1. clocking sources block diagram the proper way of changing the system clock when both the clock source and the clock divide value are being changed is as follows: if switching from a fast ?undivided? clock to a slower ?undivided? clock: 1. change the clock divide value. 2. poll for clkrdy > 1. 3. change the clock source. if switching from a slow ?undivided? clock to a faster ?undivided? clock: 1. change the clock source. 2. change the clock divide value. 3. poll for clkrdy > 1. external oscillator drive circuit xtal1 xtal2 option 2 vdd xtal2 option 1 10m ? option 4 xtal2 oscxcn xtlvld xoscmd2 xoscmd1 xoscmd0 xfcn2 xfcn1 xfcn0 precision internal oscillator en oscicl oscicn ioscen ifrdy sysclk clksel clkdiv2 clkdiv1 clkdiv0 clkrdy clksel2 clksel1 clksel0 smartclock oscillator clock divider n low power internal oscillator low power internal oscillator smartclock oscillator external oscillator precision internal oscillator clkrdy option 3 xtal2 8 low power internal oscillator divided by 8
c8051f97x rev 1.0 243 clocking sources 24.1. programmable precisi on internal oscillator all c8051f97x devices include a progra mmable precision internal oscillator that may be selected as the system clock. oscicl is factory calibrated to obtain a 24.5 mhz fr equency. see section ?1. electrical characteristics? on page 10 for complete os cillator specifications. the precision oscillator supports a sp read spectrum mode which modulates the output freque ncy in order to reduce the emi generated by the system. when enabled (sse = 1), the osc illator output frequency is modulated by a stepped triangle wave whos e frequency is equal to the oscillator freq uency divided by 384 (63.8 khz using the factory calibration). the devi ation from the nominal oscilla tor frequency is +0 %, ?1.6%, and the step size is typically 0.26% of the nomi nal frequency. when using th is mode, the typical averag e oscillator frequency is lowered from 24.5 mhz to 24.3 mhz. 24.2. low power in ternal oscillator all c8051f97x devices include a low pow er internal oscillator that defaults as the system clock after a system reset. the low power internal oscillator frequency is 20 mhz 10% and is automatically enabled when selected as the system clock and disabled when not in use. see section ?1. electrical characteristics? on page 10 for complete oscillator specifications. 24.3. external osci llator drive circuit the c8051f970/1/3/4 devices in clude an external oscillator circuit that may drive an external crystal, ceramic resonator, capacitor, or rc network. a cmos clock may also provide a clock input. figure 24.1 shows a block diagram of the four exter nal oscillator options. the ex ternal oscillator is enabled and conf igured using the oscxcn register. the external osc illator output may be selected as the system clock or used to clock some of the digital peripherals (e.g., timers, pca, etc.). see the data sheet chapters for each digital peripheral for details. see section ?1. electrical characteristics? on page 10 for complete osc illator specifications. 24.3.1. external crystal mode if a crystal or ceramic resonator is used as the external oscillator, the crystal/reson ator and a 10 m ?? resistor must be wired across the xtal1 and xtal2 pins as shown in figure 24.1, option 1. appropriate loading capacitors should be added to xtal1 and xtal2, and both pins should be configured for analog i/o with the digital output drivers disabled. figure 24.2 shows the extern al oscillator circuit for a 20 mhz quartz crystal with a manufa cturer recommended load capacitance of 12.5 pf. loading capacitors are ?in-series? as seen by the crystal and ?in-parallel? with the stray capacitance of the xtal1 and xtal2 pins. the total value of the each loading capacitor and the stray capacitance of each xtal pin should equal 12.5 pf x 2 = 25 pf. with a st ray capacitance of 10 pf per pin, the 15 pf capacitors yield an equivalent series capacit ance of 12.5 pf across the crystal. note: the recommended load capacitance depends upon the crystal a nd the manufacturer. please refer to the crystal data sheet when completing these calculations. figure 24.2. 25 mhz external crystal example 15 pf 15 pf 25 mhz xtal1 xtal2 10 mohm
c8051f97x 244 rev 1.0 clocking sources important note on external crystals: crystal oscillator circuits are quite sensitive to pcb la yout. the crystal should be placed as close as possible to the xtal pins on the device. the traces should be as short as possible and shielded with ground plane from any other trac es which could introduce noise or interference. when using an external crystal, th e external oscillator drive circuit mu st be configured by software for crystal oscillator mode or crystal oscillator mode with divide by 2 stage . the divide by 2 stage ensures that the clock derived from the external oscillator has a duty cycle of 50%. the ex ternal oscillator fr equency control value (xfcn) must also be specified based on the crystal frequ ency. the selection should be based on table 24.1. for example, a 25 mhz crystal requires an xfcn setting of 111b. when the crystal oscillator is first enabl ed, the external oscillator valid detector allows soft ware to determine when the external system clock ha s stabilized. switching to the external os cillator before the crystal oscillator has stabilized can result in unpredictable behavior. the recomme nded procedure for starting the crystal is as follows: 1. configure xtal1 and xtal2 for analog i/o and disable the digital output drivers. 2. configure and enable the external oscillator. 3. poll for xtlvld => 1. 4. switch the system clo ck to the external oscillator. 24.3.2. external rc mode if an rc network is used as the external oscillator, the circuit should be config ured as shown in fi gure 24.1, option 2. the rc network should be added to xtal2, and xtal2 should be configured for analog i/o with the digital output drivers disabled. xtal1 is not affected in rc mode. the capacitor should be no greater than 100 pf; however fo r very small capacitors, the total capacitance may be dominated by parasitic capacitance in the pcb layo ut. the resistor should be no smaller than 10 k ? . the oscillation frequency can be dete rmined by the following equation: table 24.1. recommended xfcn settings for crystal mode xfcn crystal frequency bias current typical supply current (vdd = 2.4 v) 000 f ? 20 khz 0.5 a 3.0 a, f = 32.768 khz 001 20 khz ?? f ?? 58 khz 1.5 a 4.8 a, f = 32.768 khz 010 58 khz ? f ?? 155 khz 4.8 a 9.6 a, f = 32.768 khz 011 155 khz ? f ?? 415 khz 14 a 28 a, f = 400 khz 100 415 khz ? f ?? 1.1 mhz 40 a 71 a, f = 400 khz 101 1.1 mhz ? f ?? 3.1 mhz 120 a 193 a, f = 400 khz 110 3.1 mhz ? f ?? 8.2 mhz 550 a 940 a, f = 8 mhz 111 8.2 mhz ? f ?? 25 mhz 2.6 ma 3.9 ma, f = 25 mhz
c8051f97x rev 1.0 245 clocking sources to determine the required external oscillator frequency cont rol value (xfcn) in the oscxcn register, first select the rc network value to produce the desired frequency of oscillati on. for example, if the frequency desired is 100 khz, let r = 246 k ? , and c = 50 pf: referencing table 24.2, the recommended xfcn setting is 010. when the rc oscillator is first enabled, the external os cillator valid detector allows software to determine when oscillation has stabilized. the reco mmended procedur e for starting the rc oscillator is as follows: 1. configure xtal2 for analog i/o and disable the digital output drivers. 2. configure and enable the external oscillator. 3. poll for xtlvld => 1. 4. switch the system clo ck to the external oscillator. table 24.2. recommended xfcn settings for rc and c modes xfcn approximate frequency range (rc and c mode) k factor (c mode) typical supply current/ actual measured frequency (c mode, vdd = 2.4 v) 000 f ?? 25 khz k factor = 0.87 3.0 a, f = 11 khz, c = 33 pf 001 25 khz ?? f ?? 50 khz k factor = 2.6 5.5 a, f = 33 khz, c = 33 pf 010 50 khz ?? f ?? 100 khz k factor = 7.7 13 a, f = 98 khz, c = 33 pf 011 100 khz ?? f ?? 200 khz k factor = 22 32 a, f = 270 khz, c = 33 pf 100 200 khz ?? f ?? 400 khz k factor = 65 82 a, f = 310 khz, c = 46 pf 101 400 khz ?? f ?? 800 khz k factor = 180 242 a, f = 890 khz, c = 46 pf 110 800 khz ?? f ?? 1.6 mhz k factor = 664 1.0 ma, f = 2.0 mhz, c = 46 pf 111 1.6 mhz ?? f ?? 3.2 mhz k factor = 1590 4.6 ma, f = 6.8 mhz, c = 46 pf f 1.23 10 3 ? rc ? -------------------------- - = where f = frequency of clock in mhz r = pull-up resistor value in k ? v dd = power supply voltage in volts c = capacitor value on the xtal2 pin in pf f 1.23 10 3 ? rc ? --------------------------- 1.23 10 3 ? 246 50 ? -------------------------- - 100 khz === where f = frequency of clock in mhz r = pull-up resistor value in k ? v dd = power supply voltage in volts c = capacitor value on the xtal2 pin in pf
c8051f97x 246 rev 1.0 clocking sources 24.3.3. external capacitor mode if a capacitor is used as the external oscillator, the circuit should be c onfigured as shown in figure 24.1, option 3. the capacitor should be added to xtal2, and xtal2 should be configured for analog i/o with the digital output drivers disabled. xtal1 is not affected in rc mode. the capacitor should be no greater than 100 pf; however, for very small capacitors, the total capacitance may be dominated by parasitic capacitance in the pcb layou t. the oscillation frequency a nd the required external oscillator frequency control value (xfc n) in the oscxcn register can be determined by the following equation: below is an example of selecting the capacitor and finding the frequency of oscillation assume v dd = 3.0 v and f = 150 khz: since a frequency of roughly 150 khz is desired, select the k factor from table 24.2 as kf = 22: therefore, the xfcn value to use in this ex ample is 011 and c is approximately 50 pf. the recommended startup procedure for c mode is the same as rc mode. 24.3.4. external cmos clock mode if an external cmos clock is used as the external oscillator, the clock should be directly routed into xtal2. the xtal2 pin should be configured as a digital input. xtal1 is not used in external cmos clock mode. the external oscillator valid de tector will always return zero when the exte rnal oscillator is configured to external cmos clock mode. where f = frequency of clock in mhz r = pull-up resistor value in k ? v dd = power supply voltage in volts c = capacitor value on the xtal2 pin in pf f kf cv dd ? --------------------- = f kf cv dd ? --------------------- = 0.150 mhz kf c3.0 ? ------------------ = 0.150 mhz 22 c 3.0 v ? ------------------------ = c 22 0.150 mhz 3.0 v ? ------------------------------------------------ - = c 48.8 pf =
c8051f97x rev 1.0 247 clocking sources 24.4. special function regi sters for selecting and conf iguring the system clock the clocking sources on c8051f97x devices are enabl ed and configured using the oscicn, oscicl, oscxcn and the smartclock internal registers. see section ?21. smartclock (real time clock)? on page 292 for smartclock register descriptions. the system clock source for the mcu can be selected using the clksel register. to minimize active mode current, the oneshot ti mer which sets flash read time should by bypassed when the system clock is greater than 10 mhz. see the flscl register description for details. the clock selected as the system clock can be divided by 1, 2, 4, 8, 16, 32, 64, or 128. when switching between two clock divide values, the transition may take up to 1 28 cycles of the undivided cl ock source. the clkrdy flag can be polled to determine when the new clock divide value has been applied. the clock divider must be set to "divide by 1" when entering suspend or sleep mode. the system clock source may also be switched on-the-fly. th e switchover takes effect after one clock period of the slower oscillator.
c8051f97x 248 rev 1.0 clocking sources 24.5. clock selecti on control registers register 24.1. clksel: clock select bit 7 6 5 4 3 2 1 0 name clkrdy clkdiv reserved clksl type r rw r rw reset 0 0 1 1 0 1 0 0 sfr page = 0x0; sfr address: 0xa9 bit name function 7 clkrdy system clock divider clock ready flag. 0: the selected clock divide setting has not been applied to the system clock. 1: the selected clock divide setting has been applied to the system clock. 6:4 clkdiv clock source divider. this field controls the divider applied to th e clock source selected by clksl. the output of this divider is the system clock (sysclk). 000: sysclk is equal to selected clock source divided by 1. 001: sysclk is equal to selected clock source divided by 2. 010: sysclk is equal to selected clock source divided by 4. 011: sysclk is equal to select ed clock source divided by 8. 100: sysclk is equal to selected clock source divided by 16. 101: sysclk is equal to selected clock source divided by 32. 110: sysclk is equal to select ed clock source divided by 64. 111: sysclk is equal to selected clock source divided by 128. 3 reserved must write reset value. 2:0 clksl clock source select. selects the oscillator to be used as the undivided system clock source. 000: clock derived from the internal precision high-frequency oscillator. 001: clock derived from the external oscillator circuit. 010: clock derived from the internal low power oscillator divided by 8. 011: clock derived from the rtc. 100: clock derived from the internal low power oscillator. 101-111: reserved.
c8051f97x rev 1.0 249 clocking sources register 24.2. pclken: low power peripheral clock enable bit 7 6 5 4 3 2 1 0 name pclken7 pclken6 pclken5 pclken4 pclken3 pclken2 pclken1 pclken0 type rw rw rw rw rw rw rw rw reset 0 0 0 0 0 0 0 0 sfr page = 0x0; sfr address: 0xf6 bit name function 7 pclken7 low power active mode pe ripheral set 3 enable. 0: disable clocks of timer 0, 1, 2, crc0, c2, rtc0, and port match in low power active mode. 1: enable clocks of timer 0, 1, 2, crc0, c2, rtc0, and port match in low power active mode. 6 pclken6 low power active mode pe ripheral set 2 enable. 0: disable clocks of pca0, cs0, and adc0 in low power active mode. 1: enable clocks of pc a0, cs0, and adc0 in low power active mode. 5 pclken5 low power active mode pe ripheral set 1 enable. 0: disable clocks of mac0 in low power active mode. 1: enable clocks of mac0 in low power active mode. 4 pclken4 low power active mode pe ripheral set 0 enable. 0: disable clocks of uart0, timer 3, spi0, and i2c0 in low power active mode. 1: enable clocks of uart0, timer 3, spi 0, and i2c0 in low power active mode. 3 pclken3 low power idle mode pe ripheral set 3 enable. 0: disable clocks of timer 0, 1, 2, crc0, c2, rtc0, and po rt match in low power idle mode. 1: enable clocks of timer 0, 1, 2, crc0, c2, rtc0, and port matc h in low power idle mode. 2 pclken2 low power idle mode pe ripheral set 2 enable. 0: disable clocks of pca0, cs0, and adc0 in low power idle mode. 1: enable clocks of pca0, cs0, and adc0 in low power idle mode. 1 pclken1 low power idle mode pe ripheral set 1 enable. 0: disable clocks of mac0 in low power idle mode. 1: enable clocks of mac0 in low power idle mode. 0 pclken0 low power idle mode pe ripheral set 0 enable. 0: disable clocks of uart0, timer 3, spi0, and i2c0 in low power idle mode. 1: enable clocks of uart0, timer 3, spi0, and i2c0 in lo w power idle mode.
c8051f97x 250 rev 1.0 clocking sources register 24.3. clkmode: clock mode bit 7 6 5 4 3 2 1 0 name reserved lpme ecsr fcam type r rw rw rw reset 0 0 0 0 0 0 0 0 sfr page = 0x0; sfr address: 0xf7 bit name function 7:3 reserved must write reset value. 2 lpme low power mode enable. setting this bit allows the device to enter low power active/idle mo de. pclken settings are only enabled when this bit is set. 1 ecsr clock request enable. when this bit is set, the source clocks will on ly be requested when an incoming request is active or a peripheral clock is enabled. 0 fcam force clock tree enable. when this bit is set, clock gating will only be performed in idle mode. this allows a user to have complete access to a ll sfrs in active mode, but still get the benefits of clock gat - ing in idle mode.
c8051f97x rev 1.0 251 clocking sources 24.6. high frequency oscillator registers register 24.4. oscicl: high frequency oscillator calibration bit 7 6 5 4 3 2 1 0 name sse oscicl type rw rw reset 0 x x x x x x x sfr page = 0x0; sfr address: 0xaf bit name function 7 sse spread spectrum enable. 0: spread spectrum clock dithering disabled. 1: spread spectrum clock dithering enabled. 6:0 oscicl oscillator calibration. these bits determine the intern al oscillator period. when se t to 00000000b, the oscillator operates at its fastest settin g. when set to 11111111b, the os cillator operates at its slow - est setting. the reset value is factory calib rated to generate an in ternal oscillator fre - quency of 24.5 mhz.
c8051f97x 252 rev 1.0 clocking sources register 24.5. oscicn: high frequency oscillator control bit 7 6 5 4 3 2 1 0 name ioscen ifrdy reserved type rw r rw reset 0 0 x x x x x x sfr page = 0x0; sfr address: 0xb2 bit name function 7 ioscen high frequency oscillator enable. 0: high frequency oscillator disabled. 1: high frequency oscillator enabled. 6 ifrdy internal oscillator frequency ready flag. 0: high frequency oscillator is not running at its pr ogrammed fr equency. 1: high frequency oscillator is ru nning at its prog rammed frequency. 5:0 reserved must write reset value. notes: 1. read-modify-write operations such as orl and anl must be us ed to set or clear the enable bit of this register. 2. oscbias (reg0cn.4) must be set to 1 be fore enabling the high frequency oscillator.
c8051f97x rev 1.0 253 clocking sources 24.7. external oscillator registers register 24.6. oscxcn: external oscillator control bit 7 6 5 4 3 2 1 0 name xclkvld xoscmd reserved xfcn type r rw rw rw reset 0 0 0 0 0 0 0 0 sfr page = 0x0; sfr address: 0xb1 bit name function 7 xclkvld external oscilla tor valid flag. provides external oscillator st atus and is valid at all time s for all modes of operation except external cmos clock mode and extern al cmos clock mode with divide by 2. in these modes, xclkvld always returns 0. 0: external oscillator is unused or not yet stable. 1: external oscillator is running and stable. 6:4 xoscmd external oscillator mode. 000: external oscilla tor circuit disabled. 001: reserved. 010: external cmos clock mode. 011: external cmos clock mode with divide by 2 stage. 100: rc oscillator mode. 101: capacitor oscillator mode. 110: crystal oscillator mode. 111: crystal oscillator mode with divide by 2 stage. 3 reserved must write reset value. 2:0 xfcn external oscillator frequency control. controls the external oscillator bias current. the value selected for this field depends on the frequency ra nge of the external oscillator.
c8051f97x 254 rev 1.0 smartclock (real time clock, rtc0) 25. smartclock (real time clock, rtc0) c8051f97x devices include an ultra low power 32-bit smar tclock peripheral (real time clock) with alarm. the smartclock has a dedicated 32 khz oscillator that can be co nfigured for use with or without a crystal. no external resistor or loading capacitors are required. the on-chip loading capacitors are programmable to 16 discrete levels allowing compatibility with a wide range of crystals. th e smartclock can operate directly from a 0.9?3.6 v battery voltage and remains operational even when the device goe s into its lowest power down mode. c8051f97x devices also support an ultra low power internal lfo that reduces sleep mode current. the smartclock allows a maximum of 36 hour 32-bit independent time-keeping when used with a 32.768 khz watch crystal. the smartclock provides an alarm and missing smartclock events, which could be used as reset or wakeup sources. see section ?27. reset sources and supply monitor? on page 323 and section ?16. power management? on page 94 for details on reset sources and low-power mode wake-up sources, respectively. figure 25.1. smartclock block diagram smartclock oscillator smartclock cip-51 cpu xtal4 xtal3 rtc0cn capturen rtc0xcf rtc0xcn alarmn rtc0adr rtc0dat interface registers internal registers smartclock state machine wake-up 32-bit smartclock timer programmable load capacitors power/ clock mgmt interrupt lfo
c8051f97x rev 1.0 255 smartclock (real time clock, rtc0) 25.1. smartclock interface the smartclock interface consists of two registers: rtc0adr and rtc0dat. these interface registers are located on the cip-51?s sfr map and provide access to the smartclock internal registers listed in table 25.1 . the smartclock internal registers can only be accessed indirectly through the smartclock interface. 25.1.1. using rtc0adr and rtc0dat to ac cess smartclock internal registers the smartclock internal registers can be read and written using rtc0adr and rtc0dat. the rtc0adr register selects the smartclock inte rnal register that will be targeted by subsequent re ads or writes. recommended instruction timing is provided in this secti on. if the recommended instruct ion timing is not followed, then busy (rtc0adr.7) should be checked prior to each re ad or write operation to make sure the smartclock interface is not busy performing the previous read or writ e operation. a smartclock writ e operation is initiated by writing to the rtc0dat register. below is an exam ple of writing to a smartclock internal register. 1. poll busy (rtc0adr.7) unt il it returns 0 or follow recommended instruction timing. 2. write 0x05 to rtc0adr. this selects the internal rtc0xcn register at smartclock address 0x05. 3. write 0x00 to rtc0dat. this operation wr ites 0x00 to the internal rtc0cn register. a smartclock read operation is in itiated by setting the smartclock in terface busy bit. this transfers the contents of the internal register se lected by rtc0adr to rtc0dat. the transferred data will remain in rtc0dat until the next read or write operation. below is an example of reading a smartclock internal register. 1. poll busy (rtc0adr.7) unt il it returns 0 or follow recommended instruction timing. 2. write 0x05 to rtc0adr. this selects the internal rtc0xcn register at smartclock address 0x05. 3. write 1 to busy. this initiates the transfer of data from rtc0xcn to rtc0dat. 4. poll busy (rtc0adr.7) unt il it returns 0 or follow re commend instruction timing. 5. read data from rtc0dat. this data is a copy of the rtc0xcn register. note: the rtc0adr and rtc0dat registers will retain their state upon a device reset. 25.1.2. rtc0adr short strobe feature reads and writes to indirect smartclo ck registers normally take 7 system clo ck cycles. to minimize the indirect register access time, the short strobe feature decreases the read and write access time to 6 system clocks. the short strobe feature is automatically enabled on reset and can be manually enabled/disabled using the short (rtc0adr.4) control bit. recommended instruction timing for a single register read with short strobe enabled: mov rtc0adr, #095h nop nop table 25.1. smartclock internal registers smartclock address smartclock register register name description 0x00?0x03 capturen smartclock capture registers four registers used for setting the 32-bit smartclock timer or read ing its current value. 0x04 rtc0cn smartclock control register controls the operation of the smartclock state machine. 0x05 rtc0xcn smartclock oscillator control register controls the operation of the smartclock oscillator. 0x06 rtc0xcf smartclock oscillator configuration register controls the value of the progammable oscillator load capacitance and enables/disables autostep. 0x08?0x0b alarmn smartclock alarm registers four registers used for setting or reading the 32-bit smartclock alarm value.
c8051f97x 256 rev 1.0 smartclock (real time clock, rtc0) nop mov a, rtc0dat ? recommended instruction timing for a single register write with short strobe enabled: mov rtc0adr, #0h mov rtc0dat, #000h nop 25.1.3. smartclock interface autoread feature when autoread is enabled, each read from rtc0dat init iates the next indirect read operation on the smartclock internal register selected by rtc0adr. software should set the busy bit once at the beginning of each series of consecutive reads. software should follow recommended in struction timing or check if the smartclock interface is busy prior to reading rtc0dat. autoread is enabled by settin g autord (rtc0adr.6) to logic 1. 25.1.4. rtc0adr auto increment feature for ease of reading and writing the 32-bit capture and alarm values, rtc0adr automatically increments after each read or write to a capturen or alarmn regist er. this speeds up the process of setting an alarm or reading the current smartclock timer value. autoincrement is always enabled. recommended instruction timing for a multi-byte regist er read with short strobe and auto read enabled: mov rtc0adr, #0d0h nop nop nop mov a, rtc0dat nop nop mov a, rtc0dat nop nop mov a, rtc0dat nop nop mov a, rtc0dat recommended instruction timing for a multi-by te register write with short strobe enabled: mov rtc0adr, #010h mov rtc0dat, #05h nop mov rtc0dat, #06h nop mov rtc0dat, #07h nop mov rtc0dat, #08h nop
c8051f97x rev 1.0 257 smartclock (real time clock, rtc0) 25.2. smartclock clocking sources the smartclock peripheral is clocked from its own timebase, independent of the system clock. the smartclock timebase can be derived fr om the internal lfo or the smartclock oscillator circuit, which has two modes of operation: crystal mode, and self-oscillate mode. the osc illation frequency is 32.768 khz in crystal mode and can be programmed in the range of 10 khz to 40 khz in self-oscillate mode. t he internal lfo frequency is 16.4 khz 20%. the frequency of th e smartclock oscillator can be measur ed with respect to another oscillator using an on-chip timer. see section ?32. timers (timer0, timer1, timer2, and timer3)? on page 390 for more information on how this can be accomplished. note: the smartclock timebase can be selected as the system clock and routed to a port pin. see section ?24. clocking sources? on page 242 for information on selecting the system clock source and section ?26. port i/o (port 0, port 1, port 2, port 3, port 4, port 5, port 6, crossbar, and port match)? on page 278 for information on how to route the system clock to a port pin. 25.2.1. using the smartclock oscillator with a crystal when using crystal mode, a 32.768 khz crystal should be connected bet ween xtal3 and xtal4. no other external components are required. the following steps show how to start the smartclock crystal oscillator in software: 1. configure the xtal3 and xtal4 pins for analog i/o. 2. set smartclock to cr ystal mode (xmode = 1). 3. disable automatic gain control (agcint) and en able bias doubling (biasx2) for fast crystal startup. 4. set the desired loading capacitance (rtc0xcf). 5. enable power to the smartclo ck oscillator circuit (rtc0int = 1). 6. wait 20 ms. 7. poll the smartclock clock valid bit (cl kvld) until the crystal oscillator stabilizes. 8. poll the smartclock load capacitance ready bit (loadrdy) until the load capacitance reaches its programmed value. 9. enable automatic gain cont rol (agcint) and disable bias do ubling (biasx2) for maximum power savings. 10. enable the smartclo ck missing clock detector. 11. wait 2 ms. 12. clear the pmu0cf wake-up source flags.
c8051f97x 258 rev 1.0 smartclock (real time clock, rtc0) 25.2.2. using the smartclock os cillator in self-oscillate mode when using self-oscillate mode, the xt al3 and xtal4 pins are internally shorted together. the following steps show how to configure smartclock for use in self-oscillate mode: 1. set smartclock to self -oscillate mode (xmode = 0). 2. set the desired oscillation frequency: ? for oscillation at about 20 khz, set biasx2 = 0. ? for oscillation at about 40 khz, set biasx2 = 1. 3. the oscillator starts oscillating instantaneously. 4. fine tune the oscillati on frequency by adjusting th e load capacitance (rtc0xcf). 25.2.3. using the low frequency oscillator (lfo) the low frequency oscillator pr ovides an ultra low power, on-chip clock source to the smartclock. the typical frequency of oscillation is 16.4 khz 20%. no external components are required to use the lfo and the xtal3 and xtal4 pins do not need to be shorted together. the following steps show how to configure smartclock for use with the lfo: 1. enable and select the low frequency oscillato r (lfoint = 1). 2. the lfo starts oscillating instantaneously. when the lfo is enabled, the smartclock oscillator incremen ts bit 1 of the 32-bit timer (instead of bit 0). this effectively multiplies the lfo frequency by 2, making the rtc timebase behave as if a 32.768 khz crystal is connected at the output.
c8051f97x rev 1.0 259 smartclock (real time clock, rtc0) 25.2.4. programmable load capacitance the programmable lo ad capacitance has 16 values to support crystal oscillators with a wide range of recommended load capacitance. if automatic load capacita nce stepping is enabled, the crystal load capacitors start at the smallest setting to allow a fast startup ti me, then slowly increase the capacitance until the final programmed value is reached. the final programmed loadin g capacitor value is specified using the loadcap bits in the rtc0xcf register. the loadcap setting specifies th e amount of on-chip load capacitance and does not include any stray pcb capacitance. once the final progr ammed loading capacitor value is reached, the loadrdy flag will be set by hardware to logic 1. when using the smartclock oscillator in self-oscillate mode, th e programmable load capa citance can be used to fine tune the oscillation frequency. in most cases, increasing the load capacito r value will result in a decrease in oscillation frequency. ta b l e 25.2 shows the crystal load capacitance for various settings of loadcap. table 25.2. smartclock load capacitance settings loadcap crystal load capacitance equivalent capacitance seen on xtal3 and xtal4 0000 4.0 pf 8.0 pf 0001 4.5 pf 9.0 pf 0010 5.0 pf 10.0 pf 0011 5.5 pf 11.0 pf 0100 6.0 pf 12.0 pf 0101 6.5 pf 13.0 pf 0110 7.0 pf 14.0 pf 0111 7.5 pf 15.0 pf 1000 8.0 pf 16.0 pf 1001 8.5 pf 17.0 pf 1010 9.0 pf 18.0 pf 1011 9.5 pf 19.0 pf 1100 10.5 pf 21.0 pf 1101 11.5 pf 23.0 pf 1110 12.5 pf 25.0 pf 1111 13.5 pf 27.0 pf
c8051f97x 260 rev 1.0 smartclock (real time clock, rtc0) 25.2.5. automatic gain control (crystal mode only) and smartclock bias doubling automatic gain control allows the smartclock oscillator to trim the oscillation amplitude of a crystal in order to achieve the lowest possible power cons umption. automatic gain control auto matically detects when the oscillation amplitude has reached a point where it safe to reduce the drive current, therefore, it may be enabled during crystal startup. it is recommended to enable automatic gain control in most systems which use the smartclock oscillator in crystal mode. the followin g are recommended crystal specificati ons and operating conditions when automatic gain co ntrol is enabled: ?? esr < 50 k ? ?? load capacitance < 10 pf ?? supply voltage < 3.0 v ?? temperature > ?20 c when using automatic gain cont rol, it is recommended to perform an oscillation robust ness test to ensure that the chosen crystal will oscillate under the worst case condition to which the system will be exposed. the worst case condition that sh ould result in the least robust oscillation is at the following system condit ions: lowest temperature, highest supply voltage, highest esr, highest load capaci tance, and lowest bias cu rrent (agc enabled, bias double disabled). to perform the oscillation robustness test, the smartclo ck oscillator should be e nabled and selected as the system clock source. next, the sysclk signal should be routed to a port pin configured as a push-pull digital output. the positive duty cycl e of the output clock can be used as an in dicator of oscillation robustness. as shown in figure 25.2 , duty cycles less than 55% indicate a robust oscillation. as the dut y cycle approaches 60%, oscillation becomes less reliable and the risk of clock fa ilure increases. increasing the bias current (by disabling agc) will always improve oscillation robu stness and will reduce the ou tput clock?s duty cycle. this test should be performed at the worst case system condit ions, as results at very low temperat ures or high supply voltage will vary from results taken at room temperature or low supply voltage. figure 25.2. interpreting oscillation robustness (duty cycle) test results as an alternative to pe rforming the oscillation robustness test, automatic gain co ntrol may be disabled at the cost of increased power consumption (approximately 200 na). disabling automatic gain control will provide the crystal oscillator with higher immunity against external factors wh ich may lead to clock failu re. automatic gain control must be disabled if us ing the smartclock oscillato r in self-oscillate mode. ta b l e 25.3 shows a summary of the oscillato r bias settings. the smartclock bias doubling feature allows the self-oscillation frequency to be increase d (almost doubled) and allows a high er crystal drive strength in crystal mode. high crystal drive strength is recommended when the crystal is exposed to poor environmental conditions such as excessive moisture. smart clock bias doubling is enabled by setting bi asx2 (rtc0xcn.5) to 1. duty cycle 25% 55% 60% safe operating zone low risk of clock failure high risk of clock failure
c8051f97x rev 1.0 261 smartclock (real time clock, rtc0) . table 25.3. smartclock bias settings mode setting power consumption crystal bias double off, agc on lowest 600 na bias double off, agc off low 800 na bias double on, agc on high bias double on, agc off highest self-oscillate bias double off low bias double on high
c8051f97x 262 rev 1.0 smartclock (real time clock, rtc0) 25.2.6. missing sm artclock detector the missing smartclock detector is a one-shot circuit en abled by setting mclkint (rtc0cn.6) to 1. when the smartclock missing clock detector is enabled, oscf ail (rtc0cn.5) is set by hardware if smartclock oscillator remains high or low for more than 100 s. a smartclock missing clock detector timeout can trigger an interrupt, wake the device from a low power mode, or reset the device. see section ?13. interrupts? on page 79 , section ?16. power management? on page 94 , and section ?27. reset sources and supply monitor? on page 323 for more information. note: the smartclock missing clock detector should be disabled when making changes to the oscillator settings in rtc0xcn. 25.2.7. smartclock oscillat or crystal valid detector the smartclock oscillator crystal valid de tector is an oscillation amplitude detector circ uit used during crystal startup to determine when oscillation has started and is nearly stable. the output of th is detector can be read from the clkvld bit (rtx0xcn.4). notes: 1. the clkvld bit has a blanking interval of 2 ms. during the first 2 ms after turning on the crystal oscillator, the output of clkvld is not valid. 2. this smartclock crystal valid detector (clkvld) is not intended for detecting an oscillator failure. the missing smartclock detector (clkfail) should be used for this purpose. 25.3. smartclock time r and alarm function the smartclock timer is a 32-bit counter that, when running (rtc0tr = 1), is incremented every smartclock oscillator cycle. the timer has an alar m function that can be set to generate an interrupt, wake the device from a low power mode, or reset the dev ice at a specific time. see section ?13. interrupts? on page 79 , section ?16. power management? on page 94 , and section ?27. reset sources and supply monitor? on page 323 for more information. the smartclock timer includes an auto reset feature, which automatically resets the timer to zero one smartclock cycle after an alarm occurs. when using auto reset, the alarm match value should always be set to 1 count less than the desired match value. auto reset can be enabled by writing a 1 to alrm (rtc0cn.2). 25.3.1. setting and reading the smartclock timer value the 32-bit smartclock timer can be set or read using th e six capturen internal registers. note that the timer does not need to be stopped before reading or setting its value. the following steps can be used to set the timer value: 1. write the desired 32-bit set value to the capturen registers. 2. write 1 to rtc0set. this will tr ansfer the contents of the capturen registers to the smartclock timer. 3. operation is comple te when rtc0set is cleared to 0 by hardware. the following steps can be used to read the current timer value: 1. write 1 to rtc0cap. this will transfer the co ntents of the timer to the capturen registers. 2. poll rtc0cap until it is cleared to 0 by hardware. 3. a snapshot of the timer value can be read from the capturen registers
c8051f97x rev 1.0 263 smartclock (real time clock, rtc0) 25.3.2. setting a smartclock alarm the smartclock alarm function compares the 32-bit value of smartclock timer to the value of the alarmn registers. an alarm event is triggered if the smartclock timer is equal to the alarmn registers. if auto reset is enabled, the 32-bit timer will be cleared to zero one smartclo ck cycle after the alarm event. the smartclock alarm event can be configured to reset the mcu, wake it up from a low power mode, or generate an interrupt. see section ?13. interrupts? on page 79 , section ?16. power management? on page 94 , and section ?27. reset sources and supply monitor? on page 323 for more information. the following steps can be used to set up a smartclock alarm: 1. disable smartclock alarm events (rtc0aint = 0). 2. set the alarmn registers to the desired value. 3. enable smartclock alarm events (rtc0aint = 1). when using the smartclock in self-osc illate or crystal modes, the alarm is triggered every n + 2 rtc cycles except for the first alarm, which triggers after n rtc cycl es. n is the value written into the 32-bit alarm register. when using the smartclock with the internal lfo, the alar m is triggered every n/2 + 2 rtc cycles except for the first alarm, which triggers after n/2 rt c cycles. n is the value written into th e 32-bit alarm register. if n is odd, then the hardware uses n/2 rounded down. notes: 1. the alrm bit, which is used as the smartclock alarm event flag, is cleared by disabling smartclock alarm events (rtc0aint = 0). 2. if autoreset is disabled, disabling (rtc0aint = 0) th en re-enabling alarm events (rtc0aint = 1) after a smartclock alarm without modifying alarmn registers w ill automatically schedule the next alarm after 2^32 smartclock cycles (approximately 36 hours using a 32.768 khz crystal). 3. the smartclock alarm event flag will remain asserted for a maximum of one smartclock cycle. see section ?16. power management? on page 94 for information on how to capture a smartclock alarm event using a flag which is not automatically cl eared by hardware. 4. when an external clock is used as the smartclock source, the system clock speed must be more than 9 times the smartclock speed for the smartclock al arm functionality to work correctly. 5. when an external clock source is used as the smartclock so urce, the system clock speed must be more than 5 times the smartclock speed for the smartclock al arm functionality to work correctly.
c8051f97x 264 rev 1.0 smartclock (real time clock, rtc0) 25.3.3. software consider ations for using the smartclock timer and alarm the smartclock timer and alarm have two operating mo des to suit varying applications. the two modes are described below: mode 1: ? the first mode uses the smartclock timer as a perpetual timebase which is never rese t to zero. every 36 hours, the timer is allowed to overflow without being stopped or disrupted. the alarm interval is software managed and is added to the alrmn registers by software after each alarm. this allows the alarm match value to always stay ahead of the timer by one software managed interval. if so ftware uses 32-bit unsigned addition to increment the alarm match value, then it does not need to handle overflows since both the timer and the al arm match value will overflow in the same manner. this mode is ideal for applicat ions which have a long alarm interval (e.g., 24 or 36 hours) and/or have a need for a perpetual timebase. an example of an application that needs a perpetual ti mebase is one whose wake-up interval is constantly changing. for these applications, software ca n keep track of the number of timer overflows in a 16-bit variable, extending the 32-bit (36 hour) timer to a 48-bit (272 year) perpetual timebase. mode 2: ? the second mode uses the smartclock timer as a general purpose up counter which is auto reset to zero by hardware after each alarm. the alarm interval is ma naged by hardware and stored in the alrmn registers. software only needs to set the alarm interval once during device initialization. after each alarm, software should keep a count of the number of alarms that have occurred in order to keep track of time. this mode is ideal for applications th at require minimal software intervention and/or have a fixed alarm interval. this mode is the most power efficient si nce it requires less cpu time per alarm. important note: the alarm interval will be 2 more smartclock cycles than the expected value because 1 cycle holds the alarm signal high and another cycle is used to reset the alarm.
c8051f97x rev 1.0 265 smartclock (real time clock, rtc0) 25.4. rtc0 control registers register 25.1. rtc0adr: rtc address bit 7 6 5 4 3 2 1 0 name busy autord reserved short addr type rw rw r rw rw reset 0 0 0 0 0 0 0 0 sfr page = 0x0; sfr address: 0xac bit name function 7 busy rtc interface busy indicator. this bit indicates the rtc interface status. writin g a 1 to this bit initiates an indirect read. 6 autord rtc interface autoread enable. when autoread is enabled, firmware should set the busy bit once at the beginning of each series of consecutive read s. firmware must check if th e rtc interface is busy prior to reading rtc0dat. 0: disable autoread. firmware must write the busy bit for each rtc indirect read oper - ation. 1: enable autoread. the next rtc indirect re ad operation is init iated when firmware reads the rtc0dat register. 5 reserved must write reset value. 4 short short strobe enable. enables/disables the short strobe feature. 0: disable short strobe. 1: enable short strobe. 3:0 addr rtc indirect register address. sets the currently-selected rtc internal register. note: the addr bits increment after each indi rect read/write operation that targets a capturen or alar mn internal rtc register.
c8051f97x 266 rev 1.0 smartclock (real time clock, rtc0) register 25.2. rtc0dat: rtc data bit 7 6 5 4 3 2 1 0 name rtc0dat type rw reset 0 0 0 0 0 0 0 0 sfr page = 0x0; sfr address: 0xad bit name function 7:0 rtc0dat rtc data. holds data transferred to/from the internal rtc register selected by rtc0adr. note: read-modify-write instructions (orl, anl, etc.) should not be used on this register.
c8051f97x rev 1.0 267 smartclock (real time clock, rtc0) register 25.3. rtc0cn: rtc control bit 7 6 5 4 3 2 1 0 name rtc0en mclken oscfail rtc0tr rtc0aen alrm rtc0set rtc0cap type rw rw rw rw rw rw rw rw reset 0 0 x 0 0 0 0 0 indirect address: 0x04 bit name function 7 rtc0en rtc enable. enables/disables the rtc oscillato r and associated bias currents. 0: disable rtc oscillator. 1: enable rtc oscillator. 6 mclken missing rtc detector enable. enables/disables the missing rtc detector. 0: disable missing rtc detector. 1: enable missing rtc detector. 5 oscfail rtc oscillator fail event flag. set by hardware when a missing rtc detector timeout occurs. must be cleared by firm - ware. the value of this bit is not defi ned when the rtc oscillator is disabled. 4 rtc0tr rtc timer run control. controls if the rtc timer is running or stopped (holds current value). 0: rtc timer is stopped. 1: rtc timer is running. 3 rtc0aen rtc alarm enable. enables/disables the rtc alarm function. also clears the alrm flag. 0: disable rtc alarm. 1: enable rtc alarm. 2 alrm rtc alarm event flag and auto reset enable. reads return the state of the alarm event flag. writes enable/disable the auto reset function. 1 rtc0set rtc timer set. writing 1 initiates a rtc timer set operation. th is bit is cleared to 0 by hardware to indi - cate that the timer set operation is complete. 0 rtc0cap rtc timer capture. writing 1 initiates a rtc timer capture operation. this bit is cleared to 0 by hardware to indicate that the timer capture operation is complete. note: the alrm flag will remain assert ed for a maximum of one rtc cycle.
c8051f97x 268 rev 1.0 smartclock (real time clock, rtc0) register 25.4. rtc0xcn: rtc oscillator control bit 7 6 5 4 3 2 1 0 name agcen xmode biasx2 clkvld lfoen reserved type rw rw rw r r r reset 0 0 0 0 0 0 0 0 indirect address: 0x05 bit name function 7 agcen rtc oscillator automatic gain control (agc) enable. 0: disable agc. 1: enable agc. 6 xmode rtc oscillator mode. selects crystal or self oscillate mode. 0: self-oscillate mode selected. 1: crystal mode selected. 5 biasx2 rtc oscillator bias double enable. enables/disables the bias double feature. 0: disable the bias double feature. 1: enable the bias double feature. 4 clkvld rtc oscillator crystal valid indicator. indicates if oscillation amplitude is su fficient for maintaining oscillation. 0: oscillation has not started or oscillation amplitude is too low to maintain oscillation. 1: sufficient oscillati on amplitude detected. 3 lfoen low frequency oscillator enable and select. overrides xmode and selects the internal lo w frequency oscillator (lfosc) as the rtc oscillator source. 0: xmode determines rt c oscillator source. 1: lfosc enabled and selected as rtc oscillator source. 2:0 reserved must write reset value.
c8051f97x rev 1.0 269 smartclock (real time clock, rtc0) register 25.5. rtc0xcf: rtc oscillator configuration bit 7 6 5 4 3 2 1 0 name autostp loadrdy reserved loadcap type rw r r rw reset 0 0 0 0 x x x x indirect address: 0x06 bit name function 7 autostp automatic load capacitance stepping enable. enables/disables automatic load capacitance stepping. 0: disable load capacitance stepping. 1: enable load capacitance stepping. 6 loadrdy load capacitance ready indicator. set by hardware when the load capacitance matches the programmed value. 0: load capacitance is currently stepping. 1: load capacitance has reached it programmed value. 5:4 reserved must write reset value. 3:0 loadcap load capacitance programmed value. holds the desired load capacitance value.
c8051f97x 270 rev 1.0 smartclock (real time clock, rtc0) register 25.6. capture0: rtc timer capture 0 bit 7 6 5 4 3 2 1 0 name capture0 type rw reset 0 0 0 0 0 0 0 0 indirect address: 0x00 bit name function 7:0 capture0 rtc timer capture 0. the capture3-capture0 registers are used to read or set the 32-bit rtc timer. data is transferred to or from the rtc timer when the rtc0set or rtc0cap bits are set.
c8051f97x rev 1.0 271 smartclock (real time clock, rtc0) register 25.7. capture1: rtc timer capture 1 bit 7 6 5 4 3 2 1 0 name capture1 type rw reset 0 0 0 0 0 0 0 0 indirect address: 0x01 bit name function 7:0 capture1 rtc timer capture 1. the capture3-capture0 registers are used to read or set the 32-bit rtc timer. data is transferred to or from the rtc timer when the rtc0set or rtc0cap bits are set.
c8051f97x 272 rev 1.0 smartclock (real time clock, rtc0) register 25.8. capture2: rtc timer capture 2 bit 7 6 5 4 3 2 1 0 name capture2 type rw reset 0 0 0 0 0 0 0 0 indirect address: 0x02 bit name function 7:0 capture2 rtc timer capture 2. the capture3-capture0 registers are used to read or set the 32-bit rtc timer. data is transferred to or from the rtc timer when the rtc0set or rtc0cap bits are set.
c8051f97x rev 1.0 273 smartclock (real time clock, rtc0) register 25.9. capture3: rtc timer capture 3 bit 7 6 5 4 3 2 1 0 name capture3 type rw reset 0 0 0 0 0 0 0 0 indirect address: 0x03 bit name function 7:0 capture3 rtc timer capture 3. the capture3-capture0 registers are used to read or set the 32-bit rtc timer. data is transferred to or from the rtc timer when the rtc0set or rtc0cap bits are set.
c8051f97x 274 rev 1.0 smartclock (real time clock, rtc0) register 25.10. alarm0: rtc alarm programmed value 0 bit 7 6 5 4 3 2 1 0 name alarm0 type rw reset 0 0 0 0 0 0 0 0 indirect address: 0x08 bit name function 7:0 alarm0 rtc alarm programmed value 0. the alarm3-alarm0 registers are used to se t an alarm event for the rtc timer. the rtc alarm should be disabled (rtc0aen=0) when updating these registers.
c8051f97x rev 1.0 275 smartclock (real time clock, rtc0) register 25.11. alarm1: rtc alarm programmed value 1 bit 7 6 5 4 3 2 1 0 name alarm1 type rw reset 0 0 0 0 0 0 0 0 indirect address: 0x09 bit name function 7:0 alarm1 rtc alarm programmed value 1. the alarm3-alarm0 registers are used to se t an alarm event for the rtc timer. the rtc alarm should be disabled (rtc0aen=0) when updating these registers.
c8051f97x 276 rev 1.0 smartclock (real time clock, rtc0) register 25.12. alarm2: rtc alarm programmed value 2 bit 7 6 5 4 3 2 1 0 name alarm2 type rw reset 0 0 0 0 0 0 0 0 indirect address: 0x0a bit name function 7:0 alarm2 rtc alarm programmed value 2. the alarm3-alarm0 registers are used to se t an alarm event for the rtc timer. the rtc alarm should be disabled (rtc0aen=0) when updating these registers.
c8051f97x rev 1.0 277 smartclock (real time clock, rtc0) register 25.13. alarm3: rtc alarm programmed value 3 bit 7 6 5 4 3 2 1 0 name alarm3 type rw reset 0 0 0 0 0 0 0 0 indirect address: 0x0b bit name function 7:0 alarm3 rtc alarm programmed value 3. the alarm3-alarm0 registers are used to se t an alarm event for the rtc timer. the rtc alarm should be disabled (rtc0aen=0) when updating these registers.
c8051f97x 278 rev 1.0 port i/o (port 0, port 1, port 2, port 3, po rt 4, port 5, port 6, crossbar, and port match) 26. port i/o (port 0, port 1, port 2, po rt 3, port 4, port 5, port 6, crossbar, and port match) digital and analog resources on the c8051f97x family are externally available on the device?s multi-purpose i/o pins. port pins p0.0-p2.7 can be defined as general-purpo se i/o (gpio), assigned to one of the internal digital resources through the crossbar, or assigned to an analog function. port pins p3.0-p6.1 can be used as gpio. port pin p5.2 is shared with the c2 interface data signal (c2d). the designer has complete control over which functions are assigned, limited only by the number of physical i/o pins. this resource assignment flexibility is achieved through the use of a priority crossbar decoder. note that the state of a port i/o pin can always be read in the corresponding port latch, regardless of the crossbar settings. the crossbar assigns the selected internal digital reso urces to the i/o pins based on the priority decoder (figure 26.2 and figure 26.3). the registers xbr0 a nd xbr1 are used to select internal digital functions. the port i/o cells are configured as either push-pull or open-drain in the port output mode registers (pnmdout, where n = 0,1). additionally, each bank of port pins (p0, p1, p2, p3, p4, and p5) have two selectable drive strength settings. the p6 pins only support digital open-drain mo de and cannot be configured as digital push-pull pins. figure 26.1. port i/o functional block diagram smbus0 2 spi0 4 priority crossbar decoder adc0 in cs0 in uart0 2 i2c0 slave in / out port 0 control & config p0.0 p0.7 port 1 control & config p1.0 p1.7 port 2 control & config p2.0 p2.7 port 3 control & config p3.0 p3.7 port 4 control & config p4.0 p4.7 port 5 control & config port 6 control & config p5.1 p5.2 p5.0 p6.0 p6.1 int0 / int1 port match sysclk pca (cexn) timer 0 timer 1 1 3 pca (eci) 1 1 1
c8051f97x rev 1.0 279 port i/o (port 0, port 1, port 2, port 3, po rt 4, port 5, port 6, crossbar, and port match) 26.1. general port i/o initialization port i/o initialization cons ists of the following steps: 1. select the input mode (analog or digital) for all port pins, using the port input mode register (pnmdin). 2. select the output mode (open-drain or push-pull) for all port pins, using the port output mode register (pnmdout). 3. select any pins to be skipped by the i/o cr ossbar using the port sk ip registers (pnskip). 4. assign port pins to desired peripherals. 5. enable the cros sbar (xbare = ?1?). all port pins must be configured as either analog or digital inputs. any pi ns to be used as comparator or adc inputs should be configured as an analog inputs. when a pin is configured as an analog input, its weak pullup, digital driver, and digital receiver are disabled. this pr ocess saves power and reduces noise on the analog input. pins configured as digital inputs may still be used by analog peripherals; howev er this practice is not recommended. additionally, all analog input pins should be configured to be skipped by the crossbar (accomplished by setting the associated bits in pnskip). port input mode is set in th e pnmdin register, where a ?1? indicates a digital input, and a ?0? indicates an analog input. all pins default to digital inputs on reset. the output driver characteristics of the i/o pins are defined using the port output mode registers (pnmdout). each port output driver can be configured as either open drain or push-pull. this selection is required even for the digital resources selected in the xbrn registers, and is not automatic. when the weakpud bit in xbr1 is ?0?, a weak pullup is enabled for all port i/ o configured as open -drain. weakpud does not affe ct the push-pull port i/o. furthermore, the weak pullup is turned off on an output that is driving a ?0? to avoid unnecessary power dissipation. registers xbr0 and xbr1 must be loaded with the appropriate values to select the digital i/o functions required by the design. setting the xbare bit in xbr2 to ?1? enables the crossbar. until the crossbar is enabled, the external pins remain as standard port i/o (in input mo de), regardless of the xbrn register settings. for given xbrn register settings, one can determine the i/o pin-ou t using the priority decode table; as an alternative, silicon labs provides configuration utility software to determ ine the port i/o pin-as signments based on the crossbar register settings. the crossbar must be enabled to use port pins as stan dard port i/o in output mode. port output drivers of all crossbar pins are disabled whenever the crossbar is disabled.
c8051f97x 280 rev 1.0 port i/o (port 0, port 1, port 2, port 3, po rt 4, port 5, port 6, crossbar, and port match) 26.2. assigning port i/o pins to analog and digital functions port i/o pins can be assigned to various analog, digital, a nd external interrupt functions. the port pins assigned to analog functions should be configured for analog i/o, an d port pins assigned to digital or external interrupt functions should be configured for digital i/o. 26.2.1. assigning port i/o pins to analog functions table 26.1 shows all available analog functions that requi re port i/o assignments. ta ble 26.1 shows the potential mapping of port i/o to each analog function. table 26.1. port i/o assignment for analog functions analog function potentially assi gnable port pins sfr(s) used for assignment qfn-48 qfn-32 qfn-28 adc input p0.0 ? p5.2 p0.0 ? p3.2, p5.2 p0.0 ? p2.1, p5.2 pnmdin, amux0pn, pn, adc0 registers capacitive sense input p0.0 ? p5.2 p0.0 ? p3.2, p5.2 p0.0 ? p2.1, p5.2 pnmdin, amux0pn, pn, cs0 registers voltage reference (vref) p0.0 p0.0 p0.0 ref0cn, pnskip, p0.0 bit set, pnmdin external oscillator input (xtal1) p1.0 p0.5 oscxcn, amux0pn (cleared), pn bit set, pnmdin external oscillator input (xtal2) p1.1 p0.6 oscxcn, amux0pn (cleared), p0.1 bit set, pnmdin smartclock oscillator input (xtal3) p0.6 p0.3 rtc0cn, amux0pn (cleared), p0.0 bit set, pnmdin smartclock oscillator input (xtal4) p0.7 p0.4 rtc0cn, amux0pn (cleared), p0.1 bit set, pnmdin
c8051f97x rev 1.0 281 port i/o (port 0, port 1, port 2, port 3, po rt 4, port 5, port 6, crossbar, and port match) 26.2.2. assigning port i/o pins to digital functions any port pins not assigned to analog functions may be assign ed to digital functions or used as gpio. most digital functions rely on the crossbar for pin assignment; however, some digital functions bypass the crossbar in a manner similar to the analog functions listed above. table 26.2 sh ows all digital functions available through the crossbar and the potential mapping of port i/o to each function. 26.2.3. assigning port i/o pins to fixed digital functions fixed digital functions include external clock input as well as external event tr igger functions, which can be used to trigger events such as an adc conversion, fire an interrupt or wake the device from idle mode when a transition occurs on a digital i/o pin. the fixed digital functions do not require dedicated pins and will function on both gpio pins and pins in use by the crossbar. fixed digital func tions cannot be used on pins configured for analog i/o. table 26.3 shows all available fixed digital functions a nd the potential mapping of port i/o to each function. table 26.2. port i/o assignment for digital functions digital function potentially assign able port pins sfr(s) used for assignment qfn-48 qfn-32 qfn-28 smbus0, uart0, spi0, sysclk, pca0 (cex0-2 and eci), t0, or t1. any port pin available for assignment by the crossbar. this includes p0.0 ? p2.7 pins which have their pnskip bit set to ?0?. xbr0, xbr1, xbr2 any pin used for gpio p0.0 ? p5.2, p6.0 ? p6.1 p0.0 ? p3.2, p5.2, p6.0 ? p6.1 p0.0 ? p2.1, p5.2, p6.0 ? p6.1 p0skip, p1skip, p2skip table 26.3. port i/o assignment for fixed digital functions function potentially assign able port pins sfr(s) used for assignment qfn-48 qfn-32 qfn-28 external interrupt 0 p0.0 - p0.7 it01cf external interrupt 1 p0.0 - p0.7 it01cf conversion start (cnvstr) p0.6 adc0cn port match p0.0 - p2.7 p0.0 - p2.7 p0.0 - p2.1 p0mask, p0mat p1mask, p1mat p2mask, p2mat i2c slave 0 p6.0, p6.1 i2c0cn
c8051f97x 282 rev 1.0 port i/o (port 0, port 1, port 2, port 3, po rt 4, port 5, port 6, crossbar, and port match) 26.3. priority crossbar decoder the priority crossbar decoder assigns a priority to each i/ o function, starting at the top with uart0. when a digital resource is selected, the least-significant unassigned port pi n is assigned to that resource. if a port pin is assigned, the crossbar skips that pin wh en assigning the next select ed resource. additionally, th e crossbar will skip port pins whose associated bits in the pnskip registers are set. the pnskip registers allow software to skip port pins that are to be used for analog input, dedicated functions, or gpio. important note on crossbar configuration: if a port pin is claimed by a pe ripheral without use of the crossbar, its corresponding pnskip bit should be set. this applies to p0.0 if vref is used, xtal 1, xtal2, xtal3, or xtal4 pins on a qfn-32 or qfn-48 package, p0.6 if the adc is configured to use the external conversion start signal (cnvstr), and any selected adc or comparator inputs. the crossbar skips selected pins as if they were already assigned, and moves to the next unassigned pin. figure 26.2 shows all of the potential peripheral-to-pin as signments available to the crossbar. note that this does not mean any peripheral can always be assigned to the highlighted pins. the ac tual pin assignments are determined by the priority of the enabled peripherals. figure 26.2. crossbar priority decoder?possible pin assignments sysclk pca0-cex0 pca0-cex1 pca0-cex2 pca0-eci timer0-t0 timer1-t1 0 0 0 0 0 0 0 0 p0skip pin skip settings spi0-sck spi0-miso spi0-mosi spi0-nss* 0 0 0 0 0 0 0 0 p1skip the crossbar peripherals are assigned in priority order from top to bottom. these boxes represent port pins which can potentially be assigned to a peripheral. special function signals are not assigned by the crossbar. when these signals are enabled, the crossbar should be manua lly configured to skip the corresponding port pins. pins can be ?skipped? by setting the corresponding bit in pnskip to 1. * nss is only pinned out when the spi is in 4-wire mode. qfn-48 package xtal3 / cnvstr qfn-32 package qfn-24 package pins not available on crossbar n/a 0 0 0 0 0 0 0 0 p2skip n/a n/a n/a n/a n/a n/a n/a n/a n/a n/a xtal2 / cnvstr cnvstr xtal4 xtal1 xtal2 xtal1 xtal4 xtal3 vref vref vref uart0-tx uart0-rx smb0-sda smb0-scl 0 1 2 3 4 5 6 7 p0 port pin number 0 1 2 3 4 5 6 7 p1 x p3 0 1 2 3 4 5 6 7 p2 x p4 x p5 x p6
c8051f97x rev 1.0 283 port i/o (port 0, port 1, port 2, port 3, po rt 4, port 5, port 6, crossbar, and port match) registers xbr0 and xbr1are used to assign the digital i/o resources to the physical i/o port pins. note that when the smbus is selected, the crossbar assigns both pins a ssociated with the smbus (sda and scl); when uart0 is selected, the crossbar assigns both pins associated with uart0 (tx and rx). standard port i/os appear contiguously after the prioritized functions have been assigned. figure 26.3 shows an example of the resulting pin assignments of the device with smbus0, spi0, and two channels of pca0 enabled and p0.3, p0.4, p1.0, and p1 .1 skipped (p0skip = 0x18, p1skip = 0x03). smbus0 is the highest priority and it will be assign ed first. the next-highest enabl ed peripheral is spi0. p0.2 is available, so spi0 takes this pin. the next pins, miso, mosi, and nss are routed to p0.5, p0.6, and p0.7, respectively, because p0.3 and p0.4 are skipped. the pca0 cex0 and cex1are then routed to p1.2 and p1.3. the other pins on the device are available for use as gener al-purpose digital i/o or analog functions. figure 26.3. crossbar priority decoder example note: the spi can be operated in either 3-wire or 4-wire m odes, pending the state of the nssmd1?nssmd0 bits in register spi0cn. according to the spi mode, the nss signal may or may not be routed to a port pin. sysclk pca0-cex0 pca0-cex1 pca0-cex2 pca0-eci timer0-t0 timer1-t1 0 0 0 1 1 0 0 0 p0skip pin skip settings spi0-sck spi0-miso spi0-mosi spi0-nss* 1 1 0 0 0 0 0 0 p1skip the crossbar peripherals are assigned in priority order from top to bottom. these boxes represent port pins which can potentially be assigned to a peripheral. special function signals are not assigned by the crossbar. when these signals are enabled, the crossbar should be manua lly configured to skip the corresponding port pins. pins can be ?skipped? by setting the corresponding bit in pnskip to 1. * nss is only pinned out when the spi is in 4-wire mode. qfn-48 package xtal3 / cnvstr qfn-32 package qfn-24 package pins not available on crossbar n/a 0 0 0 0 0 0 0 0 p2skip n/a n/a n/a n/a n/a n/a n/a n/a n/a n/a xtal2 / cnvstr cnvstr xtal4 xtal1 xtal2 xtal1 xtal4 xtal3 vref vref vref uart0-tx uart0-rx smb0-sda smb0-scl 0 1 2 3 4 5 6 7 p0 port pin number 0 1 2 3 4 5 6 7 p1 x p3 0 1 2 3 4 5 6 7 p2 x p4 x p5 x p6
c8051f97x 284 rev 1.0 port i/o (port 0, port 1, port 2, port 3, po rt 4, port 5, port 6, crossbar, and port match) 26.4. port i/o m odes of operation port pins are configured by firmware as digital or analog i/o using the pnmdin registers. on reset, all port i/o cells default to a high impedance state with weak pull-ups enabl ed. until the crossbar is enabled, both the high and low port i/o drive circuits are explicitly di sabled on all crossbar pins. port pins co nfigured as digital i/o may still be used by analog peripherals; however, this practice is no t recommended and may result in measurement errors. 26.4.1. configurin g port pins for analog modes any pins to be used for analog functions should be c onfigured for analog mode. when a pin is configured for analog i/o, its weak pullup, digital driver, and digital receiv er are disabled. port pins co nfigured for analog functions will always read back a value of ?0? in the corresponding pn port latch register. to co nfigure a pin as analog, the following steps should be taken: 1. clear the bit associated with the pin in the pnmdin register to ?0?. this selects analog mode for the pin. 2. set the bit associat ed with the pin in the pn register to ?1?. 3. skip the bit associated with the pin in the pnskip register to ensure the crossbar does not attempt to assign a function to the pin. 26.4.2. configurin g port pins for digital modes any pins to be used by digital peripherals or as gpio should be configured as digital i/o (pnmdin.n = ?1?). for digital i/o pins, one of two output modes (push-pull or ope n-drain) must be selected using the pnmdout registers. push-pull outputs (pnmdout.n = ?1?) drive the port pad to the supply rails based on the output logic value of the port pin. open-drain outputs have the high side driver disabled; therefore, they only drive the port pad to the low- side rail when the output logic value is ?0? and become high impedance inputs (both high low drivers turned off) when the output logic value is ?1?. when a digital i/o cell is placed in the high impedance state, a weak pull-up transistor pulls the port pad to the high- side rail to ensure the digital input is at a defined logic st ate. weak pull-ups are disabled when the i/o cell is driven low to minimize power consumption, and they may be globally disabled by setti ng weakpud to ?1?. the user should ensure that digital i/o are alwa ys internally or externally pulled or driven to a valid logic state to minimize power consumption. port pins configured for digital i/o al ways read back the logic state of the port pad, regardless of the output logic value of the port pin. to configure a pin as digital input: 1. set the bit associated with the pin in the pnmdin register to ?1?. this selects digital mode for the pin. 2. clear the bit associated with the pin in the pnmdout r egister to ?0?. this configures the pin as open-drain. 3. set the bit associated with the pin in the pn register to ?1?. this tells the output driver to ?drive? logic high. because the pin is configured as open-drain, the high-s ide driver is not active, and the pin may be used as an input. open-drain outputs are configured exac tly as digital inputs. however, the pin may be driven low by an assigned peripheral, or by writing ?0? to the associated bi t in the pn register if the signal is a gpio. to configure a pin as a digital, push-pull output: 1. set the bit associated with the pin in the pnmdin register to ?1?. this selects digital mode for the pin. 2. set the bit associated with the pin in the pnmdout register to ?1?. this configures the pin as push-pull. if a digital pin is to be used as a general-purpose i/o, or with a digital function that is not part of the crossbar, the bit associated with the pin in the pnskip register can be set to ?1? to ensure the crossbar does not attempt to assign a function to the pin. 26.4.3. port drive strength port drive strength can be controlled on a pin-by-pin basi s using the pndrv registers. each pin has a bit in the associated pndrv register to select the high or low driv e strength setting for the pin. by default, all pins are configured for low drive strength.
c8051f97x rev 1.0 285 port i/o (port 0, port 1, port 2, port 3, po rt 4, port 5, port 6, crossbar, and port match) figure 26.4. port i/o cell block diagram 26.5. port match port match functionality allows system events to be triggered by a logic value change on one or more port i/o pins. a software controlled value stored in the pnmatch register s specifies the expected or normal logic values of the associated port pins (for example, p0match.0 would corr espond to p0.0). a port mismatch event occurs if the logic levels of the port?s input pins no longer match the softwa re controlled value. this allo ws software to be notified if a certain change or pattern occurs on the input pins regardless of the xbrn settings. the pnmask registers can be used to individually select which pins should be compared against the pnmatch registers. a port mismatch event is generated if (pn & pnmask) does no t equal (pnmatch & pnmask) for all ports with a pnmat and pnmask register. a port mismatch event may be used to generate an interrup t or wake the device from idle mode. see the interrupts and power options chapters for more details on interrupt and wake-up sources. 26.6. direct read/write access to port i/o pins all port i/o are accessed through corresponding special fu nction registers (sfrs) that are both byte addressable and bit addressable. when writing to a port, the value wri tten to the sfr is latched to maintain the output data value at each pin. when reading, the logic levels of th e port's input pins are returned regardless of the xbrn settings (i.e., even when the pin is assigned to another signa l by the crossbar, the port register can always read its corresponding port i/o pin). the exception to this is the execution of the read-modify-write instructions that target a port latch register as the destinat ion. the read-modify-write instructio ns when operating on a port sfr are the following: anl, orl, xrl, jbc, cpl, inc, dec, djnz and mov, clr or setb, w hen the destination is an individual bit in a port sfr. for these instructions, the value of the latch regist er (not the pin) is read, modified, and written back to the sfr. gnd vdd vdd (weak) port pad to/from analog peripheral pxmdin.x (1 for digital) (0 for analog) px.x ? output logic value (port latch or crossbar) xbare (crossbar enable) px.x ? input logic value (reads 0 when pin is configured as an analog i/o) pxmdout.x (1 for push-pull) (0 for open-drain) weakpud (weak pull-up disable)
c8051f97x 286 rev 1.0 port i/o (port 0, port 1, port 2, port 3, po rt 4, port 5, port 6, crossbar, and port match) 26.7. port configuration registers register 26.1. xbr0: port i/o crossbar 0 bit 7 6 5 4 3 2 1 0 name ecie pca0me syscke smb0e spi0e urt0e type rw rw rw rw rw rw reset00000000 sfr page = 0xf; sfr address: 0x95 table 26.4. xbr0 register bit descriptions bit name function 7 ecie pca0 external counter input enable. 0: eci unavailable at port pin. 1: eci routed to port pin. 6:4 pca0me pca module i/o enable. 000: all pca i/o unavailable at port pins. 001: cex0 routed to port pin. 010: cex0, cex1 routed to port pins. 011: cex0, cex1, cex2 routed to port pins. 100-111: reserved. 3 syscke sysclk output enable. 0: sysclk unavailable at port pin. 1: sysclk output routed to port pin. 2 smb0e smbus0 i/o enable. 0: smbus0 i/o unavailable at port pins. 1: smbus0 i/o routed to port pins. 1 spi0e spi i/o enable. 0: spi i/o unavailable at port pins. 1: spi i/o routed to port pins. the spi can be assigned either 3 or 4 gpio pins. 0 urt0e uart i/o output enable. 0: uart i/o unavailable at port pin. 1: uart tx, rx routed to port pins p0.4 and p0.5.
c8051f97x rev 1.0 287 port i/o (port 0, port 1, port 2, port 3, po rt 4, port 5, port 6, crossbar, and port match) register 26.2. xbr1: port i/o crossbar 1 bit 7 6 5 4 3 2 1 0 name weakpud xbare reserved t1e t0e type rw rw rw rw rw reset00000000 sfr page = 0xf; sfr address: 0x96 table 26.5. xbr1 register bit descriptions bit name function 7 weakpud port i/o weak pullup disable. 0: weak pullups enabled (except for ports whose i/o are configured for analog mode). 1: weak pullups disabled. 6 xbare crossbar enable. 0: crossbar disabled. 1: crossbar enabled. 5:2 reserved must write reset value. 1 t1e t1 enable. 0: t1 unavailable at port pin. 1: t1 routed to port pin. 0 t0e t0 enable. 0: t0 unavailable at port pin. 1: t0 routed to port pin.
c8051f97x 288 rev 1.0 port i/o (port 0, port 1, port 2, port 3, po rt 4, port 5, port 6, crossbar, and port match) 26.8. port i/o control registers register 26.3. p0mask: port 0 mask bit 7 6 5 4 3 2 1 0 name b7 b6 b5 b4 b3 b2 b1 b0 type rw rw rw rw rw rw rw rw reset00000000 sfr page = 0xf; sfr address: 0x8b table 26.6. p0mask register bit descriptions bit name function 7 b7 port 0 bit 7 mask value. 0: p0.7 pin logic value is ignored and will not cause a po rt mismatch event. 1: p0.7 pin logic value is compared to p0mat.7. 6 b6 port 0 bit 6 mask value. 0: p0.6 pin logic value is ignored and will not cause a po rt mismatch event. 1: p0.6 pin logic value is compared to p0mat.6. 5 b5 port 0 bit 5 mask value. 0: p0.5 pin logic value is ignored and will not cause a po rt mismatch event. 1: p0.5 pin logic value is compared to p0mat.5. 4 b4 port 0 bit 4 mask value. 0: p0.4 pin logic value is ignored and will not cause a po rt mismatch event. 1: p0.4 pin logic value is compared to p0mat.4. 3 b3 port 0 bit 3 mask value. 0: p0.3 pin logic value is ignored and will not cause a po rt mismatch event. 1: p0.3 pin logic value is compared to p0mat.3. 2 b2 port 0 bit 2 mask value. 0: p0.2 pin logic value is ignored and will not cause a po rt mismatch event. 1: p0.2 pin logic value is compared to p0mat.2. 1 b1 port 0 bit 1 mask value. 0: p0.1 pin logic value is ignored and will not cause a po rt mismatch event. 1: p0.1 pin logic value is compared to p0mat.1. 0 b0 port 0 bit 0 mask value. 0: p0.0 pin logic value is ignored and will not cause a po rt mismatch event. 1: p0.0 pin logic value is compared to p0mat.0.
c8051f97x rev 1.0 289 port i/o (port 0, port 1, port 2, port 3, po rt 4, port 5, port 6, crossbar, and port match) register 26.4. p0mat: port 0 match bit 7 6 5 4 3 2 1 0 name b7 b6 b5 b4 b3 b2 b1 b0 type rw rw rw rw rw rw rw rw reset11111111 sfr page = 0xf; sfr address: 0xf4 table 26.7. p0mat register bit descriptions bit name function 7 b7 port 0 bit 7 match value. 0: p0.7 pin logic value is compared with logic low. 1: p0.7 pin logic value is compared with logic high. 6 b6 port 0 bit 6 match value. 0: p0.6 pin logic value is compared with logic low. 1: p0.6 pin logic value is compared with logic high. 5 b5 port 0 bit 5 match value. 0: p0.5 pin logic value is compared with logic low. 1: p0.5 pin logic value is compared with logic high. 4 b4 port 0 bit 4 match value. 0: p0.4 pin logic value is compared with logic low. 1: p0.4 pin logic value is compared with logic high. 3 b3 port 0 bit 3 match value. 0: p0.3 pin logic value is compared with logic low. 1: p0.3 pin logic value is compared with logic high. 2 b2 port 0 bit 2 match value. 0: p0.2 pin logic value is compared with logic low. 1: p0.2 pin logic value is compared with logic high. 1 b1 port 0 bit 1 match value. 0: p0.1 pin logic value is compared with logic low. 1: p0.1 pin logic value is compared with logic high. 0 b0 port 0 bit 0 match value. 0: p0.0 pin logic value is compared with logic low. 1: p0.0 pin logic value is compared with logic high.
c8051f97x 290 rev 1.0 port i/o (port 0, port 1, port 2, port 3, po rt 4, port 5, port 6, crossbar, and port match) register 26.5. p0: port 0 pin latch bit 7 6 5 4 3 2 1 0 name b7 b6 b5 b4 b3 b2 b1 b0 type rw rw rw rw rw rw rw rw reset11111111 sfr page = all; sfr address: 0x80 (bit-addressable) table 26.8. p0 register bit descriptions bit name function 7 b7 port 0 bit 7 latch. 0: p0.7 is low. set p0.7 to drive low. 1: p0.7 is high. set p0.7 to drive or float high. 6 b6 port 0 bit 6 latch. 0: p0.6 is low. set p0.6 to drive low. 1: p0.6 is high. set p0.6 to drive or float high. 5 b5 port 0 bit 5 latch. 0: p0.5 is low. set p0.5 to drive low. 1: p0.5 is high. set p0.5 to drive or float high. 4 b4 port 0 bit 4 latch. 0: p0.4 is low. set p0.4 to drive low. 1: p0.4 is high. set p0.4 to drive or float high. 3 b3 port 0 bit 3 latch. 0: p0.3 is low. set p0.3 to drive low. 1: p0.3 is high. set p0.3 to drive or float high. 2 b2 port 0 bit 2 latch. 0: p0.2 is low. set p0.2 to drive low. 1: p0.2 is high. set p0.2 to drive or float high. 1 b1 port 0 bit 1 latch. 0: p0.1 is low. set p0.1 to drive low. 1: p0.1 is high. set p0.1 to drive or float high. 0 b0 port 0 bit 0 latch. 0: p0.0 is low. set p0.0 to drive low. 1: p0.0 is high. set p0.0 to drive or float high. notes: 1. writing this register sets the port latch logic value for the associated i/o pins configured as digital i/o. 2. reading this register returns the logic value at the pin, regardless if it is configured as output or input.
c8051f97x rev 1.0 291 port i/o (port 0, port 1, port 2, port 3, po rt 4, port 5, port 6, crossbar, and port match) register 26.6. p0mdin: port 0 input mode bit 7 6 5 4 3 2 1 0 name b7 b6 b5 b4 b3 b2 b1 b0 type rw rw rw rw rw rw rw rw reset11111111 sfr page = 0xf; sfr address: 0xec table 26.9. p0mdin register bit descriptions bit name function 7 b7 port 0 bit 7 input mode. 0: p0.7 pin is configured for analog mode. 1: p0.7 pin is configured for digital mode. 6 b6 port 0 bit 6 input mode. 0: p0.6 pin is configured for analog mode. 1: p0.6 pin is configured for digital mode. 5 b5 port 0 bit 5 input mode. 0: p0.5 pin is configured for analog mode. 1: p0.5 pin is configured for digital mode. 4 b4 port 0 bit 4 input mode. 0: p0.4 pin is configured for analog mode. 1: p0.4 pin is configured for digital mode. 3 b3 port 0 bit 3 input mode. 0: p0.3 pin is configured for analog mode. 1: p0.3 pin is configured for digital mode. 2 b2 port 0 bit 2 input mode. 0: p0.2 pin is configured for analog mode. 1: p0.2 pin is configured for digital mode. 1 b1 port 0 bit 1 input mode. 0: p0.1 pin is configured for analog mode. 1: p0.1 pin is configured for digital mode. 0 b0 port 0 bit 0 input mode. 0: p0.0 pin is configured for analog mode. 1: p0.0 pin is configured for digital mode. note: port pins configured for analog mo de have their weak pullup, digital driver, and digital receiver disabled.
c8051f97x 292 rev 1.0 port i/o (port 0, port 1, port 2, port 3, po rt 4, port 5, port 6, crossbar, and port match) register 26.7. p0mdout: port 0 output mode bit 7 6 5 4 3 2 1 0 name b7 b6 b5 b4 b3 b2 b1 b0 type rw rw rw rw rw rw rw rw reset00000000 sfr page = 0xf; sfr address: 0xd9 table 26.10. p0mdout register bit descriptions bit name function 7 b7 port 0 bit 7 output mode. 0: p0.7 output is open-drain. 1: p0.7 output is push-pull. 6 b6 port 0 bit 6 output mode. 0: p0.6 output is open-drain. 1: p0.6 output is push-pull. 5 b5 port 0 bit 5 output mode. 0: p0.5 output is open-drain. 1: p0.5 output is push-pull. 4 b4 port 0 bit 4 output mode. 0: p0.4 output is open-drain. 1: p0.4 output is push-pull. 3 b3 port 0 bit 3 output mode. 0: p0.3 output is open-drain. 1: p0.3 output is push-pull. 2 b2 port 0 bit 2 output mode. 0: p0.2 output is open-drain. 1: p0.2 output is push-pull. 1 b1 port 0 bit 1 output mode. 0: p0.1 output is open-drain. 1: p0.1 output is push-pull. 0 b0 port 0 bit 0 output mode. 0: p0.0 output is open-drain. 1: p0.0 output is push-pull.
c8051f97x rev 1.0 293 port i/o (port 0, port 1, port 2, port 3, po rt 4, port 5, port 6, crossbar, and port match) register 26.8. p0skip: port 0 skip bit 7 6 5 4 3 2 1 0 name b7 b6 b5 b4 b3 b2 b1 b0 type rw rw rw rw rw rw rw rw reset00000000 sfr page = 0xf; sfr address: 0xb6 table 26.11. p0skip register bit descriptions bit name function 7 b7 port 0 bit 7 skip. 0: p0.7 pin is not skipped by the crossbar. 1: p0.7 pin is skipped by the crossbar. 6 b6 port 0 bit 6 skip. 0: p0.6 pin is not skipped by the crossbar. 1: p0.6 pin is skipped by the crossbar. 5 b5 port 0 bit 5 skip. 0: p0.5 pin is not skipped by the crossbar. 1: p0.5 pin is skipped by the crossbar. 4 b4 port 0 bit 4 skip. 0: p0.4 pin is not skipped by the crossbar. 1: p0.4 pin is skipped by the crossbar. 3 b3 port 0 bit 3 skip. 0: p0.3 pin is not skipped by the crossbar. 1: p0.3 pin is skipped by the crossbar. 2 b2 port 0 bit 2 skip. 0: p0.2 pin is not skipped by the crossbar. 1: p0.2 pin is skipped by the crossbar. 1 b1 port 0 bit 1 skip. 0: p0.1 pin is not skipped by the crossbar. 1: p0.1 pin is skipped by the crossbar. 0 b0 port 0 bit 0 skip. 0: p0.0 pin is not skipped by the crossbar. 1: p0.0 pin is skipped by the crossbar.
c8051f97x 294 rev 1.0 port i/o (port 0, port 1, port 2, port 3, po rt 4, port 5, port 6, crossbar, and port match) register 26.9. p0drv: port 0 drive strength bit 7 6 5 4 3 2 1 0 name b7 b6 b5 b4 b3 b2 b1 b0 type rw rw rw rw rw rw rw rw reset00000000 sfr page = 0xf; sfr address: 0x99 table 26.12. p0drv register bit descriptions bit name function 7 b7 port 0 bit 7 drive strength. 0: p0.7 output has low output drive strength. 1: p0.7 output has high output drive strength. 6 b6 port 0 bit 6 drive strength. 0: p0.6 output has low output drive strength. 1: p0.6 output has high output drive strength. 5 b5 port 0 bit 5 drive strength. 0: p0.5 output has low output drive strength. 1: p0.5 output has high output drive strength. 4 b4 port 0 bit 4 drive strength. 0: p0.4 output has low output drive strength. 1: p0.4 output has high output drive strength. 3 b3 port 0 bit 3 drive strength. 0: p0.3 output has low output drive strength. 1: p0.3 output has high output drive strength. 2 b2 port 0 bit 2 drive strength. 0: p0.2 output has low output drive strength. 1: p0.2 output has high output drive strength. 1 b1 port 0 bit 1 drive strength. 0: p0.1 output has low output drive strength. 1: p0.1 output has high output drive strength. 0 b0 port 0 bit 0 drive strength. 0: p0.0 output has low output drive strength. 1: p0.0 output has high output drive strength.
c8051f97x rev 1.0 295 port i/o (port 0, port 1, port 2, port 3, po rt 4, port 5, port 6, crossbar, and port match) register 26.10. p1mask: port 1 mask bit 7 6 5 4 3 2 1 0 name b7 b6 b5 b4 b3 b2 b1 b0 type rw rw rw rw rw rw rw rw reset00000000 sfr page = 0xf; sfr address: 0x8c table 26.13. p1mask register bit descriptions bit name function 7 b7 port 1 bit 7 mask value. 0: p1.7 pin logic value is ignored and will not cause a po rt mismatch event. 1: p1.7 pin logic value is compared to p1mat.7. 6 b6 port 1 bit 6 mask value. 0: p1.6 pin logic value is ignored and will not cause a po rt mismatch event. 1: p1.6 pin logic value is compared to p1mat.6. 5 b5 port 1 bit 5 mask value. 0: p1.5 pin logic value is ignored and will not cause a po rt mismatch event. 1: p1.5 pin logic value is compared to p1mat.5. 4 b4 port 1 bit 4 mask value. 0: p1.4 pin logic value is ignored and will not cause a po rt mismatch event. 1: p1.4 pin logic value is compared to p1mat.4. 3 b3 port 1 bit 3 mask value. 0: p1.3 pin logic value is ignored and will not cause a po rt mismatch event. 1: p1.3 pin logic value is compared to p1mat.3. 2 b2 port 1 bit 2 mask value. 0: p1.2 pin logic value is ignored and will not cause a po rt mismatch event. 1: p1.2 pin logic value is compared to p1mat.2. 1 b1 port 1 bit 1 mask value. 0: p1.1 pin logic value is ignored and will not cause a po rt mismatch event. 1: p1.1 pin logic value is compared to p1mat.1. 0 b0 port 1 bit 0 mask value. 0: p1.0 pin logic value is ignored and will not cause a po rt mismatch event. 1: p1.0 pin logic value is compared to p1mat.0.
c8051f97x 296 rev 1.0 port i/o (port 0, port 1, port 2, port 3, po rt 4, port 5, port 6, crossbar, and port match) register 26.11. p1mat: port 1 match bit 7 6 5 4 3 2 1 0 name b7 b6 b5 b4 b3 b2 b1 b0 type rw rw rw rw rw rw rw rw reset11111111 sfr page = 0xf; sfr address: 0xf5 table 26.14. p1mat register bit descriptions bit name function 7 b7 port 1 bit 7 match value. 0: p1.7 pin logic value is compared with logic low. 1: p1.7 pin logic value is compared with logic high. 6 b6 port 1 bit 6 match value. 0: p1.6 pin logic value is compared with logic low. 1: p1.6 pin logic value is compared with logic high. 5 b5 port 1 bit 5 match value. 0: p1.5 pin logic value is compared with logic low. 1: p1.5 pin logic value is compared with logic high. 4 b4 port 1 bit 4 match value. 0: p1.4 pin logic value is compared with logic low. 1: p1.4 pin logic value is compared with logic high. 3 b3 port 1 bit 3 match value. 0: p1.3 pin logic value is compared with logic low. 1: p1.3 pin logic value is compared with logic high. 2 b2 port 1 bit 2 match value. 0: p1.2 pin logic value is compared with logic low. 1: p1.2 pin logic value is compared with logic high. 1 b1 port 1 bit 1 match value. 0: p1.1 pin logic value is compared with logic low. 1: p1.1 pin logic value is compared with logic high. 0 b0 port 1 bit 0 match value. 0: p1.0 pin logic value is compared with logic low. 1: p1.0 pin logic value is compared with logic high.
c8051f97x rev 1.0 297 port i/o (port 0, port 1, port 2, port 3, po rt 4, port 5, port 6, crossbar, and port match) register 26.12. p1: port 1 pin latch bit 7 6 5 4 3 2 1 0 name b7 b6 b5 b4 b3 b2 b1 b0 type rw rw rw rw rw rw rw rw reset11111111 sfr page = all; sfr address: 0x90 (bit-addressable) table 26.15. p1 register bit descriptions bit name function 7 b7 port 1 bit 7 latch. 0: p1.7 is low. set p1.7 to drive low. 1: p1.7 is high. set p1.7 to drive or float high. 6 b6 port 1 bit 6 latch. 0: p1.6 is low. set p1.6 to drive low. 1: p1.6 is high. set p1.6 to drive or float high. 5 b5 port 1 bit 5 latch. 0: p1.5 is low. set p1.5 to drive low. 1: p1.5 is high. set p1.5 to drive or float high. 4 b4 port 1 bit 4 latch. 0: p1.4 is low. set p1.4 to drive low. 1: p1.4 is high. set p1.4 to drive or float high. 3 b3 port 1 bit 3 latch. 0: p1.3 is low. set p1.3 to drive low. 1: p1.3 is high. set p1.3 to drive or float high. 2 b2 port 1 bit 2 latch. 0: p1.2 is low. set p1.2 to drive low. 1: p1.2 is high. set p1.2 to drive or float high. 1 b1 port 1 bit 1 latch. 0: p1.1 is low. set p1.1 to drive low. 1: p1.1 is high. set p1.1 to drive or float high. 0 b0 port 1 bit 0 latch. 0: p1.0 is low. set p1.0 to drive low. 1: p1.0 is high. set p1.0 to drive or float high. notes: 1. writing this register sets the port latch logic value for the associated i/o pins configured as digital i/o. 2. reading this register returns the logic value at the pin, regardless if it is configured as output or input.
c8051f97x 298 rev 1.0 port i/o (port 0, port 1, port 2, port 3, po rt 4, port 5, port 6, crossbar, and port match) register 26.13. p1mdin: port 1 input mode bit 7 6 5 4 3 2 1 0 name b7 b6 b5 b4 b3 b2 b1 b0 type rw rw rw rw rw rw rw rw reset11111111 sfr page = 0xf; sfr address: 0xed table 26.16. p1mdin register bit descriptions bit name function 7 b7 port 1 bit 7 input mode. 0: p1.7 pin is configured for analog mode. 1: p1.7 pin is configured for digital mode. 6 b6 port 1 bit 6 input mode. 0: p1.6 pin is configured for analog mode. 1: p1.6 pin is configured for digital mode. 5 b5 port 1 bit 5 input mode. 0: p1.5 pin is configured for analog mode. 1: p1.5 pin is configured for digital mode. 4 b4 port 1 bit 4 input mode. 0: p1.4 pin is configured for analog mode. 1: p1.4 pin is configured for digital mode. 3 b3 port 1 bit 3 input mode. 0: p1.3 pin is configured for analog mode. 1: p1.3 pin is configured for digital mode. 2 b2 port 1 bit 2 input mode. 0: p1.2 pin is configured for analog mode. 1: p1.2 pin is configured for digital mode. 1 b1 port 1 bit 1 input mode. 0: p1.1 pin is configured for analog mode. 1: p1.1 pin is configured for digital mode. 0 b0 port 1 bit 0 input mode. 0: p1.0 pin is configured for analog mode. 1: p1.0 pin is configured for digital mode. note: port pins configured for analog mo de have their weak pullup, digital driver, and digital receiver disabled.
c8051f97x rev 1.0 299 port i/o (port 0, port 1, port 2, port 3, po rt 4, port 5, port 6, crossbar, and port match) register 26.14. p1mdout: port 1 output mode bit 7 6 5 4 3 2 1 0 name b7 b6 b5 b4 b3 b2 b1 b0 type rw rw rw rw rw rw rw rw reset00000000 sfr page = 0xf; sfr address: 0xdc table 26.17. p1mdout register bit descriptions bit name function 7 b7 port 1 bit 7 output mode. 0: p1.7 output is open-drain. 1: p1.7 output is push-pull. 6 b6 port 1 bit 6 output mode. 0: p1.6 output is open-drain. 1: p1.6 output is push-pull. 5 b5 port 1 bit 5 output mode. 0: p1.5 output is open-drain. 1: p1.5 output is push-pull. 4 b4 port 1 bit 4 output mode. 0: p1.4 output is open-drain. 1: p1.4 output is push-pull. 3 b3 port 1 bit 3 output mode. 0: p1.3 output is open-drain. 1: p1.3 output is push-pull. 2 b2 port 1 bit 2 output mode. 0: p1.2 output is open-drain. 1: p1.2 output is push-pull. 1 b1 port 1 bit 1 output mode. 0: p1.1 output is open-drain. 1: p1.1 output is push-pull. 0 b0 port 1 bit 0 output mode. 0: p1.0 output is open-drain. 1: p1.0 output is push-pull.
c8051f97x 300 rev 1.0 port i/o (port 0, port 1, port 2, port 3, po rt 4, port 5, port 6, crossbar, and port match) register 26.15. p1skip: port 1 skip bit 7 6 5 4 3 2 1 0 name b7 b6 b5 b4 b3 b2 b1 b0 type rw rw rw rw rw rw rw rw reset00000000 sfr page = 0xf; sfr address: 0xc6 table 26.18. p1skip register bit descriptions bit name function 7 b7 port 1 bit 7 skip. 0: p1.7 pin is not skipped by the crossbar. 1: p1.7 pin is skipped by the crossbar. 6 b6 port 1 bit 6 skip. 0: p1.6 pin is not skipped by the crossbar. 1: p1.6 pin is skipped by the crossbar. 5 b5 port 1 bit 5 skip. 0: p1.5 pin is not skipped by the crossbar. 1: p1.5 pin is skipped by the crossbar. 4 b4 port 1 bit 4 skip. 0: p1.4 pin is not skipped by the crossbar. 1: p1.4 pin is skipped by the crossbar. 3 b3 port 1 bit 3 skip. 0: p1.3 pin is not skipped by the crossbar. 1: p1.3 pin is skipped by the crossbar. 2 b2 port 1 bit 2 skip. 0: p1.2 pin is not skipped by the crossbar. 1: p1.2 pin is skipped by the crossbar. 1 b1 port 1 bit 1 skip. 0: p1.1 pin is not skipped by the crossbar. 1: p1.1 pin is skipped by the crossbar. 0 b0 port 1 bit 0 skip. 0: p1.0 pin is not skipped by the crossbar. 1: p1.0 pin is skipped by the crossbar.
c8051f97x rev 1.0 301 port i/o (port 0, port 1, port 2, port 3, po rt 4, port 5, port 6, crossbar, and port match) register 26.16. p1drv: port 1 drive strength bit 7 6 5 4 3 2 1 0 name b7 b6 b5 b4 b3 b2 b1 b0 type rw rw rw rw rw rw rw rw reset00000000 sfr page = 0xf; sfr address: 0x9a table 26.19. p1drv register bit descriptions bit name function 7 b7 port 1 bit 7 drive strength. 0: p1.7 output has low output drive strength. 1: p1.7 output has high output drive strength. 6 b6 port 1 bit 6 drive strength. 0: p1.6 output has low output drive strength. 1: p1.6 output has high output drive strength. 5 b5 port 1 bit 5 drive strength. 0: p1.5 output has low output drive strength. 1: p1.5 output has high output drive strength. 4 b4 port 1 bit 4 drive strength. 0: p1.4 output has low output drive strength. 1: p1.4 output has high output drive strength. 3 b3 port 1 bit 3 drive strength. 0: p1.3 output has low output drive strength. 1: p1.3 output has high output drive strength. 2 b2 port 1 bit 2 drive strength. 0: p1.2 output has low output drive strength. 1: p1.2 output has high output drive strength. 1 b1 port 1 bit 1 drive strength. 0: p1.1 output has low output drive strength. 1: p1.1 output has high output drive strength. 0 b0 port 1 bit 0 drive strength. 0: p1.0 output has low output drive strength. 1: p1.0 output has high output drive strength.
c8051f97x 302 rev 1.0 port i/o (port 0, port 1, port 2, port 3, po rt 4, port 5, port 6, crossbar, and port match) register 26.17. p2mask: port 2 mask bit 7 6 5 4 3 2 1 0 name b7 b6 b5 b4 b3 b2 b1 b0 type rw rw rw rw rw rw rw rw reset00000000 sfr page = 0xf; sfr address: 0x84 table 26.20. p2mask register bit descriptions bit name function 7 b7 port 2 bit 7 mask value. 0: p2.7 pin logic value is ignored and will not cause a po rt mismatch event. 1: p2.7 pin logic value is compared to p2mat.7. 6 b6 port 2 bit 6 mask value. 0: p2.6 pin logic value is ignored and will not cause a po rt mismatch event. 1: p2.6 pin logic value is compared to p2mat.6. 5 b5 port 2 bit 5 mask value. 0: p2.5 pin logic value is ignored and will not cause a po rt mismatch event. 1: p2.5 pin logic value is compared to p2mat.5. 4 b4 port 2 bit 4 mask value. 0: p2.4 pin logic value is ignored and will not cause a po rt mismatch event. 1: p2.4 pin logic value is compared to p2mat.4. 3 b3 port 2 bit 3 mask value. 0: p2.3 pin logic value is ignored and will not cause a po rt mismatch event. 1: p2.3 pin logic value is compared to p2mat.3. 2 b2 port 2 bit 2 mask value. 0: p2.2 pin logic value is ignored and will not cause a po rt mismatch event. 1: p2.2 pin logic value is compared to p2mat.2. 1 b1 port 2 bit 1 mask value. 0: p2.1 pin logic value is ignored and will not cause a po rt mismatch event. 1: p2.1 pin logic value is compared to p2mat.1. 0 b0 port 2 bit 0 mask value. 0: p2.0 pin logic value is ignored and will not cause a po rt mismatch event. 1: p2.0 pin logic value is compared to p2mat.0.
c8051f97x rev 1.0 303 port i/o (port 0, port 1, port 2, port 3, po rt 4, port 5, port 6, crossbar, and port match) register 26.18. p2mat: port 2 match bit 7 6 5 4 3 2 1 0 name b7 b6 b5 b4 b3 b2 b1 b0 type rw rw rw rw rw rw rw rw reset11111111 sfr page = 0xf; sfr address: 0x85 table 26.21. p2mat register bit descriptions bit name function 7 b7 port 2 bit 7 match value. 0: p2.7 pin logic value is compared with logic low. 1: p2.7 pin logic value is compared with logic high. 6 b6 port 2 bit 6 match value. 0: p2.6 pin logic value is compared with logic low. 1: p2.6 pin logic value is compared with logic high. 5 b5 port 2 bit 5 match value. 0: p2.5 pin logic value is compared with logic low. 1: p2.5 pin logic value is compared with logic high. 4 b4 port 2 bit 4 match value. 0: p2.4 pin logic value is compared with logic low. 1: p2.4 pin logic value is compared with logic high. 3 b3 port 2 bit 3 match value. 0: p2.3 pin logic value is compared with logic low. 1: p2.3 pin logic value is compared with logic high. 2 b2 port 2 bit 2 match value. 0: p2.2 pin logic value is compared with logic low. 1: p2.2 pin logic value is compared with logic high. 1 b1 port 2 bit 1 match value. 0: p2.1 pin logic value is compared with logic low. 1: p2.1 pin logic value is compared with logic high. 0 b0 port 2 bit 0 match value. 0: p2.0 pin logic value is compared with logic low. 1: p2.0 pin logic value is compared with logic high.
c8051f97x 304 rev 1.0 port i/o (port 0, port 1, port 2, port 3, po rt 4, port 5, port 6, crossbar, and port match) register 26.19. p2: port 2 pin latch bit 7 6 5 4 3 2 1 0 name b7 b6 b5 b4 b3 b2 b1 b0 type rw rw rw rw rw rw rw rw reset11111111 sfr page = all; sfr address: 0xa0 (bit-addressable) table 26.22. p2 register bit descriptions bit name function 7 b7 port 2 bit 7 latch. 0: p2.7 is low. set p2.7 to drive low. 1: p2.7 is high. set p2.7 to drive or float high. 6 b6 port 2 bit 6 latch. 0: p2.6 is low. set p2.6 to drive low. 1: p2.6 is high. set p2.6 to drive or float high. 5 b5 port 2 bit 5 latch. 0: p2.5 is low. set p2.5 to drive low. 1: p2.5 is high. set p2.5 to drive or float high. 4 b4 port 2 bit 4 latch. 0: p2.4 is low. set p2.4 to drive low. 1: p2.4 is high. set p2.4 to drive or float high. 3 b3 port 2 bit 3 latch. 0: p2.3 is low. set p2.3 to drive low. 1: p2.3 is high. set p2.3 to drive or float high. 2 b2 port 2 bit 2 latch. 0: p2.2 is low. set p2.2 to drive low. 1: p2.2 is high. set p2.2 to drive or float high. 1 b1 port 2 bit 1 latch. 0: p2.1 is low. set p2.1 to drive low. 1: p2.1 is high. set p2.1 to drive or float high. 0 b0 port 2 bit 0 latch. 0: p2.0 is low. set p2.0 to drive low. 1: p2.0 is high. set p2.0 to drive or float high. notes: 1. writing this register sets the port latch logic value for the associated i/o pins configured as digital i/o. 2. reading this register returns the logic value at the pin, regardless if it is configured as output or input.
c8051f97x rev 1.0 305 port i/o (port 0, port 1, port 2, port 3, po rt 4, port 5, port 6, crossbar, and port match) register 26.20. p2mdin: port 2 input mode bit 7 6 5 4 3 2 1 0 name b7 b6 b5 b4 b3 b2 b1 b0 type rw rw rw rw rw rw rw rw reset11111111 sfr page = 0xf; sfr address: 0xee table 26.23. p2mdin register bit descriptions bit name function 7 b7 port 2 bit 7 input mode. 0: p2.7 pin is configured for analog mode. 1: p2.7 pin is configured for digital mode. 6 b6 port 2 bit 6 input mode. 0: p2.6 pin is configured for analog mode. 1: p2.6 pin is configured for digital mode. 5 b5 port 2 bit 5 input mode. 0: p2.5 pin is configured for analog mode. 1: p2.5 pin is configured for digital mode. 4 b4 port 2 bit 4 input mode. 0: p2.4 pin is configured for analog mode. 1: p2.4 pin is configured for digital mode. 3 b3 port 2 bit 3 input mode. 0: p2.3 pin is configured for analog mode. 1: p2.3 pin is configured for digital mode. 2 b2 port 2 bit 2 input mode. 0: p2.2 pin is configured for analog mode. 1: p2.2 pin is configured for digital mode. 1 b1 port 2 bit 1 input mode. 0: p2.1 pin is configured for analog mode. 1: p2.1 pin is configured for digital mode. 0 b0 port 2 bit 0 input mode. 0: p2.0 pin is configured for analog mode. 1: p2.0 pin is configured for digital mode. note: port pins configured for analog mo de have their weak pullup, digital driver, and digital receiver disabled.
c8051f97x 306 rev 1.0 port i/o (port 0, port 1, port 2, port 3, po rt 4, port 5, port 6, crossbar, and port match) register 26.21. p2mdout: port 2 output mode bit 7 6 5 4 3 2 1 0 name b7 b6 b5 b4 b3 b2 b1 b0 type rw rw rw rw rw rw rw rw reset00000000 sfr page = 0xf; sfr address: 0xdd table 26.24. p2mdout register bit descriptions bit name function 7 b7 port 2 bit 7 output mode. 0: p2.7 output is open-drain. 1: p2.7 output is push-pull. 6 b6 port 2 bit 6 output mode. 0: p2.6 output is open-drain. 1: p2.6 output is push-pull. 5 b5 port 2 bit 5 output mode. 0: p2.5 output is open-drain. 1: p2.5 output is push-pull. 4 b4 port 2 bit 4 output mode. 0: p2.4 output is open-drain. 1: p2.4 output is push-pull. 3 b3 port 2 bit 3 output mode. 0: p2.3 output is open-drain. 1: p2.3 output is push-pull. 2 b2 port 2 bit 2 output mode. 0: p2.2 output is open-drain. 1: p2.2 output is push-pull. 1 b1 port 2 bit 1 output mode. 0: p2.1 output is open-drain. 1: p2.1 output is push-pull. 0 b0 port 2 bit 0 output mode. 0: p2.0 output is open-drain. 1: p2.0 output is push-pull.
c8051f97x rev 1.0 307 port i/o (port 0, port 1, port 2, port 3, po rt 4, port 5, port 6, crossbar, and port match) register 26.22. p2skip: port 2 skip bit 7 6 5 4 3 2 1 0 name b7 b6 b5 b4 b3 b2 b1 b0 type rw rw rw rw rw rw rw rw reset00000000 sfr page = 0xf; sfr address: 0xc7 table 26.25. p2skip register bit descriptions bit name function 7 b7 port 2 bit 7 skip. 0: p2.7 pin is not skipped by the crossbar. 1: p2.7 pin is skipped by the crossbar. 6 b6 port 2 bit 6 skip. 0: p2.6 pin is not skipped by the crossbar. 1: p2.6 pin is skipped by the crossbar. 5 b5 port 2 bit 5 skip. 0: p2.5 pin is not skipped by the crossbar. 1: p2.5 pin is skipped by the crossbar. 4 b4 port 2 bit 4 skip. 0: p2.4 pin is not skipped by the crossbar. 1: p2.4 pin is skipped by the crossbar. 3 b3 port 2 bit 3 skip. 0: p2.3 pin is not skipped by the crossbar. 1: p2.3 pin is skipped by the crossbar. 2 b2 port 2 bit 2 skip. 0: p2.2 pin is not skipped by the crossbar. 1: p2.2 pin is skipped by the crossbar. 1 b1 port 2 bit 1 skip. 0: p2.1 pin is not skipped by the crossbar. 1: p2.1 pin is skipped by the crossbar. 0 b0 port 2 bit 0 skip. 0: p2.0 pin is not skipped by the crossbar. 1: p2.0 pin is skipped by the crossbar.
c8051f97x 308 rev 1.0 port i/o (port 0, port 1, port 2, port 3, po rt 4, port 5, port 6, crossbar, and port match) register 26.23. p2drv: port 2 drive strength bit 7 6 5 4 3 2 1 0 name b7 b6 b5 b4 b3 b2 b1 b0 type rw rw rw rw rw rw rw rw reset00000000 sfr page = 0xf; sfr address: 0x9b table 26.26. p2drv register bit descriptions bit name function 7 b7 port 2 bit 7 drive strength. 0: p2.7 output has low output drive strength. 1: p2.7 output has high output drive strength. 6 b6 port 2 bit 6 drive strength. 0: p2.6 output has low output drive strength. 1: p2.6 output has high output drive strength. 5 b5 port 2 bit 5 drive strength. 0: p2.5 output has low output drive strength. 1: p2.5 output has high output drive strength. 4 b4 port 2 bit 4 drive strength. 0: p2.4 output has low output drive strength. 1: p2.4 output has high output drive strength. 3 b3 port 2 bit 3 drive strength. 0: p2.3 output has low output drive strength. 1: p2.3 output has high output drive strength. 2 b2 port 2 bit 2 drive strength. 0: p2.2 output has low output drive strength. 1: p2.2 output has high output drive strength. 1 b1 port 2 bit 1 drive strength. 0: p2.1 output has low output drive strength. 1: p2.1 output has high output drive strength. 0 b0 port 2 bit 0 drive strength. 0: p2.0 output has low output drive strength. 1: p2.0 output has high output drive strength.
c8051f97x rev 1.0 309 port i/o (port 0, port 1, port 2, port 3, po rt 4, port 5, port 6, crossbar, and port match) register 26.24. p3: port 3 pin latch bit 7 6 5 4 3 2 1 0 name b7 b6 b5 b4 b3 b2 b1 b0 type rw rw rw rw rw rw rw rw reset11111111 sfr page = 0x0; sf r address: 0xe1 table 26.27. p3 register bit descriptions bit name function 7 b7 port 3 bit 7 latch. 0: p3.7 is low. set p3.7 to drive low. 1: p3.7 is high. set p3.7 to drive or float high. 6 b6 port 3 bit 6 latch. 0: p3.6 is low. set p3.6 to drive low. 1: p3.6 is high. set p3.6 to drive or float high. 5 b5 port 3 bit 5 latch. 0: p3.5 is low. set p3.5 to drive low. 1: p3.5 is high. set p3.5 to drive or float high. 4 b4 port 3 bit 4 latch. 0: p3.4 is low. set p3.4 to drive low. 1: p3.4 is high. set p3.4 to drive or float high. 3 b3 port 3 bit 3 latch. 0: p3.3 is low. set p3.3 to drive low. 1: p3.3 is high. set p3.3 to drive or float high. 2 b2 port 3 bit 2 latch. 0: p3.2 is low. set p3.2 to drive low. 1: p3.2 is high. set p3.2 to drive or float high. 1 b1 port 3 bit 1 latch. 0: p3.1 is low. set p3.1 to drive low. 1: p3.1 is high. set p3.1 to drive or float high. 0 b0 port 3 bit 0 latch. 0: p3.0 is low. set p3.0 to drive low. 1: p3.0 is high. set p3.0 to drive or float high. notes: 1. writing this register sets the port latch logic value for the associated i/o pins configured as digital i/o. 2. reading this register returns the logic value at the pin, regardless if it is configured as output or input.
c8051f97x 310 rev 1.0 port i/o (port 0, port 1, port 2, port 3, po rt 4, port 5, port 6, crossbar, and port match) register 26.25. p3mdin: port 3 input mode bit 7 6 5 4 3 2 1 0 name b7 b6 b5 b4 b3 b2 b1 b0 type rw rw rw rw rw rw rw rw reset11111111 sfr page = 0xf; sfr address: 0xef table 26.28. p3mdin register bit descriptions bit name function 7 b7 port 3 bit 7 input mode. 0: p3.7 pin is configured for analog mode. 1: p3.7 pin is configured for digital mode. 6 b6 port 3 bit 6 input mode. 0: p3.6 pin is configured for analog mode. 1: p3.6 pin is configured for digital mode. 5 b5 port 3 bit 5 input mode. 0: p3.5 pin is configured for analog mode. 1: p3.5 pin is configured for digital mode. 4 b4 port 3 bit 4 input mode. 0: p3.4 pin is configured for analog mode. 1: p3.4 pin is configured for digital mode. 3 b3 port 3 bit 3 input mode. 0: p3.3 pin is configured for analog mode. 1: p3.3 pin is configured for digital mode. 2 b2 port 3 bit 2 input mode. 0: p3.2 pin is configured for analog mode. 1: p3.2 pin is configured for digital mode. 1 b1 port 3 bit 1 input mode. 0: p3.1 pin is configured for analog mode. 1: p3.1 pin is configured for digital mode. 0 b0 port 3 bit 0 input mode. 0: p3.0 pin is configured for analog mode. 1: p3.0 pin is configured for digital mode. note: port pins configured for analog mo de have their weak pullup, digital driver, and digital receiver disabled.
c8051f97x rev 1.0 311 port i/o (port 0, port 1, port 2, port 3, po rt 4, port 5, port 6, crossbar, and port match) register 26.26. p3mdout: port 3 output mode bit 7 6 5 4 3 2 1 0 name b7 b6 b5 b4 b3 b2 b1 b0 type rw rw rw rw rw rw rw rw reset00000000 sfr page = 0xf; sfr address: 0xdf table 26.29. p3mdout register bit descriptions bit name function 7 b7 port 3 bit 7 output mode. 0: p3.7 output is open-drain. 1: p3.7 output is push-pull. 6 b6 port 3 bit 6 output mode. 0: p3.6 output is open-drain. 1: p3.6 output is push-pull. 5 b5 port 3 bit 5 output mode. 0: p3.5 output is open-drain. 1: p3.5 output is push-pull. 4 b4 port 3 bit 4 output mode. 0: p3.4 output is open-drain. 1: p3.4 output is push-pull. 3 b3 port 3 bit 3 output mode. 0: p3.3 output is open-drain. 1: p3.3 output is push-pull. 2 b2 port 3 bit 2 output mode. 0: p3.2 output is open-drain. 1: p3.2 output is push-pull. 1 b1 port 3 bit 1 output mode. 0: p3.1 output is open-drain. 1: p3.1 output is push-pull. 0 b0 port 3 bit 0 output mode. 0: p3.0 output is open-drain. 1: p3.0 output is push-pull.
c8051f97x 312 rev 1.0 port i/o (port 0, port 1, port 2, port 3, po rt 4, port 5, port 6, crossbar, and port match) register 26.27. p3drv: port 3 drive strength bit 7 6 5 4 3 2 1 0 name b7 b6 b5 b4 b3 b2 b1 b0 type rw rw rw rw rw rw rw rw reset00000000 sfr page = 0xf; sfr address: 0x9c table 26.30. p3drv register bit descriptions bit name function 7 b7 port 3 bit 7 drive strength. 0: p3.7 output has low output drive strength. 1: p3.7 output has high output drive strength. 6 b6 port 3 bit 6 drive strength. 0: p3.6 output has low output drive strength. 1: p3.6 output has high output drive strength. 5 b5 port 3 bit 5 drive strength. 0: p3.5 output has low output drive strength. 1: p3.5 output has high output drive strength. 4 b4 port 3 bit 4 drive strength. 0: p3.4 output has low output drive strength. 1: p3.4 output has high output drive strength. 3 b3 port 3 bit 3 drive strength. 0: p3.3 output has low output drive strength. 1: p3.3 output has high output drive strength. 2 b2 port 3 bit 2 drive strength. 0: p3.2 output has low output drive strength. 1: p3.2 output has high output drive strength. 1 b1 port 3 bit 1 drive strength. 0: p3.1 output has low output drive strength. 1: p3.1 output has high output drive strength. 0 b0 port 3 bit 0 drive strength. 0: p3.0 output has low output drive strength. 1: p3.0 output has high output drive strength.
c8051f97x rev 1.0 313 port i/o (port 0, port 1, port 2, port 3, po rt 4, port 5, port 6, crossbar, and port match) register 26.28. p4: port 4 pin latch bit 7 6 5 4 3 2 1 0 name b7 b6 b5 b4 b3 b2 b1 b0 type rw rw rw rw rw rw rw rw reset11111111 sfr page = 0x0; sf r address: 0xe2 table 26.31. p4 register bit descriptions bit name function 7 b7 port 4 bit 7 latch. 0: p4.7 is low. set p4.7 to drive low. 1: p4.7 is high. set p4.7 to drive or float high. 6 b6 port 4 bit 6 latch. 0: p4.6 is low. set p4.6 to drive low. 1: p4.6 is high. set p4.6 to drive or float high. 5 b5 port 4 bit 5 latch. 0: p4.5 is low. set p4.5 to drive low. 1: p4.5 is high. set p4.5 to drive or float high. 4 b4 port 4 bit 4 latch. 0: p4.4 is low. set p4.4 to drive low. 1: p4.4 is high. set p4.4 to drive or float high. 3 b3 port 4 bit 3 latch. 0: p4.3 is low. set p4.3 to drive low. 1: p4.3 is high. set p4.3 to drive or float high. 2 b2 port 4 bit 2 latch. 0: p4.2 is low. set p4.2 to drive low. 1: p4.2 is high. set p4.2 to drive or float high. 1 b1 port 4 bit 1 latch. 0: p4.1 is low. set p4.1 to drive low. 1: p4.1 is high. set p4.1 to drive or float high. 0 b0 port 4 bit 0 latch. 0: p4.0 is low. set p4.0 to drive low. 1: p4.0 is high. set p4.0 to drive or float high. notes: 1. writing this register sets the port latch logic value for the associated i/o pins configured as digital i/o. 2. reading this register returns the logic value at the pin, regardless if it is configured as output or input.
c8051f97x 314 rev 1.0 port i/o (port 0, port 1, port 2, port 3, po rt 4, port 5, port 6, crossbar, and port match) register 26.29. p4mdin: port 4 input mode bit 7 6 5 4 3 2 1 0 name b7 b6 b5 b4 b3 b2 b1 b0 type rw rw rw rw rw rw rw rw reset11111111 sfr page = 0xf; sfr address: 0xf1 table 26.32. p4mdin register bit descriptions bit name function 7 b7 port 4 bit 7 input mode. 0: p4.7 pin is configured for analog mode. 1: p4.7 pin is configured for digital mode. 6 b6 port 4 bit 6 input mode. 0: p4.6 pin is configured for analog mode. 1: p4.6 pin is configured for digital mode. 5 b5 port 4 bit 5 input mode. 0: p4.5 pin is configured for analog mode. 1: p4.5 pin is configured for digital mode. 4 b4 port 4 bit 4 input mode. 0: p4.4 pin is configured for analog mode. 1: p4.4 pin is configured for digital mode. 3 b3 port 4 bit 3 input mode. 0: p4.3 pin is configured for analog mode. 1: p4.3 pin is configured for digital mode. 2 b2 port 4 bit 2 input mode. 0: p4.2 pin is configured for analog mode. 1: p4.2 pin is configured for digital mode. 1 b1 port 4 bit 1 input mode. 0: p4.1 pin is configured for analog mode. 1: p4.1 pin is configured for digital mode. 0 b0 port 4 bit 0 input mode. 0: p4.0 pin is configured for analog mode. 1: p4.0 pin is configured for digital mode. note: port pins configured for analog mo de have their weak pullup, digital driver, and digital receiver disabled.
c8051f97x rev 1.0 315 port i/o (port 0, port 1, port 2, port 3, po rt 4, port 5, port 6, crossbar, and port match) register 26.30. p4mdout: port 4 output mode bit 7 6 5 4 3 2 1 0 name b7 b6 b5 b4 b3 b2 b1 b0 type rw rw rw rw rw rw rw rw reset00000000 sfr page = 0xf; sfr address: 0xc3 table 26.33. p4mdout register bit descriptions bit name function 7 b7 port 4 bit 7 output mode. 0: p4.7 output is open-drain. 1: p4.7 output is push-pull. 6 b6 port 4 bit 6 output mode. 0: p4.6 output is open-drain. 1: p4.6 output is push-pull. 5 b5 port 4 bit 5 output mode. 0: p4.5 output is open-drain. 1: p4.5 output is push-pull. 4 b4 port 4 bit 4 output mode. 0: p4.4 output is open-drain. 1: p4.4 output is push-pull. 3 b3 port 4 bit 3 output mode. 0: p4.3 output is open-drain. 1: p4.3 output is push-pull. 2 b2 port 4 bit 2 output mode. 0: p4.2 output is open-drain. 1: p4.2 output is push-pull. 1 b1 port 4 bit 1 output mode. 0: p4.1 output is open-drain. 1: p4.1 output is push-pull. 0 b0 port 4 bit 0 output mode. 0: p4.0 output is open-drain. 1: p4.0 output is push-pull.
c8051f97x 316 rev 1.0 port i/o (port 0, port 1, port 2, port 3, po rt 4, port 5, port 6, crossbar, and port match) register 26.31. p4drv: port 4 drive strength bit 7 6 5 4 3 2 1 0 name b7 b6 b5 b4 b3 b2 b1 b0 type rw rw rw rw rw rw rw rw reset00000000 sfr page = 0xf; sfr address: 0xb9 table 26.34. p4drv register bit descriptions bit name function 7 b7 port 4 bit 7 drive strength. 0: p4.7 output has low output drive strength. 1: p4.7 output has high output drive strength. 6 b6 port 4 bit 6 drive strength. 0: p4.6 output has low output drive strength. 1: p4.6 output has high output drive strength. 5 b5 port 4 bit 5 drive strength. 0: p4.5 output has low output drive strength. 1: p4.5 output has high output drive strength. 4 b4 port 4 bit 4 drive strength. 0: p4.4 output has low output drive strength. 1: p4.4 output has high output drive strength. 3 b3 port 4 bit 3 drive strength. 0: p4.3 output has low output drive strength. 1: p4.3 output has high output drive strength. 2 b2 port 4 bit 2 drive strength. 0: p4.2 output has low output drive strength. 1: p4.2 output has high output drive strength. 1 b1 port 4 bit 1 drive strength. 0: p4.1 output has low output drive strength. 1: p4.1 output has high output drive strength. 0 b0 port 4 bit 0 drive strength. 0: p4.0 output has low output drive strength. 1: p4.0 output has high output drive strength.
c8051f97x rev 1.0 317 port i/o (port 0, port 1, port 2, port 3, po rt 4, port 5, port 6, crossbar, and port match) register 26.32. p5: port 5 pin latch bit 7 6 5 4 3 2 1 0 name reserved b2 b1 b0 type rw rw rw rw reset00000111 sfr page = 0x0; sf r address: 0xe3 table 26.35. p5 register bit descriptions bit name function 7:3 reserved must write reset value. 2 b2 port 5 bit 2 latch. 0: p5.2 is low. set p5.2 to drive low. 1: p5.2 is high. set p5.2 to drive or float high. 1 b1 port 5 bit 1 latch. 0: p5.1 is low. set p5.1 to drive low. 1: p5.1 is high. set p5.1 to drive or float high. 0 b0 port 5 bit 0 latch. 0: p5.0 is low. set p5.0 to drive low. 1: p5.0 is high. set p5.0 to drive or float high. notes: 1. writing this register sets the port latch logic value for the associated i/o pins configured as digital i/o. 2. reading this register returns the logic value at the pin, regardless if it is configured as output or input.
c8051f97x 318 rev 1.0 port i/o (port 0, port 1, port 2, port 3, po rt 4, port 5, port 6, crossbar, and port match) register 26.33. p5mdin: port 5 input mode bit 7 6 5 4 3 2 1 0 name reserved b2 b1 b0 type rw rw rw rw reset00000111 sfr page = 0xf; sfr address: 0xf2 table 26.36. p5mdin register bit descriptions bit name function 7:3 reserved must write reset value. 2 b2 port 5 bit 2 input mode. 0: p5.2 pin is configured for analog mode. 1: p5.2 pin is configured for digital mode. 1 b1 port 5 bit 1 input mode. 0: p5.1 pin is configured for analog mode. 1: p5.1 pin is configured for digital mode. 0 b0 port 5 bit 0 input mode. 0: p5.0 pin is configured for analog mode. 1: p5.0 pin is configured for digital mode. note: port pins configured for analog mo de have their weak pullup, digital driver, and digital receiver disabled.
c8051f97x rev 1.0 319 port i/o (port 0, port 1, port 2, port 3, po rt 4, port 5, port 6, crossbar, and port match) register 26.34. p5mdout: port 5 output mode bit 7 6 5 4 3 2 1 0 name reserved b2 b1 b0 type rw rw rw rw reset00000000 sfr page = 0xf; sfr address: 0xff table 26.37. p5mdout register bit descriptions bit name function 7:3 reserved must write reset value. 2 b2 port 5 bit 2 output mode. 0: p5.2 output is open-drain. 1: p5.2 output is push-pull. 1 b1 port 5 bit 1 output mode. 0: p5.1 output is open-drain. 1: p5.1 output is push-pull. 0 b0 port 5 bit 0 output mode. 0: p5.0 output is open-drain. 1: p5.0 output is push-pull.
c8051f97x 320 rev 1.0 port i/o (port 0, port 1, port 2, port 3, po rt 4, port 5, port 6, crossbar, and port match) register 26.35. p5drv: port 5 drive strength bit 7 6 5 4 3 2 1 0 name reserved b2 b1 b0 type rw rw rw rw reset00000000 sfr page = 0xf; sfr address: 0x9d table 26.38. p5drv register bit descriptions bit name function 7:3 reserved must write reset value. 2 b2 port 5 bit 2 drive strength. 0: p5.2 output has low output drive strength. 1: p5.2 output has high output drive strength. 1 b1 port 5 bit 1 drive strength. 0: p5.1 output has low output drive strength. 1: p5.1 output has high output drive strength. 0 b0 port 5 bit 0 drive strength. 0: p5.0 output has low output drive strength. 1: p5.0 output has high output drive strength.
c8051f97x rev 1.0 321 port i/o (port 0, port 1, port 2, port 3, po rt 4, port 5, port 6, crossbar, and port match) register 26.36. p6: port 6 pin latch bit 7 6 5 4 3 2 1 0 name reserved b1 b0 type rw rw rw reset00000011 sfr page = 0x0; sf r address: 0xe4 table 26.39. p6 register bit descriptions bit name function 7:2 reserved must write reset value. 1 b1 port 6 bit 1 latch. 0: p6.1 is low. set p6.1 to drive low. 1: p6.1 is high. set p6.1 to drive or float high. 0 b0 port 6 bit 0 latch. 0: p6.0 is low. set p6.0 to drive low. 1: p6.0 is high. set p6.0 to drive or float high. notes: 1. writing this register sets the port latch logic value for the associated i/o pins configured as digital i/o. 2. reading this register returns the logic value at the pin, regardless if it is configured as output or input. register 26.37. p6mdin: port 6 input mode bit 7 6 5 4 3 2 1 0 name reserved b1 b0 type rw rw rw reset00000011 sfr page = 0xf; sfr address: 0x97 table 26.40. p6mdin register bit descriptions bit name function 7:2 reserved must write reset value. 1 b1 port 6 bit 1 input mode. 0: p6.1 pin is configured for analog mode. 1: p6.1 pin is configured for digital mode. note: port pins configured for analog mo de have their weak pullup, digital driver, and digital receiver disabled.
c8051f97x 322 rev 1.0 port i/o (port 0, port 1, port 2, port 3, po rt 4, port 5, port 6, crossbar, and port match) 0 b0 port 6 bit 0 input mode. 0: p6.0 pin is configured for analog mode. 1: p6.0 pin is configured for digital mode. table 26.40. p6mdin register bit descriptions bit name function note: port pins configured for analog mo de have their weak pullup, digital driver, and digital receiver disabled.
c8051f97x rev 1.0 323 reset sources and supply monitor 27. reset sources and supply monitor reset circuitry allows the controller to be easily placed in a predefined default condition. upon entering this reset state, the following events occur: ?? cip-51 halts program execution ?? special function registers (sfrs) are initialized to their defined reset values ?? external port pins are placed in a known state ?? interrupts and timers are disabled. all sfrs are reset to the predefined values noted in the sfr detailed descriptions. the contents of internal data memory are unaffected during a reset; any previously stored data is preserved. however, since the stack pointer sfr is reset, the stack is effect ively lost, even though the data on the stack is not altered. the port i/o latches are reset to 0xff (all logic ones) in open-drain, low-drive mode. weak pullups are enabled during and after the reset. for v dd monitor and power-on resets, the rst pin is driven low until the device exits the reset state. note that during a power-on event, there may be a short delay before the por circuitry fires and the rst pin is driven low. during that time, the rst pin will be weakly pulled to the v dd supply pin. on exit from the reset state, the pr ogram counter (pc) is reset, the watc hdog timer is enabled and the system clock defaults to the internal oscillator. program exec ution begins at location 0x0000. figure 27.1. reset sources reset sources rst supply monitor or power-up missing clock detector watchdog timer software reset smartclock alarm/error system reset flash error
c8051f97x 324 rev 1.0 reset sources an d supply monitor 27.1. power-on reset during power-up, the por circuit will fi re. when por fires, the device is held in a reset state and the rst pin is driven low until v dd settles above v rst . two delays are present during the su pply ramp time. first, a delay will occur before the por circuitry fires and pulls the rst pin low. a second delay occurs before the device is released from reset; the delay decreases as the v dd ramp time increases (v dd ramp time is defined as how fast v dd ramps from 0 v to v rst ). figure 27.2. plots the power-on reset timing. for ramp times less than 1 ms, the power-on reset time (t por ) is typically less than 0.3 ms. additi onally, the power supply must reach v rst before the por circuit will release the device from reset. on exit from a power-on reset, the pors f flag (rstsrc.1) is set by hardware to logic 1. when porsf is set, all of the other reset flags in the rstsrc register are indeterm inate (porsf is cleared by all other resets). since all resets cause program execution to begin at the same lo cation (0x0000) software can read the porsf flag to determine if a power-up was the cause of reset. the cont ent of internal data memory should be assumed to be undefined after a power-on reset. the v dd monitor is enabled following a power-on reset. figure 27.2. power-on reset timing power-on reset rst t volts logic high logic low t por v d d
c8051f97x rev 1.0 325 reset sources and supply monitor 27.2. power-fail reset / supply monitor c8051f97x devices have a supply monitor that is enabled and selected as a reset source after each power-on or power fail reset. when enabled and selected as a reset source, any power down transition or power irregularity that causes v dd to drop below v rst will cause the rst pin to be driven low and the cip-51 will be held in a reset state (see figure 27.3). when v dd returns to a level above v rst , the cip-51 will be released from the reset state. after a power-fail reset, the porsf flag reads 1, the contents of ram invalid, and the v dd supply monitor is enabled and selected as a reset source. the enable state of the v dd supply monitor and it s selection as a reset source is only altered by power-on and power-fail resets. for example, if the v dd supply monitor is deselected as a reset source and disabled by software, then a software reset is performed, the v dd supply monitor will remain disabled and deselected after the reset. in battery-operated systems, the conten ts of ram can be preserved near the end of the battery?s usable life if the device is placed in sleep mode prior to a power-fail rese t occurring. when the device is in sleep mode, the power- fail reset is automatically disabled and the contents of ram are preserved as long as v dd does not fall below v por . a large capacitor can be used to hold the power supply voltage above v por while the user is replacing the battery. upon waking from sleep mode, the enable and reset source select state of the v dd supply monitor are restored to the value last set by the user. to allow software early notification that a power failure is about to occur, the vddok bit is cleared when the v dd supply falls below the v warn threshold. the vddok bit can be configured to generate an interrupt. see section ?13. interrupts? on page 79 for more details. important note: to protect the integrity of flash contents, the v dd supply monitor must be enabled and selected as a reset source if software contains routines which erase or write flash memory. if the v dd supply monitor is not enabled, any erase or write performe d on flash memory will cause a flash error device reset. memory. if the vdd supply monito r is not enabled, any er ase or write performed on flash memory will be ignored. figure 27.3. vdd supply monitor threshold t volts vdd reset threshol d (v rst ) vdd moni tor reset rst
c8051f97x 326 rev 1.0 reset sources an d supply monitor 27.3. enabling the vdd monitor the vdd supply monitor is enabled by default. however, in systems which disable the supply monitor, it must be enabled before selecting it as a reset source. selecting the vdd supply monitor as a reset source before it has stabilized may generate a system reset. in systems where this reset would be undesirable, a delay should be introduced between enabling the vdd supply monitor and se lecting it as a reset source. no delay should be introduced in systems where software contains routines that erase or write flash memory. the procedure for enabling the vdd supply monitor and selecting it as a reset source is: 1. enable the vdd supply monitor (vmonen = 1). 2. wait for the vdd supply monitor to stabilize (optional). 3. enable the vdd monitor as a reset source in the rstsrc register. 27.4. external reset the external rst pin provides a means for external circuitry to fo rce the device into a reset state. asserting an active-low signal on the rst pin generates a reset; an external pullup and/or decoupling of the rst pin may be necessary to avoid erroneous noise-induced resets. the pinrsf flag is set on ex it from an external reset. 27.5. missing cl ock detector reset the missing clock detector (mcd) is a one-s hot circuit that is triggered by th e system clock. if the system clock remains high or low for more than the mcd time window, the one-shot will ti me out and generate a reset. after a mcd reset, the mcdrsf flag will read 1, signifying the mcd as the reset so urce; otherwise, th is bit reads 0. writing a 1 to the mcdrsf bit enables the missing clock de tector; writing a 0 disables it. the state of the rst pin is unaffected by this reset. 27.6. pca watchdog timer reset the programmable watchdog timer (wdt) function of t he programmable counter array (pca) can be used to prevent software from running out of control during a system malfunction. the pca wdt function can be enabled or disabled by software as described in the pca watchdog timer section. if a system malfunction prevents user software from updating the wdt, a reset is generated an d the wdtrsf bit is set to ?1?. the state of the rst pin is unaffected by this reset. 27.7. flash error reset if a flash read/write/era se or program read targets an illegal address, a system rese t is generated. this may occur due to any of the following: ?? a flash write or erase is attempted above user code space. ?? a flash read is attempted above user code space. ?? a program read is attempted above user code space (i.e. a branch instruction to the reserved area). ?? a flash read, write or erase attempt is re stricted due to a flash security setting. the ferror bit is set following a flash error reset. the state of the rst pin is unaffected by this reset. 27.8. smartclock reset the smartclock can generate a system reset on two events: smartclo ck oscillator fail or smartclock alarm. the smartclock oscillator fail event oc curs when the smartclock missing clock detector is enabled and the smartclock clock is below approximately 20 khz. a smartclock alarm event occurs when the smartclock alarm is enabled and the smartclock timer value matc hes the alarmn registers. the smartclock can be configured as a reset source by writing a 1 to the rtc0re flag (rstsrc.7). the smartclock reset remains functional even when the device is in the low po wer suspend or sleep mode. the state of the rst pin is unaffected by this reset. 27.9. software reset software may force a reset by writing a 1 to the swrsf bit. the swrsf bit will read 1 following a software forced reset. the state of the rst pin is unaffected by this reset.
c8051f97x rev 1.0 327 reset sources and supply monitor 27.10. reset sources control registers register 27.1. rstsrc: reset source bit 7 6 5 4 3 2 1 0 name rtc0re ferror reserved swrsf wdtrsf mcdrsf porsf pinrsf type rw rw rw rw rw rw rw rw resetxxxxxxxx sfr page = 0x0; sf r address: 0xef table 27.1. rstsrc register bit descriptions bit name function 7 rtc0re rtc reset enable and flag. read: this bit reads 1 if a rtc alarm or oscillator fail caused the last reset. write: writing a 1 to this bit enables the rtc as a reset source. 6 ferror flash error reset flag. this read-only bit is set to '1' if a flash read/write/erase error caused the last reset. 5 reserved must write reset value. 4 swrsf software reset force and flag. read: this bit reads 1 if last rese t was caused by a write to swrsf. write: writing a 1 to this bit forces a system reset. 3 wdtrsf watchdog timer reset flag. this read-only bit is set to '1' if a watc hdog timer overflow caused the last reset. 2 mcdrsf missing clock detector enable and flag. read: this bit reads 1 if a missing clock detector timeout caused the last reset. write: writing a 1 to this bit enables the mi ssing clock detector. the mcd triggers a reset if a missing clock condition is detected. 1 porsf power-on / supply monitor reset flag, and supply monitor reset enable. read: this bit reads 1 anytime a power-on or supply monitor reset has occurred. write: writing a 1 to this bit enables the supply monitor as a reset source. 0 pinrsf hw pin reset flag. this read-only bit is set to '1' if the rst pin caused the last reset. notes: 1. reads and writes of the rstsrc regist er access different logic in the device. reading the register always returns status information to indicate the source of the most recent reset. writing to the register activates certain options as reset sources. it is recommended to not use any kind of read-modify-write operation on this register. 2. when the porsf bit reads back '1' all other rstsrc flags are indeterminate. 3. writing '1' to the porsf bit when the supply monitor is not enabled and stabilized may cause a system reset.
c8051f97x 328 rev 1.0 reset sources an d supply monitor 27.11. supply monito r control registers register 27.2. vdm0cn: vdd supply monitor control bit 7 6 5 4 3 2 1 0 name vdmen vddstat vddok reserved vddokie reserved type rw r r r rw r reset1xx01000 sfr page = 0x0; sfr address: 0xff table 27.2. vdm0cn register bit descriptions bit name function 7 vdmen v dd supply monitor enable. this bit turns the v dd supply monitor circuit on/off. the v dd supply monitor cannot gen - erate system resets until it is also selected as a reset source in register rstsrc. 0: disable the v dd supply monitor. 1: enable the v dd supply monitor. 6 vddstat v dd supply status. this bit indicates the current power supply status. 0: v dd is at or below the vrst threshold. 1: v dd is above the vrst threshold. 5 vddok v dd supply status (early warning). this bit indicates the current vdd power supply status. 0: v dd is at or below the vddwarn threshold. 1: v dd is above the vddwarn threshold. 4 reserved must write reset value. 3 vddokie v dd early warning interrupt enable. enables the v dd early warning interrupt. 0: disable the v dd early warning interrupt. 1: enable the v dd early warning interrupt. 2:0 reserved must write reset value.
c8051f97x rev 1.0 329 serial peripheral interface (spi0) 28. serial peripheral interface (spi0) the serial peripheral interface (spi0) provides access to a flexible, full-duplex synchronous serial bus. spi0 can operate as a master or slave device in both 3-wire or 4-wire modes, and supports multiple masters and slaves on a single spi bus. the slave-select (nss) signal can be config ured as an input to select spi0 in slave mode, or to disable master mode operation in a multi-master environmen t, avoiding contention on th e spi bus when more than one master attempts simultaneous data transfers. nss can also be configured as a chip-select output in master mode, or disabled for 3-wire operation. additional genera l purpose port i/o pins can be used to select multiple slave devices in master mode. figure 28.1. spi0 block diagram spi0 shift register miso mosi clock rate generator sysclk bus control master or slave sck polarity sck phase nss control sck nss spi0dat tx buffer rx buffer
c8051f97x 330 rev 1.0 serial peripheral interface (spi0) 28.1. signal descriptions the four signals used by spi0 (mosi, miso, sck, nss) are described below. 28.1.1. master out, slave in (mosi) the master-out, slave-in (mosi) signal is an output from a master device and an input to slave devices. it is used to serially transfer data from the master to the slave. this signal is an output when spi0 is operating as a master and an input when spi0 is operating as a slave. data is transferred most-si gnificant bit first. when configured as a master, mosi is driven by the msb of the shift register in both 3- and 4-wire mode. 28.1.2. master in, slave out (miso) the master-in, slave-out (miso) signal is an output from a slave device and an input to the master device. it is used to serially transfer data from the slave to the mast er. this signal is an input when spi0 is operating as a master and an output when spi0 is oper ating as a slave. data is transferred most-significant bit first. the miso pin is placed in a high-impedance state when the spi module is disabled and when the spi operates in 4-wire mode as a slave that is not selected. when acting as a slave in 3-wi re mode, miso is always driven by the msb of the shift register. 28.1.3. serial clock (sck) the serial clock (sck) signal is an output from the mast er device and an input to sl ave devices. it is used to synchronize the transfer of data betw een the master and slave on the mosi and miso lines. spi0 generates this signal when operating as a master. the sck signal is ig nored by a spi slave when the slave is not selected (nss = 1) in 4-wire slave mode. 28.1.4. slave select (nss) the function of the slave-select (nss) signal is dependent on the setting of the nssmd1 and nssmd0 bits in the spi0cn register. there are three possible mo des that can be selected with these bits: 1. nssmd[1:0] = 00: 3-wire master or 3-wire sl ave mode: spi0 operates in 3-wire mode, and nss is disabled. when operating as a slave device, spi0 is always selected in 3- wire mode. since no select signal is present, spi0 must be the only slave on the bus in 3-wire mode. this is intended for point-to-point communication between a master and one slave. 2. nssmd[1:0] = 01: 4-wire slave or multi-master mo de: spi0 operates in 4-wire mode, and nss is enabled as an input. when operating as a slave, nss select s the spi0 device. when operating as a master, a 1-to- 0 transition of the nss signal disables the master func tion of spi0 so that multiple master devices can be used on the same spi bus. 3. nssmd[1:0] = 1x: 4-wire mast er mode: spi0 operates in 4-wire mode, and nss is enabled as an output. the setting of nssmd0 determines what logic level th e nss pin will output. this co nfiguration should only be used when operating spi0 as a master device. see figure 28.2, figure 28.3, and figure 28.4 for typica l connection diagrams of th e various operational modes. note that the setting of nssmd bits affects the pinout of the device. when in 3-wire master or 3-wire slave mode, the nss pin will not be mapped by the crossbar. in all other mo des, the nss signal will be mapped to a pin on the device.
c8051f97x rev 1.0 331 serial peripheral interface (spi0) 28.2. spi0 master mode operation a spi master device initiates all data transfers on a spi bu s. spi0 is placed in master mode by setting the master enable flag (msten, spi0cn.6). writing a byte of data to the spi0 data regi ster (spi0dat) when in master mode writes to the transmit buffer. if the spi shift register is empty, the byte in the transmi t buffer is moved to the shift register, and a data transfer begins. the spi0 master immedi ately shifts out the data serially on the mosi line while providing the serial clock on sck. the sp if (spi0cn.7) flag is set to logic 1 at the end of the transfer. if interrupts are enabled, an interrupt request is generated when the spi f flag is set. while the spi0 master transfers data to a slave on the mosi line, the addressed sp i slave device simultaneously transfers the contents of its shift register to the spi master on the miso line in a full-duplex operation. therefore, the spif flag serves as both a transmit- complete and receive-data-ready flag. the data byte rece ived from the slave is transferred msb-first into the master's shift register. when a byte is fully shifted into the register, it is moved to the re ceive buffer where it can be read by the processor by reading spi0dat. when configured as a master, spi0 can operate in one of three different modes: multi-master mode, 3-wire single- master mode, and 4-wire single-master mode. the defa ult, multi-master mode is active when nssmd1 (spi0cn.3) = 0 and nssmd0 (spi0cn.2) = 1. in this mode, nss is an input to the device, and is used to disable the master spi0 when another master is accessing th e bus. when nss is pulled low in this mode, msten (spi0cn.6) and spien (spi0cn.0) are set to 0 to disabl e the spi master device, and a mode fault is generated (modf, spi0cn.5 = 1). mode fault will gen erate an interr upt if enabled. spi0 must be manually re -enabled in software under these circumstances. in multi-master systems, devices will ty pically default to being slave devices while they are not acting as the system master device . in multi-master mode, slave devices can be addressed individually (if needed) using general-purpose i/o pins . figure 28.2 shows a connection diagram between two master devices and a single slave in multiple-master mode. 3-wire single-master mode is active wh en nssmd1 (spi0cn. 3) = 0 and nssmd0 (spi0cn.2) = 0. in this mode, nss is not used, and is not mapped to an external port pin through the crossbar. any slave devices that must be addressed in this mode should be selected using general-purpose i/o pins. figure 28.3 shows a connection diagram between a master device in 3-wire master mode and a slave device. 4-wire single-master mode is active when nssmd1 (spi0cn.3) = 1. in this mo de, nss is configured as an output pin, and can be used as a slave-select signal for a singl e spi device. in this mode, the output value of nss is controlled (in software) with the bit nssmd0 (spi0cn.2). additional slav e devices can be addressed using general-purpose i/o pins. figure 28.4 shows a connection diagram for a master device and a slave device in 4- wire mode.
c8051f97x 332 rev 1.0 serial peripheral interface (spi0) figure 28.2. multiple-master mode connection diagram figure 28.3. 3-wire single master and 3-wire single slave mode connection diagram figure 28.4. 4-wire single master mode and 4-wire slave mode connection diagram master device 1 miso mosi sck nss slave device miso mosi sck nss master device 2 miso mosi sck nss port pin port pin slave device master device miso mosi sck miso mosi sck slave device master device miso mosi sck miso mosi sck nss nss
c8051f97x rev 1.0 333 serial peripheral interface (spi0) 28.3. spi0 slave mode operation when spi0 is enabled and not configured as a master, it will operate as a spi slave. as a slave, bytes are shifted in through the mosi pin and out through the miso pin by a master device controlling th e sck signal. a bit counter in the spi0 logic counts sck edges. when 8 bits have been sh ifted through the shift register, the spif flag is set to logic 1, and the byte is copied into the receive buffer. da ta is read from the receive buffer by reading spi0dat. a slave device cannot initiate transfers. data to be transfe rred to the master device is pre-loaded into the shift register by writing to spi0dat. writes to spi0dat are double- buffered, and are placed in the transmit buffer first. if the shift register is empty, the content s of the transmit buffer will immediately be transferred into the shift register. when the shift register already contains data, the spi will load the shift register with the trans mit buffer?s contents after the last sck edge of the ne xt (or current) spi transfer. when configured as a slave, spi0 can be configured for 4- wire or 3-wire operation. the default, 4-wire slave mode, is active when nssmd1 (spi0cn.3) = 0 and nssmd0 (spi0c n.2) = 1. in 4-wire mode, the nss signal is routed to a port pin and configured as a digital i nput. spi0 is enabled when nss is logic 0, and disabled when nss is logic 1. the bit counter is reset on a falling edge of nss. note that the nss si gnal must be driven low at least 2 system clocks before the first active edge of sck for each byte transfer. figure 28 .4 shows a connection diagram between two slave devices in 4-wire sl ave mode and a master device. the 3-wire slave mode is active when nssmd1 (spi0cn.3) = 0 and nssmd0 (s pi0cn.2) = 0. nss is not used in this mode, and is not mapped to an external port pin th rough the crossbar. since there is no way of uniquely addressing the device in 3-wire slave mode, spi0 must be th e only slave device present on the bus. it is important to note that in 3-wire slave mode there is no external me ans of resetting the bit counter that determines when a full byte has been received. the bit counter can only be rese t by disabling and re-enablin g spi0 with the spien bit. figure 28.3 shows a connection diagram between a slav e device in 3-wire slave mode and a master device. 28.4. spi0 interrupt sources when spi0 interrupts are enab led, the following four flag s will generate an interr upt when they are set to logic 1: all of the following bits must be cleared by software. ?? the spi interrupt flag, spif ( spi0cn.7) is set to logic 1 at the end of each byte transfer. this flag can occur in all spi0 modes. ?? the write collision flag, wcol (spi0cn. 6) is set to logic 1 if a write to spi0dat is attempted when the transmit buffer has not been emptied to the spi shift re gister. when this occurs, the write to spi0dat will be ignored, and the transmit buff er will not be written.this flag can occur in all spi0 modes. ?? the mode fault flag modf (spi0cn.5) is set to logi c 1 when spi0 is configured as a master, and for multi-master mode and the nss pin is pulled low. when a mode fault occurs, the msten and spien bits in spi0cn are set to logic 0 to disable spi0 and allow another master device to access the bus. ?? the receive overrun flag rxovrn (spi0cn.4) is se t to logic 1 when configured as a slave, and a transfer is completed and the receive buffer still holds an unread by te from a previous transfer. the new byte is not transferred to the receive buffer, allowing t he previously received data byte to be read. the data byte which caused the overrun is lost. 28.5. serial clock phase and polarity four combinations of serial clock phase and polarity ca n be selected using the clock control bits in the spi0 configuration register (spi0cfg). the ckpha bit (spi0cfg.5) selects one of two clock phases (edge used to latch the data). the ckpol bit (spi0cfg.4) selects between an active-high or active-low clock. both master and slave devices must be configured to use the same clock phase and polarity. spi0 should be disabled (by clearing the spien bit, spi0cn.0) when changing the clock phase or polarity. the clock and data line relationships for master mode are shown in figure 28.5. for slave mode, the clock and data relationships are shown in figure 28.6 and figure 28.7. note that ckpha should be set to 0 on both the master and sl ave spi when communicating between two silicon labs c8051 devices.
c8051f97x 334 rev 1.0 serial peripheral interface (spi0) the spi0 clock rate register (spi0ckr) co ntrols the master mode serial clock frequency. this register is ignored when operating in slave mode. when the spi is configured as a master, the maximum data transfer rate (bits/sec) is one-half the system clock frequency or 12.5 mhz, whiche ver is slower. when the spi is configured as a slave, the maximum data transfer rate (bits/sec) for full-duplex oper ation is 1/10 the system clock frequency, provided that the master issues sck, nss (in 4-wire slave mode), and the serial input data synchronously with the slave?s system clock. if the master issues sck, nss, and the serial input data asyn chronously, the maximum data transfer rate (bits/sec) must be less than 1/10 the system clock fr equency. in the special case where the master only wants to transmit data to the slave and does not need to receiv e data from the slave (i.e. half-duplex operation), the spi slave can receive data at a maximum data transfer rate (bits/sec) of 1/4 the system clock frequency. this is provided that the master issues sck, nss, and the seri al input data synchronously with the slave?s system clock. figure 28.5. master mode data/clock timing figure 28.6. slave mode data/clock timing (ckpha = 0) sck (ckpol=0, ckpha=0) sck (ckpol=0, ckpha=1) sck (ckpol=1, ckpha=0) sck (ckpol=1, ckpha=1) msb bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 miso/mosi nss (must remain high in multi-master mode) msb bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 miso nss (4-wire mode) msb bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 mosi sck (ckpol=0, ckpha=0) sck (ckpol=1, ckpha=0)
c8051f97x rev 1.0 335 serial peripheral interface (spi0) figure 28.7. slave mode data/clock timing (ckpha = 1) 28.6. spi special function registers spi0 is accessed and controlled throug h four special function registers in the system controller: spi0cn control register, spi0dat data register, spi0cfg configuration register, and spi0ckr clock rate register. the four special function registers related to the operation of the spi0 bus are described in the following figures. figure 28.8. spi master timing (ckpha = 0) sck (ckpol=0, ckpha=1) sck (ckpol=1, ckpha=1) msb bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 miso nss (4-wire mode) msb bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 mosi sck* t mckh t mckl mosi t mis miso * sck is shown for ckpol = 0. sck is the opposite polarity for ckpol = 1. t mih
c8051f97x 336 rev 1.0 serial peripheral interface (spi0) figure 28.9. spi master timing (ckpha = 1) figure 28.10. spi slave timing (ckpha = 0) sck* t mckh t mckl miso t mih mosi * sck is shown for ckpol = 0. sck is the opposite polarity for ckpol = 1. t mis sck* t se nss t ckh t ckl mosi t sis t sih miso t sd t soh * sck is shown for ckpol = 0. sck is the opposite polarity for ckpol = 1. t sez t sdz
c8051f97x rev 1.0 337 serial peripheral interface (spi0) figure 28.11. spi slave timing (ckpha = 1) sck* t se nss t ckh t ckl mosi t sis t sih miso t sd t soh * sck is shown for ckpol = 0. sck is the opposite polarity for ckpol = 1. t slh t sez t sdz
c8051f97x 338 rev 1.0 serial peripheral interface (spi0) table 28.1. spi slave timing parameters parameter description min max units master mode timing (see figure 28.8 and figure 28.9 ) t mckh sck high time 1 x t sysclk ? ns t mckl sck low time 1 x t sysclk ? ns t mis miso valid to sck shift edge 1 x t sysclk + 20 ? ns t mih sck shift edge to miso change 0 ? ns slave mode timing (see figure 28.10 and figure 28.11 ) t se nss falling to first sck edge 2 x t sysclk ? ns t sd last sck edge to nss rising 2 x t sysclk ? ns t sez nss falling to miso valid ? 4 x t sysclk ns t sdz nss rising to miso high-z ? 4 x t sysclk ns t ckh sck high time 5 x t sysclk ? ns t ckl sck low time 5 x t sysclk ? ns t sis mosi valid to sck sample edge 2 x t sysclk ? ns t sih sck sample edge to mosi change 2 x t sysclk ? ns t soh sck shift edge to miso change ? 4 x t sysclk ns t slh last sck edge to miso change ? (ckpha = 1 only) 6 x t sysclk 8 x t sysclk ns note: t sysclk is equal to one per iod of the device syst em clock (sysclk).
c8051f97x rev 1.0 339 serial peripheral interface (spi0) 28.7. spi control registers register 28.1. spi0cfg: spi0 configuration bit 7 6 5 4 3 2 1 0 name spibsy msten ckpha ckpol slvsel nssin srmt rxbmt type r rw rw rw r r r r reset 0 0 0 0 0 1 1 1 sfr page = 0x0; sfr address: 0xa1 table 28.2. spi0cfg register bit descriptions bit name function 7 spibsy spi busy. this bit is set to logic 1 when a spi transf er is in progress (master or slave mode). 6 msten master mode enable. 0: disable master mode. operate in slave mode. 1: enable master mode. operate as a master. 5 ckpha spi0 clock phase. 0: data centered on first edge of sck period. 1: data centered on second edge of sck period. 4 ckpol spi0 clock polarity. 0: sck line low in idle state. 1: sck line high in idle state. 3 slvsel slave selected flag. this bit is set to logic 1 whenever the nss pin is low indicating spi0 is the selected slave. it is cleared to logic 0 when nss is hi gh (slave not selected). this bit does not indi - cate the instantaneous value at the nss pin, but rather a de-glitched version of the pin input. 2 nssin nss instantaneous pin input. this bit mimics the instantaneous value that is present on the nss port pin at the time that the register is read. this input is not de-glitched. 1 srmt shift register empty. this bit is valid in slave mode only and will be set to logic 1 when a ll data has been trans - ferred in/out of the shift register, and there is no new information available to read from the transmit buffer or wr ite to the receive buffer. it returns to logic 0 when a data byte is transferred to the shift register from the transmit buffer or by a transition on sck. srmt = 1 when in master mode. 0 rxbmt receive buffer empty. this bit is valid in slave mode only and will be set to logic 1 when the receive buffer has been read and contains no new information. if there is new information available in the receive buffer that has not be en read, this bit will return to logic 0. rxbmt = 1 when in master mode. note: in slave mode, data on mosi is sampled in the center of each data bit. in master mode, data on miso is sampled one sysclk before the end of each data bit, to provide maximum sett ling time for the slave device.
c8051f97x 340 rev 1.0 serial peripheral interface (spi0) register 28.2. spi0cn: spi0 control bit 7 6 5 4 3 2 1 0 name spif wcol modf rxovrn nssmd txbmt spien type rw rw rw rw rw r rw reset 0 0 0 0 0 1 1 0 sfr page = 0x0; sfr address: 0xf8 (bit-addressable) table 28.3. spi0cn register bit descriptions bit name function 7 spif spi0 interrupt flag. this bit is set to logic 1 by hardware at th e end of a data transfer. if spi interrupts are enabled, an interrupt will be ge nerated. this bit is not automatically cl eared by hardware, and must be cleared by firmware. 6 wcol write collision flag. this bit is set to logic 1 if a write to spi0d at is attempted when txbmt is 0. when this occurs, the write to spi0dat will be ignored, and the tr ansmit buffer will not be written. if spi interrupts ar e enabled, an inte rrupt will be generat ed. this bit is not automatically cleared by hardware, and must be cleared by firmware. 5 modf mode fault flag. this bit is set to logic 1 by hardware when a mast er mode collision is detected (nss is low, msten = 1, and nssmd = 01). if spi interrupts are enabled , an interrupt will be generated. this bit is not automatically cl eared by hardware, and must be cleared by firmware. 4 rxovrn receive overrun flag. this bit is valid for slave mode only and is set to logic 1 by hardware when the receive buffer still holds unread data from a previous transfer and the last bi t of the current trans - fer is shifted into the spi0 shift register. if spi interrupts are enabl ed, an interrupt will be generated. this bit is not automatically cl eared by hardware, and must be cleared by firmware. 3:2 nssmd slave select mode. selects between the following nss operation modes: 00: 3-wire slave or 3-wire master mode. nss signal is not routed to a port pin. 01: 4-wire slave or multi-master mo de. nss is an input to the device. 10: 4-wire single-master mode. nss is an output and logic low. 11: 4-wire single-master mode. ns s is an output and logic high. 1 txbmt transmit buffer empty. this bit will be set to logic 0 when new data has been written to the transmit buffer. when data in the transmit buffer is transferred to the spi shift regist er, this bit will be set to logic 1, indicating that it is safe to write a new byte to the transmit buffer. 0 spien spi0 enable. 0: disable the spi module. 1: enable the spi module.
c8051f97x rev 1.0 341 serial peripheral interface (spi0) register 28.3. spi0ckr: spi0 clock rate bit 7 6 5 4 3 2 1 0 name spi0ckr type rw reset00000000 sfr page = 0x0; sfr address: 0xa2 table 28.4. spi0ckr register bit descriptions bit name function 7:0 spi0ckr spi0 clock rate. these bits determine the frequency of the sck output when the spi0 module is config - ured for master mode operation. the sck clock frequency is a divided version of the system clock, and is given in the following equation, where sysclk is the system clock frequency and spi0ckr is the 8-bit value held in the spi0ckr register. for 0 <= spi0ckr <= 255 f sck sysclk 2 spi0ckr 1 + ?? ? ----------------------------------------------- =
c8051f97x 342 rev 1.0 serial peripheral interface (spi0) register 28.4. spi0dat: spi0 data bit 7 6 5 4 3 2 1 0 name spi0dat type rw reset00000000 sfr page = 0x0; sfr address: 0xa3 table 28.5. spi0dat register bit descriptions bit name function 7:0 spi0dat spi0 transmit and receive data. the spi0dat register is used to transmit and receive spi0 data. writing data to spi0 - dat places the data into the transmit buffer and initiates a transfer when in master mode. a read of spi0dat returns the contents of the receive buffer.
c8051f97x rev 1.0 343 system management bus / i2c (smbus0) 29. system management bus / i 2 c (smbus0) the smbus i/o interface is a two-wire, bidirectional serial bus. the smbus is compliant with the system management bus specification, versi on 1.1, and compatible with the i 2 c serial bus. reads and writes to the smbu s by the system controller are byte oriented with the smbus interface autonomously controlling the serial transfer of the data. data can be transf erred at up to 1/20th of th e system clock as a master or slave (this can be faster than allowed by the smbus spec ification, depending on the sy stem clock used). a method of extending the clock-low duration is available to accommodate devices wit h different speed ca pabilities on the same bus. the smbus may operate as a master and/or slave, and ma y function on a bus with mu ltiple masters. the smbus provides control of sda (serial data), scl (serial clock) generation and synchronization, arbitration logic, and start/stop control and generation. the smbus peripher als can be fully driven by software (i.e., software accepts/rejects slave addresses, and generates acks), or hardware slave address re cognition and automatic ack generation can be enabled to minimize software overhead . a block diagram of the smbus0 peripheral is shown in figure 29.1. figure 29.1. smbus0 block diagram smbus0 slave address recognition smb0dat master scl clock generation shift register sda scl state control logic si timers 0, 1 or 2 scl low timer 3 data / address
c8051f97x 344 rev 1.0 system management bus / i2c (smbus0) 29.1. supporting documents it is assumed the reader is fam iliar with or has access to th e following supporting documents: 1. the i 2 c-bus and how to use it (including sp ecifications), philips semiconductor. 2. the i 2 c-bus specification?version 2.0, philips semiconductor. 3. system management bu s specification?version 1. 1, sbs implementers forum. 29.2. smbus configuration figure 29.2 shows a typical smbus configuration. the sm bus specification allows any recessive voltage between 3.0 v and 5.0 v; different devices on the bus may operate at different voltage levels. however, the maximum voltage on any port pin must conform to the electrical characteristics specific ations. the bi-directional scl (serial clock) and sda (serial data) lines must be connected to a positive power supply voltage through a pullup resistor or similar circuit. every device connected to the bus must have an open-drain or open-collector output for both the scl and sda lines, so that both are pulled high (recessive state) when the bus is free. the maximum number of devices on the bus is limited only by t he requirement that the rise and fall times on the bus not exceed 300 ns and 1000 ns, respectively. figure 29.2. typical smbus configuration 29.3. smbus operation two types of data transfers are possible: data transfers from a master transmitter to an addressed slave receiver (write), and data transfers from an addressed slave trans mitter to a master receiver (read). the master device initiates both types of data transfers and provides the serial clock pulses on scl. the smbus interface may operate as a master or a slave, and multiple master de vices on the same bus are supported. if two or more masters attempt to initia te a data transfer simultaneously, an arbitrat ion scheme is employed with a single master always winning the arbitration. it is not necessary to spec ify one device as the master in a system; any device who transmits a start and a slave address becomes the master for the duration of that transfer. a typical smbus transaction consists of a start condit ion followed by an address byte (bits7?1: 7-bit slave address; bit0: r/w direction bit), one or more bytes of dat a, and a stop condition. bytes that are received (by a master or slave) are acknowledged (ack) with a low sd a during a high scl (see figure 29.3). if the receiving device does not ack, the transmitting device will read a nack (not acknowledge), wh ich is a high sda during a high scl. the direction bit (r/w) occupies the least-significant bit posi tion of the address byte. the direction bit is set to logic 1 to indicate a "read" operation and cleared to logic 0 to indicate a "write" operation. vdd = 3.6v master device slave device 1 slave device 2 vdd = 3v vdd = 3.8v vdd = 3v sda scl
c8051f97x rev 1.0 345 system management bus / i2c (smbus0) all transactions are initiated by a ma ster, with one or more addressed slav e devices as the target. the master generates the start condition and then transmits the sl ave address and direction bit. if the transaction is a write operation from the master to the slave, the master transmits the data a byte at a time waiting for an ack from the slave at the end of each byte. for read operat ions, the slave transmits the data waiting for an ack from the master at the end of each byte. at the end of the data transfer, the master generates a stop condition to terminate the transactio n and free the bus. figure 29.3 illu strates a typical smbus transaction. figure 29.3. smbus transaction 29.3.1. transmitter vs. receiver on the smbus communications interface, a device is the ?transmitter? when it is sending an address or data byte to another device on the bus. a device is a ?r eceiver? when an address or data byte is being sent to it from another device on the bus. the transmitter controls the sda lin e during the address or data byte. after each byte of address or data information is sent by the transmitter, the receiver sends an ack or nack bit during the ack phase of the transfer, during which ti me the receiver controls the sda line. 29.3.2. arbitration a master may start a transfer only if the bus is free. the bus is free after a stop condition or after the scl and sda lines remain high for a specified ti me (see section ?29.3.5. scl high (smb us free) timeout? on page 346). in the event that two or more devices attempt to begin a transf er at the same time, an arbi tration scheme is employed to force one master to give up the bus. the master devi ces continue transmitting unt il one attempts a high while the other transmits a low. since the bus is open-drain, the bus will be pulled low. th e master attempting the high will detect a low sda and lose the arbitration. the winning master continues its transmission without interruption; the losing master becomes a slave and receives the rest of the transfer if addressed. this arbitration scheme is non-destructive: one devic e always wins, and no data is lost. 29.3.3. clock low extension smbus provides a clock synchronization mechanism, similar to i2c, which allows devices with different speed capabilities to coexist on th e bus. a clock-low extension is used during a transfer in order to allow slower slave devices to communicate with faster masters. the slave ma y temporarily hold the scl line low to extend the clock low period, effectively decreasin g the serial clock frequency. 29.3.4. scl low timeout if the scl line is held low by a slave device on the bus, no further communication is possible. furthermore, the master cannot force the scl line high to correct the erro r condition. to solve this problem, the smbus protocol specifies that devices participating in a transfer must detect any clock cycle held low longer than 25 ms as a ?timeout? condition. devices that have detected the timeout condition must reset the communication no later than 10 ms after detecting the timeout condition. for the smbus0 interface, timer 3 is used to implement scl low timeouts. the scl low timeout feature is enabled by setting the smb0toe bit in smb0cf. the associated timer is forced to reload when scl is high, and allowed to count when scl is low. with the associated timer enab led and configured to overflow after 25 ms (and smb0toe set), the timer interrupt service routine can be used to reset (disable and re-enable) the smbus in the event of an scl low timeout. sla6 sda sla5-0 r/w d7 d6-0 scl slave address + r/w data byte start ack nack stop
c8051f97x 346 rev 1.0 system management bus / i2c (smbus0) 29.3.5. scl high (smbus free) timeout the smbus specification stipul ates that if the scl and sda lines remain high for more that 50 s, the bus is designated as free. when the smb0fte bit in smb0cf is set, the bus will be considered free if scl and sda remain high for more than 10 smbus clock source periods (as defined by the timer configured for the smbus clock source). if the smbus is waiting to generate a master star t, the start will be generated following this timeout. a clock source is required for free timeout det ection, even in a slave-only implementation. 29.4. using the smbus the smbus can operate in both master and slave modes. the interface provides timing and shifting control for serial transfers; higher level protocol is determined by user software. the smbus interface provides the following application-independent features: ?? byte-wise serial data transfers ?? clock signal generation on scl (master mode only) and sda data synchronization ?? timeout/bus error recognition, as defined by the smb0cf configuration register ?? start/stop timing, detection, and generation ?? bus arbitration ?? interrupt generation ?? status information ?? optional hardware recognition of slave address and automatic acknowledgement of address/data smbus interrupts are generated for each data byte or slave address that is transferred. when hardware acknowledgement is disabled, the point at which the inte rrupt is generated depends on whether the hardware is acting as a data transmitter or receiver. when a transm itter (i.e., sending address/data, receiving an ack), this interrupt is generated after the ack cycl e so that software may read the rece ived ack value; when receiving data (i.e., receiving address/data, sending an ack), this interr upt is generated before the ack cycle so that software may define the outgoing ack value. if hardware acknowledgement is enabled, these interrupts are always generated after the ack cycle. see section 29.5 for more details on transmission sequences. interrupts are also generated to indicate the beginning of a transfer when a master (start generated), or the end of a transfer when a slave (stop detected). software sh ould read the smb0cn (smbus control register) to find the cause of the smbus interrupt. table 29.5 provides a quick smb0cn decoding reference. 29.4.1. smbus conf iguration register the smbus configuration register (smb0cf) is used to enable the smbus master and/or slave modes, select the smbus clock source, and select the smbus timing and time out options. when the ensmb bit is set, the smbus is enabled for all master and slave events. slave events may be disabled by setting the inh bit. with slave events inhibited, the smbus interface will still monitor the scl and sda pins; however, the interface will nack all received addresses and will no t generate any slave interrupts. when the inh bit is set, all slave events will be inhibited following the next start (interrupts will c ontinue for the duration of the current transfer). table 29.1. smbus clock source selection smbcs smbus0 clock source 00 timer 0 overflow 01 timer 1 overflow 10 timer 2 high byte overflow 11 timer 2 low byte overflow
c8051f97x rev 1.0 347 system management bus / i2c (smbus0) the smbcs bit field selects the smbus clock source, which is used only when operating as a master or when the free timeout detection is enabled. when operating as a master, overflows from the selected source determine the absolute minimum scl low and high times as defined in equation 29.1.the selected clock source may be shared by other peripherals so long as the timer is left running at all times. equation 29.1. minimum scl high and low times the selected clock source should be configured to establish the minimum scl high and low times as per equation 29.1. when the interface is operating as a mast er (and scl is not driven or extended by any other devices on the bus), the typical smbus bit rate is approximated by equation 29.2. equation 29.2. typical smbus bit rate figure 29.4 shows the typical scl generation described by equation 29.2. notice that t high is typically twice as large as t low . the actual scl output may vary due to other de vices on the bus (scl may be extended low by slower slave devices, or dr iven low by contending master devices). th e bit rate when oper ating as a master will never exceed the limits defined by equation equation 29.1. figure 29.4. typical smbus scl generation setting the exthold bit extends the minimum setup and hold times for the sda lin e. the minimum sda setup time defines the absolute minimum time that sda is stable before scl transitions from low-to-high. the minimum sda hold time defines the absolute minimum time that th e current sda value remains st able after scl transitions from high-to-low. exthold should be set so that the minimum setup and hold times meet the smbus specification requirements of 250 ns and 300 ns, respectively. table 29.2 shows the minimum setup and hold times for the two exthold settings. setup and hold ti me extensions are typically necessary for smbus compliance when sysclk is above 10 mhz. table 29.2. minimum sda setup and hold times exthold minimum sda setup time minimum sda hold time 0 t low ? 4 system clocks or 1 system clock + s/w delay * 3 system clocks 1 11 system clocks 12 system clocks t highmin t lowmin 1 f clocksourceoverflow ---------------- ------------------ ----------- - == bitrate f clocksourceoverflow 3 --------------- ----------------- ------------- - = scl timer source overflows scl high timeout t low t high
c8051f97x 348 rev 1.0 system management bus / i2c (smbus0) with the smbtoe bit set, timer 3 should be configured to overflow after 25 ms in order to detect scl low timeouts (see section ?29.3.4. scl low timeou t? on page 345). the smbus interfac e will force the associated timer to reload while scl is high, and allow the timer to count when scl is low. the timer interrupt service routine should be used to reset smbus communication by disabling and re-enabling the smbus. smbus free timeout detec tion can be enabled by setting the smbfte bit. when this bit is set, the bus will be considered free if sda and scl remain high for more than 10 smbus clock source periods (see figure 29.4). 29.4.2. smbus pin swap the smbus peripheral is assigned to pins using the priori ty crossbar decoder. by default, the smbus signals are assigned to port pins starting with sda on the lower-nu mbered pin, and scl on the next available pin. the swap bit in the smbtc register can be set to 1 to reverse the order in which the smbus signals are assigned. 29.4.3. smbus timing control the sdd field in the smbtc register is used to restri ct the detection of a start condition under certain circumstances. in some systems where there is significant mis-match between the impedance or the capacitance on the sda and scl lines, it may be possible for scl to fall after sda during an address or data transfer. such an event can cause a false start detection on the bus. these kind of events are not expected in a standard smbus or i2c-compliant system. in most systems this parameter should not be adjusted, and it is recommended that it be left at its default value. by default, if the scl falling edge is detected after the falling e dge of sda (i.e. one sysclk cycle or more), the device will detect this as a start condition. the sdd fiel d is used to increase the am ount of hold time that is required between sda and scl falling be fore a start is recognized. an addi tional 2, 4, or 8 sysclks can be added to prevent false start detection in systems where the bus conditions warrant this. 29.4.4. smb0cn control register smb0cn is used to control the interface and to provid e status information. the higher four bits of smb0cn (master, txmode, sta, and sto) form a status vector that can be used to jump to service routines. master indicates whether a device is the master or slave duri ng the current transfer. txmode indicates whether the device is transmitting or receiving data for the current byte. sta and sto indicate that a start and/or stop has been detected or generated since the last smbus interrupt. sta and sto are also used to generate start and stop c onditions when operating as a master. writing a 1 to sta will cause the smbus interface to enter master mode and generate a start when the bus becomes free (sta is not cleared by hardware after the start is gener ated). writing a 1 to sto wh ile in master mode will cause the interface to generate a stop and end the current tran sfer after the next ack cycle. if sto and sta are both set (while in master mode), a stop followed by a start will be generated. the arblost bit indicates that the interface has lost an arbitration. this may occu r anytime the interface is transmitting (master or slave). a lost arbitration while operating as a slave indicates a bus error condition. arblost is cleared by hardware each time si is cleared. the si bit (smbus interrupt flag) is set at the beginning and end of each transfer, after each byte frame, or when an arbitration is lost; see table 29.3 for more details. important note about the si bit: the smbus interface is stalle d while si is set; thus scl is held low, and the bus is stalled until software clears si. note: setup time for ack bit transmissions and the msb of all da ta transfers. when using software acknowledgment, the s/ w delay occurs between the time smb0dat or ack is written and when si0 is cleared. note that if si is cleared in the same write that defines the outgoing ack value, s/w delay is zero. table 29.2. minimum sda setup and hold times exthold minimum sda setup time minimum sda hold time
c8051f97x rev 1.0 349 system management bus / i2c (smbus0) 29.4.4.1. software ack generation when the ehack bit in register smb0adm is cleared to 0, the firmware on th e device must detect incoming slave addresses and ack or nack the slave address and incoming data bytes. as a receiver, writing the ack bit defines the outgoing ack value; as a transmitter, reading the ac k bit indicates the value received during the last ack cycle. ackrq is set each time a byte is received, indicati ng that an outgoing ack value is needed. when ackrq is set, software should write the desir ed outgoing value to the ack bit before clearing si. a nack will be generated if software does not writ e the ack bit before clearing si. sda will reflect the defined ack value immediately following a write to the ack bit; howeve r scl will remain low until si is cleare d. if a received slave address is not acknowledged, further slave events will be ignored unt il the next start is detected. 29.4.4.2. hardwa re ack generation when the ehack bit in register smb0adm is set to 1, automatic slave address recognition and ack generation is enabled. more detail about automatic slave address recognition can be found in section 29.4.5. as a receiver, the value currently specified by the ack bit will be automatica lly sent on the bus during the ack cycle of an incoming data byte. as a transmitter, reading the ack bit indicates the value rece ived on the last ack cycle. the ackrq bit is not used when hardware ack generation is enabled. if a received slave address is nacked by hardware, further slave events will be ignore d until the next start is detected, and no interrupt will be generated. table 29.3 lists all sources for hardware changes to the smb0cn bits. refer to table 29.5 for smbus status decoding using the smb0cn register. table 29.3. sources for hardware changes to smb0cn bit set by hardware when: cleared by ha rdware when: master ?? a start is generated. ?? a stop is generated. ?? arbitration is lost. txmode ?? start is generated. ?? smb0dat is written before the start of an smbus frame. ?? a start is detected. ?? arbitration is lost. ?? smb0dat is not written before the start of an smbus frame. sta ?? a start followed by an address byte is received. ?? must be cleared by software. sto ?? a stop is detected while addressed as a slave. ?? arbitration is lost due to a detected stop. ?? a pending stop is generated. ackrq ?? a byte has been received and an ack response value is needed (only when hardware ack is not enabled). ?? after each ack cycle. arblost ?? a repeated start is detected as a master when sta is low (unwanted repeated start). ?? scl is sensed low while attempting to generate a stop or repeated start condition. ?? sda is sensed low while transmitting a 1 (excluding ack bits). ?? each time sin is cleared. ack ?? the incoming ack value is low ? (acknowledge). ?? the incoming ack value is high (not acknowledge).
c8051f97x 350 rev 1.0 system management bus / i2c (smbus0) 29.4.5. hardware slave address recognition the smbus hardware has the capabilit y to automatically recognize incomi ng slave addresses and send an ack without software intervention. automatic slave address recogn ition is enabled by setting the ehack bit in register smb0adm to 1. this will enable bo th automatic slave address recogn ition and automati c hardware ack generation for received bytes (as a master or slave). mo re detail on automatic hardware ack generation can be found in section 29.4.4.2. the registers used to define which address(es) are recognized by the hardware are the smbus slave address register and the smbus slave address mask register. a single address or range of addresses (including the general call address 0x00) can be specif ied using these two regist ers. the most-significant seven bits of the two registers are used to define which addresses will be acked. a 1 in a bit of the slave address mask slvm enables a comparison between the received slave address and the hard ware?s slave address slv for that bit. a 0 in a bit of the slave address mask means that bit will be treated as a ?don?t care ? for comparison purposes . in this case, either a 1 or a 0 value are acceptable on the incoming slave address . additionally, if the gc bi t in register smb0adr is set to 1, hardware will recognize the general call addr ess (0x00). table 29.4 show s some example parameter settings and the slave addresses that will be recognized by hard ware under thos e conditions. 29.4.6. data register the smbus data register smb0dat holds a byte of serial data to be transmitted or one that has just been received. software may safely read or write to the data regi ster when the si flag is set. software should not attempt to access the smb0dat register when the smbus is enabled and the si flag is cleared to logic 0, as the interface may be in the process of shifting a byte of data into or out of the register. data in smb0dat is always shif ted out msb first. after a byte has been rece ived, the first bit of received data is located at the msb of smb0dat. while da ta is being shifted out, data on the bus is simultaneously being shifted in. smb0dat always contains the last data byte present on the bus. in the event of lost arbitration, the transition from master transmitter to slave receiver is made with the correct data or address in smb0dat. si ?? a start has been generated. ?? lost arbitration. ?? a byte has been transmitted and an ack/ nack received. ?? a byte has been received. ?? a start or repeated start followed by a slave address + r/w has been received. ?? a stop has been received. ?? must be cleared by software. table 29.4. hardware address recognition examples (ehack = 1) hardware slave address slv slave address mask slvm gc bit slave addresses recognized by hardware 0x34 0x7f 0 0x34 0x34 0x7f 1 0x34, 0x00 (general call) 0x34 0x7e 0 0x34, 0x35 0x34 0x7e 1 0x34, 0x35, 0x00 (general call) 0x70 0x73 0 0x70, 0x74, 0x78, 0x7c table 29.3. sources for hardware changes to smb0cn bit set by hardware when: cleared by hardware when:
c8051f97x rev 1.0 351 system management bus / i2c (smbus0) 29.5. smbus transfer modes the smbus interface may be co nfigured to operate as mast er and/or slave. at any particular time, it will be operating in one of the following four modes: master trans mitter, master receiver, slave transmitter, or slave receiver. the smbus interface enters master mode any ti me a start is generated, and remains in master mode until it loses an arbitration or generates a stop. an sm bus interrupt is generated at the end of all smbus byte frames. the position of the ack interrupt when operat ing as a receiver depends on whether hardware ack generation is enabled. as a receiver, the interrupt for an ack occurs before the ack with hardware ack generation disabled, and after the ack when hardware ack generation is enabled. as a transmitter, interrupts occur after the ack, regardless of whether hardwar e ack generation is enabled or not. 29.5.1. write se quence (master) during a write sequence, an smbus mast er writes data to a slave device. t he master in this transfer will be a transmitter during the address byte, and a transmitter during all data bytes. the smbus interface generates the start condition and transmits the first byte containing the a ddress of the target slave and the data direction bit. in this case the data direction bit (r/w) will be logic 0 (write). the master then transmits on e or more bytes of serial data. after each byte is transmitted, an acknowledge bit is generated by the slave. the transfer is ended when the sto bit is set and a stop is generat ed. the interface will switch to master receiver mode if smb0dat is not written following a master transmitter interrupt. figure 29 .5 shows a typical master write sequence. two transmit data bytes are shown, though any number of bytes may be tran smitted. notice that all of the ?data byte transferred? interrupts occur after the ack cycle in this mode, regardless of whether hardware ack generation is enabled. figure 29.5. typical master write sequence a a a s w p data byte data byte sla s = start p = stop a = ack w = write sla = slave address received by smbus interface transmitted by smbus interface interrupts with hardware ack disabled (ehack = 0) interrupts with hardware ack enabled (ehack = 1)
c8051f97x 352 rev 1.0 system management bus / i2c (smbus0) 29.5.2. read sequence (master) during a read sequence, an smbus mast er reads data from a slave device. the master in this transfer will be a transmitter during the address byte, and a receiver during all data bytes. the smbus interface generates the start condition and transmits the first byte containing the a ddress of the target slave and the data direction bit. in this case the data direction bit (r/w) will be logic 1 (read). serial data is then rece ived from the slave on sda while the smbus outputs the serial clock. the slav e transmits one or more bytes of serial data. if hardware ack generation is disabled, the ackrq is set to 1 and an interrupt is generated after each received byte. software must write the ack bit at that time to ack or nack the received byte. with hardware ack generation enable d, the smbus hard ware will automatically gene rate the ack/nack, and then post the interrupt. it is important to note that the appropriate ack or nack value should be set up by the software prior to receiving the byte when hardware ack generation is enabled. writing a 1 to the ack bit generates an ack; writing a 0 generates a nack. software should write a 0 to the ack bit for the last data transfer, to transmit a nack. the interface exits master receiver mode after the sto bit is set and a stop is generated. the interfac e will switch to master transmitter m ode if smb0dat is written while an active master receiver. figure 29.6 shows a typical mast er read sequence. two received data bytes are shown, though any number of bytes may be received. notice that the ?data byte transferred? interrupts occur at different places in the sequence, depending on whether hardware ack generation is enabled. the interrupt occurs before the ack with hardware ack generation disabled, and after the ack when hardware ack generation is enabled. figure 29.6. typical master read sequence data byte data byte a n a s r p sla s = start p = stop a = ack n = nack r = read sla = slave address received by smbus interface transmitted by smbus interface interrupts with hardware ack disabled (ehack = 0) interrupts with hardware ack enabled (ehack = 1)
c8051f97x rev 1.0 353 system management bus / i2c (smbus0) 29.5.3. write sequence (slave) during a write sequence, an smbus ma ster writes data to a sl ave device. the slave in this transfer will be a receiver during the address byte, and a receiver during a ll data bytes. when slave events are enabled (inh = 0), the interface enters slave receiver mode when a start fo llowed by a slave address and direction bit (write in this case) is received. if hardware ack generation is disa bled, upon entering slave receiver mode, an interrupt is generated and the ackrq bit is set. the software must respond to the received slave address with an ack, or ignore the received slave ad dress with a nack. if hardware ack genera tion is enabled, the hardware will apply the ack for a slave address which ma tches the criteria set up by smb0 adr and smb0adm. the interrupt will occur after the ack cycle. if the received slave address is ignor ed (by software or hardwar e), slave interrupts will be inhibited until the next start is detected. if the received slave address is acknowledged, zero or more data bytes are received. if hardware ack generation is disabled, the ackrq is set to 1 and an interrupt is generated after each received byte. software must write the ack bit at that time to ack or nack the received byte. with hardware ack generation enable d, the smbus hard ware will automatically gene rate the ack/nack, and then post the interrupt. it is important to note that the appropriate ack or nack value should be set up by the software prior to receiving the byte when hardware ack generation is enabled. the interface exits slave receiver mo de after receiving a stop. the interf ace will switch to slave transmitter mode if smb0dat is written while an active slave receiver. figure 29.7 show s a typical slave write sequence. two received data bytes are shown, though any number of bytes may be received. notice that the ?data byte transferred? interrupts occur at different places in th e sequence, depending on whether hardware ack generation is enabled. the interrupt occurs before the ack with hardware ack generation disabled, and after the ack when hardware ack generation is enabled. figure 29.7. typical slave write sequence p w sla s data byte data byte a a a s = start p = stop a = ack w = write sla = slave address received by smbus interface transmitted by smbus interface interrupts with hardware ack disabled (ehack = 0) interrupts with hardware ack enabled (ehack = 1)
c8051f97x 354 rev 1.0 system management bus / i2c (smbus0) 29.5.4. read se quence (slave) during a read sequence, an smbus ma ster reads data from a slave device . the slave in this transfer will be a receiver during the address byte, and a transmitter during a ll data bytes. when slave events are enabled (inh = 0), the interface enters slave receiver mode (to receiv e the slave address) when a start followed by a slave address and direction bit (read in this case) is received. if hardware ack generation is disabled, upon entering slave receiver mode, an interrupt is generated and the ackrq bit is set. the software must respond to the received slave address with an ack, or ignore the received slave address with a nack. if hardware ack generation is enabled, the hardware will apply the ack for a slave address wh ich matches the criteria set up by smb0adr and smb0adm. the interr upt will occur after the ack cycle. if the received slave address is ignor ed (by software or hardwar e), slave interrupts will be inhibited until the next start is detected. if the received slave address is acknowle dged, zero or more data bytes are transmitted. if the received slave address is acknowledged, data should be written to smb0dat to be transmitted. the interface enters slave transmitter mode, and transmits one or more by tes of data. after each byte is transmitted, the master sends an acknowledge bit; if the acknowledge bit is an ack, smb0dat should be written with the next data byte. if the acknowledge bit is a nack, smb0dat should not be writ ten to before si is cleared (an error condition may be generated if smb0dat is wri tten following a received nack while in slave transmitter mode). the interface exits slave transmitter mode after receiving a stop. the interface will switch to slav e receiver mode if smb0dat is not written following a slave transmitter interrupt. figure 29.8 shows a typical slave read sequence. two transmitted data bytes are shown, though any number of bytes may be tran smitted. notice that all of the ?data byte transferred? interrupts occur after the ack cycle in this mode, regardless of whether hardware ack generation is enabled. figure 29.8. typical slave read sequence 29.6. smbus status decoding the current smbus status can be easily decoded using th e smb0cn register. the appropriate actions to take in response to an smbus event depend on whether hardwa re slave address recognition and ack generation is enabled or disabled. table 29.5 describes the typical ac tions when hardware slave address recognition and ack generation is disabled. table 29.6 describes the typica l actions when hardware slave address recognition and ack generation is enabled. in the tables, status vector refers to the four upper bits of smb0cn: master, txmode, sta, and sto. the shown response options are only the typical responses; application-specific procedures are allowed as long as they conform to the sm bus specification. highlighted responses are allowed by hardware but do not conform to the smbus specification. p r sla s data byte data byte a n a s = start p = stop n = nack r = read sla = slave address received by smbus interface transmitted by smbus interface interrupts with hardware ack disabled (ehack = 0) interrupts with hardware ack enabled (ehack = 1)
c8051f97x rev 1.0 355 system management bus / i2c (smbus0) table 29.5. smbus status decoding: hardware ack disabled (ehack = 0) mode values read current smbus state typical response options values to write next status vector expected status vector ackrq arblost ack sta sto ack master transmitter 1110 0 0 x a master start was generated. load slave address + r/w into smb0dat. 0 0 x 1100 1100 000 a master data or address byte was transmitted; nack received. set sta to restart transfer. 1 0 x 1110 abort transfer. 0 1 x ? 001 a master data or address byte was transmitted; ack received. load next data byte into smb0- dat. 0 0 x 1100 end transfer with stop. 0 1 x ? end transfer with stop and start another transfer. 1 1 x ? send repeated start. 1 0 x 1110 switch to master receiver mode (clear si without writing new data to smb0dat). 0 0 x 1000 master receiver 1000 1 0 x a master data byte was received; ack requested. acknowledge received byte; read smb0dat. 0 0 1 1000 send nack to indi cate last byte, and send stop. 0 1 0 ? send nack to indi cate last byte, and send stop followed by start. 1 1 0 1110 send ack followed by repeated start. 1 0 1 1110 send nack to indi cate last byte, and send repeated start. 1 0 0 1110 send ack and switch to master transmitter mode (write to smb0dat before clearing si). 0 0 1 1100 send nack and switch to mas- ter transmitter mode (write to smb0dat before clearing si). 0 0 0 1100
c8051f97x 356 rev 1.0 system management bus / i2c (smbus0) slave transmitter 0100 000 a slave byte was transmitted; nack received. no action required (expecting stop condition). 0 0 x 0001 001 a slave byte was transmitted; ack received. load smb0dat with next data byte to transmit. 0 0 x 0100 01x a slave byte was transmitted; error detected. no action required (expecting master to end transfer). 0 0 x 0001 0101 0 x x an illegal stop or bus error was detected while a slave transmission was in progress. clear sto. 0 0 x ? slave receiver 0010 10x a slave address + r/w was received; ack requested. if write, ackno wledge received address 0 0 1 0000 if read, load smb0dat with data byte; ack received address 0 0 1 0100 nack received address. 0 0 0 ? 11x lost arbitration as master; slave address + r/w received; ack requested. if write, ackno wledge received address 0 0 1 0000 if read, load smb0dat with data byte; ack received address 0 0 1 0100 nack received address. 0 0 0 ? reschedule failed transfer; nack received address. 1 0 0 1110 0001 00x a stop was detected while addressed as a slave transmitter or slave receiver. clear sto. 0 0 x ? 11x lost arbitration while attempting a stop. no action required (transfer complete/aborted). 0 0 0 ? 0000 1 0 x a slave byte was received; ack requested. acknowledge received byte; read smb0dat. 0 0 1 0000 nack received byte. 0 0 0 ? bus error condition 0010 0 1 x lost arbitration while attempting a repeated start. abort failed transfer. 0 0 x ? reschedule failed transfer. 1 0 x 1110 0001 0 1 x lost arbitration due to a detected stop. abort failed transfer. 0 0 x ? reschedule failed transfer. 1 0 x 1110 0000 1 1 x lost arbitration while transmitting a data byte as master. abort failed transfer. 0 0 0 ? reschedule failed transfer. 1 0 0 1110 table 29.5. smbus status decoding: hardware ack disabled (ehack = 0) (continued) mode values read current smbus state typical response options values to write next status vector expected status vector ackrq arblost ack sta sto ack
c8051f97x rev 1.0 357 system management bus / i2c (smbus0) table 29.6. smbus status decoding: hardware ack enabled (ehack = 1) mode values read current smbus state typical response options values to write next status vector expected status vector ackrq arblost ack sta sto ack master transmitter 1110 0 0 x a master start was generated. load slave address + r/w into smb0dat. 0 0 x 1100 1100 000 a master data or address byte was transmitted; nack received. set sta to restart transfer. 1 0 x 1110 abort transfer. 0 1 x ? 001 a master data or address byte was transmitted; ack received. load next data byte into smb0- dat. 0 0 x 1100 end transfer with stop. 0 1 x ? end transfer with stop and start another transfer. 1 1 x ? send repeated start. 1 0 x 1110 switch to master receiver mode (clear si without writing new data to smb0dat). set ack for initial data byte. 0 0 1 1000 master receiver 1000 001 a master data byte was received; ack sent. set ack for next data byte; read smb0dat. 0 0 1 1000 set nack to indicate next data byte as the last data byte; read smb0dat. 0 0 0 1000 initiate repeated start. 1 0 0 1110 switch to master transmitter mode (write to smb0dat before clearing si). 0 0 x 1100 000 a master data byte was received; nack sent (last byte). read smb0dat; send stop. 0 1 0 ? read smb0dat; send stop followed by start. 1 1 0 1110 initiate repeated start. 1 0 0 1110 switch to master transmitter mode (write to smb0dat before clearing si). 0 0 x 1100
c8051f97x 358 rev 1.0 system management bus / i2c (smbus0) slave transmitter 0100 000 a slave byte was transmitted; nack received. no action required (expecting stop condition). 0 0 x 0001 001 a slave byte was transmitted; ack received. load smb0dat with next data byte to transmit. 0 0 x 0100 01x a slave byte was transmitted; error detected. no action required (expecting master to end transfer). 0 0 x 0001 0101 0 x x an illegal stop or bus error was detected while a slave transmission was in progress. clear sto. 0 0 x ? slave receiver 0010 00x a slave address + r/w was received; ack sent. if write, set ack for first data byte. 0 0 1 0000 if read, load smb0dat with data byte 0 0 x 0100 01x lost arbitration as master; slave address + r/w rece ived; ack sent. if write, set ack for first data byte. 0 0 1 0000 if read, load smb0dat with data byte 0 0 x 0100 reschedule failed transfer 1 0 x 1110 0001 00x a stop was detected while addressed as a slave transmitter or slave receiver. clear sto. 0 0 x ? 01x lost arbitration while attempting a stop. no action required (transfer complete/aborted). 0 0 0 ? 0000 0 0 x a slave byte was received. set ack for next data byte; read smb0dat. 0 0 1 0000 set nack for next data byte; read smb0dat. 0 0 0 0000 bus error condition 0010 0 1 x lost arbitration while attempting a repeated start. abort failed transfer. 0 0 x ? reschedule failed transfer. 1 0 x 1110 0001 0 1 x lost arbitration due to a detected stop. abort failed transfer. 0 0 x ? reschedule failed transfer. 1 0 x 1110 0000 0 1 x lost arbitration while transmitting a data byte as master. abort failed transfer. 0 0 x ? reschedule failed transfer. 1 0 x 1110 table 29.6. smbus status decoding: hardware ack enabled (ehack = 1) (continued) mode values read current smbus state typical response options values to write next status vector expected status vector ackrq arblost ack sta sto ack
c8051f97x rev 1.0 359 system management bus / i2c (smbus0) 29.7. i2c / smbus control registers register 29.1. smb0cf: smbus 0 configuration bit 7 6 5 4 3 2 1 0 name ensmb inh busy exthold smbtoe smbfte smbcs type rw rw r rw rw rw rw reset00000000 sfr page = 0x0; sfr address: 0xc1 table 29.7. smb0cf register bit descriptions bit name function 7 ensmb smbus enable. this bit enables the smbus interface when set to 1. when enabled, the interface con - stantly monitors the sda and scl pins. 6 inh smbus slave inhibit. when this bit is set to logic 1, the smbus does not generate an interrupt when slave events occur. this effectively removes the smbus slave from the bus. master mode interrupts are not affected. 5 busy smbus busy indicator. this bit is set to logic 1 by hardware when a transfer is in progress. it is cleared to logic 0 when a stop or free-timeout is sensed. 4 exthold smbus setup and hold ti me extension enable. this bit controls the sda setup and hold times. 0: disable sda extended setup and hold times. 1: enable sda extended setup and hold times. 3 smbtoe smbus scl timeout detection enable. this bit enables scl low timeout detection. if se t to logic 1, the smbus forces timer 3 to reload while scl is high and allows timer 3 to count when scl goes low. if timer 3 is configured to split mode, only th e high byte of the timer is held in reload while scl is high. timer 3 should be programmed to gener ate interrupts at 25 ms, and the timer 3 interrupt service routine shou ld reset smbus communication. 2 smbfte smbus free timeout detection enable. when this bit is set to logic 1, the bus will be considered free if sc l and sda remain high for more than 10 smbus clock source periods. 1:0 smbcs smbus clock source selection. this field selects the smbus clock source, which is used to generate the smbus bit rate. see the smbus clock timing section for additional details. 00: timer 0 overflow. 01: timer 1 overflow. 10: timer 2 high byte overflow. 11: timer 2 low byte overflow.
c8051f97x 360 rev 1.0 system management bus / i2c (smbus0) register 29.2. smb0cn: smbus 0 control bit 7 6 5 4 3 2 1 0 name master txmode sta sto ackrq arblost ack si type r r rw rw r r rw rw reset00000000 sfr page = 0x0; sfr address: 0xc0 (bit-addressable) table 29.8. smb0cn register bit descriptions bit name function 7 master smbus master/slave indicator. this read-only bit indicates when the smbus is operating as a master. 0: smbus operating in slave mode. 1: smbus operating in master mode. 6 txmode smbus transmit mode indicator. this read-only bit indicates when the smbus is operating as a transmitter. 0: smbus in receiver mode. 1: smbus in transmitter mode. 5 sta smbus start flag. when reading sta, a '1' indicates that a start or repeated start condition was detected on the bus. writing a '1' to the sta bit initiates a start or repeated start on the bus. 4 sto smbus stop flag. when reading sto, a '1' indicates that a stop condition was detected on the bus (in slave mode) or is pending (in master mode). when acting as a master, writing a '1' to the st o bit initiates a stop condition on the bus. this bit is cleared by hardware. 3 ackrq smbus acknowledge request. 0: no ack requested. 1: ack requested. 2 arblost smbus arbitration lost indicator. 0: no arbitration error. 1: arbitration error occurred. 1 ack smbus acknowledge. when read as a master, the ack bit indica tes whether an ack (1) or nack (0) is received during the most recent byte transfer. as a slave, this bit should be written to send an ack (1) or nack (0) to a master request. note that the logic level of the ack bit on the smbus interface is inverted from the logic of the register ack bit.
c8051f97x rev 1.0 361 system management bus / i2c (smbus0) 0 si smbus interrupt flag. this bit is set by hardware to indicate that the current smbus state machine operation (such as writing a data or address byte) is co mplete. while si is set, scl is held low and smbus is stalled. si must be cleared by fi rmware. clearing si init iates the next smbus state machine operation. table 29.8. smb0cn register bit descriptions bit name function
c8051f97x 362 rev 1.0 system management bus / i2c (smbus0) register 29.3. smb0adr: smbus 0 slave address bit 7 6 5 4 3 2 1 0 name slv gc type rw rw reset00000000 sfr page = 0x0; sfr address: 0xf4 table 29.9. smb0adr register bit descriptions bit name function 7:1 slv smbus hardware slave address. defines the smbus slave address(es) for automatic hardware acknowledgement. only address bits which have a 1 in the corresponding bit position in slvm are checked against the incoming address. this allows multiple addresses to be recognized. 0 gc general call address enable. when hardware address recogn ition is enabled (ehack = 1), this bit will determine whether the general call address (0x00) is also recognized by hardware. 0: general call address is ignored. 1: general call address is recognized.
c8051f97x rev 1.0 363 system management bus / i2c (smbus0) register 29.4. smb0adm: smbus 0 slave address mask bit 7 6 5 4 3 2 1 0 name slvm ehack type rw rw reset11111110 sfr page = 0x0; sfr address: 0xf5 table 29.10. smb0adm register bit descriptions bit name function 7:1 slvm smbus slave address mask. defines which bits of register smb0adr are compared with an incoming address byte, and which bits are ignored. any bit set to 1 in slvm enables comparisons with the corre - sponding bit in slv. bits set to 0 are ignored (can be either 0 or 1 in the incoming address). 0 ehack hardware acknowledge enable. enables hardware acknowledgement of slave address and received data bytes. 0: firmware must manually acknowledge all incoming address and data bytes. 1: automatic slave address recognition and hardware acknowledge is enabled.
c8051f97x 364 rev 1.0 system management bus / i2c (smbus0) register 29.5. smb0dat: smbus 0 data bit 7 6 5 4 3 2 1 0 name smb0dat type rw reset00000000 sfr page = 0x0; sfr address: 0xc2 table 29.11. smb0dat register bit descriptions bit name function 7:0 smb0dat smbus 0 data. the smb0dat register contains a byte of data to be transmitted on the smbus serial interface or a byte that has just been rece ived on the smbus serial interface. the cpu can safely read from or write to this register whenever the si serial interrupt flag is set to logic 1. the serial data in the register remains stable as long as the si flag is set. when the si flag is not set, the system may be in the process of shifting data in/out and the cpu should not attempt to access this register.
c8051f97x rev 1.0 365 i2c slave 30. i 2 c slave the i2cslave0 interface is a 2-wire, bidirectiona l serial bus that is compatible with the i 2 c bus specification 3.0. it is capable of transferring in high-speed mode (hs-mode) at speeds of up to 3.4 mbps. either the cpu or the dma can write to the i 2 c interface, and the i 2 c interface can autonomous ly control the serial transfer of data. the interface also supports clock stretchi ng for cases where the cpu may be temporarily prohibited from transmitting a byte or processing a received byte during an i 2 c transaction. it can also operate in sleep mode without an active system clock and wake the cpu when a matching slave address is received. it operates only as an i 2 c slave device. the i2cslave0 peripheral pr ovides control of the scl (serial clock) synchronization, sda (serial da ta), scl clock stretching, i 2 c arbitration logic, and low power mode operation. the block diagram of the i2cslave0 peripheral and the associated sfrs is shown in figure 30.1 . figure 30.1. i2cslave0 block diagram i2c0slad i2c0din i2c0dout scl sda buffer_in buffer_out i2c0 slave control logic - scl synchronization - sda control - clock stretching - dma interface - hardware slave address recognition - automatic ack generation - irq generation - i2c pad selection - scl timeout detection (via timer 3) - high speed mode detection - wake-on-address-match operation during sleep mode - low power mode operation dma interface dma transfer from xram dma transfer to xram i2c pad control i2c0stat wr i2c0cntl sladdr6 sladdr5 sladdr4 sladdr3 sladdr2 sladdr1 sladdr0 hsmode active i2c0int nack start stop rd i2c0sel touten preloaddis i2c0en busy i 2 c interrupt and wake-up signalling
c8051f97x 366 rev 1.0 i2c slave 30.1. supporting documents it is assumed that the re ader is familiar or ha s access to the following supporting documents: ?? the i 2 c-bus specification and the user manual rev. 0.3. 30.2. the i 2 c configuration figure 30.2 shows a typical i 2 c configuration. the i 2 c specification allows any recessive voltage between 3.0 and 5.0 v; different devices on the bus may op erate at different voltage levels. note: the port pins on the c8051f97x devices are not 5 v tolerant, therefore, the device may only be used in i 2 c networks where the supply voltage does not exceed v dd . the bidirectional scl and sda lines mu st be connected to a positive power supply voltage through a pull-up resistor or similar circuit. every device connected to the bus must have an open-drain or open-collector output for both the scl and sda lines, so that both are pulled high (recessive state) when the bus is free. the maximum number of devices on the bus is limited only by the requir ement that the rise and fall times on the bus not exceed the specifications defined in the i 2 c standard. figure 30.2. typical i 2 c configuration 30.3. i2cslave0 operation the i2cslave0 peripheral supports two types of data transfers: i 2 c read data transfers where data is transferred from the c8051f97x?s i 2 c slave peripheral to an i 2 c master, and i 2 c write data transfers where data is transferred from an i 2 c master to the c8051f97x?s i 2 c slave peripheral. the i 2 c master initiates both types of data transfers and provides the serial clock pulses that the i 2 c slave peripheral detects on the scl pin. a typical i 2 c transaction consists of a start condition followed by an address byte (bits7-1: 7-bit slave address; bit0: r/w direction bit), one or more bytes of data, and a stop condition. bytes that are received are acknowledged (ack) with a low sda during a high scl (refer to figure 30.3 ). figure 30.3. i 2 c transaction vdd = 3 v master device slave device 1 slave device 2 vdd = 3 v vdd = 3 v vdd = 3 v sda scl sla6 sda sla5-0 r/w d7 d6-0 scl slave address + r/w data byte start ack nack stop
c8051f97x rev 1.0 367 i2c slave the direction bit (r/w) occupies the least-significant bit posi tion of the address byte. the direction bit is set to logic 1 to indicate a ?read? operation and cleared to logic 0 to indicate a ?write? operation. all transactions are initiated by a ma ster, with one or more addressed slav e devices as the target. the master generates the start condition and then transmits the sl ave address and direction bit. if the transaction is a write operation from the master to the slave, the master transmits the data a byte at a time waiting for an ack from the slave at the end of each byte. for read operat ions, the slave transmits the data waiting for an ack from the master at the end of each byte. at the end of the data transfer, the master generates a stop condition to terminate the transaction and free the bus. figure 30.3 illustrates a typical i 2 c transaction. 30.3.1. transmitter vs. receiver on the i 2 c communications interface, a device is the ?transmitter? when it is sending an address or data byte to another device on the bus. a device is a ?r eceiver? when an address or data byte is being sent to it from another device on the bus. the transmitter controls the sda lin e during the address or data byte. after each byte of address or data information is sent by the transmitter, the receiver sends an ack or nack bit during the ack phase of the transfer, during which ti me the receiver controls the sda line. 30.3.2. clock stretching the i 2 c bus specification provides transaction pause mech anism, which allows the slave device to force the master into a wait state until the slave device is ready fo r the next byte transaction. this is performed by the i 2 c slave holding the scl line low. hence, it is important that the master i 2 c device must not drive the scl line using a push-pull output. in the c8051f97x i2cslave0 peripheral, clock stretching is only performed on the scl falling edge associated with the ack or nack bit. clock stretching is always performed on every byte tr ansaction that is addressed to the i2cslave0 peripheral. clock stretching is completed by th e i2cslave0 peripheral when it releases the scl line from the low state. the i2cslave0 peripheral releases th e scl line when any one of the following conditions are met: ?? software writes a 0 to th e i2c0int bit in i2c0stat, ?? dma completes a data transfer to or from the i2cslave0 peripheral in response to a dma request from the i2cslave0 peripheral.
c8051f97x 368 rev 1.0 i2c slave 30.3.3. scl low timeout if the scl line is held low by a slave device on the bus, no further communication is possible. furthermore, the master cannot force the scl line high to correct the error condition. to solve this problem, the i2cslave0 peripheral supports a timeout feature to allow th e firmware to detect and handle this condition. this feature is enabled when the touten bit in i2c0cntl is set, and timer 3 is configured to run in 16-bit auto- reload mode (t3split set to 0 in tmr3cn). when this featur e is enabled, timer 3 is forced to reload when scl is high, and allowed to count when scl is low. with timer 3 enabled and configured to overflow after a system- defined time (and touten bit set), the timer 3 interrupt service routine can be used to detect and handle this error condition. 30.3.4. hs-mode the i 2 c specification supports high-speed mode (hs-mode) tran sfer which allows devices to transfer data at rates of up to 3.4 mbps and yet remain fully downwa rd compatible with slower speed devices. this allows hs-mode devices to operate in a mixed-speed bus system. refer to the i 2 c specification for details on the electrical and timing requirements for hs-mode operation. the i2cslave0 peripheral is compatible with the i 2 c hs-mode operation without any software intervention other than requiring that firmware enable the i2cslave0 peripheral. by default, the i 2 c bus operates at speeds of up to fast-mode (f/s mode) only, where the maximum transfer rate is 400 kbps. the i 2 c bus switches to from f/s mode to hs-mode on ly after the following sequence of bits appear on the i 2 c bus: 1. start bit (s) 2. 8-bit master code (0000 1xxx) 3. nack bit (n) the hs-mode master codes are reserved 8-bit codes whic h are not used for slave add ressing or other purposes. an hs-mode compatible i 2 c master device will switch the i 2 c bus to hs-mode by transmitting the above sequence of bits on the i 2 c bus at a transfer rate of not more than 400 kbps. after that, the master can switch to hs-mode to transfer data at a rate of up to 3.4 mbps. the i 2 c bus switches back to f/s mode when the i 2 c master transmits a stop bit. figure 30.4 shows this in clearer detail. figure 30.4. data transfer switching between f/s mode and hs-mode master code s n sr sla r/w a data+acks a/n p master code s n sr sla r/w a data+acks a/n sr sla r/w a p f/s-mode hs-mode f/s-mode hs-mode
c8051f97x rev 1.0 369 i2c slave 30.3.5. dma and cp u mode operations the i2cslave0 peripheral can operate in either cpu or dma mode. in cpu mode, all data transfers occur through software reading from the i2c0din register or writing to the i2c0dout register. by default, the i2cslave0 peripheral operates in cpu mode for all i 2 c read and write requests. in dma mode, all data transfers are executed by the dm a peripheral automatically without any cpu intervention. however, i2c0int must still be cleared by firmware after a start+sl ave address has been received. when a dma channel has been selected and enabled for data tr ansfer from i2c0din to xram , the i2cslave0 peripheral operates in dma mode for all i 2 c write requests. when a dma channel has been selected and enabled for data transfer from xram to i2c0dout, the i2cslave0 peripheral operates in dma mode for all i 2 c read requests. 30.4. using the i2cslave0 module i2cslave0 operates only in slave mode. the interface prov ides timing and shifting control for serial transfers; higher level protocol is determined by user software. the i 2 c interface provides the following application- independent features: ?? byte-wise serial data transfers ?? sda data synchronization ?? timeout recognition, as defined by the i2c0cntl configuration register ?? start/stop detection ?? interrupt generation ?? status information ?? interfacing to the dma to automate data transfers ?? high-speed i 2 c mode detection ?? automatic wakeup from sleep mode when matching slave address is received ?? hardware recognition of slave address and automatic acknowledgme nt of address/data an i2cslave0 interrupt is generated when the rd, wr or stop bit is set in the i2c0stat sfr. it is also generated when the active bit goes low to indicate the end of an i 2 c bus transfer. refer to the i2c0stat sfr definition for complete details on the conditi ons for the setting and clearing of these bits. 30.4.1. i2c0cntl control register the i2c0cntl register is used to control the i2cslave0 interface (see sfr definition 26.5). the two bits, i2c0sel and i2c0en, are used to enable and disable the i2cslave0 interface and associated pins. the i2cslave0 peripheral must be enabled in the following sequence: 1. set i2c0sel bit in the i2c0cntl sfr. 2. set i2c0en bit in the i2c0cntl sfr. this correct sequence of enabling the i2cslave0 ensures the peripheral processes the initial data transfers correctly. touten is used to enable the scl low timeout detection. refer to section scl low timeout for more details. preloaddis is used to contro l whether the data byte must be preloaded before the first scl clock of an i 2 c read transaction. it should always be set to 1. busy bit controls the automati c hardware acknowledgment of i 2 c slave address match or i 2 c write transactions. when cleared to 0, automatic hardware acknowledgment is enabled. 30.4.2. i2c0stat status register the i2c0stat register is used to provide status information (see sfr definition 26.4). the hsmode bit is used to indicate whether the i2c bus is operating in high-speed mode as defined in the i2c spec ification. this bit is set after the i2c bus is detected to be operating in hs-mode (refer to section hs-mode for details on how the i2c bus switch modes). when the i2c bus switches back to f/s-mode operation, the hsmode bit is cleared. the setting and clearing of the status bits are described in detail in section i2c transfer modes and the sfr definition 26.4.
c8051f97x 370 rev 1.0 i2c slave 30.4.3. i2c0slad slave address register the i2cslave0 peripheral can be configured to recogn ize a specific slave address and respond with an ack without any software intervention. this feature is enabled by software in the following sequence writes to the i2cslave0 registers; 1. clearing busy bit in i2c0cntl to enable automati c ack response. 2. writing the slave address to i2c0slad. 3. setting i2c0sel bit in i2c0cntl to enable the scl and sda pads. 4. setting i2c0en bit in i2c0cnt l to enable the i2cslave0 peripheral. 30.4.4. i2c0din received data register the i2c0din register holds the serial data that has just been received on the i 2 c bus and addressed to the local device. when the i2cslave0 is operating in cpu mode for i 2 c write operations, software may safely read from this register when the i2c0int flag is set. it is not safe to read from this register in any one of the following conditions: ?? the i2c0int flag is cleared to logic 0. ?? the i2cslave0 is operating in dma mode for i 2 c write operations. when the i2cslave0 is operating in dma mode for i 2 c write operations, software should access the received data from the xram where the dma has transferred the received data. 30.4.5. i2c0dout tran smit data register the i2c0dout register holds the serial data that is to be transmitted on the i 2 c bus. when the i2cslave0 is operating in cpu mode for i 2 c read operations, software may safely write to this register when the i2c0int flag is set. it is not safe to write to this regist er in any one of the following conditions: ?? the i2c0int flag is cleared to logic 0 ?? the i2cslave0 is operating in dma mode for i 2 c read operations when the i2cslave0 is operating in dma mode for i 2 c read operations, software should setup the data to be transmitted in xram and configure the dma to transfe r the data from xram to the i2c0dout register.
c8051f97x rev 1.0 371 i2c slave 30.5. i2c transfer modes the i2cslave0 interface may be operating in either i 2 c write or i 2 c read mode. data transfers can also be controlled by dma, depending on whether a dma channel has selected i 2 c read or write as a data transfer function. the following sub-sections describe in detail the setting and clearing of various status bits in the i2c0stat register during different modes of operations. in all modes, the i2cslave0 peripheral performs clock stretching automatically on every scl falling edge associated with the ack or nack bit. 30.5.1. i2c write se quence (cpu mode) figure 30.5 shows the details of how the i2c0stat status bits change during an i 2 c write data transfer. figure 30.5. typical i 2 c write sequence in cpu mode note that at ?f? in the above sequence, it is possible to l eave the busy bit at 0. in this case, the master will receive an ack instead at ?g? and it would still be possible for the i 2 c master to generate a stop bit immediately after the ack. sla a i2c0 module ? cpu mode ? clock stretch ? write sleep active s a db0 a db1 a db2 sr sla a n db3 p int 1 2 3 int int int int int 1 sla+w wakes cpu from sleep mode. automatic ack if busy was 0. 2 int generated ? starting clock stretch. cpu clears i2c0int, which releases scl 3 cpu fetches db0 from i2c0din; ack bit cleared to ?0?; cpu clears i2c0int, which releases scl 4 slave doesn?t care whether it generates nack or ack. state machine response is the same for both. stop bit (p) generates interrupt. no clock stretch. cpu clears i2c0int 5 4 5 a b c d f g a i2c0stat = x1101010; cpu clears start and i2c0int b c d f g h i2c0stat = x1100010; cpu fetches db0 from i2c0din and clears i2c0int i2c0stat = x1100010; cpu fetches db1 from i2c0din and clears i2c0int i2c0stat = x1100010; cpu fetches db2 from i2c0din and clears i2c0int i2c0stat = x1101010; cpu clears start and i2c0int; cpu writes ?1? to busy to nack future data transfers int h i2c0stat = x0100100; cpu clears stop and i2c0int i2c0stat = x1110010; cpu fetches db3 from i2c0din and clears i2c0int, nack; cpu writes ?0? to busy to ack future data transfers i2c0 int i2c0 int i2c0 int i2c0 int i2c0 int i2c0 int i2c0 int * at a, b, c, d, f, g : bits are set/cleared at 9 th scl falling edge. cpu clears i2c0int to release scl w w no int x no int x x i2c0stat = x1001000 at 8 th scl rising edge int e e i2c0stat = x0100000; cpu services end of transaction and clears i2c0int i2c0 int no int s = start p = stop a = ack n = nack r = read w = write sr = repeated start shaded blocks are generated by slave device
c8051f97x 372 rev 1.0 i2c slave 30.5.2. i 2 c read sequence (cpu mode) figure 30.6 shows the details of how the i2c0stat status bits change during an i 2 c read data transfer. figure 30.6. typical i2c read sequence in cpu mode note that the i 2 c master must always generate a nack before it can generate a repeated start bit or a stop bit. this is because the nack will cause the i 2 c slave to release the sda line for the i 2 c master to generate the start or stop bit. 30.5.3. i 2 c write sequence (dma mode) figure 30.7 shows the details of how the i2c0stat status bits change during an i 2 c write data transfer. sla a i2c0 module ? cpu mode ? clock stretch ? read sleep active s a db0 a db1 n db2 sr sla a n db3 p int 1 2 3 int 4 int int int int int 1 sla+r wakes cpu from sleep. sla is ack if busy was 0. 2 int generated. cpu writes db0 into i2c0dout. scl is held until cpu clears i2c0int. cpu clears i2c0int, releasing scl 3 scl held low; nack bit reads ?0?; cpu writes db1 into i2c0dout and clears i2c0int 4 nack switches i2c slave to idle state and generates int. any following db are ignored. if rpstart follows after nack, the start sticky bit will be set, but no interrupt. 5 stop generates interrupt. no clock stretch. cpu clears i2c0int 5 a b c d e f g a i2c0stat = x1101001; cpu clears start. cpu writes db0 into i2c0dout and clears i2c0int b i2c0stat = x1100001; cpu writes db1 into i2c0dout and clears i2c0int c i2c0stat = x1100001; cpu writes db2 into i2c0dout and clears i2c0int d i2c0stat = x0110001; cpu prepares for stop or rpstart and clears i2c0int and clears nack e f g i2c0stat = x0110001; cpu prepares for stop or rpstart and clears i2c0int and clears nack i2c0stat = x0100100; cpu clears stop and clears i2c0int i2c0stat = x1101001; cpu clears start. cpu writes db3 into i2c0dout and clears i2c0int i2c0 int i2c0 int i2c0 int i2c0 int i2c0 int i2c0 int i2c0 int * at a, b, c, d, e, f : bits are set/cleared at 9 th scl falling edge. cpu clears i2c0int to release scl r r no int x no int x x i2c0stat = x1001000 at 8 th scl rising edge no int s = start p = stop a = ack n = nack r = read w = write sr = repeated start shaded blocks are generated by slave device
c8051f97x rev 1.0 373 i2c slave figure 30.7. typical i 2 c write sequence in dma mode sla a i2c0 module ? dma mode ? clock stretch ? write sleep active s a db0 a db1 a db2 sr sla a a db3 p int 1 2 3 no int no int int int 1 sla+w wakes cpu from sleep mode. 2 int generated. cpu configures dma for i2c write. scl is held low until cpu clears i2c0int. 3 dma fetches db0 from i2c0din and asserts i2c_dma_ack which releases scl 4 dma generates ?done? interrupt. scl is released by assertion of i2c_dma_ack. cpu disables dma for i2c write. stop generates interrupt. no clock stretch. cpu clears i2c0int 5 4 5 a b c f g a i2c0stat = x1101010; cpu clears start; cpu configures dma for 4 bytes of i2c write transfer and clears i2c0int b c f g h i2c0stat = x1000000; dma transfers db0 from i2c0din to xram i2c0stat = x1000000; dma transfers db1 from i2c0din to xram i2c0stat = x1101010; cpu clears start; cpu configures dma for i2c write and clears i2c0int int h i2c0stat = x0100100; cpu clears stop and i2c0int. i2c0stat = x1000000; dma transfers db3 from i2c0din to xram. cpu services dma done interrupt no int no int dma int i2c0 int i2c0 int i2c0 int * at a, f: bits are set at 9 th scl falling edge. cpu clears i2c0int to release scl * at b, c, d, f, g: i2c_dma_req asserted on 9 th scl falling edge. i2c_dma_ack releases scl w w no int x no int x int e no int d x i2c0stat = x1001000 at 8 th scl rising edge no int d i2c0stat = x1000000; dma transfers db2 from i2c0din to xram no int e i2c0stat = x0100000; cpu services end of transaction and clears i2c0int i2c0 int s = start p = stop a = ack n = nack r = read w = write sr = repeated start shaded blocks are generated by slave device
c8051f97x 374 rev 1.0 i2c slave 30.5.4. i 2 c read sequence (dma mode) figure 30.8. typical i 2 c read sequence in dma mode sla a i2c0 module ? dma mode ? clock stretch ? read sleep active s a db0 a db1 n db2 sr sla a n db3 p int 1 2 3 no int 4 no int int int int int 1 sla+r wakes cpu from sleep mode. 2 int generated. cpu configures dma for i2c read. cpu performs sw dma request to transfer db0 from xram to i2c0dout. scl is held until cpu clears i2c0int. 3 dma transfers db1 from xram to i2c0dout and asserts i2c_dma_ack which releases scl 4 nack switches i2c slave into idle state. any following db are ignored. if rpstart follows nack, the start sticky bit will be set, but no interrupt. 5 stop generates interrupt. no clock stretch. cpu clears i2c0int 5 a b c d e f g a i2c0int = x1101001; cpu clears start. cpu configures dma for i2c read; cpu starts sw dma to transfer db0 from xram to i2cdout. cpu clears i2c0int b i2c0stat = x1000000; dma transfers db1 from xram to i2c0dout c i2c0stat = x1000000; dma transfers db2 from xram to i2c0dout d i2c0stat = x0110001; nack causes i2c to not generate i2c_dma_req. cpu clears i2c0int, nack. cpu disables dma. e f g i2c0stat = x0110001; nack causes i2c to not generate i2c_dma_req. cpu clears i2c0int, nack. cpu disables dma. i2c0stat = x0100100; cpu clears stop and clears i2c0int i2c0int = x1101001; cpu clears start. cpu configures dma for i2c read; cpu starts sw dma to transfer db3 from xram to i2cdout. cpu clears i2c0int no int no int i2c0 int i2c0 int i2c0 int i2c0 int i2c0 int * at a, d, e, f: bits are set at 9 th scl falling edge. scl released when cpu clear i2c0int * at b, c: i2c_dma_req asserted at 9 th scl falling edge. scl released by i2c_dma_ack r r 4 no int x no int x x i2c0int = x1001000 at 8 th scl rising edge no int s = start p = stop a = ack n = nack r = read w = write sr = repeated start shaded blocks are generated by slave device
c8051f97x rev 1.0 375 i2c slave 30.6. i2cslave0 slave registers register 30.1. i2c0din: i2c0 received data bit 7 6 5 4 3 2 1 0 name i2c0din type r reset 0 0 0 0 0 0 0 0 sfr page = 0xf; sfr address: 0xa5 bit name function 7:0 i2c0din i2c0 received data. this field is the data byte received fr om the i2c bus during a write operation.
c8051f97x 376 rev 1.0 i2c slave register 30.2. i2c0dout: i2c0 transmit data bit 7 6 5 4 3 2 1 0 name i2c0dout type rw reset 0 0 0 0 0 0 0 0 sfr page = 0xf; sfr address: 0xa4 bit name function 7:0 i2c0dout i2c0 transmit data. this field is the data byte to transmit to the i2c bus during a read operation.
c8051f97x rev 1.0 377 i2c slave register 30.3. i2c0slad: i2c0 slave address bit 7 6 5 4 3 2 1 0 name reserved i2c0slad type rw rw reset 0 0 0 0 0 0 0 0 sfr page = 0xf; sfr address: 0xad bit name function 7 reserved must write reset value. 6:0 i2c0slad i2c hardware slave address. this field defines the i2c0 slave addres s for automatic hardware acknowledgement. when the received i2c address matches this fi eld, hardware sets th e i2c0int bit in the i2c0stat register.
c8051f97x 378 rev 1.0 i2c slave register 30.4. i2c0stat: i2c0 status bit 7 6 5 4 3 2 1 0 name hsmode active i2c0int nack start stop wr rd type r r rw rw rw rw rw rw reset 0 0 0 0 0 0 0 0 sfr page = 0xf; sfr address: 0xf8 (bit-addressable) bit name function 7 hsmode high speed mode. this bit is set to 1 by hardware when a high speed master code is received received and automatically clears when a stop event occurs. 6 active bus active. this bit is set to 1 by hardware when an incoming slave address matches and automati - cally clears when the transfer completes with either a stop or a nack event. 5 i2c0int i2c interrupt. this bit is set when a read (rd), write (wr) , or a stop event (stop) occurs. this bit will also set when the active bit goes low to in dicate the end of a transfer. this bit will generate an in terrupt, and hardware will aut omatically clear this bit after the rd and wr bits clear. 4 nack nack. this bit is set by hardware when one of the following conditions are met: - a nack is transmitted by either a master or a slave when the active bit is high. - an i2c slave transmits a nack to a matching slave address. hardware will automatically clear this bit. 3 start start. this bit is set by hardware when a start is received and a matching slave address is received. hardware will au tomatically clear this bit. 2 stop stop. this bit is set by hardware when a stop is received and the last slave address received matches the value in the i2c0slad register . hardware will automatically clear this bit. 1 wr i2c write. this bit is set by hardware on the 9th scl falling edge when one of the following condi - tions are met: - the i2c0 slave responds with an ack, and the dma has not enabled i2c write as a data transfer function. - the i2c0 slave responds with a nack, and the dma has not enabled i2c write as a data transfer function. - the current byte transaction has a matching i2c0 slave address and the 8th bit was a write bit (0). this bit will set the i2c0int bi t and generate an interrupt, if enabled. hardware will auto - matically clear this bit.
c8051f97x rev 1.0 379 i2c slave 0 rd i2c read. this bit is set by hardware on the 9th scl falling edge when one of the following condi - tions are met: - the i2c master responds with an ack, an d the dma has not enabled i2c0 slave read as a data transfer function. - i2c master responds with a nack. - the current byte transaction has a matching i2c slave address and the 8th bit was a read bit (1). this bit will set the i2c0int bi t and generate an interrupt, if enabled. hardware will auto - matically clear this bit. bit name function
c8051f97x 380 rev 1.0 i2c slave register 30.5. i2c0cn: i2c0 control bit 7 6 5 4 3 2 1 0 name reserved puen pinmd timeout preload i2c0en busy type r rw rw rw rw rw rw reset 0 0 0 0 0 1 0 1 sfr page = 0xf; sfr address: 0xac bit name function 7:6 reserved must write reset value. 5 puen i2c pull-up enable. 0: disable internal pull-up resistors for the i2c0 slave scl and sda pins. 1: enable internal pull-up resistors for the i2c0 slave scl and sda pins. 4 pinmd pin mode enable. 0: set the i2c0 slave pins in gpio mode. 1: set the i2c0 slave pins in i2c mode. 3 timeout timeout enable. when this bit is set, timer 3 will start counting only when scl is low. when scl is high, timer 3 will auto-reload with the value from the reload registers. timer 3 must be config - ured for 16-bit auto-reload mode. 0: disable i2c scl timeout detection using timer 3. 1: enable i2c scl timeout detection using timer 3. 2 preload preload disable. 0: data bytes must be written into the i2c0do ut register before the 8th scl clock of the matching slave address byte transfer arrives for an i2c read operation. 1: data bytes need not be preloaded for i2c read operations. the data byte can be writ - ten to i2c0dout duri ng interrupt servic ing or by the dma. 1 i2c0en i2c enable. this bit enables the i2c0 slave module. pinmd must be enabled first before this bit is enabled. 0: disable the i2c0 slave module. 1: enable the i2c0 slave module. 0 busy busy. 0: device will acknow ledge an i2c master. 1: device will not respond to an i2c master . all i2c data sent to the device will be nacked.
c8051f97x rev 1.0 381 universal asynchronous r eceiver/transmitter (uart0) 31. universal asynchronous receiver/transmitter (uart0) uart0 is an asynchronous, full duplex serial port offe ring modes 1 and 3 of the standard 8051 uart. enhanced baud rate support allows a wide range of clock sources to generate standard baud rates (details in section ?31.1. enhanced baud rate generation? on page 381). rece ived data buffering allows uart0 to start reception of a second incoming data byte before software has finished reading the previous data byte. uart0 has two associated sfrs: serial control register 0 (scon0) and serial data buffer 0 (sbuf0). the single sbuf0 location provides access to both transmit and receive registers. writes to sbuf0 always access the transmit register. reads of sbuf0 always access the buffered receive register; it is not possible to read data from the transmit register. with uart0 interrupts enabled, an interrupt is generated each time a transmit is comple ted (ti is set in scon0), or a data byte has been received (ri is set in scon0). the uart0 interrupt flags are not cleared by hardware when the cpu vectors to the interrupt service routine. they must be cl eared manually by software, allowing soft- ware to determine the cause of the uart0 interrupt (transmit complete or receive complete). figure 31.1. uart0 block diagram 31.1. enhanced ba ud rate generation the uart0 baud rate is generated by timer 1 in 8-bit au to-reload mode. the tx clock is generated by tl1; the rx clock is generated by a copy of tl 1 (shown as rx timer in figure 31.2), wh ich is not user-accessible. both tx and rx timer overflows are divided by two to generate the tx and rx baud rates. the rx timer runs when timer 1 is enabled, and uses the same reload value (th1). however, an rx timer reload is forced when a start condition is detected on the rx pin. th is allows a receive to begin any time a start is detected, independent of the tx timer state. uart0 sbuf (8 lsbs) input shift register rx baud rate generator (timer 1) start detection output shift register tx tb8 (9 th bit) rb8 (9 th bit) control / configuration ti, ri interrupts tx clk rx clk
c8051f97x 382 rev 1.0 universal asynchronous receiver/transmitter (uart0) figure 31.2. uart0 baud rate logic timer 1 should be configured for mode 2, 8-bit auto-reload. the timer 1 reload value should be set so that overflows will occur at two times the desi red uart baud rate frequency. note that timer 1 may be clocked by one of six sources: sysclk, sysclk/4, sysc lk/12, sysclk/48, the exte rnal oscillator clock/8, or an external input t1. for any given timer 1 overflow rate, the uart0 baud rate is determined by equation 31.1. equation 31.1. uart0 baud rate timer 1 overflow rate is selected as described in the timer section. a quick reference for typical baud rates and system clock frequencies is given in table 31.1. start detection tx clock 2 rx clock 2 tl1 th1 rx timer baud rate generator (in timer 1) uartbaudrate 1 2 -- - t1_overflow_rate ? =
c8051f97x rev 1.0 383 universal asynchronous r eceiver/transmitter (uart0) 31.2. operational modes uart0 provides standard asynchronous, full duplex communicati on. the uart mode (8-bit or 9-bit) is selected by the s0mode bit in register scon. 31.2.1. 8-bit uart 8-bit uart mode uses a total of 10 bits per data byte: one start bit, eight data bits (lsb first), and one stop bit. data are transmitted lsb first from the tx pin and received at the rx pin. on receive, the eight data bits are stored in sbuf0 and the stop bit goes into rb8 in the scon register. data transmission begins when software writes a data byte to the sbuf0 register. the ti transmit interrupt flag is set at the end of the transmission (the beginning of the stop -bit time). data reception can begin any time after the ren receive enable bit is set to logic 1. after the stop bi t is received, the data byte will be loaded into the sbuf0 receive register if the following conditions are met: ri must be logic 0, and if mce is logic 1, the stop bit must be logic 1. in the event of a receive data overrun, the first received 8 bits are latched into the sbuf0 receive register and the following overrun data bits are lost. if these conditions are met, the eight bits of data is stored in sbuf0, the stop bit is stored in rb8 and the ri flag is set. if these conditions are not met, sbuf0 and rb8 will not be loaded and the ri flag will not be set. an interrupt will occur if enabled when either ti or ri is set. figure 31.3. 8-bit uart timing diagram d1 d0 d2 d3 d4 d5 d6 d7 start bit mark stop bit bit times bit sampling space
c8051f97x 384 rev 1.0 universal asynchronous receiver/transmitter (uart0) 31.2.2. 9-bit uart 9-bit uart mode uses a total of eleven bits per data by te: a start bit, 8 data bits (lsb first), a programmable ninth data bit, and a stop bit. the state of the ninth transmit data bit is determined by the val ue in tb8, which is assigned by user software. it can be assigned the value of the parity flag (bit p in register psw) for error detection, or used in multiprocessor comm unications. on receive, the ninth data bit g oes into rb8 and the stop bit is ignored. data transmission begins when an instruction writes a data byte to the sbuf0 register. the ti transmit interrupt flag is set at the end of the transmission (the beginning of the stop-bit time). data reception can begin any time after the ren receive enable bit is se t to 1. after the stop bit is received , the data byte will be loaded into the sbuf0 receive register if the following conditions are met: (1 ) ri must be logic 0, and (2 ) if mce is logic 1, the 9th bit must be logic 1 (when mce is logic 0, the state of the ninth data bit is unimportant). if these conditions are met, the eight bits of data are stored in sbuf0, the ninth bit is stored in rb8, and the ri flag is set to 1. if the above conditions are not met, sbuf0 and rb 8 will not be loaded and the ri flag will no t be set to 1. a uart0 interrupt will occur if enabled when either ti or ri is set to 1. figure 31.4. 9-bit uart timing diagram d1 d0 d2 d3 d4 d5 d6 d7 start bit mark stop bit bit times bit sampling space d8
c8051f97x rev 1.0 385 universal asynchronous r eceiver/transmitter (uart0) 31.3. multiprocessor communications 9-bit uart mode supports multiprocessor communication between a master processor and one or more slave processors by special use of the ninth data bit. when a ma ster processor wants to transmit to one or more slaves, it first sends an address byte to select the target(s). an add ress byte differs from a data byte in that its ninth bit is logic 1; in a data byte, the ninth bit is always set to logic 0. setting the mce bit of a slave processor configures its ua rt such that when a stop bit is received, the uart will generate an interrupt only if the ninth bit is logic 1 (rb8 = 1) signifying an address byte has been received. in the uart interrupt handler, software will compare the received addr ess with the slave's own a ssigned 8-bit address. if the addresses match, the slave will clear its mce bit to e nable interrupts on the rec eption of the following data byte(s). slaves that weren't address ed leave their mce bits set and do not gen erate interrupts on the reception of the following data bytes, thereby ignoring the data. once the entire message is received, the addressed slave resets its mce bit to ignore all transmissions until it receives the next address byte. multiple addresses can be assigned to a single slave and/ or a single address can be assigned to multiple slaves, thereby enabling "broadcast" transmissions to more than one slave simultaneously. the master processor can be configured to receive all transmissions or a protocol ca n be implemented such that the master/slave role is temporarily reversed to enable half-duplex transm ission between the original master and slave(s). figure 31.5. uart multi-processor mode interconnect diagram master device slave device tx rx rx tx slave device rx tx slave device rx tx v+
c8051f97x 386 rev 1.0 universal asynchronous receiver/transmitter (uart0) table 31.1. timer settings for standard baud rates using the internal 24.5 mhz oscillator frequency: 49 mhz target baud rate (bps) baud rate % error oscillator divide factor timer clock source sca1?sca0 (pre-scale select) 1 t1m 1 timer 1 reload value (hex) sysclk from internal osc. 230400 ?0.32% 106 sysclk xx 2 1 0xcb 115200 ?0.32% 212 sysclk xx 1 0x96 57600 0.15% 426 sysclk xx 1 0x2b 28800 ?0.32% 848 sysclk/4 01 0 0x96 14400 0.15% 1704 sysclk/12 00 0 0xb9 9600 ?0.32% 2544 sysclk/12 00 0 0x96 2400 ?0.32% 10176 sysclk/48 10 0 0x96 1200 0.15% 20448 sysclk/48 10 0 0x2b notes: 1. sca1 ? sca0 and t1m bit definitions can be found in timer1 chapter. 2. x = don?t care.
c8051f97x rev 1.0 387 universal asynchronous r eceiver/transmitter (uart0) 31.4. uart control registers register 31.1. scon0: uart0 serial port control bit 7 6 5 4 3 2 1 0 name smode reserved mce ren tb8 rb8 ti ri typerw r rwrwrwrwrwrw reset01000000 sfr page = all; sfr address: 0x98 (bit-addressable) table 31.2. scon0 register bit descriptions bit name function 7 smode serial port 0 operation mode. selects the uart0 operation mode. 0: 8-bit uart with variable baud rate (mode 0). 1: 9-bit uart with variable baud rate (mode 1). 6 reserved must write reset value. 5 mce multiprocessor communication enable. this bit enables checking of the stop bit or the 9th bit in multi-drop communication buses. the function of this bit is dependent on the uart0 operation mode selected by the smode bit. in mode 0 (8-bits), the peripheral will check that t he stop bit is logic 1. in mode 1 (9-bits) the peripheral will ch eck for a logic 1 on the 9th bit. 0: ignore level of 9th bit / stop bit. 1: ri is set and an interrupt is generated only when the stop bit is logic 1 (mode 0) or when the 9th bit is logic 1 (mode 1). 4 ren receive enable. 0: uart0 reception disabled. 1: uart0 reception enabled. 3 tb8 ninth transmission bit. the logic level of this bit will be sent as th e ninth transmission bit in 9-bit uart mode (mode 1). unused in 8-bit mode (mode 0). 2 rb8 ninth receive bit. rb8 is assigned the value of the stop bit in mode 0; it is assigned the value of the 9th data bit in mode 1. 1 ti transmit interrupt flag. set by hardware when a byte of data has been transmitted by uart0 (after the 8th bit in 8-bit uart mode, or at the beginning of the stop bit in 9-bit uart mode). when the uart0 interrupt is enabled, setting this bit ca uses the cpu to vector to the uart0 inter - rupt service routine. this bit must be cleared manually by firmware.
c8051f97x 388 rev 1.0 universal asynchronous receiver/transmitter (uart0) 0 ri receive interrupt flag. set to 1 by hardware when a byte of data has been received by uart0 (set at the stop bit sampling time). when the uart0 interrupt is enabled, setting this bit to 1 causes the cpu to vector to the uart0 in terrupt service routine. this bit must be cleared manually by firmware. table 31.2. scon0 register bit descriptions bit name function
c8051f97x rev 1.0 389 universal asynchronous r eceiver/transmitter (uart0) register 31.2. sbuf0: uart0 serial port data buffer bit 7 6 5 4 3 2 1 0 name sbuf0 type rw reset00000000 sfr page = 0x0; sfr address: 0x99 table 31.3. sbuf0 register bit descriptions bit name function 7:0 sbuf0 serial data buffer. this sfr accesses two registers; a transmit shift register and a receive latch register. when data is written to sbuf0, it goes to the transmit shift register and is held for serial transmission. writing a byte to sbuf0 in itiates the transmission. a read of sbuf0 returns the contents of the receive latch.
c8051f97x 390 rev 1.0 timers (timer0, timer1, timer2, and timer3) 32. timers (timer0, timer1, timer2, and timer3) each mcu in the c8051f97x family includes four counte r/timers: two are 16-bit counter/timers compatible with those found in the standard 8051, and two are 16-bit auto-reload timers for timing peripherals or for general purpose use. these timers can be used to measure time intervals, count ex ternal events and generate periodic interrupt requests. timer 0 and timer 1 are nearly identi cal and have four primary modes of operation. timer 2 and timer 3 are also identical and offer bo th 16-bit and split 8-bit timer functionality wit h auto-reload capabilities. timer 2 and timer 3 both offer a capture function, but ar e different in their system-lev el connections. timer 2 is capable of performing a capture function on an external signal input routed through the crossbar, while the timer 3 capture is dedicated to the lo w-frequency oscillator output. table 32.1 summarizes the modes available to each timer. timers 0 and 1 may be clocked by one of five sour ces, determined by the timer mode select bits (t1m ? t0m) and the clock scale bits (sca1 ? sca0). the clock scale bits define a pres caled clock from which timer 0 and/or timer 1 may be clocked. timer 0/1 may then be configured to use this prescaled clock signal or the system clock. timer 2 and timer 3 may be clocked by the system clock, the system clock divided by 12, or the external oscillato r clock source divided by 8. timer 0 and timer 1 may also be operated as counters. when functioning as a counter, a counter/timer register is incremented on each high-to-low transition at the selected input pin (t0 or t1). events with a frequency of up to one-fourth the system clock frequency can be counted. the i nput signal need not be periodic, but it must be held at a given level for at least two full system clock c ycles to ensure the leve l is properly sampled. all four timers are capable of clocki ng other peripherals and triggering events in the system. the individual peripherals select which timer to use for their respec tive functions. table 32.2 summarizes the peripheral connections for each timer. note that the timer 2 and timer 3 high overflows apply to the full timer when operating in 16-bit mode or the high-byte timer when operating in 8-bit split mode. table 32.1. timer modes timer 0 and timer 1 modes timer 2 modes timer 3 modes 13-bit counter/timer 16-bit timer with auto-reload 16-bit timer with auto-reload 16-bit counter/timer two 8-bit timers with auto-reload two 8-bit timers with auto-reload 8-bit counter/timer with auto-reload two 8-bit counter/timers (timer 0 only) table 32.2. timer peripheral clocking / event triggering function t0 overflow t1 overflow t2 high overflow t2 low overflow t3 high overflow t3 low overflow uart0 baud rate x smbus0 clock rate x x x x smbus0 scl low timeout x pca0 clock x adc0 conversion start x x* x* x* x* *note: the high-side overflow is used when the timer is in16-bit mode. the low-side overflow is used in 8-bit mode.
c8051f97x rev 1.0 391 timers (timer0, timer1, timer2, and timer3) 32.1. timer 0 and timer 1 timer 0 and timer 1 are each implemented as a16-bit regist er accessed as two separate bytes: a low byte (tl0 or tl1) and a high byte (th0 or th1). the counter/timer c ontrol register (tcon) is used to enable timer 0 and timer 1 as well as indicate status. timer 0 interrupts can be enabled by setting the et0 bit in the ie register. timer 1 interrupts can be enabled by setting the et1 bit in the ie register. both counter/timers operate in one of four primary modes selected by setting the mode select bits t1m1 ? t0m0 in the counter/timer mode register (tmod). each timer can be configured independently for the operating modes described below.
c8051f97x 392 rev 1.0 timers (timer0, timer1, timer2, and timer3) 32.1.1. mode 0: 13 -bit counter/timer timer 0 and timer 1 operate as 13-bit counter/timers in mode 0. the following describes the configuration and operation of timer 0. however, both timers operate identic ally, and timer 1 is configured in the same manner as described for timer 0. the th0 register holds the eight msbs of the 13-bit count er/timer. tl0 holds the five lsbs in bit positions tl0.4 ? tl0.0. the three upper bits of tl0 (tl0.7 ? tl0.5) are indeterminate and should be masked out or ignored when reading. as the 13-bit timer register increments and over flows from 0x1fff (all ones) to 0x0000, the timer overflow flag tf0 in tcon is set and an interrupt will occur if timer 0 in terrupts are enabled. the ct0 bit in the tmod register selects the counter/timer' s clock source. when ct0 is set to logic 1, high-to-low transitions at the selected timer 0 input pin (t0) incremen t the timer register. clearing ct selects the clock defined by the t0m bit in register ckcon. when t0m is set, timer 0 is clocked by th e system clock. when t0m is cleared, timer 0 is clocked by the source sele cted by the clock scale bits in ckcon. setting the tr0 bit enables the timer when either gate0 in the tmod register is logic 0 or the input signal int0 is active as defined by bit in0pl in register it01cf. setting gate0 to 1 allows the timer to be controlled by the external input signal int0 , facilitating pulse width measurements setting tr0 does not force the timer to reset. the timer registers should be loaded with the desired initial value before the timer is enabled. tl1 and th1 form the 13-bit register for timer 1 in the same manner as described above for tl0 and th0. timer 1 is configured and controlled using the relevant tcon and tmod bits just as with timer 0. the input signal int1 is used with timer 1; the /int1 polarity is defined by bit in1pl in register it01cf. figure 32.1. t0 mode 0 block diagram 32.1.2. mode 1: 16 -bit counter/timer mode 1 operation is the same as mode 0, except that the counter/timer registers use all 16 bits. the counter/timers are enabled and configured in mode 1 in the same manner as for mode 0. tr0 gate0 int0 counter/timer 0 x x disabled 1 0 x enabled 1 1 0 disabled 1 1 1 enabled note: x = don't care tclk tr0 0 1 0 1 sysclk pre-scaled clock gate0 in0pl xor t0m t0 int0 ct0 tl0 (5 bits) th0 (8 bits) tf0 (interrupt flag)
c8051f97x rev 1.0 393 timers (timer0, timer1, timer2, and timer3) 32.1.3. mode 2: 8-bit counter/timer with auto-reload mode 2 configures timer 0 and timer 1 to operate as 8-bit counter/timers with automatic reload of the start value. tl0 holds the count and th0 holds the reload value. when the counter in tl0 overflows from all ones to 0x00, the timer overflow flag tf0 in the tcon register is set and the counter in tl0 is reloaded from th0. if timer 0 interrupts are enabled, an interrupt will occur when the tf0 flag is set. the reload value in th 0 is not c hanged. tl0 must be initialized to the desired value before enabling t he timer for the first count to be correct. when in mode 2, timer 1 operates identically to timer 0. both counter/timers are enabled and configured in mode 2 in the same manner as mode 0. setting the tr0 bit enables the timer when either gate0 in the tmod re gister is logic 0 or when the input signal int0 is active as defined by bit in0pl in register it01cf. figure 32.2. t0 mode 2 block diagram reload tl0 (8 bits) th0 (8 bits) tf0 (interrupt flag) tclk tr0 0 1 0 1 sysclk pre-scaled clock gate0 in0pl xor t0m t0 int0 ct0
c8051f97x 394 rev 1.0 timers (timer0, timer1, timer2, and timer3) 32.1.4. mode 3: two 8-bit counter/timers (timer 0 only) in mode 3, timer 0 is configured as two separate 8-bit co unter/timers held in tl0 and th0. the counter/timer in tl0 is controlled using the timer 0 c ontrol/status bits in tcon and tmod : tr0, ct0, gate0 and tf0. tl0 can use either the system clock or an external input signal as its timebase. the th0 register is restricted to a timer function sourced by the system clock or prescaled clock. th0 is enabled usin g the timer 1 run control bit tr1. th0 sets the timer 1 overflow flag tf1 on overflow and thus controls the timer 1 interrupt. timer 1 is inactive in mode 3. when timer 0 is operating in mode 3, timer 1 can be operated in modes 0, 1 or 2, but cannot be clocked by external signals nor set the tf 1 flag and generate an interrupt. however, the timer 1 overflow can be used to generate baud rates for the smbu s and/or uart, and/or initiate adc conversions. while timer 0 is operating in mode 3, timer 1 run control is handled through its mode settings. to run timer 1 while timer 0 is in mode 3, set the timer 1 mode as 0, 1, or 2. to disable timer 1, configure it for mode 3. figure 32.3. t0 mode 3 block diagram tclk tr0 0 1 0 1 sysclk pre-scaled clock gate0 in0pl xor t0m t0 int0 ct0 tr1 tl0 (8 bits) tf0 (interrupt flag) th0 (8 bits) tf1 (interrupt flag)
c8051f97x rev 1.0 395 timers (timer0, timer1, timer2, and timer3) 32.2. timer 2 timer 2 is a 16-bit timer formed by two 8-bit sfrs: tmr2l (low byte) and tmr2h (high byte). timer 2 may operate in 16-bit auto-reload mode or (split) 8-bit auto-reload mode. the t2split bit in tmr2cn defines the timer 2 oper - ation mode. timer 2 can also be used in capture mode to measure the smartclock or the comparator 0 period with respect to an other oscillator. the ability to meas ure the comparator 0 period with respect to the system clock makes using touch sense switches very easy. timer 2 may be clocked by the system cl ock, the system clock divided by 12, smartclock divided by 8, or comparator 0 output. note that the smartclock divided by 8 and comparator 0 output is synchronized with the system clock. 32.2.1. 16-bit timer with auto-reload when t2split in the tmr2cn register is zero, timer 2 operates as a 16-bit timer with auto-reload. timer 2 can be clocked by sysclk, sysclk divided by 12 , smartclock divided by 8, or comparator 0 output. as the 16-bit timer register increments and overflows from 0xffff to 0x 0000, the 16-bit value in the timer 2 reload registers (tmr2rlh and tmr2rll) is loaded into the timer 2 register as shown in figure 32.4 , and the timer 2 high byte overflow flag (tmr2cn.7) is set. if timer 2 interrupts are enabled (i f ie.5 is set), an inte rrupt will be generated on each timer 2 overflow. additionally, if timer 2 interrupts are enabled and the tf2lint bit is se t, an interrupt will be generated each time the lower 8 bits (tmr2l) overflow from 0xff to 0x00. figure 32.4. timer 2 16-bit mode block diagram sysclk tmr2l tmr2h tmr2rll tmr2rlh reload tclk 0 1 tr2 tmr2cn t2split tf2cen tf2l tf2h t2xclk tr2 interrupt tf2len to adc, smbus to smbus tl2 overflow ckcon t 3 m h t 3 m l s c a 0 s c a 1 t 0 m t 2 m h t 2 m l t 1 m smartclock / 8 sysclk / 12 00 t2xclk[1:0] 01
c8051f97x 396 rev 1.0 timers (timer0, timer1, timer2, and timer3) 32.2.2. 8-bit timers with auto-reload when t2split is set, timer 2 operates as two 8-bit timers (tmr2h and tmr2l). both 8-bit timers operate in auto- reload mode as shown in figure 32.5 . tmr2rll holds the reload value fo r tmr2l; tmr2rlh holds the reload value for tmr2h. the tr2 bit in tm r2cn handles the run cont rol for tmr2h. tmr2l is always running when configured for 8-bit mode. each 8-bit timer may be configured to use sysclk, sysclk divided by 12, smartclock divided by 8 or comparator 0 output. the timer 2 clock select bits (t2mh and t2ml in ckcon) select either sysclk or the clock defined by the timer 2 external clock select bits (t2x clk[1:0] in tmr2cn), as follows: the tf2h bit is set when tmr2h overfl ows from 0xff to 0x00; the tf2l bit is set when tmr2l overflows from 0xff to 0x00. when timer 2 interrupts are enabled (ie.5), an interrupt is generated each time tmr2h overflows. if timer 2 interrupts are enabled and tf2lint (tmr2cn.5) is set, an interrupt is generat ed each time either tmr2l or tmr2h overflows. when tf2lint is enabled, software must check the tf2h and tf2l flags to determine the source of the timer 2 interrupt. the tf2h and tf2l interrupt flags are not cleared by hardware and must be man - ually cleared by software. figure 32.5. timer 2 8-bit mode block diagram t2mh t2xclk[1:0] tmr2h clock source t2ml t2xclk[1:0] tmr2l clock source 0 00 sysclk / 12 0 00 sysclk / 12 0 01 smartclock / 8 0 01 smartclock / 8 0 10 reserved 0 10 reserved 0 11 comparator 0 0 11 comparator 0 1 x sysclk 1 x sysclk tclk tmod t 1 m 1 t 1 m 0 c / t 1 g a t e 1 g a t e 0 c / t 0 t 0 m 1 t 0 m 0 tcon tf0 tr0 tr1 tf1 ie1 it1 ie0 it0 interrupt tl0 (8 bits) reload th0 (8 bits) 0 1 0 1 sysclk pre-scaled clock it01cf i n 1 s l 1 i n 1 s l 0 i n 1 s l 2 i n 1 p l i n 0 p l i n 0 s l 2 i n 0 s l 1 i n 0 s l 0 tr0 gate0 in0pl xor /int0 t0 crossbar ckcon t 3 m h t 3 m l s c a 0 s c a 1 t 0 m t 2 m h t 2 m l t 1 m
c8051f97x rev 1.0 397 timers (timer0, timer1, timer2, and timer3) 32.2.3. comparator 0/smartclock capture mode the capture mode in timer 2 allows either comparator 0 or the smartclock period to be measured against the system clock or the system clock divided by 12. comparator 0 and the smartclock period can also be compared against each other. timer 2 capture mode is enabled by setting tf2cint to 1. timer 2 should be in 16-bit auto- reload mode when using capture mode. when capture mode is enabl ed, a capture event will be gener ated either every comparator 0 rising edge or every 8 smartclock clock cycles, depending on the t2xclk1 sett ing. when the capture event occurs, the contents of timer 2 (tmr2h:tmr2l) are loaded into the timer 2 reload registers (tmr2rlh:tmr2rll) and the tf2h flag is set (triggering an interrupt if timer 2 interrupts are enabled). by recording the difference between two successive timer capture values, the comparator 0 or smartclock period can be determined with respect to the timer 2 clock. the timer 2 clock should be much faster than the capture clock to achieve an accurate reading. for example, if t2ml = 1b, t2xclk1 = 0b, and tf2cint = 1b, timer 2 will clock ev ery sysclk and capture every smartclock clock divided by 8. if the sysclk is 24.5 mhz and the di fference between tw o successive cap - tures is 5984, then the smartclock clock is as follows: 24.5 mhz/(5984/8) = 0.032754 mhz or 32.754 khz. this mode allows software to determ ine the exact smartclock frequency in self-oscillate m ode and the time between consecutive comparator 0 rising edges, which is useful for dete cting changes in the capacitance of a touch sense switch. figure 32.6. timer 2 capture mode block diagram smartclock / 8 sysclk 0 1 t2xclk1 ckcon t 3 m h t 3 m l s c a 0 s c a 1 t 0 m t 2 m h t 2 m l t 1 m tmr2l tmr2h tclk tr2 tmr2rll tmr2rlh capture tmr2cn t2split t2xclk1 tf2cen tf2l tf2h t2xclk0 tr2 tf2len tf2cen interrupt sysclk / 12 x0 t2xclk[1:0] 11 0 smartclock / 8
c8051f97x 398 rev 1.0 timers (timer0, timer1, timer2, and timer3) 32.3. timer 3 timer 3 is a 16-bit timer formed by two 8-bit sfrs: tmr3 l (low byte) and tmr3h (high byte). timer 3 may operate in 16-bit auto-reload mode or (split) 8-bit auto-reload mode. the t3split bit in the tmr3cn register defines the timer 3 operation mode. timer 3 can also be used in capture mode to measur e the external oscillator source or the smartclock oscillato r period with respect to another oscillator. timer 3 may be clocked by the system cl ock, the system clock divided by 12, ex ternal oscillator source divided by 8, or the smartclock oscillator. the ex ternal oscillator source divided by 8 and smartclock oscillator is synchro- nized with the system clock. 32.3.1. 16-bit timer with auto-reload when t3split in the tmr3cn register is zero, timer 3 operates as a 16-bit timer with auto-reload. timer 3 can be clocked by sysclk, sysclk divided by 12, external oscilla tor clock source divided by 8, or smartclock oscilla- tor. as the 16-bit timer register increments and overflow s from 0xffff to 0x0000, the 16-bit value in the timer 3 reload registers (tmr3rlh and tmr3rll) is loaded into t he timer 3 register as shown in figure 32.7, and the timer 3 high byte overflow flag (tmr3cn. 7) is set. if timer 3 interrupts are ena bled (if eie1.7 is set), an interrupt will be generated on each timer 3 overflow. additionally, if timer 3 interrupts are enabled and the tf3lint bit is set (tmr3cn.5), an inte rrupt will be generated each ti me the lower 8 bits (tmr3l) overflow from 0xff to 0x00. figure 32.7. timer 3 16-bit mode block diagram sysclk tmr3l tmr3h tmr3rll tmr3rlh reload tclk 0 1 tr3 tmr3cn t3split t3xclk1 tf3cen tf3l tf3h t3xclk0 tr3 interrupt tf3len to adc ckcon t 3 m h t 3 m l s c a 0 s c a 1 t 0 m t 2 m h t 2 m l t 1 m external clock / 8 sysclk / 12 00 t3xclk[1:0] 01 11 smartclock
c8051f97x rev 1.0 399 timers (timer0, timer1, timer2, and timer3) 32.3.2. 8-bit timers with auto-reload when t3split is set, timer 3 operates as two 8-bit timers (tmr3h and tmr3l). both 8-bit timers operate in auto- reload mode as shown in figure 32.8. tmr3rll holds the reload value for tmr3l; tmr3rlh holds the reload value for tmr3h. the tr3 bit in tm r3cn handles the run cont rol for tmr3h. tmr3l is always running when configured for 8-bit mode. each 8-bit timer may be configured to use sysclk, sysclk divided by 12, th e external oscilla tor clock source divided by 8, or the smartclock. the timer 3 clock se lect bits (t3mh and t3ml in ckcon) select either sysclk or the clock defined by the ti mer 3 external clock sele ct bits (t3xclk[1:0] in tmr3cn), as follows: the tf3h bit is set when tmr3h overfl ows from 0xff to 0x00; the tf3l bit is set when tmr3l overflows from 0xff to 0x00. when timer 3 interrupts are enabled, an inte rrupt is generated each time tmr3h overflows. if timer 3 interrupts are enabled and tf3lint (tmr3cn.5) is set, an interrupt is generated each time either tmr3l or tmr3h overflows. when tf3lint is enabled, software must check the tf3h and tf3l flags to determine the source of the timer 3 interrupt. the tf3h and tf3l interrupt flags are not cleared by hardware and must be man- ually cleared by software. figure 32.8. timer 3 8-bit mode block diagram t3mh t3xclk[1:0] tmr3h clock source t3ml t3xclk[1:0] tmr3l clock source 0 00 sysclk / 12 0 00 sysclk / 12 0 01 smartclock 0 01 smartclock 0 10 reserved 0 10 reserved 0 11 external clock / 8 0 11 external clock / 8 1 x sysclk 1 x sysclk sysclk tclk 0 1 tr3 1 0 tmr3h tmr3rlh reload reload tclk tmr3l tmr3rll interrupt tmr3cn t3split t3xclk1 tf3cen tf3len tf3l tf3h t3xclk0 tr3 to adc ckcon t 3 m h t 3 m l s c a 0 s c a 1 t 0 m t 2 m h t 2 m l t 1 m external clock / 8 sysclk / 12 00 t3xclk[1:0] 01 11 smartclock
c8051f97x 400 rev 1.0 timers (timer0, timer1, timer2, and timer3) 32.3.3. smartclock/external oscillator capture mode the capture mode in timer 3 allows ei ther smartclock or the external osc illator period to be measured against the system clock or th e system clock divided by 12. smartclock and the external oscillator period can also be compared against each other. setting tf3cint to 1 enables the sm artclock/external oscillator capture mode for timer 3. in this mode, t3split should be set to 0, as the full 16-bit timer is used. when capture mode is enabled, a capture event will be generated eith er every smartclock rising edge or every 8 external clock cycles, depending on the t3xclk1 setting. when the capture event occurs, the contents of timer 3 (tmr3h:tmr3l) are loaded into the timer 3 reload registers (tmr3rlh:tmr3rll) and the tf3h flag is set (triggering an interrupt if timer 3 interrupts are enabled) . by recording the difference between two successive timer capture values, the smartclock or external clock period can be determined with respect to the timer 3 clock. the timer 3 clock should be much faster than the capture clock to achieve an accurate reading. for example, if t3ml = 1b, t3xclk1 = 0b, and tf3cint = 1b, ti mer 3 will clock every sysclk and capture every smartclock rising edge. if sysclk is 24.5 mhz and the difference between two successive captures is 350 counts, then the smartclock period is as follows: 350 x (1 / 24.5 mhz) = 14.2 s. this mode allows software to determine the exact frequency of the extern al oscillator in c and rc mode or the time between consecutive smartclock rising edges, which is useful for determining the smartclock frequency. figure 32.9. timer 3 capture mode block diagram external clock/8 sysclk 0 1 t3xclk1 ckcon t 3 m h t 3 m l s c a 0 s c a 1 t 0 m t 2 m h t 2 m l t 1 m tmr3l tmr3h tclk tr3 tmr3rll tmr3rlh capture tmr3cn t3split t3xclk1 tf3cen tf3l tf3h t3xclk0 tr3 tf3len tf3cen interrupt sysclk/12 x0 t3xclk[1:0] 01 11 smartclock 0 1 smartclock external clock/8
c8051f97x rev 1.0 401 timers (timer0, timer1, timer2, and timer3) 32.4. timer control registers register 32.1. ckcon: clock control bit 7 6 5 4 3 2 1 0 name t3mh t3ml t2mh t2ml t1m t0m sca type rw rw rw rw rw rw rw reset00000000 sfr page = 0x0; sfr address: 0x8e table 32.3. ckcon register bit descriptions bit name function 7 t3mh timer 3 high byte clock select. selects the clock supplied to the timer 3 high byte (split 8-bit timer mode only). 0: timer 3 high byte uses the clock defined by the t3xclk bit in tmr3cn. 1: timer 3 high byte uses the system clock. 6 t3ml timer 3 low byte clock select. selects the clock supplied to timer 3. select s the clock supplied to the lower 8-bit timer in split 8-bit timer mode. 0: timer 3 low byte uses the clock defined by the t3xclk bit in tmr3cn. 1: timer 3 low byte uses the system clock. 5 t2mh timer 2 high byte clock select. selects the clock supplied to the timer 2 high byte (split 8-bit timer mode only). 0: timer 2 high byte uses the clock defined by the t2xclk bit in tmr2cn. 1: timer 2 high byte uses the system clock. 4 t2ml timer 2 low byte clock select. selects the clock supplied to timer 2. if timer 2 is configured in split 8-bit timer mode, this bit selects the clock supp lied to the lower 8-bit timer. 0: timer 2 low byte uses the clock defined by the t2xclk bit in tmr2cn. 1: timer 2 low byte uses the system clock. 3 t1m timer 1 clock select. selects the clock source su pplied to timer 1. ignored when c/t1 is set to 1. 0: timer 1 uses the clock defined by the prescale field, sca. 1: timer 1 uses the system clock. 2 t0m timer 0 clock select. selects the clock source su pplied to timer 0. ignored when c/t0 is set to 1. 0: counter/timer 0 uses the clock defined by the prescale field, sca. 1: counter/timer 0 uses the system clock.
c8051f97x 402 rev 1.0 timers (timer0, timer1, timer2, and timer3) 1:0 sca timer 0/1 prescale. these bits control the timer 0/1 clock prescaler: 00: system clock divided by 12. 01: system clock divided by 4. 10: system clock divided by 48. 11: external oscillator divided by 8 (synchronized with the system clock). table 32.3. ckcon register bit descriptions bit name function
c8051f97x rev 1.0 403 timers (timer0, timer1, timer2, and timer3) register 32.2. tcon: timer 0/1 control bit 7 6 5 4 3 2 1 0 name tf1 tr1 tf0 tr0 ie1 it1 ie0 it0 type rw rw rw rw rw rw rw rw reset00000000 sfr page = 0x0; sfr address: 0x88 (bit-addressable) table 32.4. tcon register bit descriptions bit name function 7 tf1 timer 1 overflow flag. set to 1 by hardware when timer 1 overflows. this flag can be cleared by firmware but is automatically cleared when the cpu vectors to the timer 1 interrupt service routine. 6 tr1 timer 1 run control. timer 1 is enabled by setting this bit to 1. 5 tf0 timer 0 overflow flag. set to 1 by hardware when timer 0 overflows. this flag can be cleared by firmware but is automatically cleared when the cpu vectors to the timer 0 interrupt service routine. 4 tr0 timer 0 run control. timer 0 is enabled by setting this bit to 1. 3 ie1 external interrupt 1. this flag is set by hardware when an edge/level of type defined by it1 is detected. it can be cleared by firmware but is automatically cleared when the cpu vectors to the external interrupt 1 service routine in edge-triggered mode. 2 it1 interrupt 1 type select. this bit selects whether the configured int1 interrupt will be edge or level sensitive. int1 is configured active low or high by the in1pl bit in register it01cf. 0: int1 is level triggered. 1: int1 is edge triggered. 1 ie0 external interrupt 0. this flag is set by hardware when an edge/level of type defined by it0 is detected. it can be cleared by firmware but is automatically cleared when the cpu vectors to the external interrupt 0 service routine in edge-triggered mode. 0 it0 interrupt 0 type select. this bit selects whether the configured int0 interrupt will be edge or level sensitive. int0 is configured active low or high by the in0pl bit in register it01cf. 0: int0 is level triggered. 1: int0 is edge triggered.
c8051f97x 404 rev 1.0 timers (timer0, timer1, timer2, and timer3) register 32.3. tmod: timer 0/1 mode bit 7 6 5 4 3 2 1 0 name gate1 ct1 t1m gate0 ct0 t0m type rw rw rw rw rw rw reset00000000 sfr page = 0x0; sfr address: 0x89 table 32.5. tmod register bit descriptions bit name function 7 gate1 timer 1 gate control. 0: timer 1 enabled when tr1 = 1 irrespective of int1 logic level. 1: timer 1 enabled only when tr1 = 1 and int1 is active as defined by bit in1pl in reg - ister it01cf. 6 ct1 counter/timer 1 select. 0: timer mode. timer 1 increments on the clock defined by t1m in the ckcon register. 1: counter mode. timer 1 increments on high-t o-low transitions of an external pin (t1). 5:4 t1m timer 1 mode select. these bits select the timer 1 operation mode. 00: mode 0, 13-bit counter/timer 01: mode 1, 16-bit counter/timer 10: mode 2, 8-bit counter/timer with auto-reload 11: mode 3, timer 1 inactive 3 gate0 timer 0 gate control. 0: timer 0 enabled when tr0 = 1 irrespective of int0 logic level. 1: timer 0 enabled only when tr0 = 1 and int0 is active as defined by bit in0pl in reg - ister it01cf. 2 ct0 counter/timer 0 select. 0: timer mode. timer 0 increments on the clock defined by t0m in the ckcon register. 1: counter mode. timer 0 increments on high-t o-low transitions of an external pin (t0). 1:0 t0m timer 0 mode select. these bits select the timer 0 operation mode. 00: mode 0, 13-bit counter/timer 01: mode 1, 16-bit counter/timer 10: mode 2, 8-bit counter/timer with auto-reload 11: mode 3, two 8-bit counter/timers
c8051f97x rev 1.0 405 timers (timer0, timer1, timer2, and timer3) 32.5. timer 0/1 registers register 32.4. tl0: timer 0 low byte bit 7 6 5 4 3 2 1 0 name tl0 type rw reset00000000 sfr page = 0x0; sfr address: 0x8a table 32.6. tl0 register bit descriptions bit name function 7:0 tl0 timer 0 low byte. the tl0 register is the low byte of the 16-bit timer 0.
c8051f97x 406 rev 1.0 timers (timer0, timer1, timer2, and timer3) register 32.5. tl1: timer 1 low byte bit 7 6 5 4 3 2 1 0 name tl1 type rw reset00000000 sfr page = 0x0; sfr address: 0x8b table 32.7. tl1 register bit descriptions bit name function 7:0 tl1 timer 1 low byte. the tl1 register is the low byte of the 16-bit timer 1.
c8051f97x rev 1.0 407 timers (timer0, timer1, timer2, and timer3) register 32.6. th0: timer 0 high byte bit 7 6 5 4 3 2 1 0 name th0 type rw reset00000000 sfr page = 0x0; sfr address: 0x8c table 32.8. th0 register bit descriptions bit name function 7:0 th0 timer 0 high byte. the th0 register is the high byte of the 16-bit timer 0.
c8051f97x 408 rev 1.0 timers (timer0, timer1, timer2, and timer3) register 32.7. th1: timer 1 high byte bit 7 6 5 4 3 2 1 0 name th1 type rw reset00000000 sfr page = 0x0; sfr address: 0x8d table 32.9. th1 register bit descriptions bit name function 7:0 th1 timer 1 high byte. the th1 register is the high byte of the 16-bit timer 1.
c8051f97x rev 1.0 409 timers (timer0, timer1, timer2, and timer3) 32.6. timer 2 registers register 32.8. tmr2cn: timer 2 control bit 7 6 5 4 3 2 1 0 name tf2h tf2l tf2len tf2cen t2split tr2 t2xclk type rw rw rw rw rw rw rw reset00000000 sfr page = all; sfr address: 0xc8 (bit-addressable) table 32.10. tmr2cn register bit descriptions bit name function 7 tf2h timer 2 high byte overflow flag. set by hardware when the timer 2 high byte overflows from 0xff to 0x00. in 16-bit mode, this will occur when timer 2 overflows from 0x ffff to 0x0000. when the timer 2 interrupt is enabled, setting this bit causes th e cpu to vector to th e timer 2 interrupt ser - vice routine. this bit must be cleared by firmware. 6 tf2l timer 2 low byte overflow flag. set by hardware when the timer 2 low byte overflows from 0xff to 0x00. tf2l will be set when the low byte overflows regardless of the timer 2 mode. this bit must be cleared by firmware. 5 tf2len timer 2 low byte interrupt enable. when set to 1, this bit enables timer 2 low by te interrupts. if timer 2 interrupts are also enabled, an in terrupt will be ge nerated when the low byte of timer 2 overflows. 4 tf2cen timer 2 capture enable. when set to 1, this bit enables timer 2 capture mode. if tf2cen is set and timer 2 interrupts are enabled, an inte rrupt will be generated based on the selected input capture source, and the current 16-bit timer value in tmr2h:tmr2l will be copied to tmr2rlh:tmr2rll. 3 t2split timer 2 split mode enable. when this bit is set, timer 2 operates as two 8-bit timers with auto-reload. 0: timer 2 operates in 16-bit auto-reload mode. 1: timer 2 operates as two 8-bit auto-reload timers. 2 tr2 timer 2 run control. timer 2 is enabled by setting this bit to 1. in 8-bit mode, this bit enables/disables tmr2h only; tmr2l is always enabled in split mode.
c8051f97x 410 rev 1.0 timers (timer0, timer1, timer2, and timer3) 1:0 t2xclk timer 2 external clock select. this bit selects the external clock source for timer 2. if timer 2 is in 8-bit mode, this bit selects the external oscillator clock source for both timer bytes. however, the timer 2 clock select bits (t2mh and t2ml in regi ster ckcon) may still be used to select between the external clock and the system cl ock for either timer. note: external clock sources are synchronized with the system clock. 00: external clock is sysclk/1 2. capture trigger is rtc/8. 01: capture trigger is rtc/8. 10: external clock is sysclk/12. 11: external clock is rtc/8. table 32.10. tmr2cn register bit descriptions bit name function
c8051f97x rev 1.0 411 timers (timer0, timer1, timer2, and timer3) register 32.9. tmr2rll: timer 2 reload low byte bit 7 6 5 4 3 2 1 0 name tmr2rll type rw reset00000000 sfr page = 0x0; sfr address: 0xca table 32.11. tmr2rll register bit descriptions bit name function 7:0 tmr2rll timer 2 reload low byte. when operating in one of the auto-reload modes, tmr2rll holds the reload value for the low byte of timer 2 (tmr2l). when operating in capture mode, tmr2rll is the cap - tured value of tmr2l.
c8051f97x 412 rev 1.0 timers (timer0, timer1, timer2, and timer3) register 32.10. tmr2rlh: timer 2 reload high byte bit 7 6 5 4 3 2 1 0 name tmr2rlh type rw reset00000000 sfr page = 0x0; sfr address: 0xcb table 32.12. tmr2rlh register bit descriptions bit name function 7:0 tmr2rlh timer 2 reload high byte. when operating in one of the auto-reload modes, tmr2rlh holds the reload value for the high byte of timer 2 (tmr2h). when operating in capture mode, tmr2rlh is the captured value of tmr2h.
c8051f97x rev 1.0 413 timers (timer0, timer1, timer2, and timer3) register 32.11. tmr2l: timer 2 low byte bit 7 6 5 4 3 2 1 0 name tmr2l type rw reset00000000 sfr page = 0x0; sfr address: 0xcc table 32.13. tmr2l register bit descriptions bit name function 7:0 tmr2l timer 2 low byte. in 16-bit mode, the tmr2l register contains the low byte of the 16-bit timer 2. in 8-bit mode, tmr2l contains the 8-bit low byte timer value.
c8051f97x 414 rev 1.0 timers (timer0, timer1, timer2, and timer3) register 32.12. tmr2h: timer 2 high byte bit 7 6 5 4 3 2 1 0 name tmr2h type rw reset00000000 sfr page = 0x0; sfr address: 0xcd table 32.14. tmr2h register bit descriptions bit name function 7:0 tmr2h timer 2 high byte. in 16-bit mode, the tmr2h register contains t he high byte of the 16-bit timer 2. in 8-bit mode, tmr2h contains the 8-bit high byte timer value.
c8051f97x rev 1.0 415 timers (timer0, timer1, timer2, and timer3) 32.7. timer 3 registers register 32.13. tmr3cn: timer 3 control bit 7 6 5 4 3 2 1 0 name tf3h tf3l tf3len tf3cen t3split tr3 t3xclk type rw rw rw rw rw rw r rw reset00000000 sfr page = 0x0; sfr address: 0x91 table 32.15. tmr3cn register bit descriptions bit name function 7 tf3h timer 3 high byte overflow flag. set by hardware when the timer 3 high byte overflows from 0xff to 0x00. in 16-bit mode, this will occur when timer 3 overflows from 0x ffff to 0x0000. when the timer 3 interrupt is enabled, setting this bit causes th e cpu to vector to th e timer 3 interrupt ser - vice routine. this bit must be cleared by firmware. 6 tf3l timer 3 low byte overflow flag. set by hardware when the timer 3 low byte overflows from 0xff to 0x00. tf3l will be set when the low byte overflows regardless of the timer 3 mode. this bit must be cleared by firmware. 5 tf3len timer 3 low byte interrupt enable. when set to 1, this bit enables timer 3 low by te interrupts. if timer 3 interrupts are also enabled, an in terrupt will be ge nerated when the low byte of timer 3 overflows. 4 tf3cen timer 3 capture enable. when set to 1, this bit enables timer 3 capture mode. if tf3cen is set and timer 3 interrupts are enabled, an inte rrupt will be generated based on the selected input capture source, and the current 16-bit timer value in tmr3h:tmr3l will be copied to tmr3rlh:tmr3rll. 3 t3split timer 3 split mode enable. when this bit is set, timer 3 operates as two 8-bit timers with auto-reload. 0: timer 3 operates in 16-bit auto-reload mode. 1: timer 3 operates as two 8-bit auto-reload timers. 2 tr3 timer 3 run control. timer 3 is enabled by setting this bit to 1. in 8-bit mode, this bit enables/disables tmr3h only; tmr3l is always enabled in split mode.
c8051f97x 416 rev 1.0 timers (timer0, timer1, timer2, and timer3) 1:0 t3xclk timer 3 external clock select. this bit selects the external clock source for timer 3. if timer 3 is in 8-bit mode, this bit selects the external oscillator clock source for both timer bytes. however, the timer 3 clock select bits (t3mh and t3ml in regi ster ckcon) may still be used to select between the external clock and the system cl ock for either timer. note: external clock sources are synchronized with the system clock. 00: external clock is sysclk /12. capture trigger is rtc. 01: external clock is external os cillator/8. capture trigger is rtc. 10: external clock is s ysclk/12. capture trigger is external oscillator/8. 11: external clock is rtc. capture trigger is external oscillator/8. table 32.15. tmr3cn register bit descriptions bit name function
c8051f97x rev 1.0 417 timers (timer0, timer1, timer2, and timer3) register 32.14. tmr3rll: timer 3 reload low byte bit 7 6 5 4 3 2 1 0 name tmr3rll type rw reset00000000 sfr page = 0x0; sfr address: 0x92 table 32.16. tmr3rll register bit descriptions bit name function 7:0 tmr3rll timer 3 reload low byte. when operating in one of the auto-reload modes, tmr3rll holds the reload value for the low byte of timer 3 (tmr3l). when operating in capture mode, tmr3rll is the cap - tured value of tmr3l.
c8051f97x 418 rev 1.0 timers (timer0, timer1, timer2, and timer3) register 32.15. tmr3rlh: timer 3 reload high byte bit 7 6 5 4 3 2 1 0 name tmr3rlh type rw reset00000000 sfr page = 0x0; sfr address: 0x93 table 32.17. tmr3rlh register bit descriptions bit name function 7:0 tmr3rlh timer 3 reload high byte. when operating in one of the auto-reload modes, tmr3rlh holds the reload value for the high byte of timer 3 (tmr3h). when operating in capture mode, tmr3rlh is the captured value of tmr3h.
c8051f97x rev 1.0 419 timers (timer0, timer1, timer2, and timer3) register 32.16. tmr3l: timer 3 low byte bit 7 6 5 4 3 2 1 0 name tmr3l type rw reset00000000 sfr page = 0x0; sfr address: 0x94 table 32.18. tmr3l register bit descriptions bit name function 7:0 tmr3l timer 3 low byte. in 16-bit mode, the tmr3l register contains the low byte of the 16-bit timer 3. in 8-bit mode, tmr3l contains the 8-bit low byte timer value.
c8051f97x 420 rev 1.0 timers (timer0, timer1, timer2, and timer3) register 32.17. tmr3h: timer 3 high byte bit 7 6 5 4 3 2 1 0 name tmr3h type rw reset00000000 sfr page = 0x0; sfr address: 0x95 table 32.19. tmr3h register bit descriptions bit name function 7:0 tmr3h timer 3 high byte. in 16-bit mode, the tmr3h register contains t he high byte of the 16-bit timer 3. in 8-bit mode, tmr3h contains the 8-bit high byte timer value.
c8051f97x rev 1.0 421 programmable co unter array (pca0) 33. programmable counter array (pca0) the programmable counter array (pca0) provides enh anced timer functionality while requiring less cpu intervention than the standard 8051 counter/timers. the pca consists of a dedicated 16-bit counter/timer and three 16-bit capture/compare modules. each capture/compare module has its own associated i/o line (cexn) which is routed through the crossbar to port i/o when enabled. the counter/timer is driven by a programmable timebase that can select between six sources: s ystem clock, system clock divided by four, system clock divided by twelve, the external oscillator clock source divi ded by 8, smartclock divided by 8, ti mer 0 overflows, or an external clock signal on the eci input pin. each ca pture/compare module may be configured to operate independently in one of six modes: edge-triggered capture, software timer, high-speed output, frequency output, 8 to 11-bit pwm, or 16-bit pwm (each mode is described in section ?33.3. capture/compare modules? on page 424 ). the external oscillator clock option is ideal for real-time clock (rtc) fu nctionality, allowing the pca to be clocked by a precision external oscillator while the internal oscillato r drives the system cl ock. the pca is configured and controlled through the system controller's special function registers. the pca block diagram is shown in figure 33.1 important note: the pca module 2 may be used as a watchdog timer (wdt), and is enabled in this mode following a system reset. access to certain pca registers is re stricted while wdt mode is enabled. see section 33.4 for details. figure 33.1. pca block diagram capture/compare module 1 capture/compare module 0 capture/compare module 2 / wdt cex1 eci crossbar cex2 cex0 port i/o 16-bit counter/timer pca clock mux sysclk/12 sysclk/4 timer 0 overflow eci sysclk external clock/8 smartclock/8
c8051f97x 422 rev 1.0 programmable counter array (pca0) 33.1. pca counter/timer the 16-bit pca counter/timer consists of two 8-bit sfrs: pca0l and pca0h. pca0h is t he high byte (msb) of the 16-bit counter/timer and pca0l is the low byte (lsb). reading pca0l automatically latches the value of pca0h into a ?snapshot? register; the following pca0h read accesses this ?snapshot? register. reading the pca0l register first guarantees an accurate reading of the entire 16-bit pca0 counter. reading pca0h or pca0l does not disturb the counter operation. the cps2 ? cps0 bits in the pca0md register select the timebase for the counter/timer as shown in ta b l e 33.1 . when the counter/timer overflows from 0xffff to 0x0000, the counter overflow flag (cf) in pca0md is set to logic 1 and an interrupt request is generated if cf interrupts are enabled. setting the ecf bit in pca0md to logic 1 enables the cf flag to generate an interrupt request. the cf bit is not automatically cleared by hardware when the cpu vectors to the interrupt service routine, and must be cleared by software. clearing the cidl bit in the pca0md register allows the pca to continue no rmal operation while the cpu is in idle mode. figure 33.2. pca counter/timer block diagram table 33.1. pca timebase input options cps2 cps1 cps0 timebase 0 0 0 system clock divided by 12 0 0 1 system clock divided by 4 0 1 0 timer 0 overflow 0 1 1 high-to-low transitions on eci (max rate = system clock divided by 4) 1 0 0 system clock 101 external oscillator source divided by 8 1 110 smartclock oscillator source divided by 8 2 111 reserved notes: 1. external oscillator source divided by 8 is synchronized with the system clock. 2. smartclock oscillator source divided by 8 is synchronized with the system clock. pca0cn c f c r c c f 0 c c f 2 c c f 1 pca0md c i d l w d t e e c f c p s 1 c p s 0 w d l c k c p s 2 idle 0 1 pca0h pca0l snapshot register to sfr bus overflow to pca interrupt system cf pca0l read to pca modules sysclk/12 sysclk/4 timer 0 overflow eci 000 001 010 011 100 101 sysclk external clock/8 smartclock/8 110
c8051f97x rev 1.0 423 programmable co unter array (pca0) 33.2. pca0 interrupt sources figure 33.3 shows a diagram of the pca interrupt tree. there are five independent event flags that can be used to generate a pca0 interrupt. they are: the main pca counter overflow flag (cf), which is set upon a 16-bit overflow of the pca0 counter, an intermediate overflow flag (cov f), which can be set on an overflow from the 8th, 9th, 10th, or 11th bit of the pca0 counte r, and the individual flags for each pca channel (ccf0, ccf1, and ccf2), which are set according to the operation mode of that m odule. these event flags are always set when the trigger condition occurs. each of these flags can be individua lly selected to generate a pca0 interrupt, using the corresponding interrupt enable flag (ecf for cf, ecov for covf, and eccfn for each ccfn). pca0 interrupts must be globally enabled before any individual interrupt so urces are recognized by the processor. pca0 interrupts are globally enabled by setting the ea bit and the epca0 bit to logic 1. figure 33.3. pca interrupt block diagram pca0cn c f c r c c f 0 c c f 2 c c f 1 pca0md c i d l w d t e e c f c p s 1 c p s 0 w d l c k c p s 2 0 1 pca module 0 (ccf0) pca module 1 (ccf1) eccf1 0 1 eccf0 0 1 pca module 2 (ccf2) eccf2 pca counter/timer 16- bit overflow 0 1 interrupt priority decoder epca0 0 1 ea 0 1 pca0cpmn (for n = 0 to 2) p w m 1 6 n e c o m n e c c f n t o g n p w m n c a p p n c a p n n m a t n pca counter/timer 8, 9, 10 or 11-bit overflow 0 1 set 8, 9, 10, or 11 bit operation pca0pwm a r s e l e c o v c l s e l 0 c l s e l 1 c o v f
c8051f97x 424 rev 1.0 programmable counter array (pca0) 33.3. capture/compare modules each module can be configured to operate independently in one of six operation modes: edge-triggered capture, software timer, high-speed output, frequency output, 8 to 11-bit pulse width modulato r, or 16-bit pulse width modulator. each module has special function registers (s frs) associated with it in the cip-51 system controller. these registers are used to exchange data with a m odule and configure the module's mode of operation. ta b l e 33.2 summarizes the bit settings in the pca0cpmn and pca0pwm registers used to select the pca capture/compare module?s operating mode. note that all mo dules set to use 8, 9, 10, or 11-bit pwm mode must use the same cycle length (8?11 bits). setting the eccfn bi t in a pca0cpmn register enables the module's ccfn interrupt. table 33.2. pca0cpm and pca0pwm bit settings for pca capture/compare modules operational mode pca0cpmn pca0pwm bit number 7 6 5 4 3 2 1 0 7 6 5 4?2 1?0 capture triggered by positive edge on cexn x x 1 0 0 0 0 a 0 x b xxx xx capture triggered by negative edge on cexn x x 0 1 0 0 0 a 0 x b xxx xx capture triggered by any transition on cexn x x 1 1 0 0 0 a 0 x b xxx xx software timer x c 0 0 1 0 0 a 0 x b xxx xx high speed output x c 0 0 1 1 0 a 0 x b xxx xx frequency output x c 0 0 0 1 1 a 0 x b xxx xx 8-bit pulse width modulator ( note 7 ) 0 c 0 0 e 0 1 a 0 x b xxx 00 9-bit pulse width modulator ( note 7 ) 0 c 0 0 e 0 1 a d x b xxx 01 10-bit pulse width modulator ( note 7 ) 0 c 0 0 e 0 1 a d x b xxx 10 11-bit pulse width modulator ( note 7 ) 0 c 0 0 e 0 1 a d x b xxx 11 16-bit pulse width modulator 1 c 0 0 e 0 1 a 0 x b xxx xx notes: 1. x = don?t care (no functional difference for individual module if 1 or 0). 2. a = enable interrupts for this module (pca interrupt triggered on ccfn set to 1). 3. b = enable 8th, 9th, 10th or 11th bit overfl ow interrupt (depends on setting of clsel[1:0]). 4. c = when set to 0, the digital comparator is off. for hi gh speed and frequency output modes, the associated pin will not toggle. in any of the pwm modes, th is generates a 0% duty cycle (output = 0). 5. d = selects whether the capture/compare register (0) or the auto-reload regist er (1) for the associated channel is accessed via addresses pc a0cphn and pca0cpln. 6. e = when set, a match event will cause the ccfn flag for the associated channel to be set. 7. all modules set to 8, 9, 10 or 11-bit pw m mode use the same cycle length setting.
c8051f97x rev 1.0 425 programmable co unter array (pca0) 33.3.1. edge-triggered capture mode in this mode, a valid transition on th e cexn pin causes the pca to capture the value of the pca counter/timer and load it into the corresponding module's 16-bit captur e/compare register (pca0cpln and pca0cphn). the cappn and capnn bits in the pca0cpmn register are used to select the type of transition that triggers the capture: low-to- high transition (positive edge), high-to-low transition (negative edge), or either transition (positive or negative edge). when a capture occurs, the capture/compare flag (ccfn) in pca0cn is set to logic 1. an interrupt request is generated if the ccfn interr upt for that module is enabled. the ccfn bit is not automatically cleared by hardware when the cpu vectors to the interrupt service routine, and must be cleared by software. if both cappn and capnn bits are set to logic 1, then the state of the port pin associated with cexn can be read directly to determine whet her a rising-edge or fallin g-edge caused the capture. figure 33.4. pca capture mode diagram note: the cexn input signal must remain high or low for at least 2 system clock cycles to be re cognized by the hardware. pca0l pca0cpln pca timebase cexn crossbar port i/o pca0h capture pca0cphn 0 1 0 1 (to ccfn) pca0cpmn p w m 1 6 n e c o m n e c c f n t o g n p w m n c a p p n c a p n n m a t n pca0cn c f c r c c f 0 c c f 2 c c f 1 pca interrupt x 000x x
c8051f97x 426 rev 1.0 programmable counter array (pca0) 33.3.2. software timer (compare) mode in software timer mode, the pca counte r/timer value is compared to the modu le's 16-bit capture/compare register (pca0cphn and pca0cpln). when a match occurs, the capture/compare flag (ccfn) in pca0cn is set to logic 1. an interrupt request is generated if the ccfn interr upt for that module is enabled. the ccfn bit is not automatically cleared by hardware when the cpu vectors to the interrupt service routine, and must be cleared by software. setting the ecomn and matn bits in the pca0cpmn register enables software timer mode. important note about capture/compare registers : when writing a 16-bit value to the pca0 capture/compare registers, the low byte should always be written first. writing to pca0cpln cl ears the ecomn bit to 0; writing to pca0cphn sets ecomn to 1. figure 33.5. pca software timer mode diagram match 16-bit comparator pca0h pca0cphn enable pca0l pca timebase pca0cpln 00 00 0 1 x enb enb 0 1 write to pca0cpln write to pca0cphn reset pca0cpmn p w m 1 6 n e c o m n e c c f n t o g n p w m n c a p p n c a p n n m a t n x pca0cn c f c r c c f 0 c c f 2 c c f 1 pca interrupt
c8051f97x rev 1.0 427 programmable co unter array (pca0) 33.3.3. high-speed output mode in high-speed output mode, a module?s associated cexn pin is toggled each time a match occurs between the pca counter and the module's 16-bit capture/compare register (pca0cphn and pca0cpln). when a match occurs, the capture/compare flag (ccfn) in pca0cn is set to logic 1. an interrupt request is generated if the ccfn interrupt for that module is en abled. the ccfn bit is not automatica lly cleared by hardware when the cpu vectors to the interrupt service routine, and must be cleared by software. setting the togn, matn, and ecomn bits in the pca0cpmn register enab les the high-speed ou tput mode. if ecomn is cl eared, the associated pin will retain its state, and not toggle on the next match event. important note about capture/compare registers : when writing a 16-bit value to the pca0 capture/compare registers, the low byte should always be written first. writing to pca0cpln cl ears the ecomn bit to 0; writing to pca0cphn sets ecomn to 1. figure 33.6. pca high-speed output mode diagram match 16-bit comparator pca0h pca0cphn enable pca0l pca timebase pca0cpln 0 1 00 0x enb enb 0 1 write to pca0cpln write to pca0cphn reset pca0cpmn p w m 1 6 n e c o m n e c c f n t o g n p w m n c a p p n c a p n n m a t n x cexn crossbar port i/o toggle 0 1 togn pca0cn c f c r c c f 0 c c f 2 c c f 1 pca interrupt
c8051f97x 428 rev 1.0 programmable counter array (pca0) 33.3.4. frequency output mode frequency output mode produces a programmable-frequency sq uare wave on the module?s associated cexn pin. the capture/compare module high byte holds the number of pca clocks to co unt before the output is toggled. the frequency of the square wave is then defined by equation 33.1 . equation 33.1. square wave frequency output where f pca is the frequency of the clock selected by the cps2 ? 0 bits in the pca mode register, pca0md. the lower byte of the capture/compare module is compared to the pca counter low byte; on a match, cexn is toggled and the offset held in the high byte is added to th e matched value in pca0cpln. frequency output mode is enabled by setting the ecomn, togn, and pwmn bits in the pca0cpmn register. note that the matn bit should normally be set to 0 in this mode. if the matn bit is se t to 1, the ccfn flag for th e channel will be set when the 16- bit pca0 counter and the 16-bit capture/co mpare register for the channel are equal. figure 33.7. pca frequency output mode 33.3.5. 8-bit, 9-bit, 10-bit and 11-bit pulse width modulator modes each module can be used independently to generate a pu lse width modulated (pwm) output on its associated cexn pin. the frequency of the output is dependent on th e timebase for the pca counter/timer, and the setting of the pwm cycle length (8, 9, 10 or 11-b its). for backwards-compatibility with th e 8-bit pwm mode available on other devices, the 8-bit pwm mode operates slightly different than 9, 10 and 11-bit pwm modes. it is important to note that all channels configured for 8/9/10/11-bit pwm mode will use the same cycle length. it is not possible to configure one channel for 8-bit pwm mode and another for 11-bit mode (for example). however, other pca channels can be configured to pin c apture, high-speed output, software time r, frequency output, or 16-bit pwm mode independently. f cexn f pca 2 pca 0 cphn ? ------------------- --------------------- - = note: a value of 0x00 in the pca0cphn re gister is equal to 256 for this equation. 8-bit comparator pca0l enable pca timebase match pca0cphn 8-bit adder pca0cpln adder enable cexn crossbar port i/o toggle 0 1 togn 000 x pca0cpmn p w m 1 6 n e c o m n e c c f n t o g n p w m n c a p p n c a p n n m a t n x enb enb 0 1 write to pca0cpln write to pca0cphn reset
c8051f97x rev 1.0 429 programmable co unter array (pca0) 33.3.6. 8-bit pulse width modulator mode the duty cycle of the pwm output signal in 8-bit pwm mode is varied using the module's pca0cpln capture/ compare register. when the value in the low byte of th e pca counter/timer (pca0l) is equal to the value in pca0cpln, the output on the cexn pi n will be set. when the count value in pca0l overflows, the cexn output will be reset (see figure 33.8 ). also, when the counter/timer low byte (pca0l) overflows from 0xff to 0x00, pca0cpln is reloaded automatically with the value stored in the module?s capture/compare high byte (pca0cphn) without software intervention. setting the ecomn and pwmn bits in the pca0cpmn register, and setting the clsel bits in register pca0pwm to 00b enables 8-bit pulse width modulator mode. if the matn bit is set to 1, the ccfn flag for the module will be set each time an 8-bit comp arator match (risin g edge) occurs. the covf flag in pca0pwm can be used to detect the overfl ow (falling edge), which w ill occur every 256 pca clock cycles. the duty cycle for 8-bit pwm mode is given in equation 33.2 . important note about capture/compare registers : when writing a 16-bit value to the pca0 capture/compare registers, the low byte should always be written first. writing to pca0cpln cl ears the ecomn bit to 0; writing to pca0cphn sets ecomn to 1. equation 33.2. 8-bit pwm duty cycle using equation 33.2 , the largest duty cycle is 100% (pca0cphn = 0), and the smallest duty cycle is 0.39% (pca0cphn = 0xff). a 0% duty cycle may be generated by clearing the ecomn bit to 0. figure 33.8. pca 8-bit pwm mode diagram duty cycle 256 pca 0 cphn ? ?? 256 ------------------ ----------------- ---------------- = 8-bit comparator pca0l pca0cpln pca0cphn cexn crossbar port i/o enable overflow pca timebase 00x0 x q q set clr s r match pca0cpmn p w m 1 6 n e c o m n e c c f n t o g n p w m n c a p p n c a p n n m a t n 0 pca0pwm a r s e l e c o v c l s e l 0 c l s e l 1 c o v f x0 0 0 enb enb 0 1 write to pca0cpln write to pca0cphn reset covf
c8051f97x 430 rev 1.0 programmable counter array (pca0) 33.3.7. 9/10/11-bit pulse width modulator mode the duty cycle of the pwm output signal in 9/10/11-bit pw m mode should be varied by writing to an ?auto-reload? register, which is dual-mapped into the pca0cphn and pca0cpln register locations. the data written to define the duty cycle should be right-justified in the registers. the auto-reload registers are accessed (read or written) when the bit arsel in pca0pwm is set to 1. the capture/compar e registers are accessed when arsel is set to 0. when the least-significant n bits of the pca0 counter ma tch the value in the associated module?s capture/compare register (pca0cpn), the output on cexn is asserted hi gh. when the counter overflows from the nth bit, cexn is asserted low (see figure 33.9 ). upon an overflow from the nth bit, the co vf flag is set, and the value stored in the module?s auto-reload register is loaded into the captur e/compare register. the value of n is determined by the clsel bits in register pca0pwm. the 9, 10 or 11-bit pwm mode is selected by setting the ecomn and pwmn bits in the pca0cpmn register, and setting the clsel bits in register pca0pwm to the desired cycle length (other than 8-bits). if the matn bit is set to 1, the ccfn flag for the module will be set each time a comparator match (r ising edge) occurs. the covf flag in pca0pwm can be used to detect the overflow (falling edg e), which will occur every 512 (9-bit), 1024 (10-bit) or 2048 (11-bit) pca clock cycles. the duty cy cle for 9/10/11-bit pwm mode is given in equation 33.2 , where n is the number of bits in the pwm cycle. important note about pca0cphn and pca0cpln registers : when writing a 16-bit value to the pca0cpn registers, the low byte should always be written first. writing to pca0cpln cl ears the ecomn bit to 0; writing to pca0cphn sets ecomn to 1. equation 33.3. 9, 10, and 11-bit pwm duty cycle a 0% duty cycle may be generated by clearing the ecomn bit to 0. figure 33.9. pca 9, 10 and 11-bit pwm mode diagram duty cycle 2 n pca 0 cpn ? ?? 2 n ------------------ -------------- ----------- - = n-bit comparator pca0h:l (capture/compare) pca0cph:ln (right-justified) (auto-reload) pca0cph:ln (right-justified) cexn crossbar port i/o enable overflow of n th bit pca timebase 00x0 x q q set clr s r match pca0cpmn p w m 1 6 n e c o m n e c c f n t o g n p w m n c a p p n c a p n n m a t n 0 pca0pwm a r s e l e c o v c l s e l 0 c l s e l 1 c o v f x enb enb 0 1 write to pca0cpln write to pca0cphn reset r/w when arsel = 1 r/w when arsel = 0 set ?n? bits: 01 = 9 bits 10 = 10 bits 11 = 11 bits
c8051f97x rev 1.0 431 programmable co unter array (pca0) 33.3.8. 16-bit pulse width modulator mode a pca module may also be operated in 16-bit pwm mode. 16-bit pwm mode is independent of the other (8/9/10/ 11-bit) pwm modes. in this mode, the 16-bit capture/comp are module defines the number of pca clocks for the low time of the pwm signal. when the pca counter matche s the module contents, the output on cexn is asserted high; when the 16-bit counter overflows, cexn is asserted low. to output a varying du ty cycle, new value writes should be synchronized with pca ccfn match interrupts. 16-bit pwm mode is enabled by setting the ecomn, pwmn, and pwm16n bits in the pca0cpmn register. for a varying duty cycle, match interrupts should be enabled (eccfn = 1 and matn = 1) to help synchronize the capture/co mpare register writes. if the matn bit is set to 1, the ccfn flag for the module will be set each time a 16-bit comparator match (ri sing edge) occurs. the cf flag in pca0cn can be used to detect the overflow (falling ed ge). the duty cycle for 16-bit pwm mode is given by equation 33.4 . important note about capture/compare registers : when writing a 16-bit value to the pca0 capture/compare registers, the low byte should always be written first. writing to pca0cpln cl ears the ecomn bit to 0; writing to pca0cphn sets ecomn to 1. equation 33.4. 16-bit pwm duty cycle using equation 33.4 , the largest duty cycle is 100% (pca0cpn = 0), and the smallest duty cycle is 0.0015% (pca0cpn = 0xffff). a 0% duty cycle may be generated by clearing the ecomn bit to 0. figure 33.10. pca 16-bit pwm mode duty cycle 65536 pca 0 cpn ? ?? 65536 ------------------ ------------------ ---------------- - = pca0cpln pca0cphn enable pca ti mebase 00x0 x pca0cpmn p w m 1 6 n e c o m n e c c f n t o g n p w m n c a p p n c a p n n m a t n 1 16-bit comparator cexn crossbar port i/ o overflow q q set clr s r mat ch pca0h pca0l enb enb 0 1 wr i t e t o pca0cpln wr i t e t o pca0cphn reset
c8051f97x 432 rev 1.0 programmable counter array (pca0) 33.4. watchdog timer mode a programmable watchdog timer (wdt) function is availa ble through the pca module 2. the wdt is used to generate a reset if the time between writes to the wd t update register (pca0cph2) exceed a specified limit. the wdt can be configured and enabled/disabled as needed by software. with the wdte bit set in the pca0md register, module 2 operates as a watchdog timer (wdt). the module 2 high byte is compared to the pca counter high byte; the mo dule 2 low byte holds the offset to be used when wdt updates are performed. the watchdog timer is enabled on reset. writes to some pca registers are restricted while the watchdog timer is enabled. the wdt will generate a reset shortly after code begins execution. to avoid this reset, the wdt should be explicit ly disabled (and optionally re -configured and re-enabled if it is used in the system). 33.4.1. watchdog timer operation while the wdt is enabled: ? pca counter is forced on. ? writes to pca0l and pca0h are not allowed. ? pca clock source bits (cps2 ? cps0) are frozen. ? pca idle control bit (cidl) is frozen. ? module 2 is forced into software timer mode. ? writes to the module 2 mode register (pca0cpm2) are disabled. while the wdt is enabled, writes to the cr bit will not change the pca counter state; the counter will run until the wdt is disabled. the pca counter run control bit (cr) will r ead zero if the wdt is enabl ed but user software has not enabled the pca counter. if a match occurs betwe en pca0cph2 and pca0h while the wdt is enabled, a reset will be generated. to prevent a wdt reset, the wdt may be updated with a write of any value to pca0cph2. upon a pca0cph2 write, pca0h plus the offs et held in pca0cpl2 is loaded into pca0cph2 (see figure 33.11 ). figure 33.11. pca module 2 with watchdog timer enabled the 8-bit offset held in pca0cph2 is compared to the upper byte of the 16-bit pca counter. this offset value is the number of pca0l overflows before a reset. up to 256 pca clocks may pass before the first pca0l overflow occurs, depending on the value of the pca0l when the updat e is performed. the total offset is then given (in pca clocks) by equation 33.5 , where pca0l is the value of the pca0l register at the time of the update. pca0h enable pca0l overflow reset pca0cpl2 8-bit adder pca0cph2 adder enable pca0md c i d l w d t e e c f c p s 1 c p s 0 w d l c k c p s 2 mat ch wr i t e t o pca0cph2 8-bit comparator
c8051f97x rev 1.0 433 programmable co unter array (pca0) equation 33.5. watchdog timer offset in pca clocks the wdt reset is generated when pca0l overflows wh ile there is a match between pca0cph2 and pca0h. software may force a wdt reset by writing a 1 to the ccf2 flag (pca0cn.2) while the wdt is enabled. 33.4.2. watchdog timer usage to configure the wdt, perform the following tasks: 1. disable the wdt by writing a 0 to the wdte bit. 2. select the desired pca clock source (with the cps2 ? cps0 bits). 3. load pca0cpl2 with the desi red wdt update offset value. 4. configure the pca idle mode (set cidl if the wdt should be suspended while the cpu is in idle mode). 5. enable the wdt by setting the wdte bit to 1. 6. reset the wdt timer by writing to pca0cph2. the pca clock source and idle mode select cannot be changed while the wdt is enabled. the watchdog timer is enabled by setting the wdte or wdlck bits in the pc a0md register. when wdlck is set, the wdt cannot be disabled until the next system reset. if wdlck is not set, the wdt is disabled by clearing the wdte bit. the wdt is enabled following any reset. the pca0 counter clock defaults to the system clock divided by 12, pca0l defaults to 0x00, and pc a0cpl2 defaults to 0x00. using equation 33.5 , this results in a wdt timeout interval of 256 pca clock cycles, or 3072 system clock cycles. ta b l e 33.3 lists some example timeout intervals for typical system clocks. table 33.3. watchdog timer timeout intervals 1 system clock (hz) pca0cpl2 timeout interval (ms) 24,500,000 255 32.1 24,500,000 128 16.2 24,500,000 32 4.1 3,062,500 2 255 257 3,062,500 2 128 129.5 3,062,500 2 32 33.1 32,000 255 24576 32,000 128 12384 32,000 32 3168 notes: 1. assumes sysclk/12 as the pca clock source, and a pca0l value of 0x00 at the update time. 2. internal sysclk reset frequency = internal oscillator divided by 8. offset 256 pca 0 cpl 2 ? ?? 256 pca 0 l ? ?? + =
c8051f97x 434 rev 1.0 programmable counter array (pca0) 33.5. pca0 control registers register 33.1. pca0cn: pca control bit 7 6 5 4 3 2 1 0 name cf cr reserved ccf2 ccf1 ccf0 type rw rw r rw rw rw reset 0 0 0 0 0 0 0 0 sfr page = 0x0; sfr address: 0xd8 (bit-addressable) table 33.4. pca0cn register bit descriptions bit name function 7 cf pca counter/timer overflow flag. set by hardware when the pca counter/timer overflows from 0xffff to 0x0000. when the counter/timer overflow (cf) interrupt is enabled, settin g this bit causes the cpu to vector to the pca interrupt service routine. this bit is not automatically cleared by hard - ware and must be cleared by firmware. 6 cr pca counter/timer run control. this bit enables/disables the pca counter/timer. 0: stop the pca counter/timer. 1: start the pca counter/timer running. 5:3 reserved must write reset value. 2 ccf2 pca module 2 capture/compare flag. this bit is set by hardware when a match or capture occurs. when the ccf2 interrupt is enabled, setting this bit causes the cpu to vector to the pca interrupt service routine. this bit is not automatically cleared by hardware and must be cleared by firmware. 1 ccf1 pca module 1 capture/compare flag. this bit is set by hardware when a match or capture occurs. when the ccf1 interrupt is enabled, setting this bit causes the cpu to vector to the pca interrupt service routine. this bit is not automatically cleared by hardware and must be cleared by firmware. 0 ccf0 pca module 0 capture/compare flag. this bit is set by hardware when a match or capture occurs. when the ccf0 interrupt is enabled, setting this bit causes the cpu to vector to the pca interrupt service routine. this bit is not automatically cleared by hardware and must be cleared by firmware.
c8051f97x rev 1.0 435 programmable co unter array (pca0) register 33.2. pca0md: pca mode bit 7 6 5 4 3 2 1 0 name cidl wdte wdlck reserved cps ecf type rw rw rw r rw rw reset 0 1 0 0 0 0 0 0 sfr page = 0x0; sfr address: 0xd9 table 33.5. pca0md register bit descriptions bit name function 7 cidl pca counter/timer idle control. specifies pca behavior when cpu is in idle mode. 0: pca continues to function normally while the system controller is in idle mode. 1: pca operation is suspended while th e system controller is in idle mode. 6 wdte watchdog timer enable. if this bit is set, pca module 2 is used as the watchdog timer. 0: disable watchdog timer. 1: enable pca module 2 as the watchdog timer. 5 wdlck watchdog timer lock. this bit locks/unlocks the watchdog timer enable. when wdlck is set, the watchdog timer may not be disabled until the next system reset. 0: watchdog timer enable unlocked. 1: watchdog timer enable locked. 4 reserved must write reset value. 3:1 cps pca counter/time r pulse select. these bits select the timebase source for the pca counter. 000: system clock divided by 12. 001: system clock divided by 4. 010: timer 0 overflow. 011: high-to-low transitions on eci (m ax rate = system cl ock divided by 4). 100: system clock. 101: external clock divided by 8 (s ynchronized with the system clock). 110: rtc divided by 8. 111: reserved. 0 ecf pca counter/timer overflow interrupt enable. this bit sets the masking of the pca co unter/timer overflow (cf) interrupt. 0: disable the cf interrupt. 1: enable a pca counter/timer overflow interrupt request when cf (pca0cn.7) is set.
c8051f97x 436 rev 1.0 programmable counter array (pca0) register 33.3. pca0pwm: pca pwm configuration bit 7 6 5 4 3 2 1 0 name arsel ecov covf reserved clsel type rw rw rw r rw reset 0 0 0 0 0 0 0 0 sfr page = 0x0; sfr address: 0xdf table 33.6. pca0pwm register bit descriptions bit name function 7 arsel auto-reload register select. this bit selects whether to read and writ e the normal pca capture/compare registers (pca0cpn), or the auto-reload registers at the same sfr addresses. this function is used to define the reload value for 9 to 11 -bit pwm modes. in all other modes, the auto- reload registers have no function. 0: read/write capture/compare regi sters at pca0cphn and pca0cpln. 1: read/write auto-reload registers at pca0cphn and pca0cpln. 6 ecov cycle overflow interrupt enable. this bit sets the masking of the cycle overflow flag (covf) interrupt. 0: covf will not genera te pca interrupts. 1: a pca interrupt will be g enerated when covf is set. 5 covf cycle overflow flag. this bit indicates an overflow of the 8th to 11th bit of the main pca counter (pca0). the specific bit used for this flag depends on t he setting of the cycle length select bits. the bit can be set by hardware or firmware, but must be cleared by firmware. 0: no overflow has occurred since the last time this bit was cleared. 1: an overflow has occurred since the last time this bit was cleared. 4:2 reserved must write reset value. 1:0 clsel cycle length select. when 16-bit pwm mode is not selected, these bits select the length of the pwm cycle. this affects all channels configured for pwm which are not using 16-bit pwm mode. these bits are ignored for individual ch annels configured to 16-bit pwm mode. 00: 8 bits. 01: 9 bits. 10: 10 bits. 11: 11 bits.
c8051f97x rev 1.0 437 programmable co unter array (pca0) register 33.4. pca0l: pca counter/timer low byte bit 7 6 5 4 3 2 1 0 name pca0l type rw reset 0 0 0 0 0 0 0 0 sfr page = 0x0; sfr address: 0xf9 table 33.7. pca0l register bit descriptions bit name function 7:0 pca0l pca counter/timer low byte. the pca0l register holds the low byte (lsb) of the 16-bit pca counter/timer. note: when the wdte bit is set to 1, the pca0l register cannot be modified by firmware. to change the contents of the pca0l register, the watchdog timer must first be disabled.
c8051f97x 438 rev 1.0 programmable counter array (pca0) register 33.5. pca0h: pca counter/timer high byte bit 7 6 5 4 3 2 1 0 name pca0h type rw reset 0 0 0 0 0 0 0 0 sfr page = 0x0; sfr address: 0xfa table 33.8. pca0h register bit descriptions bit name function 7:0 pca0h pca counter/timer high byte. the pca0h register holds the high byte (msb ) of the 16-bit pca counter/timer. reads of this register will read the contents of a "snapshot" register, whose contents are updated only when the contents of pca0l are read. note: when the wdte bit is set to 1, the pca0h register canno t be modified by firmware. to change the contents of the pca0h register, the watchdog timer must first be disabled.
c8051f97x rev 1.0 439 programmable co unter array (pca0) register 33.6. pca0cpm0: pca channel 0 capture/compare mode 0 bit 7 6 5 4 3 2 1 0 name pwm16 ecom capp capn mat tog pwm eccf type rw rw rw rw rw rw rw rw reset 0 0 0 0 0 0 0 0 sfr page = 0x0; sfr address: 0xda table 33.9. pca0cpm0 register bit descriptions bit name function 7 pwm16 channel 0 16-bit pulse width modulation enable. this bit enables 16-bit mode when pulse width modulation mode is enabled. 0: 8 to 11-bit pwm selected. 1: 16-bit pwm selected. 6 ecom channel 0 comparator function enable. this bit enables the comparator function. 5 capp channel 0 capture positive function enable. this bit enables the positive edge capture capability. 4 capn channel 0 capture negative function enable. this bit enables the negative edge capture capability. 3 mat channel 0 match function enable. this bit enables the match function. when en abled, matches of the pca counter with a module's capture/compare regist er cause the ccf0 bit in the pca0md register to be set to logic 1. 2 tog channel 0 toggle function enable. this bit enables the toggle function. when enabled, matches of the pca counter with the capture/compare register cause the logic leve l on the cex0 pin to toggle. if the pwm bit is also set to logic 1, the module operates in frequency output mode. 1 pwm channel 0 pulse width modulation mode enable. this bit enables the pwm function. when enabled, a pulse width modulated signal is out - put on the cex0 pin. 8 to 11-bit pwm is used if pwm16 is cleared to 0; 16-bit mode is used if pwm16 is set to 1. if the tog bit is also set, the module operates in frequency output mode. 0 eccf channel 0 capture/compare flag interrupt enable. this bit sets the masking of the capture/compare flag (ccf0) interrupt. 0: disable ccf0 interrupts. 1: enable a capture/compare flag interrupt request when ccf0 is set.
c8051f97x 440 rev 1.0 programmable counter array (pca0) register 33.7. pca0cpl0: pca channel 0 capture module low byte bit 7 6 5 4 3 2 1 0 name pca0cpl0 type rw reset 0 0 0 0 0 0 0 0 sfr page = 0x0; sfr address: 0xfb table 33.10. pca0cpl0 register bit descriptions bit name function 7:0 pca0cpl0 pca channel 0 capture module low byte. the pca0cpl0 register holds the low byte (l sb) of the 16-bit capture module. this reg - ister address also allows access to the low byte of the corresponding pca channel's auto-reload value for 9 to 11-bit pwm mode. the arsel bit in register pca0pwm con - trols which register is accessed. note: a write to this register will clear the module's ecom bit to a 0.
c8051f97x rev 1.0 441 programmable co unter array (pca0) register 33.8. pca0cph0: pca channel 0 capture module high byte bit 7 6 5 4 3 2 1 0 name pca0cph0 type rw reset 0 0 0 0 0 0 0 0 sfr page = 0x0; sfr address: 0xfc table 33.11. pca0cph0 register bit descriptions bit name function 7:0 pca0cph0 pca channel 0 capture module high byte. the pca0cph0 register holds the high byte (msb) of the 16-bit capture module. this register address also allows access to the hi gh byte of the corresponding pca channel's auto-reload value for 9 to 11-bit pwm mode. the arsel bit in register pca0pwm con - trols which register is accessed. note: a write to this register will set the module's ecom bit to a 1.
c8051f97x 442 rev 1.0 programmable counter array (pca0) register 33.9. pca0cpm1: pca channel 1 capture/compare mode bit 7 6 5 4 3 2 1 0 name pwm16 ecom capp capn mat tog pwm eccf type rw rw rw rw rw rw rw rw reset 0 0 0 0 0 0 0 0 sfr page = 0x0; sfr address: 0xdb table 33.12. pca0cpm1 register bit descriptions bit name function 7 pwm16 channel 1 16-bit pulse width modulation enable. this bit enables 16-bit mode when pulse width modulation mode is enabled. 0: 8 to 11-bit pwm selected. 1: 16-bit pwm selected. 6 ecom channel 1 comparator function enable. this bit enables the comparator function. 5 capp channel 1 capture positive function enable. this bit enables the positive edge capture capability. 4 capn channel 1 capture negative function enable. this bit enables the negative edge capture capability. 3 mat channel 1 match function enable. this bit enables the match function. when en abled, matches of the pca counter with a module's capture/compare regist er cause the ccf1 bit in the pca0md register to be set to logic 1. 2 tog channel 1 toggle function enable. this bit enables the toggle function. when enabled, matches of the pca counter with the capture/compare register cause the logic leve l on the cex1 pin to toggle. if the pwm bit is also set to logic 1, the module operates in frequency output mode. 1 pwm channel 1 pulse width modulation mode enable. this bit enables the pwm function. when enabled, a pulse width modulated signal is out - put on the cex1 pin. 8 to 11-bit pwm is used if pwm16 is cleared to 0; 16-bit mode is used if pwm16 is set to 1. if the tog bit is also set, the module operates in frequency output mode. 0 eccf channel 1 capture/compare flag interrupt enable. this bit sets the masking of the capture/compare flag (ccf1) interrupt. 0: disable ccf1 interrupts. 1: enable a capture/compare flag interrupt request when ccf1 is set.
c8051f97x rev 1.0 443 programmable co unter array (pca0) register 33.10. pca0cpl1: pca channel 1 capture module low byte bit 7 6 5 4 3 2 1 0 name pca0cpl1 type rw reset 0 0 0 0 0 0 0 0 sfr page = 0x0; sf r address: 0xe9 table 33.13. pca0cpl1 register bit descriptions bit name function 7:0 pca0cpl1 pca channel 1 capture module low byte. the pca0cpl1 register holds the low byte (l sb) of the 16-bit capture module. this reg - ister address also allows access to the low byte of the corresponding pca channel's auto-reload value for 9 to 11-bit pwm mode. the arsel bit in register pca0pwm con - trols which register is accessed. note: a write to this register will clear the module's ecom bit to a 0.
c8051f97x 444 rev 1.0 programmable counter array (pca0) register 33.11. pca0cph1: pca channel 1 capture module high byte bit 7 6 5 4 3 2 1 0 name pca0cph1 type rw reset 0 0 0 0 0 0 0 0 sfr page = 0x0; sf r address: 0xea table 33.14. pca0cph1 register bit descriptions bit name function 7:0 pca0cph1 pca channel 1 capture module high byte. the pca0cph1 register holds the high byte (msb) of the 16-bit capture module. this register address also allows access to the hi gh byte of the corresponding pca channel's auto-reload value for 9 to 11-bit pwm mode. the arsel bit in register pca0pwm con - trols which register is accessed. note: a write to this register will set the module's ecom bit to a 1.
c8051f97x rev 1.0 445 programmable co unter array (pca0) register 33.12. pca0cpm2: pca channel 2 capture/compare mode bit 7 6 5 4 3 2 1 0 name pwm16 ecom capp capn mat tog pwm eccf type rw rw rw rw rw rw rw rw reset 0 0 0 0 0 0 0 0 sfr page = 0x0; sfr address: 0xdc table 33.15. pca0cpm2 register bit descriptions bit name function 7 pwm16 channel 2 16-bit pulse width modulation enable. this bit enables 16-bit mode when pulse width modulation mode is enabled. 0: 8 to 11-bit pwm selected. 1: 16-bit pwm selected. 6 ecom channel 2 comparator function enable. this bit enables the comparator function. 5 capp channel 2 capture positive function enable. this bit enables the positive edge capture capability. 4 capn channel 2 capture negative function enable. this bit enables the negative edge capture capability. 3 mat channel 2 match function enable. this bit enables the match function. when en abled, matches of the pca counter with a module's capture/compare regist er cause the ccf2 bit in the pca0md register to be set to logic 1. 2 tog channel 2 toggle function enable. this bit enables the toggle function. when enabled, matches of the pca counter with the capture/compare register cause the logic leve l on the cex2 pin to toggle. if the pwm bit is also set to logic 1, the module operates in frequency output mode. 1 pwm channel 2 pulse width modulation mode enable. this bit enables the pwm function. when enabled, a pulse width modulated signal is out - put on the cex2 pin. 8 to 11-bit pwm is used if pwm16 is cleared to 0; 16-bit mode is used if pwm16 is set to 1. if the tog bit is also set, the module operates in frequency output mode. 0 eccf channel 2 capture/compare flag interrupt enable. this bit sets the masking of the capture/compare flag (ccf2) interrupt. 0: disable ccf2 interrupts. 1: enable a capture/compare flag interrupt request when ccf2 is set.
c8051f97x 446 rev 1.0 programmable counter array (pca0) register 33.13. pca0cpl2: pca channel 2 capture module low byte bit 7 6 5 4 3 2 1 0 name pca0cpl2 type rw reset 0 0 0 0 0 0 0 0 sfr page = 0x0; sf r address: 0xeb table 33.16. pca0cpl2 register bit descriptions bit name function 7:0 pca0cpl2 pca channel 2 capture module low byte. the pca0cpl2 register holds the low byte (l sb) of the 16-bit capture module. this reg - ister address also allows access to the low byte of the corresponding pca channel's auto-reload value for 9 to 11-bit pwm mode. the arsel bit in register pca0pwm con - trols which register is accessed. note: a write to this register will clear the module's ecom bit to a 0.
c8051f97x rev 1.0 447 programmable co unter array (pca0) register 33.14. pca0cph2: pca channel 2 capture module high byte bit 7 6 5 4 3 2 1 0 name pca0cph2 type rw reset 0 0 0 0 0 0 0 0 sfr page = 0x0; sf r address: 0xec table 33.17. pca0cph2 register bit descriptions bit name function 7:0 pca0cph2 pca channel 2 capture module high byte. the pca0cph2 register holds the high byte (msb) of the 16-bit capture module. this register address also allows access to the hi gh byte of the corresponding pca channel's auto-reload value for 9 to 11-bit pwm mode. the arsel bit in register pca0pwm con - trols which register is accessed. note: a write to this register will set the module's ecom bit to a 1.
c8051f97x 448 rev 1.0 c2 interface 34. c2 interface c8051f97x devices include an on-chip silicon labs 2-wire (c2) debug interface to allow flash programming and in-system debugging with the production part installed in the end application. the c2 in terface uses a clock signal (c2ck) and a bidirectional c2 data signal (c2d) to tran sfer information between the device and a host system. details on the c2 protocol can be fo und in the c2 interface specification. 34.1. c2 pin sharing the c2 protocol allows the c2 pins to be shared with user functions so that in-system debugging and flash programming may be performed. c2ck is shared with the rst pin, while the c2d signal is shared with a port i/o pin. this is possible because c2 communication is typica lly performed when the device is in the halt state, where all on-chip peripherals and user software are stalled. in th is halted state, the c2 interface can safely ?borrow? the c2ck and c2d pins. in most applications, external resistor s are required to isolate c2 interface traffic from the user application. a typical isolation c onfiguration is shown in figure 34.1. figure 34.1. typical c2 pin sharing the configuration in figure 34.1 assumes the following: 1. the user input (b) cannot change state while the target device is halted. 2. the rst pin on the target device is used as an input only. additional resistors may be necessary depending on the specific application. c2d c2ck /reset (a) input (b) output (c) c2 interface master c8051fxxx
c8051f97x rev 1.0 449 c2 interface 34.2. c2 interface registers the following describes the c2 registers necessary to perf orm flash programming through the c2 interface. all c2 registers are accessed through the c2 interface, and are not available in the sfr map for firmware access. register 34.1. c2add: c2 address bit 7 6 5 4 3 2 1 0 name c2add type rw reset00000000 this register is part of the c2 protocol. table 34.1. c2add register bit descriptions bit name function 7:0 c2add c2 address. the c2add register is accessed via the c2 interface. the valu e written to c2add selects the target data register for c2 data read and data write commands. 0x00: c2devid 0x01: c2revid 0x02: c2fpctl 0xb4: c2fpdat
c8051f97x 450 rev 1.0 c2 interface register 34.2. c2devid: c2 device id bit 7 6 5 4 3 2 1 0 name c2devid type r reset00101001 c2 address: 0x00 table 34.2. c2devid register bit descriptions bit name function 7:0 c2devid device id. this read-only register returns the 8-bit device id: 0x29 (c8051f97x).
c8051f97x rev 1.0 451 c2 interface register 34.3. c2revid: c2 revision id bit 7 6 5 4 3 2 1 0 name c2revid type r resetxxxxxxxx c2 address: 0x01 table 34.3. c2revid register bit descriptions bit name function 7:0 c2revid revision id. this read-only register returns the 8-bit revision id. for example: 0x01 = revision a.
c8051f97x 452 rev 1.0 c2 interface register 34.4. c2fpctl: c2 flash programming control bit 7 6 5 4 3 2 1 0 name c2fpctl type rw reset00000000 c2 address: 0x02 table 34.4. c2fpctl register bit descriptions bit name function 7:0 c2fpctl flash programming control register. this register is used to enable flash progr amming via the c2 interface. to enable c2 flash programming, the following codes must be written in order: 0x02, 0x01. note that once c2 flash programming is enabled, a system reset must be issued to resume normal operation.
c8051f97x rev 1.0 453 c2 interface register 34.5. c2fpdat: c2 flash programming data bit 7 6 5 4 3 2 1 0 name c2fpdat type rw reset00000000 c2 address: 0xb4 table 34.5. c2fpdat register bit descriptions bit name function 7:0 c2fpdat c2 flash programming data register. this register is used to pass flash comm ands, addresses, and data during c2 flash accesses. valid commands are listed below. 0x03: device erase 0x06: flash block read 0x07: flash block write 0x08: flash page erase
c8051f97x 454 rev 1.0 d ocument c hange l ist revision 0.1 to revision 1.0 ?? updated capacitive sense and adc input channels listed on the front page. ?? removed mention of the -i temperature grade from figure 4.1, ?c8051f97x part numbering,? on page 41 . ?? updated digital supply current numbers in ta b l e 1.2, ?global electrical characteristics,? on page 10 to reflect the latest data. ?? removed mention of 12-bit mode for adc0. ?? added a note to "17.1. adc0 analog multiplexer" on page 105 , the adc0mx register, and all amux0 registers regarding disconnecting the amux0 wh en measuring an internal signal with the adc. ?? updated "24. clocking sources" on page 242 to mention that th e external oscillator is not available on qfn-24 (c8051f972/5) packages. ?? updated "25. smartclock (real time clock, rtc0)" on page 254 references to rtc0 cn at address 0x05 to correctly re fer to rtc0xcn. ?? updated "25. smartclock (real time clock, rtc0)" on page 254 to remove mention of using an external cmos clock with the smartclock. ?? updated port pins associated with the crystal pins on each package in table 26.1, ?port i/o assignment for analog functions,? on page 280 .
c8051f97x rev 1.0 455 c ontact i nformation silicon laboratories inc. 400 west cesar chavez ? austin, tx 78701 ? tel: 1+(512) 416-8500 ? fax: 1+(512) 416-9669 ? toll free: 1+(877) 444-3032 please visit the silicon labs technical support web page: ? https://www.siliconlabs.com/suppor t/pages/contacttechnicalsupport.aspx ? and register to submit a technical support request. patent notice silicon labs invests in research and development to help our cust omers differentiate in the market with innovative low-power, s mall size, analog- intensive mixed-signal soluti ons. silicon labs' extensive patent portfolio is a testament to our unique approach and world-clas s engineering team. silicon laboratories and silicon labs are trademarks of silicon laboratories inc. other products or brandnames mentioned herein are trademarks or registered trademarks of their respective holders. the information in this document is believed to be accurate in all respects at the time of publ ication but is subject to change without notice. silicon laboratories assumes no responsibili ty for errors and omissions, and disclaim s responsibility for any consequences resu lting from the use of information included herein. a dditionally, silicon laboratorie s assumes no responsibility for the functioning of und escribed fea- tures or parameters. silicon laboratories reserves the right to make changes without further notice. silicon laboratories makes no warran- ty, representation or guarantee regarding the suitability of it s products for any particular pur pose, nor does silicon laborato ries assume any liability arising out of the application or use of any product or circuit, and specif ically disclaims any and all liability, in cluding without limitation consequential or incidental damages . silicon laboratories products are not designed, intended, or authorized for use in applica tions intend- ed to support or sustain life, or for any other application in which the failure of the silicon laboratories product could crea te a situation where personal injury or death may occur. should buyer purchase or us e silicon laboratories products for any such unintended or unaut horized application, buyer shall indemnify and hold silicon laboratories harmle ss against all claims and damages.


▲Up To Search▲   

 
Price & Availability of C8051F974

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X