AT89C5132_07 ATMEL | Alldatasheet
Document overview
- Manufacturer or author: Provided By ALLDATASHEET.COM(FREE DATASHEET DOWNLOAD SITE)
- PDF pages: 182
Technical content
Features
- Programmable Audio Output for Interfacing with Common Audio DAC – PCM Format Compatible – I 2S Format Compatible
- 8-bit MCU C51 Core-based (F MAX = 20 MHz)
- 2304 Bytes of Internal RAM
- 64K Bytes of Code Memory – AT89C5132: Flash (100K Write/Erase Cycles)
- 4K Bytes of Boot Flash Memory (AT89C5132) – ISP: Download from USB (standard) or UART (option)
- USB Rev 1.1 Device Controller – “Full Speed” Data Transmission
- Built-in PLL
- MultiMedia Card ® Interface Compatibility
- Atmel DataFlash ® SPI Interface Compatibility
- IDE/ATAPI Interface
- 2 Channels 10-bit ADC, 8 kHz (8 True Bits) – Battery Voltage Monitoring – Voice Recording Controlled by Software
- Up to 44 Bits of General-purpose I/Os – 4-bit Interrupt Keyboard Port for a 4 x n Matrix – SmartMedia ® Software Interface
- Two Standard 16-bit Timers/Counters
- Hardware Watchdog Timer
- Standard Full Duplex UART with Baud Rate Generator
- Two Wire Master and Slave Modes Controller
- SPI Master and Slave Modes Controller
- Power Management – Power-on Reset – Software Programmable MCU Clock – Idle Mode, Power-down Mode
- Operating Conditions – 3V, ±10%, 25 mA Typical Operating at 25° C – Temperature Range: -40 °C to +85 °C
- Packages – TQFP80, PLCC84 (Development Board Only) – Dice 1. Description The AT89C5132 is a mass storage device controlling data exchange between various Flash modules, HDD and CD-ROM. The AT89C5132 includes 64K Bytes of Flash memory and allows In-System Program- ming through an embedded 4K Bytes of Boot Flash Memory. The AT89C5132 include 2304 Bytes of RAM memory. The AT89C5132 provides all the necessary features f or man-machine interface including, timers, keyboard port, serial or paralle l interface (USB, SPI, IDE), ADC input, I 2S output, and all external memory interface (NAND o r NOR Flash, SmartMe- dia, MultiMedia, DataFlash cards). 2. Typical Applications
- Flash Recorder/Writer
- PDA, Camera, Mobile Phone
- PC Add-on USB Microcontroller with 64K Bytes Flash Memory AT89C5132 4173E–USB–09/07
4173E–USB–09/07 AT89C5132 3. Block Diagram Figure 3-1. AT89C5132 Block Diagram Notes: 1. Alternate function of Port 3 2. Alternate function of Port 4 3. Alternate function of Port 1 8-BIT INTERNAL BUS Clock and PLL Unit C51 (X2 CORE) RAM
2304 Bytes
KIN3:0 I2S/PCM Audio Interface AVSS AVDD AIN1:0 Ports INT0 INT1 MOSI MISO Timers 0/1 T1 T0 SPI/DataFlash Controller MCLK MCMD SCK RST AREF DSEL DCLK SCLK DOUT 64K Bytes USB Controller D+ D- UART RXD TXD IDE Interface SS Watchdog Flash Boot 4K Bytes UVSS UVDD and BRG 1 1 1 1 1 1 2 2 2 2 TWI Controller SCL SDA 1 1
4173E–USB–09/07 AT89C5132 4. Pin Description Figure 4-1. AT89C5132 80-pin TQFP Package P0.3/AD3 P0.4/AD4 P0.5/AD5 VSS VDD P0.6/AD6 P0.7/AD7 P2.0/A8 P2.1/A9 P3.1/TXD P3.2/INT0 P3.3/INT1 P3.4/T0 P3.0/RXD P2.2/A10 P2.3/A11 P2.4/A12 P2.6/A14 P2.5/A13 P2.7/A15 MCLK MDAT MCMD P0.2/AD2 P0.1/AD1 P0.0/AD0 PVSS VSS TST VSS P4.3/SS P4.2/SCK P4.1/MOSI P4.0/MISO VSS VDD RST SCLK DSEL DCLK DOUT AIN1 AIN0 AREFN AREFP AVSS AVDD P3.7/RD P3.6/WR P3.5/T1 VDD P1.0/KIN0 P1.1/KIN1 P1.2/KIN2 P1.3/KIN3 P1.4 P1.5 P1.7/SDA FILT PVDD VDD P1.6/SCL ALE ISP UVDD UVSS P5.0 P5.1 P4.7 P4.6 P5.3 P5.2 VSS VDD P4.5 P4.4 TQFP80
Note: 1. For development board only.
4.1 Signals
All the AT89C5132 signals are detailed by functionality in Table 1 to Table 14. Table 1. Ports Signal Description current consumption, floating P0 inputs must be pol arized to V DD or V SS . P1 is an 8-bit bidirectional I/O port with internal pull-ups.
Table 2. Clock Signal Description Table 3. Timer 0 and Timer 1 Signal Description P3 is an 8-bit bidirectional I/O port with internal pull-ups. P4 is an 8-bit bidirectional I/O port with internal pull-ups. To use the internal oscillator, a crystal/resonator circuit is connected to this pin. clock source for internal timing. To use the internal oscillator, a crystal/resonator circuit is connected to this pin. If an external oscillator is used, leave X2 unconne cted.
Table 4. Audio Interface Signal Description Table 5. USB Controller Signal Description Table 6. MutiMediaCard Interface Signal Description and the channel selection signal (DSEL). must be polarized to V DD or V SS . MDAT input must be polarized to V DD or V SS .
Table 7. UART Signal Description Table 8. SPI Controller Signal Description Table 9. TWI Controller Signal Description Table 10. A/D Converter Signal Description slave mode, MISO outputs data to the master control ler. slave mode, MOSI receives data from the master cont roller. slave mode, SCK receives clock from the master cont roller.
Table 11. Keypad Interface Signal Description Table 12. External Access Signal Description Table 13. System Signal Description Upper address lines for the external bus. Multiplexed higher address and data lines for the I DE interface. the address from address/data bus. reset to force execution of the internal bootloader . voltage lower than V IL is applied, whether or not the oscillator is runni ng. by connecting a capacitor between this pin and V DD .
Table 14. Power Signal Description
4.2 Internal Pin Structure
Table 15. Detailed Internal Pin Structure Section “DC Characteristics”, page 183.
- When the Two Wire controller is enabled, P 1, P 2, and P 3 transistors are disabled allowing
pseudo open-drain structure.
- In Port 2, P 1 transistor is continuously driven when outputting a high level bit address (A15:8).
4173E–USB–09/07 AT89C5132 5. Address Spaces The AT8xC5132 derivatives implement four different address spaces:
- Program/Code Memory
- Boot Memory
- Data Memory
- Special Function Registers (SFRs)
5.0.1 Code Memory
The AT89C5132 implements 64K Bytes of on-chip program/code memory in Flash technology. The Flash memory increases ROM functionality by enabling in-circuit electrical erasure and pro- gramming. Thanks to the internal charge pump, the h igh voltage needed for programming or erasing Flash cells is generated on-chip using the standard V DD voltage. Thus, the AT89C5132 can be programmed using only one voltage and allows in application software programming commonly known as IAP. Hardware programming mode is also available using specific pro- gramming tools.
5.0.2 Boot Memory
The AT89C5132 implements 4K Bytes of on-chip boot m emory provided in Flash technology. This boot memory is delivered programmed with a standard bootloader software allowing in sys- tem programming commonly known as ISP. It also cont ains some Application Programming Interfaces routines commonly known as API allowing user to develop his own bootloader.
5.0.3 Data Memory
The AT89C5132 derivatives implement 2304 bytes of on-chip data RAM. This memory is divided in two separate areas:
- 256 bytes of on-chip RAM memory (standard C51 memo ry).
- 2048 bytes of on-chip expanded RAM memory (ERAM ac cessible via MOVX instructions).
4173E–USB–09/07 AT89C5132 6. Clock Controller The AT89C5132 clock controller is based on an on-ch ip oscillator feeding an on-chip Phase Lock Loop (PLL). All internal clocks to the periphe rals and CPU core are generated by this controller.
6.1 Oscillator
The AT89C5132 X1 and X2 pins are the input and the output of a single-stage on-chip inverter (see Figure 6-1) that can be configured with off-ch ip components such as a Pierce oscillator (see Figure 6-2). Value of capacitors and crystal c haracteristics are detailed in the Section “DC Characteristics”. The oscillator outputs three different clocks: a clock for the PLL, a clock for the CPU core, and a clock for the peripherals as shown in Figure 6-1. T hese clocks are either enabled or disabled, depending on the power reduction mode as detailed i n the section “Power Management” on page 44 . The peripheral clock is used to generate the Time r 0, Timer 1, MMC, ADC, SPI, and Port sampling clocks. Figure 6-1. Oscillator Block Diagram and Symbol Figure 6-2. Crystal Connection
6.2 X2 Feature
Unlike standard C51 products that require 12 oscill ator clock periods per machine cycle, the AT89C5132 needs only 6 oscillator clock periods per machine cycle. This feature called the “X2 feature” can be enabled using the X2 bit (1) in CKCON (see Table 1) and allows the AT89C5132 to operate in 6 or 12 oscillator clock periods per machine cycle. As shown in Figure 6-1, both CPU and peripheral clocks are affected by this feature. Figure 6-3 shows the X2 mode switching waveforms. After reset, the standard mode is activa ted. In standard mode, the CPU and periph- PD PCON.1 IDL PCON.0 Peripheral CPU Core CKCON.0 ÷ 2 PER CLOCK Clock Clock Peripheral Clock Symbol CPU CLOCK CPU Core Clock Symbol OSC CLOCK Oscillator Clock Symbol Oscillator Clock VSS Q
4173E–USB–09/07 AT89C5132 eral clock frequency is the oscillator frequency di vided by 2 while in X2 mode, it is the oscillator frequency. Note: 1. The X2 bit reset value depends on the X2B bi t in the Hardware Security Byte (see Table 12 on page 24). Using the AT89C5132 (Flash Version) the system can boot either in standard or X2 mode depending on the X2B value. Using AT83C51SND1C (ROM Version) the system always boots in standard mode. X2B bit can be changed to X2 mode later by software. Figure 6-3. Mode Switching Waveforms Note: In order to prevent any incorrect operation wh ile operating in X2 mode, the user must be aware that all peripherals using clock frequency as time reference (timers…) will have their time refer- ence divided by two. For example, a free running ti mer generating an interrupt every 20 ms will then generate an interrupt every 10 ms.
6.3 PLL
6.3.1 PLL Description
The AT89C5132 PLL is used to generate internal high frequency clock (the PLL Clock) synchro- nized with an external low-frequency (the Oscillato r Clock). The PLL clock provides the audio interface, and the USB interface clocks. Figure 6-4 shows the internal structure of the PLL. The PFLD block is the Phase Frequency Comparator an d Lock Detector. This block makes the comparison between the reference clock coming from the N divider and the reverse clock com- ing from the R divider and generates some pulses on the Up or Down signal depending on the edge position of the reverse clock. The PLLEN bit i n PLLCON register is used to enable the clock generation. When the PLL is locked, the bit P LOCK in PLLCON register (see Table 3) is set. The CHP block is the Charge Pump that generates the voltage reference for the VCO by inject- ing or extracting charges from the external filter connected on PFILT pin (see Figure 6-5). Value of the filter components are detailed in the Section “DC Characteristics”. The VCO block is the Voltage Controlled Oscillator controlled by the voltage V ref produced by the charge pump. It generates a square wave signal: the PLL clock. X1 ÷ 2 Clock X2 Bi t X2 Mode (1) STD Mode STD Mode
6.3.2 PLL Programming
PLL clock frequency will depend on the audio interface clock frequencies.
6.4 Registers
Table 1. CKCON Register
Table 2. PLLNDIV Register
7 TWIX2
Set to select the oscillator clock divided by 2 as TWI clock input (X2 independent). Clear to select the peripheral clock as TWI clock i nput (X2 dependent).
6 WDX2
Set to select the oscillator clock divided by 2 as watchdog clock input (X2 independent). Clear to select the peripheral clock as watchdog cl ock input (X2 dependent). The value read from this bit is indeterminate. Do n ot set this bit.
4 SIX2
Set to select the oscillator clock divided by 2 as UART clock input (X2 independent). Clear to select the peripheral clock as UART clock input (X2 dependent).. The value read from this bit is indeterminate. Do n ot set this bit.
2 T1X2
Set to select the oscillator clock divided by two a s Timer 1 clock input (X2 independent). Clear to select the peripheral clock as Timer 1 clo ck input (X2 dependent).
1 T0X2
Set to select the oscillator clock divided by two a s timer 0 clock input (X2 independent). Clear to select the peripheral clock as timer 0 clo ck input (X2 dependent). Clear to select 12 clock periods per machine cycle (STD mode, F CPU = F PER = F OSC /2). Set to select 6 clock periods per machine cycle (X2 mode, F CPU = F PER = F OSC ). The value read from this bit is always 0. Do not se t this bit.
Table 3. PLLCON Register Table 4. PLLRDIV Register 2 LSB of the 10-bit R divider. The values read from these Bits are always 0. Do no t set these Bits.
3 PLLRES
Set this bit to reset the PLL. Clear this bit to free the PLL and allow enabling. The values read from this bit is always 0. Do not s et this bit.
1 PLLEN
0 PLOCK
Set by hardware when PLL is locked. Clear by hardware when PLL is unlocked. 8 MSB of the 10-bit R divider.
4173E–USB–09/07 AT89C5132 7. Program/Code Memory The AT89C5132 implements 64K Bytes of on-chip program/code memory. Figure 7-1 shows the split of internal and external program/code memory spaces depending on the product. The Flash memory increases EPROM and ROM functional ity by in-circuit electrical erasure and programming. The high voltage needed for programmin g or erasing Flash cells is generated on- chip using the standard V DD voltage, made possible by the internal charge pump . Thus, the AT89C5132 can be programmed using only one voltage and allows in application software pro- gramming. Hardware programming mode is also availab le using common programming tools. See the application note ‘Programming T89C51x and AT89C51x with Device Programmers’. The AT89C5132 implements an additional 4K Bytes of on-chip boot Flash memory provided in Flash memory. This boot memory is delivered program med with a standard bootloader software allowing In-System Programming (ISP). It also conta ins some Application Programming Inter- faces (API), allowing In Application Programming (IAP) by using user’s own bootloader. Figure 7-1. Program/Code Memory Organization
7.1 Flash Memory Architecture
As shown in Figure 7-2 the AT89C5132 Flash memory i s composed of four spaces detailed in the following paragraphs. Figure 7-2. AT89C5132 Memory Architecture 4K Bytes Boot Flash FFFFh F000h 0000h 64K Bytes Code Flash FFFFh F000h FFFFh 64K Bytes Flash Memory 0000h Hardware Security User 4K Bytes Flash Memory FFFFh F000h Boot Extra Row
7.1.1 User Space
7.1.2 Boot Space
Programming and the routines for In-System Application Programming. This space can only be read or written by hardware mode using a parallel programming tool.
7.1.3 Hardware Security Space
detailed in section “Hardware Security System” and can only be written by hardware.
7.1.4 Extra Row Space
- The Software Boot Vector (SBV see Table 8). This byte is used by the software bootloader to build the boot address.
- The Software Security Byte (SSB see Figure ). This byte is used to lock the execution of some bootloader commands.
7.2 Hardware Security System
always set in read disabled mode.
- Level 0 is the level of an erased part and does no t enable any security feature.
- Level 1 locks the hardware programming of both use r and boot memories.
- Level 2 locks hardware verifying of both user and boot memories.
- Level 3 locks the external execution. Notes: 1. U means unprogrammed, P means programmed an d X means don’t care (programmed or unprogrammed). 2. LB2 is not implemented in the AT89C5132 products. 3. AT89C5132 products are delivered with third level programmed to ensure that the code pro- grammed by software using ISP or user’s bootloader is secured from any hardware piracy.
Table 5. Lock Bit Features (1)
0 U U U Enable Enable Enable Enable Enable
1 U U P Enable Enable Enable Disable Enable
2 U P X Enable Enable Disable Disable Enable
4173E–USB–09/07 AT89C5132
7.3 Boot Memory Execution
As internal C51 code space is limited to 64K Bytes, some mechanisms are implemented to allow boot memory to be mapped in the code space for execution at addresses from F000h to FFFFh. The boot memory is enabled by setting the ENBOOT bi t in AUXR1 (see Table 6 ). The three ways to set this bit are detailed in the following sections.
7.3.1 Software Boot Mapping
The software way to set ENBOOT consists in writing to AUXR1 from the user’s software. This enables bootloader or API routines execution.
7.3.2 Hardware Condition Boot Mapping
The hardware condition is based on the ISP pin. When driving this pin to low level, the chip reset sets ENBOOT and forces the reset vector to F000h in stead of 0000h in order to execute the bootloader software. As shown in Figure 7-3, the hardware condition alwa ys allows in-system recovery when user’s memory has been corrupted.
7.3.3 Programmed Condition Boot Mapping
The programmed condition is based on the Bootloader Jump Bit (BLJB) in HSB. As shown in Figure 7-3, when this bit is programmed (by hardwar e or software programming mode), the chip resets ENBOOT and forces the reset vector to F000h instead of 0000h, in order to execute the bootloader software. Figure 7-3. Hardware Boot Process Algorithm The software process (bootloader) is detailed in the AT89C5132 Bootloader datasheet. Atmel’s Boot Loader HardwareSoftware Hard Cond? ISP = L? RESET Hard Cond Init ENBOOT = 1 PC = F000h FCON = 00h Prog Cond? BLJB = P? Standard Init ENBOOT = 0 PC = 0000h FCON = F0h Prog Cond Init ENBOOT = 1 PC = F000h FCON = F0h User’s Application Process Process
7.3.4 Preventing Flash Corruption
See “Reset Recommendation to Prevent Flash Corruption” on page 45 .
7.4 Registers
Table 6. AUXR1 Register
7.5 Hardware Bytes
Table 7. HSB Byte – Hardware Security Byte The values read from these Bits are indeterminate. Do not set these Bits.
5 ENBOOT
Clear this bit to disable boot Flash. The values read from this bit is indeterminate. Do not set this bit.
3 GF3 General Flag
This bit is a general-purpose user flag. This bit is stuck to logic 0 to allow INC AUXR1 ins truction without affecting GF3 flag. 1 - Reserved for Data Pointer Extension.
0 DPS
Set to select second data pointer: DPTR1. Clear to select first data pointer: DPTR0.
7 X2B (1)
Program this bit to start in X2 mode. Unprogram (erase) this bit to start in standard mod e.
6 BLJB (2)
Program this bit to execute the boot loader at addr ess F000h on next reset. Unprogram (erase) this bit to execute user’s applic ation at address 0000h on next reset. The value read from these bits is always unprogramm ed. Do not program these bits. The value read from this bit is always unprogrammed . Do not program this bit.
Reset Value = XXUU UXXX, UUUU UUUU after an hardwar e full chip erase. Note: 1. X2B initializes the X2 bit in CKCON during t he reset phase.
- In order to ensure boot loader activation at firs t power-up, AT89C5132 products are delivered
- Bits 0 to 3 (LSN) can only be programmed by hardw are mode.
Table 8. SBV Byte – Software Boot Vector Reset Value = XXXX XXXX, UUUU UUUU after an hardware full chip erase. Table 9. SSB Byte – Software Security Byte Reset Value = XXXX XXXX, UUUU UUUU after an hardware full chip erase. Refer to for bits description. Refer to the bootloader datasheet for usage informa tion (bootloader dependent). Refer to the bootloader datasheet for usage informa tion (bootloader dependent).
- The internal space mapped in three separate segme nts:
refer to the section “Special Function Registers”, page 29. Figure 8-1 shows the internal and external data mem ory spaces organization.
8.1 Internal Space
8.1.1 Lower 128 Bytes RAM
Table 10. Register Bank Selection
128 Bytes
8.1.2 Upper 128 Bytes RAM
8.1.3 Expanded RAM
See “External Space” on page 23. Table 11. ERAM Size Selection
8.2 External Space
8.2.1 Memory Interface
control signals (RD , WR , and ALE).
4 Banks of
8 Registers
nal memory interface signals. Table 12. External Data Memory Interface Signals
8.2.2 Page Access Mode
while keeping P2 for general I/O usage.
8.2.3 External Bus Cycles
write data (see Figure 8-5) in the external data memory.
4173E–USB–09/07 AT89C5132
8.3 Dual Data Pointer
8.3.1 Description
The AT89C5132 implement a second data pointer for speeding up code execution and reducing code size in case of intensive usage of external memory accesses. DPTR0 and DPTR1 are seen by the CPU as DPTR and are accessed using the SFR addresses 83h and 84h that are the DPH and DPL addresses. The DPS bit in AUXR1 register (see Table 15) is used to select whether DPTR is the dat a pointer 0 or the data pointer 1 (see Figure 8-6). Figure 8-6. Dual Data Pointer Implementation
8.3.2 Application
Software can take advantage of the additional data pointers to both increase speed and reduce code size, for example, block operations (copy, com pare, search …) are well served by using one data pointer as a “source” pointer and the othe r one as a “destination” pointer. Below is an example of block move implementation us ing the two pointers and coded in assem- bler. The latest C compiler also takes advantage of this feature by providing enhanced algorithm libraries. The INC instruction is a short (2 Bytes) and fast (6 CPU clocks) way to manipulate the DPS bit in the AUXR1 register. However, note that the INC inst ruction does not directly forces the DPS bit to a particular state, but simply toggles it. In si mple routines, such as the block move example, only the fact that DPS is toggled in the proper seq uence matters, not its actual value. In other words, the block move routine works the same whether DPS is “0” or “1” on entry. ; ASCII block move using dual data pointers ; Modifies DPTR0, DPTR1, A and PSW ; Ends when encountering NULL character ; Note: DPS exits opposite of entry state unless an extra INC AUXR1 is added AUXR1 EQU 0A2h move: mov DPTR,#SOURCE ; address of SOURCE inc AUXR1 ; switch data pointers mov DPTR,#DEST ; address of DEST mv_loop: inc AUXR1 ; switch data pointers movx A,@DPTR ; get a byte from SOURCE inc DPTR ; increment SOURCE address inc AUXR1 ; switch data pointers movx @DPTR,A ; write the byte to DEST inc DPTR ; increment DEST address jnz mv_loop ; check for NULL terminator end_move: DPH0 DPH1 DPL0 DPS AUXR1.0 DPH DPL DPL1 DPTR DPTR0 DPTR1
8.4 Registers
Table 13. PSW Register Table 14. AUXR Register
7 CY Carry Flag
Carry out from bit 1 of ALU operands.
6 AC Auxiliary Carry Flag
Carry out from bit 1 of addition operands. Refer to Table 10 for Bits description.
2 OV Overflow Flag
Overflow set by arithmetic operations.
1 F1 User Definable Flag 1
Set when ACC contains an odd number of 1’s. Cleared when ACC contains an even number of 1’s. The values read from this bit is indeterminate. Do not set this bit.
6 EXT16
Set to enable 16-bit access mode during MOVX instru ctions. Set to stretch RD or WR signals duration to 15 CPU clock periods. Clear not to stretch RD or WR signals and set duration to 3 CPU clock periods.
4 DPHDIS
Set to disable DPH output on P2 when executing MOVX @DPTR instruction. Clear to enable DPH output on P2 when executing MOV X @DPTR instruction. Refer to Table 11 for ERAM size description.
4173E–USB–09/07 AT89C5132 Reset Value = X000 1101b
1 EXTRAM
Set to select the external XRAM when executing MOVX @Ri or MOVX @DPTR instructions. Clear to select the internal expanded RAM when exec uting MOVX @Ri or MOVX @DPTR instructions. 0 AO ALE Output Enable Bit Set to output the ALE signal only during MOVX instr uctions. Clear to output the ALE signal at a constant rate o f F CPU /3. Bit Number Bit Mnemonic Description
- Special Function Registers
Table 15. C51 Core SFRs Table 16. System Management SFRs Table 17. PLL and System Clock SFRs Table 18. Interrupt SFRs
Table 19. Port SFRs Table 20. Flash Memory SFR Table 21. Timer SFRs Table 22. Audio Interface SFRs
Table 23. USB Controller SFRs Table 24. MMC Controller SFRs Table 25. IDE Interface SFR
Table 26. Serial I/O Port SFRs Table 27. SPI Controller SFRs Table 28. Special Register Table 29. Keyboard Interface SFRs Table 30. A/D Controller SFRs
Notes: 1. SFR registers with least significant nibble address equal to 0 or 8 are bit-addressable.
- NVERS reset value depends on the silicon version: 1000 0011 for AT89C5132 product
- FCON register is only available in AT89C5132 prod uct.
- FCON reset value is 00h in case of reset with har dware condition.
- CKCON reset value depends on the X2B bit (program med or unprogrammed) in the Hardware Byte.
Table 31. SFR Addresses and Reset Values
sources are enabled or disabled by the system designer and may be manipulated dynamically.
- An internal or external device initiates an inter rupt-request signal. The AT89C5132, latch
this event into a flag buffer.
- The priority of the flag is compared to the prior ity of other interrupts by the interrupt han-
dler. A high priority causes the handler to set an interrupt flag.
- This signals the instruction execution unit to ex ecute a context switch. This context
with the start address of a software service routine.
- The software service routine executes assigned ta sks and as a final activity performs a
operation then continues from the original point of interruption. Table 32. Interrupt System Signals enable separately the interrupt sources: IEN0 and IEN1 registers (see Table 35 and Table 36). IPL1 registers (see Table 10-1 to Table 39).
10.1 Interrupt System Priorities
interrupt source four possible priority levels according to Table 33.
Table 33. Priority Levels Table 34. Priority Within Same Level
4173E–USB–09/07 AT89C5132 Figure 10-1. Interrupt Control System EI2C IEN1.1 EMMC IEN1.0 EUSB IEN1.6 ESPI IEN1.2 EX0 IEN0.0 External Interrupt 0 INT0 EA IEN0.7 EX1 IEN0.2 External Interrupt 1 INT1 ET0 IEN0.1 Timer 0 ET1 IEN0.3 Timer 1 EAUD IEN0.6 Audio Interface EADC IEN1.3 A to D Converter SPI Controller USB Controller EKB IEN1.4 Keyboard MMC Controller Two-wire Controller IPH/L Interrupt Enable Lowest Priority Interrupts Highest KIN3:0 Priority Enable SCK SI SO SCL SDA Priority Interrupts ES IEN0.4 Serial Port TXD RXD MCLK MDAT MCMD AIN1:0
4173E–USB–09/07 AT89C5132
10.2 External Interrupts
10.2.1 INT1:0 Inputs
External interrupts INT0 and INT1 (INTn , n = 0 or 1) pins may each be programmed to be lev el- triggered or edge-triggered, dependent upon bits IT 0 and IT1 (ITn, n = 0 or 1) in TCON register as shown in Figure 10-2. If ITn = 0, INTn is triggered by a low level at the pin. If ITn = 1 , INTn is negative-edge triggered. External interrupts are enabled with bits EX0 and EX1 (EXn, n = 0 or 1) in IEN0. Events on INTn set the interrupt request flag IEn in TCON registe r. If the interrupt is edge-triggered, the request flag is cleared by hard ware when vectoring to the interrupt service routine. If the interrupt is level-triggered, the i nterrupt service routine must clear the request fla g and the interrupt must be deasserted before the end of the interrupt service routine. INT0 and INT1 inputs provide both the capability to exit from Power-down mode on low level sig- nals as detailed in Section “Exiting Power-down Mod e”, page 47. Figure 10-2. INT1:0 Input Circuitry
10.2.2 KIN3:0 Inputs
External interrupts KIN0 to KIN3 provide the capabi lity to connect a matrix keyboard. For detailed information on these inputs, refer to Section “Keyboard Interface”, page 152.
10.2.3 Input Sampling
External interrupt pins (INT1:0 and KIN3:0) are sampled once per peripheral cycle (6 peripheral clock periods) (see Figure 10-3). A level-triggered interrupt pin held low or high for more than 6 peripheral clock periods (12 oscillator in standard mode or 6 oscillator clock periods in X2 mode) guarantees detection. Edge-triggered external inter rupts must hold the request pin low for at least 6 peripheral clock periods. Figure 10-3. Minimum Pulse Timings INT0/1 IT0/1 TCON.0/2 EX0/1 IEN0.0/2 INT0/1 Interrupt Request IE0/1 TCON.1/3 Edge-Triggered Interrupt Level-Triggered Interrupt 1 cycle 1 cycle > 1 peripheral cycle 1 cycle > 1 peripheral cycle
10.3 Registers
Table 35. IEN0 Register Table 36. IEN1 Register Set to enable all interrupts. Clear to disable all interrupts.
6 EAUD
Set to enable audio interface interrupt. Clear to disable audio interface interrupt. The values read from this bit is always 0. Do not s et this bit. Set to enable serial port interrupt. Clear to disable serial port interrupt.
3 ET1
Set to enable Timer 1 overflow interrupt. Clear to disable Timer 1 overflow interrupt.
2 EX1
Set to enable external interrupt 1. Clear to disable external interrupt 1.
1 ET0
Set to enable timer 0 overflow interrupt. Clear to disable timer 0 overflow interrupt.
0 EX0
Set to enable external interrupt 0. Clear to disable external interrupt 0.
4173E–USB–09/07 AT89C5132 Reset Value = 0000 0000b Bit Number Bit Mnemonic Description 7 - Reserved The value read from this bit is always 0. Do not se t this bit.
6 EUSB
USB Interface Interrupt Enable Bit Set this bit to enable USB interrupts. Clear this bit to disable USB interrupts. 5 - Reserved The value read from this bit is always 0. Do not se t this bit.
4 EKB
Keyboard Interface Interrupt Enable Bit Set to enable Keyboard interrupt. Clear to disable Keyboard interrupt.
3 EADC
A to D Converter Interrupt Enable Bit Set to enable ADC interrupt. Clear to disable ADC interrupt.
2 ESPI
SPI Controller Interrupt Enable Bit Set to enable SPI interrupt. Clear to disable SPI interrupt.
1 EI2C
Two Wire Controller Interrupt Enable Bit Set to enable Two Wire interrupt. Clear to disable Two Wire interrupt.
0 EMMC
MMC Interface Interrupt Enable Bit Set to enable MMC interrupt. Clear to disable MMC interrupt.
4173E–USB–09/07 AT89C5132 Table 10-1. IPH0 Register IPH0 (S:B7h) – Interrupt Priority High Register 0 Reset Value = X000 0000b 7 6 5 4 3 2 1 0 - IPHAUD – IPHS IPHT1 IPHX1 IPHT0 IPHX0 Bit Number Bit Mnemonic Description 7 - Reserved The value read from this bit is indeterminate. Do n ot set this bit.
6 IPHAUD Audio Interface Interrupt Priority Level MSB
Refer to Table 33 for priority level description.
5 IPHMP3 MP3 Decoder Interrupt Priority Level MSB
Refer to Table 33 for priority level description.
4 IPHS Serial Port Interrupt Priority Level MSB
Refer to Table 33 for priority level description.
3 IPHT1 Timer 1 Interrupt Priority Level MSB
Refer to Table 33 for priority level description.
2 IPHX1 External Interrupt 1 Priority Level MSB
Refer to Table 33 for priority level description. 1 - Reserved The value read from this bit is indeterminate. Do n ot set this bit.
0 IPHX0 External Interrupt 0 Priority Level MSB
Refer to Table 33 for priority level description.
Table 37. IPH1 Register The value read from this bit is always 0. Do not se t this bit.
6 IPHUSB USB Interrupt Priority Level MSB
Refer to Table 33 for priority level description. The value read from this bit is always 0. Do not se t this bit.
4 IPHKB Keyboard Interrupt Priority Level MSB
Refer to Table 33 for priority level description.
3 IPHADC A to D Converter Interrupt Priority Level MSB
Refer to Table 33 for priority level description.
2 IPHSPI SPI Interrupt Priority Level MSB
Refer to Table 33 for priority level description.
1 IPHI2C Two Wire Controller Interrupt Priority Level MSB
Refer to Table 33 for priority level description.
0 IPHMMC MMC Interrupt Priority Level MSB
Refer to Table 33 for priority level description.
Table 38. IPL0 Register The value read from this bit is indeterminate. Do n ot set this bit.
6 IPLAUD Audio Interface Interrupt Priority Level LSB
Refer to Table 33 for priority level description.
5 IPLMP3 MP3 Decoder Interrupt Priority Level LSB
Refer to Table 33 for priority level description.
4 IPLS Serial Port Interrupt Priority Level LSB
Refer to Table 33 for priority level description.
3 IPLT1 Timer 1 Interrupt Priority Level LSB
Refer to Table 33 for priority level description.
2 IPLX1 External Interrupt 1 Priority Level LSB
Refer to Table 33 for priority level description.
1 IPLT0 Timer 0 Interrupt Priority Level LSB
Refer to Table 33 for priority level description.
0 IPLX0 External Interrupt 0 Priority Level LSB
Refer to Table 33 for priority level description.
Table 39. IPL1 Register The value read from this bit is always 0. Do not se t this bit.
6 IPLUSB USB Interrupt Priority Level LSB
Refer to Table 33 for priority level description. The value read from this bit is always 0. Do not se t this bit.
4 IPLKB Keyboard Interrupt Priority Level LSB
Refer to Table 33 for priority level description.
3 IPLADC A to D Converter Interrupt Priority Level LSB
Refer to Table 33 for priority level description.
2 IPLSPI SPI Interrupt Priority Level LSB
Refer to Table 33 for priority level description.
1 IPLI2C Two Wire Controller Interrupt Priority Level LSB
Refer to Table 33 for priority level description.
0 IPLMMC MMC Interrupt Priority Level LSB
Refer to Table 33 for priority level description.
the X2 mode detailed in Section “X2 Feature”, page 12.
11.1 Reset
characteristics are discussed in the Section “DC Ch aracteristics” of the AT89C5132 datasheet. The status of the Port pins during reset is detailed in Table 16 . Table 16. Pin Conditions in Special Operating Modes Note: 1. Refer to Section “Audio Output Interface”, p age 75.
11.1.1 Cold Reset
- V DD must reach the specified V DD range
- The level on X1 input pin must be outside the spec ification (V IH , V IL ) If one of these 2 conditions are not met, the microcontroller does not start correctly and can exe- cute an instruction fetch from anywhere in the prog ram space. An active level applied on the RST pin must be maintained till both of the above c onditions are met. A reset is active when the level V IH1 is reached and when the pulse width covers the per iod of time where V DD and the oscillator are not stabilized. 2 parameters have to be taken into account to determine the reset pulse width:
- V DD rise time,
- Oscillator startup time. Mode Port 0 Port 1 Port 2 Port 3 Port 4 Port 5 MMC Audio Reset Floating High High High High High Floating 1 Idle Data Data Data Data Data Data Data Data Power-down Data Data Data Data Data Data Data Data RRST RST VSS To CPU Core and Peripherals RST VDD Power-on Reset RST input circuitry P VDD From Internal Reset Source
different oscillator startup and V DD rise times. Table 17. Minimum Reset Capacitor Value for a 50 k Ω Pull-down Resistor (1) leading to a bad reset sequence.
11.1.2 Warm Reset
11.1.3 Watchdog Reset
11.2 Reset Recommendation to Prevent Flash Corruptio n
ping of the bootloader in the code area, a reset failure can be critical.
4173E–USB–09/07 AT89C5132
11.3 Idle Mode
Idle mode is a power reduction mode that reduces th e power consumption. In this mode, pro- gram execution halts. Idle mode freezes the clock t o the CPU at known states while the peripherals continue to be clocked (refer to Sectio n “Oscillator”, page 12). The CPU status before entering Idle mode is preserved, i.e., the p rogram counter and program status word reg- ister retain their data for the duration of Idle mo de. The contents of the SFRs and RAM are also retained. The status of the Port pins during Idle mode is detailed in Table 16 .
11.3.1 Entering Idle Mode
To enter Idle mode, the user must set the IDL bit i n PCON register (see Table 18). The AT89C5132 enters Idle mode upon execution of the in struction that sets IDL bit. The instruction that sets IDL bit is the last instruction executed. Note: If IDL bit and PD bit are set simultaneously, the AT89C5132 enter Power-down mode. Then it does not go in Idle mode when exiting Power-down mode.
11.3.2 Exiting Idle Mode
There are 2 ways to exit Idle mode: 1. Generate an enabled interrupt. – Hardware clears IDL bit in PCON register which res tores the clock to the CPU. Execution resumes with the interrupt service routine. Upon completion of the interrupt service routine, program execution resumes with the instruction immediately following the instruction that activated Idle mode. The general-purpose flags (GF1 and GF0 in PCON register) may be used to indicate whether an interrupt occurred during normal operation or during Idle mode. When Idle mode is exited by an interrupt, the interrupt service routine may examine GF1 and GF0. 2. Generate a reset. – A logic high on the RST pin clears IDL bit in PCON register directly and asynchronously. This restores the clock to the CPU. Program execution momentarily resumes with the instruction immediately following the instruction that activated the Idle mode and may continue for a number of clock cycles before the internal reset algorithm takes control. Reset initializes the AT89C5132 and vectors the CPU to address C:0000h. Note: During the time that execution resumes, the in ternal RAM cannot be accessed; however, it is pos- sible for the Port pins to be accessed. To avoid unexpected outputs at the Port pins, the instruction immediately following the instruction that activate d Idle mode should not write to a Port pin or to the external RAM.
11.4 Power-down Mode
The Power-down mode places the AT89C5132 in a very low power state. Power-down mode stops the oscillator and freezes all clocks at know n states (refer to the Section "Oscillator", page 12). The CPU status prior to entering Power-do wn mode is preserved, i.e., the program counter, program status word register retain their data for the duration of Power-down mode. In addition, the SFRs and RAM contents are preserved. The status of the Port pins during Power- down mode is detailed in Table 16 . Note: V DD may be reduced to as low as V RET during Power-down mode to further reduce power dissipa- tion. Notice, however, that V DD is not reduced until Power-down mode is invoked.
4173E–USB–09/07 AT89C5132
11.4.1 Entering Power-down Mode
To enter Power-down mode, set PD bit in PCON regist er. The AT89C5132 enters the Power- down mode upon execution of the instruction that se ts PD bit. The instruction that sets PD bit is the last instruction executed.
11.4.2 Exiting Power-down Mode
If VDD was reduced during the Power-down mode, do not exi t Power-down mode until V DD is restored to the normal operating level. There are 2 ways to exit the Power-down mode: 1. Generate an enabled external interrupt. – The AT89C5132 provides capability to exit from Pow er-down using INT0 , INT1 , and KIN3:0 inputs. In addition, using KIN input provides high or low level exit capability (see Section “Keyboard Interface”, page 181). Hardware clears PD bit in PCON register which starts the oscillator and restores the clocks to the CPU and peripherals. Using INTn input, execution resumes when the input is released (see Figure 11-3) while using KINx input, execution resumes after counting 1024 clock ensuring the oscillator is restarted properly (see Figure 11-4). This behavior is necessary for decoding the key while it is still pressed. In both cases, execution resumes with the interrupt service routine. Upon completion of the interrupt service routine, program execution resumes with the instruction immediately following the instruction that activated Power-down mode. Note: 1. The external interrupt used to exit Power-do wn mode must be configured as level sensitive (INT0 and INT1 ) and must be assigned the highest priority. In add ition, the duration of the interrupt must be long enough to allow the oscillat or to stabilize. The execution will only resume when the interrupt is deasserted. 2. Exit from power-down by external interrupt does n ot affect the SFRs nor the internal RAM content. Figure 11-3. Power-down Exit Waveform Using INT1:0 Figure 11-4. Power-down Exit Waveform Using KIN3:0 Note: 1. KIN3:0 can be high or low-level triggered. 2. Generate a reset. INT1:0 OSC Power-down Phase Oscillator Restart Active Phase Active phase KIN3:0 1 OSC Power-down 1024 clock count Active phase Active phase
control. Reset initializes the AT89C5132 and vectors the CPU to address 0000h. not write to a Port pin or to the external RAM.
- Exit from power-down by reset redefines all the S FRs, but does not affect the internal RAM
11.5 Registers
Table 18. PCON Register
7 SMOD1 Serial Port Mode Bit 1
Set to select double baud rate in mode 1,2 or 3.
6 SMOD0
Set to select FE bit in SCON register. Clear to select SM0 bit in SCON register. The value read from these bits is indeterminate. Do not set these bits.
3 GF1
2 GF0
Cleared by hardware when an interrupt or reset occu rs. Set to activate the Power-down mode. If IDL and PD are both set, PD takes precedence.
0 IDL
Cleared by hardware when an interrupt or reset occu rs. Set to activate the Idle mode. If IDL and PD are both set, PD takes precedence.
4173E–USB–09/07 AT89C5132 12. Timers/Counters The AT89C5132 implement two general-purpose, 16-bit Timers/Counters. They are identified as Timer 0 and Timer 1, and can be independently configured to operate in a variety of modes as a Timer or as an event Counter. When operating as a T imer, the Timer/Counter runs for a pro- grammed length of time, then issues an interrupt re quest. When operating as a Counter, the Timer/Counter counts negative transitions on an ext ernal pin. After a preset number of counts, the Counter issues an interrupt request. The various operating modes of each Timer/Counter are described in the following sections.
12.1 Timer/Counter Operations
For instance, a basic operation is Timer registers THx and TLx (x = 0, 1) connected in cascade to form a 16-bit Timer. Setting the run control bit (TRx) in TCON register (see Table 40) turns the Timer on by allowing the selected input to incremen t TLx. When TLx overflows it increments THx; when THx overflows it sets the Timer overflow flag (TFx) in TCON register. Setting the TRx does not clear the THx and TLx Timer registers. Tim er registers can be accessed to obtain the current count or to enter preset values. They can b e read at any time but TRx bit must be cleared to preset their values, otherwise the behavior of the Timer/Counter is unpredictable. The C/Tx# control bit selects Timer operation or Co unter operation by selecting the divided- down peripheral clock or external pin Tx as the sou rce for the counted signal. TRx bit must be cleared when changing the mode of operation, otherw ise the behavior of the Timer/Counter is unpredictable. For Timer operation (C/Tx# = 0), the Timer register counts the divided-down peripheral clock. The Timer register is incremented once every periph eral cycle (6 peripheral clock periods). The Timer clock rate is F PER /6, i.e., F OSC /12 in standard mode or F OSC /6 in X2 mode. For Counter operation (C/Tx# = 1), the Timer regist er counts the negative transitions on the Tx external input pin. The external input is sampled e very peripheral cycles. When the sample is high in one cycle and low in the next one, the Counter is incremented. Since it takes 2 cycles (12 peripheral clock periods) to recognize a negative t ransition, the maximum count rate is F PER /12, i.e., F OSC /24 in standard mode or F OSC /12 in X2 mode. There are no restrictions on the du ty cycle of the external input signal, but to ensure that a given level is sampled at least once before it changes, it should be held for at least one full peripheral cycle.
12.2 Timer Clock Controller
As shown in Figure 12-1, the Timer 0 (FT0) and Timer 1 (FT1) clocks are derived from either the peripheral clock (F PER ) or the oscillator clock (F OSC ) depending on the T0X2 and T1X2 Bits in CKCON register. These clocks are issued from the Cl ock Controller block as detailed in Section ’CKCON Register’, page 14. When T0X2 or T1X2 bit is set, the Timer 0 or Timer 1 clock fre- quency is fixed and equal to the oscillator clock frequency divided by 2. When cleared, the Timer clock frequency is equal to the oscillator clock frequency divided by 2 in standard mode or to the oscillator clock frequency in X2 mode.
4173E–USB–09/07 AT89C5132 Figure 12-1. Timer 0 and Timer 1 Clock Controller and Symbols
12.3 Timer 0
Timer 0 functions as either a Timer or event Counte r in four modes of operation. Figure 12-2 through Figure 12-8 show the logical configuration of each mode. Timer 0 is controlled by the four lower Bits of TMO D register (see Table 41) and Bits 0, 1, 4 and 5 of TCON register (see Table 40). TMOD register selects the method of Timer gating (GATE0), Timer or Counter operation (C/T0#) and mode of oper ation (M10 and M00). TCON register pro- vides Timer 0 control functions: overflow flag (TF0), run control bit (TR0), interrupt flag (IE0) and interrupt type control bit (IT0). For normal Timer operation (GATE0 = 0), setting TR0 allows TL0 to be incremented by the selected input. Setting GATE0 and TR0 allows external pin INT0 to control Timer operation. Timer 0 overflow (count rolls over from all 1s to a ll 0s) sets TF0 flag generating an interrupt request. It is important to stop Timer/Counter before changing mode.
12.3.1 Mode 0 (13-bit Timer)
Mode 0 configures Timer 0 as a 13-bit Timer which is set up as an 8-bit Timer (TH0 register) with a modulo 32 prescaler implemented with the lower fi ve Bits of TL0 register (see Figure 12-2). The upper three Bits of TL0 register are indetermin ate and should be ignored. Prescaler over- flow increments TH0 register. Figure 12-3 gives the overflow period calculation formula. Figure 12-2. Timer/Counter x (x = 0 or 1) in Mode 0 Figure 12-3. Mode 0 Overflow Period Formula PER CLOCK TIM0 CLOCK OSC CLOCK T0X2 CKCON.1 ÷ 2 Timer 0 Clock Timer 0 Clock Symbol PER CLOCK TIM1 CLOCK OSC CLOCK T1X2 CKCON.2 ÷ 2 Timer 1 Clock Timer 1 Clock Symbol TIMx CLOCK TRx TCON Reg TFx TCON Reg GATEx TMOD Reg ÷ 6 Overflow Timer x Interrupt Request C/Tx# TMOD Reg THx (8 Bits) TLx (5 Bits) INTx Tx 6 ⋅ (16384 – (THx, TLx)) TFx PER = FTIMx
4173E–USB–09/07 AT89C5132
12.3.2 Mode 1 (16-bit Timer)
Mode 1 configures Timer 0 as a 16-bit Timer with TH 0 and TL0 registers connected in cascade (see Figure 12-4). The selected input increments TL 0 register. Figure 12-5 gives the overflow period calculation formula when in timer mode. Figure 12-4. Timer/Counter x (x = 0 or 1) in Mode 1 Figure 12-5. Mode 1 Overflow Period Formula
12.3.3 Mode 2 (8-bit Timer with Auto-Reload)
Mode 2 configures Timer 0 as an 8-bit Timer (TL0 re gister) that automatically reloads from TH0 register (see Table 42). TL0 overflow sets TF0 flag in TCON register and reloads TL0 with the contents of TH0, which is preset by software. When the interrupt request is serviced, hardware clears TF0. The reload leaves TH0 unchanged. The ne xt reload value may be changed at any time by writing it to TH0 register. Figure 12-7 giv es the autoreload period calculation formula when in timer mode. Figure 12-6. Timer/Counter x (x = 0 or 1) in Mode 2 Figure 12-7. Mode 2 Autoreload Period Formula
12.3.4 Mode 3 (Two 8-bit Timers)
Mode 3 configures Timer 0 such that registers TL0 a nd TH0 operate as separate 8-bit Timers (see Figure 12-8). This mode is provided for applic ations requiring an additional 8-bit Timer or TRx TCON Reg TFx TCON Reg GATEx TMOD Reg Overflow Timer x Interrupt Request C/Tx# TMOD Reg TLx (8 Bits) THx (8 Bits) INTx Tx TIMx CLOCK ÷ 6 6 ⋅ (65536 – (THx, TLx)) TFx PER = FTIMx TRx TCON Reg TFx TCON Reg GATEx TMOD Reg Overflow Timer x Interrupt Request C/Tx# TMOD Reg TLx (8 Bits) THx (8 Bits) INTx Tx TIMx CLOCK ÷ 6 TFx PER = FTIMx 6 ⋅ (256 – THx)
4173E–USB–09/07 AT89C5132 Counter. TL0 uses the Timer 0 control Bits C/T0# an d GATE0 in TMOD register, and TR0 and TF0 in TCON register in the normal manner. TH0 is l ocked into a Timer function (counting FTF1/6) and takes over use of the Timer 1 interrupt (TF 1) and run control (TR1) Bits. Thus, oper- ation of Timer 1 is restricted when Timer 0 is in mode 3. Figure 12-7 gives the autoreload period calculation formulas for both TF0 and TF1 flags. Figure 12-8. Timer/Counter 0 in Mode 3: Two 8-bit Counters Figure 12-9. Mode 3 Overflow Period Formula
12.4 Timer 1
Timer 1 is identical to Timer 0 excepted for Mode 3 which is a hold-count mode. Following com- ments help to understand the differences:
- Timer 1 functions as either a Timer or event Count er in three modes of operation. Figure 12- 2 through Figure 12-6 show the logical configuration for modes 0, 1, and 2. Timer 1’s mode 3 is a hold-count mode.
- Timer 1 is controlled by the four high-order Bits of TMOD register (see Table 41 ) and Bits 2, 3, 6 and 7 of TCON register (see Figure 40). TMOD register selects the method of Timer gating (GATE1), Timer or Counter operation (C/T1#) and mode of operation (M11 and M01). TCON register provides Timer 1 control functions: overflow flag (TF1), run control bit (TR1), interrupt flag (IE1) and interrupt type control bit (IT1).
- Timer 1 can serve as the Baud Rate Generator for t he Serial Port. Mode 2 is best suited for this purpose.
- For normal Timer operation (GATE1 = 0), setting TR 1 allows TL1 to be incremented by the selected input. Setting GATE1 and TR1 allows external pin INT1 to control Timer operation.
- Timer 1 overflow (count rolls over from all 1s to all 0s) sets the TF1 flag generating an interrupt request.
- When Timer 0 is in mode 3, it uses Timer 1’s overf low flag (TF1) and run control bit (TR1). For this situation, use Timer 1 only for applications that do not require an interrupt (such as a Baud Rate Generator for the Serial Port) and switch Timer 1 in and out of mode 3 to turn it off and on.
- It is important to stop the Timer/Counter before c hanging modes. TR0 TCON.4 TF0 TCON.5 INT0 GATE0 TMOD.3 Overflow Timer 0 Interrupt Request C/T0# TMOD.2 TL0 (8 Bits) TR1 TCON.6 TH0 (8 Bits) TF1 TCON.7 Overflow Timer 1 Interrupt Request TIM0 CLOCK ÷ 6 TIM0 CLOCK ÷ 6 TF0 PER = FTIM0 6 ⋅ (256 – TL0) TF1 PER = FTIM0 6 ⋅ (256 – TH0)
4173E–USB–09/07 AT89C5132
12.4.1 Mode 0 (13-bit Timer)
Mode 0 configures Timer 1 as a 13-bit Timer, which is set up as an 8-bit Timer (TH1 register) with a modulo-32 prescaler implemented with the lower 5 Bits of the TL1 register (see Figure 12- 2). The upper 3 Bits of TL1 register are ignored. Prescaler overflow increments TH1 register.
12.4.2 Mode 1 (16-bit Timer)
Mode 1 configures Timer 1 as a 16-bit Timer with TH 1 and TL1 registers connected in cascade (see Figure 12-4). The selected input increments TL1 register.
12.4.3 Mode 2 (8-bit Timer with
Auto-Reload) Mode 2 configures Timer 1 as an 8-bit Timer (TL1 re gister) with automatic reload from TH1 reg- ister on overflow (see Figure 12-6). TL1 overflow s ets TF1 flag in TCON register and reloads TL1 with the contents of TH1, which is preset by software. The reload leaves TH1 unchanged.
12.4.4 Mode 3 (Halt)
Placing Timer 1 in mode 3 causes it to halt and hol d its count. This can be used to halt Timer 1 when TR1 run control bit is not available i.e. when Timer 0 is in mode 3.
12.5 Interrupt
Each Timer handles one interrupt source that is the timer overflow flag TF0 or TF1. This flag is set every time an overflow occurs. Flags are cleare d when vectoring to the Timer interrupt rou- tine. Interrupts are enabled by setting ETx bit in IEN0 register. This assumes interrupts are globally enabled by setting EA bit in IEN0 register. Figure 12-10. Timer Interrupt System TF0 TCON.5 ET0 IEN0.1 Timer 0 Interrupt Request TF1 TCON.7 ET1 IEN0.3 Timer 1 Interrupt Request
12.6 Registers
Table 40. TCON Register Table 41. TMOD Register
7 TF1
Cleared by hardware when processor vectors to inter rupt routine. Set by hardware on Timer/Counter overflow, when Tim er 1 register overflows.
6 TR1
Clear to turn off Timer/Counter 1. Set to turn on Timer/Counter 1.
5 TF0
Cleared by hardware when processor vectors to inter rupt routine. Set by hardware on Timer/Counter overflow, when Tim er 0 register overflows.
4 TR0
Clear to turn off Timer/Counter 0. Set to turn on Timer/Counter 0.
3 IE1
Cleared by hardware when interrupt is processed if edge-triggered (see IT1). Set by hardware when external interrupt is detected on INT1 pin.
2 IT1
Clear to select low level active (level triggered) for external interrupt 1 (INT1 ). Set to select falling edge active (edge triggered) for external interrupt 1.
1 IE0
Cleared by hardware when interrupt is processed if edge-triggered (see IT0). Set by hardware when external interrupt is detected on INT0 pin.
0 IT0
Clear to select low level active (level triggered) for external interrupt 0 (INT0 ). Set to select falling edge active (edge triggered) for external interrupt 0.
Notes: 1. Reloaded from TH1 at overflow.
- Reloaded from TH0 at overflow.
Table 42. TH0 Register
7 GATE1
Clear to enable Timer 1 whenever TR1 bit is set. Set to enable Timer 1 only while INT1 pin is high and TR1 bit is set.
6 C/T1#
Clear for Timer operation: Timer 1 counts the divid ed-down system clock. Set for Counter operation: Timer 1 counts negative transitions on external pin T1.
5 M11 Timer 1 Mode Select Bits
0 0 Mode 0: 8-bit Timer/Counter (TH1) with 5-bit p rescaler (TL1). 0 1 Mode 1: 16-bit Timer/Counter. 1 1 Mode 3: Timer 1 halted. Retains count.
4 M01
3 GATE0
Clear to enable Timer 0 whenever TR0 bit is set. pin is high and TR0 bit is set.
2 C/T0#
Clear for Timer operation: Timer 0 counts the divid ed-down system clock. Set for Counter operation: Timer 0 counts negative transitions on external pin T0.
1 M10 Timer 0 Mode Select Bit
0 0 Mode 0: 8-bit Timer/Counter (TH0) with 5-bit prescaler (TL0). 0 1 Mode 1: 16-bit Timer/Counter. 1 1 Mode 3: TL0 is an 8-bit Timer/Counter. TH0 is an 8-bit Timer using Timer 1’s TR0 and TF0 Bits.
0 M00
Table 43. TL0 Register Table 44. TH1 Register Table 45. TL1 Register
4173E–USB–09/07 AT89C5132 13. Watchdog Timer The AT89C5132 implement a hardware Watchdog Timer ( WDT) that automatically resets the chip if it is allowed to time out. The WDT provides a means of recovering from routines that do not complete successfully due to software or hardware malfunctions.
13.1 Description
The WDT consists of a 14-bit prescaler followed by a 7-bit programmable counter. As shown in Figure 13-1, the 14-bit prescaler is fed by the WDT clock detailed in section "Watchdog Clock Controller", page 57. The Watchdog Timer Reset register (WDTRST, see Tabl e 47) provides control access to the WDT, while the Watchdog Timer Program register (WDT PRG, see Figure 48) provides time-out period programming. Three operations control the WDT:
- Chip reset clears and disables the WDT.
- Programming the time-out value to the WDTPRG regis ter.
- Writing a specific two-byte sequence to the WDTRST register clears and enables the WDT. Figure 13-1. WDT Block Diagram
13.2 Watchdog Clock Controller
As shown in Figure 13-2 the WDT clock (F WDT ) is derived from either the peripheral clock (F PER ) or the oscillator clock (F OSC ) depending on the WTX2 bit in CKCON register. Thes e clocks are issued from the Clock Controller block as detailed in section "Clock Controller", page 12. When WTX2 bit is set, the WDT clock frequency is fixed a nd equal to the oscillator clock frequency divided by 2. When cleared, the WDT clock frequency is equal to the oscillator clock frequency divided by 2 in standard mode or to the oscillator clock frequency in X2 mode. Figure 13-2. WDT Clock Controller and Symbol WTO2:0 WDTPRG.2:0 WDT CLOCK ÷ 6 System 1Eh-E1h Decoder WDTRST 14-bit Prescaler RST 7-bit Counter RST To internal EN RST MATCH SET OV OSC CLOCK RST Pulse Generator Reset reset PER CLOCK WDT CLOCK OSC CLOCK WTX2 CKCON.6 ÷ 2 WDT Clock WDT Clock Symbol
13.3 Watchdog Operation
it. If it is not cleared using the previous sequenc e, the WDT overflows and forces a chip reset. value of WTO2:0 Bits. Table 48 reports the time-out period depending on the WDT frequency.
- These frequencies are achieved in X2 mode when WT X2 = 0: F WDT = F OSC .
13.3.1 WDT Behavior During Idle and Power-down Modes
Operation of the WDT during power reduction modes deserves special attention. next service period and puts the AT89C5132 back into Idle mode. The WDT is cleared and disabled if the Power-down mode is terminated by a reset. Table 46. WDT Time-Out Computation
6 MHz (1) 8 MHz (1) 10 MHz (1) 12 MHz (2) 16 MHz (2) 20 MHz (2)
13.4 Registers
Table 47. WDTRST Register Table 48. WDTPRG Register 7-0 - Watchdog Control Value . The values read from these Bits are indeterminate. Do not set these Bits. Refer to Table 46 for time-out periods.
4173E–USB–09/07 AT89C5132 14. Audio Output Interface The AT89C5132 implement an audio output interface a llowing the audio bitstream to be output in various formats. It is compatible with right and left justification PCM and I 2S formats and thanks to the on-chip PLL (see Section “Clock Contr oller”, page 12) allows connection of almost all of the commercial audio DAC families available on the market.
14.1 Description
The C51 core interfaces to the audio interface through five special function registers: AUDCON0 and AUDCON1, the Audio Control registers (see Table 51 and Table 52); AUDSTA, the Audio Status register (see Table 53); AUDDAT, the Audio D ata register (see Table 54); and AUDCLK, the Audio Clock Divider register (see Table 55). Figure 14-1 shows the audio interface block diagram , blocks are detailed in the following sections. Figure 14-1. Audio Interface Block Diagram
14.2 Clock Generator
The audio interface clock is generated by division of the PLL clock. The division factor is given by AUCD4:0 bits in AUDCLK register. Figure 14-2 sho ws the audio interface clock generator and its calculation formula. The audio interface cl ock frequency depends on the audio DAC used. AUD CLOCK UDRN AUDSTA.6 DSIZ AUDCON0.1 DSEL Clock Generator DCLK DOUT SCLK JUST4:0 AUDCON0.7:3 POL AUDCON0.2 AUDEN AUDCON1.0 HLR AUDCON0.0 Data Converter Audio Data From C51 DUP1:0 AUDCON1.2:1 SREQ AUDSTA.7 Audio Buffer AUBUSY AUDSTA.5 Data Ready AUDDAT
erated when no data is available at the data converter input. according to POL bit in AUDCON0 register as shown in Figure 14-3.
14.3 Data Converter
Table 49. DAC Format Programing Examples
4173E–USB–09/07 AT89C5132 Figure 14-4. Audio Output Format As soon as first audio data is input to the data co nverter, it enables the clock generator for gen- erating the bit and word clocks.
14.4 Audio Buffer
In voice or sound playing mode, the audio stream co mes from the C51 core through an audio buffer. The data is in 8-bit format and is sampled at 8 kHz. The audio buffer adapts the sample format and rate. The sample format is extended to 1 6 bits by filling the LSB to 00h. Rate is adapted to the DAC rate by duplicating the data usi ng DUP1:0 bits in AUDCON1 register according to Table 50. The audio buffer interfaces to the C51 core through three flags: the sample request flag (SREQ in AUDSTA register), the under-run flag (UNDR in AU DSTA register) and the busy flag (AUBUSY in AUDSTA register). SREQ and UNDR can gene rate an interrupt request as explained in Section "Interrupt Request", page 63. The buffer size is 8 Bytes large. SREQ is set when the samples number switches from 4 to 3 and re set when the samples number switches from 4 to 5; UNDR is set when the buffer becomes em pty signaling that the audio interface ran out of samples; and AUBUSY is set when the buffer is full. DSEL DCLK DOUT MSB I2S Format with DSIZ = 0 and JUST4:0 = 00001. LSB B14 MSB LSB B14 B1 B1 DSEL DCLK DOUT MSB I2S Format with DSIZ = 1 and JUST4:0 = 00001. LSB B14 MSB LSB B14 1 2 3 13 14 15 16 1 2 3 13 14 15 16 Left Channel Right Channel 1 2 3 17 18 32 1 2 3 17 18 32 DSEL DCLK DOUT B14 MSB/LSB Justified Format with DSIZ = 0 and JUST4:0 = 00000. MSB B1 B15 MSB B1 LSB LSB 1 2 3 13 14 15 16 1 2 3 13 14 15 16 Left Channel Right Channel Left Channel Right Channel DSEL DCLK DOUT 16-bit LSB Justified Format with DSIZ = 1 and JUST4 :0 = 10000. 1 16 18 32 32 Left Channel Right Channel 17 31 MSB B14 LSB B1 MSB B14 LSB B1 1 16 18 17 31 DSEL DCLK DOUT 18-bit LSB Justified Format with DSIZ = 1 and JUST4 :0 = 01110. 1 15 30 32 Left Channel Right Channel 16 31 MSB B16 B2 B1 LSB MSB B16 B2 B1 LSB 15 30 32 16 31
Table 50. Sample Duplication Factor
14.5 Interrupt Request
enable of the audio interface is provided by setting the EAUD bit in IEN0 register. flag is cleared by hardware when the interrupt service routine is executed.
14.6 Voice or Sound Playing
0 0 No sample duplication, DAC rate = 8 kHz (C51 rate ). 0 1 One sample duplication, DAC rate = 16 kHz (2 x C5 1 rate). 1 0 Two samples duplication, DAC rate = 32 kHz (4 x C 51 rate). 1 1 Three samples duplication, DAC rate = 48 kHz (6 x C51 rate).
occur for a correct voice/sound generation. It is the user’s responsibility to mask it or not.
14.7 Registers
Table 51. AUDCON0 Register Table 52. AUDCON1 Register Refer to Section "Data Converter", page 61 for bits description.
2 POL
Set to output the left channel on high level of DSE L output (PCM mode). Clear to output the left channel on the low level o f DSEL output (I 2S mode).
1 DSIZ
Set to select 32-bit data output format. Clear to select 16-bit data output format.
0 HLR
Set by software when the PLL clock frequency is 384 ·Fs. Clear by software when the PLL clock frequency is 2 56·Fs.
Table 53. AUDSTA Register Table 54. AUDDAT Register The value read from these bits is always 0. Do not set these bits.
5 MSREQ
Set to prevent the SREQ flag from generating an aud io interrupt. Clear to allow the SREQ flag to generate an audio i nterrupt.
4 MUDRN
Set to prevent the UDRN flag from generating an aud io interrupt. Clear to allow the UDRN flag to generate an audio i nterrupt. The value read from this bit is always 0. Do not se t this bit. Refer to Table 50 for bits description.
0 AUDEN
Set to enable the audio interface. Clear to disable the audio interface.
7 SREQ
empty). This bit generates an interrupt if not mask ed and if enabled in IEN0. Cleared by hardware when samples are loaded in AUDD AT.
6 UDRN
empty). This bit generates an interrupt if not mask ed and if enabled in IEN0. Cleared by hardware when samples are loaded in AUDD AT.
5 AUBUSY
Cleared by hardware when buffer is no more full. The value read from these bits is always 0. Do not set these bits.
Table 55. AUDCLK Register 8-bit sampling data for voice or sound playing. The value read from these bits is always 0. Do not set these bits. 5-bit divider for audio clock generation.
4173E–USB–09/07 AT89C5132 15. Universal Serial Bus The AT89C5132 implement a USB device controller supporting Full-speed data transfer. In addi- tion to the default control endpoint 0, it provides 3 other endpoints, which can be configured in Control, Bulk, Interrupt or Isochronous types. This allows to develop firmware conforming to most USB device classes, for example the AT89C5132 support:
- USB Mass Storage Class Control/Bulk/Interrupt (CBI ) Transport, Revision 1.0 – December 14, 1998
- USB Mass Storage Class Bulk-Only Transport, Revisi on 1.0 – September 31, 1999
- USB Device Firmware Upgrade Class, Revision 1.0 – May 13, 1999
15.0.1 USB Mass Storage Class CBI Transport
Within the CBI framework, the Control endpoint is u sed to transport command blocks as well as to transport standard USB requests. One Bulk Out en dpoint is used to transport data from the host to the device. One Bulk In endpoint is used to transport data from the device to the host. And one interrupt endpoint may also be used to signal command completion (protocol 0) but it is optional and may not be used (protocol 1). The following AT89C5132 configuration adheres to that requirements:
- Endpoint 0: 32 Bytes, Control In-Out
- Endpoint 1: 64 Bytes, Bulk Out
- Endpoint 2: 64 Bytes, Bulk In
- Endpoint 3: 8 Bytes, Interrupt In
15.0.2 USB Mass Storage Class Bulk-Only Transport
Within the Bulk-only framework, the Control endpoint is only used to transport class-specific and standard USB requests for device set-up and configu ration. One Bulk-out endpoint is used to transport commands and data from the host to the device. One Bulk in endpoint is used to trans- port status and data from the device to the host. No interrupt endpoint is needed. The following AT89C5132 configuration adheres to that requirements:
- Endpoint 0: 32 Bytes, Control In-Out
- Endpoint 1: 64 Bytes, Bulk Out
- Endpoint 2: 64 Bytes, Bulk In
- Endpoint 3: not used
15.0.3 USB Device Firmware Upgrade (DFU)
The USB Device Firmware Update (DFU) protocol can b e used to upgrade the on-chip Flash memory of the AT89C5132. This allows installing product enhancements and patches to devices that are already in the field. Two different config urations and descriptor sets are used to support DFU functions. The Run-Time configuration co-exist with the usual functions of the device, which shall be USB Mass Storage for AT89C5132. It i s used to initiate DFU from the normal operating mode. The DFU configuration is used to pe rform the firmware update after device re- configuration and USB reset. It excludes any other function. Only the default control pipe (end- point 0) is used to support DFU services in both configurations. The only possible value for the MaxPacketSize in the DFU configuration is 32 Bytes, which is the size of the FIFO implemented for endpoint 0.
4173E–USB–09/07 AT89C5132
15.1 Description
The USB device controller provides the hardware tha t the AT89C5132 need to interface a USB link to data flow stored in a double port memory. It requires a 48 MHz reference clock provided by th e clock controller as detailed in Section "Clock Controller", page 68. This clock is used to generate a 12 MHz Full Speed bit clock from the received USB differential data flow and to tran smit data according to full speed USB device tolerance. Clock recovery is done by a Digital Phase Locked Loop (DPLL) block. The Serial Interface Engine (SIE) block performs NRZI encoding and decoding, bit stuffing, CRC generation and checking, and the serial-parallel data conversion. The Universal Function Interface (UFI) controls the interface between the data flow and the Dual Port RAM, but also the interface with the C51 core itself. Figure 15-3 shows how to connect the AT89C5132 to t he USB connector. D+ and D- pins are connected through 2 termination resistors. A pull-u p resistor is implemented on D+ to inform the host of a full speed device connection. Value of th ese resistors is detailed in the section “DC Characteristics”. Figure 15-1. USB Device Controller Block Diagram Figure 15-2. USB Connection
15.1.1 Clock Controller
The USB controller clock is generated by division of the PLL clock. The division factor is given by USBCD1:0 Bits in USBCLK register (see Table 70). Fi gure 15-3 shows the USB controller clock USB CLOCK
48 MHz 12 MHz
4173E–USB–09/07 AT89C5132 generator and its calculation formula. The USB cont roller clock frequency must always be 48 MHz. Figure 15-3. USB Clock Generator and Symbol
15.1.2 Serial Interface Engine (SIE)
The SIE performs the following functions:
- NRZI data encoding and decoding
- Bit stuffing and unstuffing
- CRC generation and checking
- ACKs and NACKs automatic generation
- TOKEN type identifying
- Address checking
- Clock recovery (using DPLL) Figure 15-4. SIE Block Diagram USBCD1:0 USBCLK
48 MHz USB Clock
CRC5 & CRC16 Generator/Check USB Pattern Generator Parallel to Serial Converter Bit Stuffing NRZI Converter CRC16 Generator NRZI ‘ NRZ Bit Unstuffing Packet Bit Counter End of Packet Detector USB CLOCK
48 MHz SysClk
(12 MHz)
8 Data Out
4173E–USB–09/07 AT89C5132
15.1.3 Function Interface Unit (UFI)
The Function Interface Unit provides the interface between the AT89C5132 and the SIE. It man- ages transactions at the packet level with minimal intervention from the device firmware, which reads and writes the endpoint FIFOs. Figure 15-6 shows typical USB IN and OUT transactions reporting the split in the hardware (UFI) and software (C51) load. Figure 15-5. UFI Block Diagram Figure 15-6. USB Typical Transaction Load
15.2 USB Interrupt System
As shown in Figure 15-7, the USB controller of the AT89C5132 handle sixteen interrupt sources. These sources are separated in two groups: the endp oints interrupts and the controller inter- rupts, combined together to appear as single interr upt source for the C51 core. The USB interrupt is enabled by setting the EUSB bit in IEN1. To/From C51 Core Endpoint Control C51 side Endpoint Control USB side Endpoint 2 Endpoint 1 Endpoint 0 USBCON USBINT USBIEN UEPINT UEPIEN UEPNUM UEPSTAX USBADDR UEPCONX UEPDATX UEPRST UBYCTX UFNUMH UFNUML Asynchronous Information Transfer Control FSM To/From SIE
12 MHz DPLL
OUT Transactions: HOST UFI C51 OUT DATA0 (n Bytes) ACK Endpoint FIFO read (n Bytes) OUT DATA1 NACK OUT DATA1 ACK IN Transactions: HOST UFI C51 IN ACK Endpoint FIFO Write IN DATA1 NACK C51 interrupt IN DATA1 C51 interrupt Endpoint FIFO write
4173E–USB–09/07 AT89C5132
15.2.1 Controller Interrupt Sources
There are four controller interrupt sources which can be enabled separately in USBIEN:
- SPINT: Suspend Interrupt Flag. This flag triggers an interrupt when a USB Suspend (Idle bus for three frame periods: a J state for 3 ms) is detected.
- SOFINT: Start Of Frame Interrupt Flag. This flag triggers an interrupt when a USB start of frame packet has been received.
- EORINT: End Of Reset Interrupt Flag. This flag triggers an interrupt when a End Of Reset has been detected by the USB controller.
- WUPCPU: Wake Up CPU Interrupt Flag. This flag triggers an interrupt when the USB controller is in SUSPEND state and is re- activated by a non-idle signal from USB line.
15.2.2 Endpoint Interrupt Sources
Each endpoint supports four interrupt sources repor ted in UEPSTAX and combined together to appear as a single endpoint interrupt source in UEPINT. Each endpoint interrupt can be enabled separately in UEPIEN.
- TXCMP: Transmitted In Data Interrupt Flag. This flag triggers an interrupt after an IN packet has been transmitted for Isochronous endpoints or after it has been accepted (ACK’ed) by the host for Control, Bulk and Interrupt endpoints.
- RXOUT: Received Out Data Interrupt Flag. This flag triggers an interrupt after a new packet has been received.
- RXSETUP: Receive Setup Interrupt Flag. This flag triggers an interrupt when a valid SETUP packet has been received from the host.
- STLCRC: Stall Sent Interrupt Flag/CRC Error Interr upt Flag. This flag triggers an interrupt after a STALL handshake has been sent on the bus, for Control, Bulk and Interrupt endpoints. This flag triggers an interrupt when the last data received is corrupted for Isochronous endpoints.
15.3 Registers
Table 56. USBCON Register
Table 57. USBADDR Register
7 USBE
Set to enable the USB controller. Clear to disable and reset the USB controller.
6 SUSPCLK
Set to disable the 48 MHz clock input (Resume Detec tion is still active). Clear to enable the 48 MHz clock input.
5 SDRMWUP
The values read from this bit is always 0. Do not s et this bit.
3 UPRSM
Set by hardware when SDRMWUP has been set and if RM WUPE is enabled. Cleared by hardware after the upstream resume has b een sent.
2 RMWUPE
Set to enable request an upstream resume signalling to the host. Clear after the upstream resume has been indicated by RSMINPR. DEVICE_REMOTE_WAKEUP feature for the device.
1 CONFG
0 FADDEN
Cleared by hardware on hardware reset or when an US B reset is received. When this bit is cleared, the default function addr ess is used (0).
Table 58. USBINT Register Table 59. USBIEN Register
7 FEN
the default address (FEN is reset to 0). This field contains the default address (0) after p ower-up or USB bus reset. The values read from these Bits are always 0. Do no t set these Bits.
5 WUPCPU
interrupt when EWUPCPU is set in the USBIEN. Cleared by software after re-enabling all USB clock s.
4 EORINT
triggers a USB interrupt when EEORINT is set in USB IEN.
3 SOFINT
received. This triggers a USB interrupt when ESOFIN T is set in USBIEN. The values read from these Bits are always 0. Do no t set these Bits.
0 SPINT
3 ms) is detected. This triggers a USB interrupt wh en ESPINT is set in USBIEN.
Table 60. UEPNUM Register Table 61. UEPCONX Register The values read from these Bits are always 0. Do no t set these Bits.
5 EWUPCPU
Set to enable the Wake Up CPU interrupt. Clear to disable the Wake Up CPU interrupt.
4 EEOFINT
Set to enable the End Of Reset interrupt. This bit is set after reset. Clear to disable End Of Reset interrupt.
3 ESOFINT
Set to enable the SOF interrupt. Clear to disable the SOF interrupt. The values read from these Bits are always 0. Do no t set these Bits.
0 ESPINT
Set to enable Suspend interrupt. Clear to disable Suspend interrupt. The values read from these Bits are always 0. Do no t set these Bits. reading or writing to registers UEPSTAX, UEPDATX, UBYCTLX or UEPCONX.
Table 62. UEPSTAX Register
7 EPEN
Clear to disable the endpoint according to the devi ce configuration. The values read from this bit is always 0. Do not s et this bit.
3 DTGL
Set by hardware when a DATA1 packet is received. Cleared by hardware when a DATA0 packet is received. (for a control read transfer). packet and may ignore this bit.
2 EPDIR
Set to configure IN direction for Bulk, Interrupt a nd Isochronous endpoints. Clear to configure OUT direction for Bulk, Interrup t and Isochronous endpoints. This bit has no effect for Control endpoints.
Table 63. UEPRST Register
7 DIR
This bit is relevant only if the endpoint is config ured in Control type. Set for the data stage. Clear otherwise. The values read from this Bits are always 0. Do not set this bit.
5 STALLRQ Stall Handshake Request Bit
Set to send a STALL answer to the host for the next handshake.Clear otherwise.
4 TXRDY
Set after a packet has been written into the endpoi nt FIFO for IN data transfers. Data shall be written into the endpoint FIFO only a fter this bit has been cleared. for control read transfers).
3 STLCRC
STALLRQ. Then, the endpoint interrupt is triggered if enabled in UEPIEN. Cleared by hardware when a SETUP packet is received (see RXSETUP). the endpoint interrupt is triggered if enabled in U EPIEN. Cleared by hardware when a non corrupted data is re ceived.
2 RXSETUP
Set by hardware when a valid SETUP packet has been received from the host. interrupt is triggered if enabled in UEPIEN. Clear by software after reading the SETUP data from the endpoint FIFO.
1 RXOUT
FIFO, even if its Data packet is received while thi s bit is set. Clear by software after reading the OUT data from t he endpoint FIFO.
0 TXCMP
Clear by software before setting again TXRDY.
Table 64. UEPINT Register Table 65. UEPIEN Register The values read from these Bits are always 0. Do no t set these Bits.
3 EP3RST
hardware reset or when an USB bus reset has been re ceived.
2 EP2RST
hardware reset or when an USB bus reset has been re ceived.
1 EP1RST
hardware reset or when an USB bus reset has been re ceived.
0 EP0RST
hardware reset or when an USB bus reset has been re ceived. The values read from these Bits are always 0. Do no t set these Bits.
3 EP3INT
interrupt is enabled in UEPIEN. Must be cleared by software.
2 EP2INT
interrupt is enabled in UEPIEN. Must be cleared by software.
1 EP1INT
interrupt is enabled in UEPIEN. Must be cleared by software.
0 EP0INT
interrupt is enabled in UEPIEN. Must be cleared by software.
Table 66. UEPDATX Register Table 67. UBYCTLX Register The values read from these Bits are always 0. Do no t set these Bits.
3 EP3INTE
Set to enable the interrupts for endpoint 3. Clear to disable the interrupts for endpoint 3.
2 EP2INTE
Set to enable the interrupts for endpoint 2. Clear this bit to disable the interrupts for endpoi nt 2.
1 EP1INTE
Set to enable the interrupts for the endpoint 1. Clear to disable the interrupts for the endpoint 1.
0 EP0INTE
Set to enable the interrupts for the endpoint 0. Clear to disable the interrupts for the endpoint 0. The values read from this Bits are always 0. Do not set this bit. data Bytes received after the Data PID.
Table 68. UFNUML Register Table 69. UFNUMH Register Table 70. USBCLK Register Lower 8 Bits of the 11-bit Frame Number. The values read from these Bits are always 0. Do no t set these Bits.
5 CRCOK
Updated after every Start Of Frame packet reception . Note: The Start Of Frame interrupt is generated jus t after the PID receipt.
4 CRCERR
Updated after every Start Of Frame packet reception . Note: The Start Of Frame interrupt is generated jus t after the PID receipt. The values read from this Bits are always 0. Do not set this bit. packet. FNUM does not change if a corrupted SOF is received. The values read from these Bits are always 0. Do no t set these Bits.
4173E–USB–09/07 AT89C5132 Reset Value = 0000 0000b 1 - 0 USBCD1:0 USB Controller Clock Divider 2-bit divider for USB controller clock generation. Bit Number Bit Mnemonic Description
4173E–USB–09/07 AT89C5132 16. MultiMedia Card Controller The AT89C5132 implements a MultiMedia Card (MMC) co ntroller. The MMC is used to store files in removable Flash memory cards that can be e asily plugged or removed from the application.
16.1 Card Concept
The basic MultiMedia Card concept is based on trans ferring data via a minimal number of signals.
16.1.1 Card Signals
The communication signals are:
- CLK: with each cycle of this signal an one bit tra nsfer on the command and data lines is done. The frequency may vary from zero to the maximum clock frequency.
- CMD: is a bidirectional command channel used for c ard initialization and data transfer commands. The CMD signal has two operation modes: open-drain for initialization mode and push-pull for fast command transfer. Commands are sent from the MultiMedia Card bus master to the card and responses from the cards to the host.
- DAT: is a bidirectional data channel. The DAT sign al operates in push-pull mode. Only one card or the host is driving this signal at a time.
16.1.2 Card Registers
Within the card interface five registers are define d: OCR, CID, CSD, RCA and DSR. These can be accessed only by corresponding commands. The 32-bit Operation Conditions Register (OCR) stor es the V DD voltage profile of the card. The register is optional and can be read only. The 128-bit wide CID register carries the card iden tification information (Card ID) used during the card identification procedure. The 128-bit wide Card-Specific Data register (CSD) provides information on how to access the card contents. The CSD defines the data format, err or correction type, maximum data access time, data transfer speed, and whether the DSR register can be used. The 16-bit Relative Card Address register (RCA) car ries the card address assigned by the host during the card identification. This address is use d for the addressed host-card communication after the card identification procedure The 16-bit Driver Stage Register (DSR) can be optio nally used to improve the bus performance for extended operating conditions (depending on par ameters like bus length, transfer rate or number of cards).
16.2 Bus Concept
The MultiMedia Card bus is designed to connect either solid-state mass-storage memory or I/O- devices in a card format to multimedia applications . The bus implementation allows the cover- age of application fields from low-cost systems to systems with a fast data transfer rate. It is a single master bus with a variable number of slaves. The MultiMedia Card bus master is the bus controller and each slave is either a single mass s torage card (with possibly different technolo- gies such as ROM, OTP, Flash etc.) or an I/O-card w ith its own controlling unit (on card) to perform the data transfer. The MultiMedia Card bus also includes power connections to supply the cards.
4173E–USB–09/07 AT89C5132 The bus communication uses a special protocol (MultiMedia Card bus protocol) which is applica- ble for all devices. Therefore, the payload data tr ansfer between the host and the cards can be bidirectional.
16.2.1 Bus Lines
The MultiMedia Card bus architecture requires all c ards to be connected to the same set of lines. No card has an individual connection to the host or other devices, which reduces the con- nection costs of the MultiMedia Card system. The bus lines can be divided into three groups:
- Power supply: V SS1 and V SS2 , VDD – used to supply the cards.
- Data transfer: MCMD, MDAT – used for bidirectional communication.
- Clock: MCLK – used to synchronize data transfer ac ross the bus.
16.2.2 Bus Protocol
After a Power-on reset, the host must initialize th e cards by a special message-based MultiMe- dia Card bus protocol. Each message is represented by one of the following tokens:
- Command: a command is a token which starts an oper ation. A command is transferred serially from the host to the card on the MCMD line.
- Response: a response is a token which is sent from an addressed card (or all connected cards) to the host as an answer to a previously received command. It is transferred serially on the MCMD line.
- Data: data can be transferred from the card to the host or vice-versa. Data is transferred serially on the MDAT line. Card addressing is implemented using a session addr ess assigned during the initialization phase, by the bus controller to all currently conne cted cards. Individual cards are identified by their CID number. This method requires that every c ard will have an unique CID number. To ensure uniqueness of CIDs the CID register contains 24 Bits (MID and OID fields) which are defined by the MMCA. Every card manufacturers is re quired to apply for an unique MID (and optionally OID) number. MultiMedia Card bus data transfers are composed of these tokens. One data transfer is a bus operation. There are different types of operations. Addressed operations always contain a com- mand and a response token. In addition, some operat ions have data token, the others transfer their information directly within the command or response structure. In this case no data token is present in an operation. The Bits on the MDAT and the MCMD lines are transferred synchronous to the host clock. Two types of data transfer commands are defined:
- Sequential commands: These commands initiate a con tinuous data stream, they are terminated only when a stop command follows on the MCMD line. This mode reduces the command overhead to an absolute minimum.
- Block-oriented commands: These commands send data block succeeded by CRC Bits. Both read and write operations allow either single or multiple block transmission. A multiple block transmission is terminated when a stop command follows on the MCMD line similarly to the stream read. Figure 16-1 to Figure 16-5 show the different types of operations, on these figures, grayed tokens are from host to card(s) while white tokens are from card(s) to host.
16.2.3 Command Token Format
errors can be detected and the operation may be repeated. Command content contains the command index and addr ess information or parameters. Table 71. Command Token Format
16.2.4 Response Token Format
and succeeded (R1,R2,R4,R5) or not (R3) by a 7-bit CRC.
Table 72. R1 Response Format (Normal Response) Table 73. R2 Response Format (CID and CSD registers) Table 74. R3 Response Format (OCR Register) Table 75. R4 Response Format (Fast I/O) Table 76. R5 Response Format
16.2.5 Data Packet Format
4173E–USB–09/07 AT89C5132 in stream packets, CRC protection is not included in this case. The CRC protection algorithm for block data is a 16-bit CCITT polynomial. Figure 16-8. Data Token Format
16.2.6 Clock Control
The MMC bus clock signal can be used by the host to turn the cards into energy saving mode or to control the data flow (to avoid under-run or ove r-run conditions) on the bus. The host is allowed to lower the clock frequency or shut it down. There are a few restrictions the host must follow:
- The bus frequency can be changed at any time (unde r the restrictions of maximum data transfer frequency, defined by the cards, and the identification frequency defined by the specification document).
- It is an obvious requirement that the clock must b e running for the card to output data or response tokens. After the last MultiMedia Card bus transaction, the host is required, to provide 8 (eight) clock cycles for the card to complete the operation before shutting down the clock. Following is a list of the various bus transactions:
- A command with no response. 8 clocks after the hos t command End bit.
- A command with response. 8 clocks after the card c ommand End bit.
- A read data transaction. 8 clocks after the End bi t of the last data block.
- A write data transaction. 8 clocks after the CRC s tatus token.
- The host is allowed to shut down the clock of a “b usy” card. The card will complete the programming operation regardless of the host clock. However, the host must provide a clock edge for the card to turn off its busy signal. Without a clock edge the card (unless previously disconnected by a deselect command-CMD7) will force the MDAT line down, forever.
16.3 Description
The MMC controller interfaces to the C51 core throu gh the following eight special function registers: MMCON0, MMCON1, MMCON2, the three MMC control regis ters (see Figure 78 to Figure ); MMSTA, the MMC status register (see Figure 81); MMI NT, the MMC interrupt register (see Figure ); MMMSK, the MMC interrupt mask register (s ee Figure 83); MMCMD, the MMC com- mand register (see Figure 84); MMDAT, the MMC data register (see Figure ); and MMCLK, the MMC clock register (see Figure 86). As shown in Figure 16-9, the MMC controller is divi ded in four blocks: the clock generator that handles the MCLK (formally the MMC CLK) output to t he card, the command line controller that handles the MCMD (formally the MMC CMD) line traffic to or from the card, the data line control- ler that handles the MDAT (formally the MMC DAT) li ne traffic to or from the card, and the interrupt controller that handles the MMC controlle r interrupt sources. These blocks are detailed in the following sections.
0 Content 1Sequential Data
CRC Block Data 0 Content 1 Block Length
4173E–USB–09/07 AT89C5132 Figure 16-9. MMC Controller Block Diagram
16.4 Clock Generator
The MMC clock is generated by division of the oscillator clock (F OSC ) issued from the Clock Con- troller block as detailed in Section "Oscillator", page 12. The division factor is given by MMCD7:0 Bits in MMCLK register. Figure 16-10 shows the MMC clock generator and its output clock cal- culation formula. Figure 16-10. MMC Clock Generator and Symbol As soon as MMCEN bit in MMCON2 is set, the MMC cont roller receives its system clock. The MMC command and data clock is generated on MCLK output and sent to the command line and data line controllers. Figure 16-11 shows the MMC controller configuration flow. As exposed in Section “Clock Control”, MMCD7:0 Bits can be used to dynamically increase or reduce the MMC clock. Figure 16-11. Configuration Flow
16.5 Command Line Controller
As shown in Figure 16-12, the command line controller is divided in two channels: the command transmitter channel that handles the command transm ission to the card through the MCMD line and the command receiver channel that handles the r esponse reception from the card through the MCMD line. These channels are detailed in the following sections. OSC CLOCK MCMD MCLK 8Internal Bus MDAT Command Line Clock MMC Interrupt Request Generator Controller Data Line Controller Interrupt Controller MMCD7:0 MMCLK MMC Clock MMCclk OSCclk CLOCK MMCEN MMCON2.7 Controller Clock MMC CLOCK MMC Clock Symbol MMC Controller Configuration Configure MMC Clock MMCLK = XXh MMCEN = 1 FLOWC = 0
4173E–USB–09/07 AT89C5132 Figure 16-12. Command Line Controller Block Diagram
16.5.1 Command Transmitter
To send a command to the card, the user must load t he command index (1 byte) and argument (4 Bytes) in the command transmit FIFO using the MM CMD register. Before starting transmis- sion by setting and clearing the CMDEN bit in MMCON1 register, the user must first configure:
- RESPEN bit in MMCON1 register to indicate whether a response is expected or not.
- RFMT bit in MMCON0 register to indicate the respon se size expected.
- CRCDIS bit in MMCON0 register to indicate whether the CRC7 included in the response will be computed or not. In order to avoid CRC error, CRCDIS may be set for responses that do not include CRC7. Figure 16-13 summarizes the command transmission flow. As soon as command transmission is enabled, the CFL CK flag in MMSTA is set indicating that write to the FIFO is locked. This mechanism is implemented to avoid command over-run. The end of the command transmission is signalled by the EOCI flag in MMINT register becoming set. This flag may generate an MMC interrupt request as detailed in Section "Interrupt", page 96. The end of the command transmission also resets the CFLCK flag. The user may abort command loading by setting and c learing the CTPTR bit in MMCON0 regis- ter which resets the write pointer to the transmit FIFO. CTPTR MMCON0.4 CRPTR MMCON0.5 MCMD CMDEN MMCON1.0 TX COMMAND Line Finished State Machine Data Converter // -> Serial 5-byte FIFO MMCMD TX Pointer RFMT MMCON0.1 CRCDIS MMCON0.0 RESPEN MMCON1.1 Data Converter Serial -> // RX Pointer 17-byte FIFO MMCMD CFLCK MMSTA.0 CRC7 Generator RX COMMAND Line Finished State Machine CRC7 and Format Checker CRC7S MMSTA.2 RESPFS MMSTA.1 EOCI MMINT.5 EORI MMINT.6 Command Transmitter Command Receiver Write Read
4173E–USB–09/07 AT89C5132 Figure 16-13. Command Transmission Flow
16.5.2 Command Receiver
The end of the response reception is signalled by the EORI flag in MMINT register. This flag may generate an MMC interrupt request as detailed in Se ction "Interrupt", page 96. When this flag is set, two other flags in MMSTA register: RESPFS and CRC7S give a status on the response received. RESPFS indicates if the response format is correct or not: the size is the one expected (48 Bits or 136 Bits) and a valid End bit has been received, and CRC7S indicates if the CRC7 computation is correct or not. These Flags are clea red when a command is sent to the card and updated when the response has been received. The user may abort response reading by setting and clearing the CRPTR bit in MMCON0 regis- ter which resets the read pointer to the receive FIFO. According to the MMC specification delay between a command and a response (formally N CR parameter) cannot exceed 64 MMC clock periods. To a void any locking of the MMC controller when card does not send its response (e.g. physical ly removed from the bus), user must launch a timeout period to exit from such situation. In case of timeout user may reset the command con- troller and its internal state machine by setting and clearing the CCR bit in MMCON2 register. This timeout may be disarmed when receiving the response.
16.6 Data Line Controller
The data line controller is based on a 16-byte FIFO used both by the data transmitter channel and by the data receiver channel. Command Transmission Load Command in Buffer MMCMD = Index MMCMD = Argument Configure Response RESPEN = X RFMT = X CRCDIS = X Transmit Command CMDEN = 1 CMDEN = 0
16.6.1 FIFO Implementation
indicating the status full and empty of each FIFO.
16.6.2 Data Configuration
Table 77. Block Length Programming
4173E–USB–09/07 AT89C5132 Figure 16-15. Data Controller Configuration Flows
16.6.3 Data Transmitter
16.6.3.1 Configuration
For transmitting data to the card, user must first configure the data controller in transmission mode by setting the DATDIR bit in MMCON1 register. Figure 16-16 summarizes the data stream transmission flows in both polling and interrupt modes while Figure 16-17 summarizes the data block transm ission flows in both polling and interrupt modes, these flows assume that block length is greater than 16 data.
16.6.3.2 Data Loading
Data is loaded in the FIFO by writing to MMDAT regi ster. Number of data loaded may vary from 1 to 16 Bytes. Then if necessary (more than 16 Byte s to send) user must wait that one FIFO becomes empty (F1EI or F2EI set) before loading 8 new data.
16.6.3.3 Data Transmission
Transmission is enabled by setting and clearing DATEN bit in MMCON1 register. Data is transmitted immediately if the response has already been received, or is delayed after the response reception if its status is correct. In both cases transmission is delayed if a card sends a busy state on the data line until the end of this busy condition. According to the MMC specification, the data transf er from the host to the card may not start sooner than 2 MMC clock periods after the card resp onse was received (formally N WR parame- ter). To address all card types, this delay can be programmed using DATD1:0 Bits in MMCON2 register from 3 MMC clock periods when DATD1:0 Bits are cleared to 9 MMC clock periods when DATD2:0 Bits are set, by step of 2 MMC clock periods.
16.6.3.4 End of Transmission
The end of data frame (block or stream) transmissio n is signalled by the EOFI flag in MMINT register. This flag may generate an MMC interrupt r equest as detailed in Section "Interrupt", page 96. In data stream mode, EOFI flag is set, after reception of the End bit. This assumes user has pre- viously sent the STOP command to the card, which is the only way to stop stream transfer. In data block mode, EOFI flag is set, after recepti on of the CRC status token (see Figure 16-4). Two other flags in MMSTA register: DATFS and CRC16S report a status on the frame sent. DATFS indicates if the CRC status token format is c orrect or not, and CRC16S indicates if the card has found the CRC16 of the block correct or not. Data Single Block Configuration Data Stream Configuration Configure Format DFMT = 0 Data Multi-block Configuration Configure Format DFMT = 1 MBLOCK = 1 BLEN3:0 = XXXXb Configure Format DFMT = 1 MBLOCK = 0 BLEN3:0 = XXXXb
4173E–USB–09/07 AT89C5132
16.6.3.5 Busy Status
As shown in Figure 16-4 the card uses a busy token during a block write operation. This busy status is reported by the CBUSY flag in MMSTA regis ter and by the MCBI flag in MMINT which is set every time CBUSY toggles, i.e. when the card enters and exits its busy state. This flag may generate an MMC interrupt request as detailed in Section "Interrupt", page 96. Figure 16-16. Data Stream Transmission Flows Send STOP Command Data Stream Transmission Start Transmission DATEN = 1 DATEN = 0 FIFO Empty? F1EI or F2EI = 1? FIFO Filling Write 8 Data to MMDAT No More Data To Send? FIFOs Filling Write 16 Data to MMDAT a. Polling Mode Data Stream Initialization FIFOs Filling Write 16 Data to MMDAT Data Stream Transmission ISR FIFO Filling Write 8 Data to MMDAT Send STOP Command No More Data to Send? b. Interrupt Mode FIFO Empty? F1EI or F2EI = 1? Start Transmission DATEN = 1 DATEN = 0 Unmask FIFOs Empty F1EM = 0 F2EM = 0 Mask FIFOs Empty F1EM = 1 F2EM = 1
4173E–USB–09/07 AT89C5132 Figure 16-17. Data Block Transmission Flows
16.6.4 Data Receiver
16.6.4.1 Configuration
To receive data from the card, the user must first configure the data controller in reception mode by clearing the DATDIR bit in MMCON1 register. Figure 16-18 summarizes the data stream reception f lows in both polling and interrupt modes while Figure 16-19 summarizes the data block recept ion flows in both polling and interrupt modes, these flows assume that block length is greater than 16 Bytes.
16.6.4.2 Data Reception
The end of data frame (block or stream) reception i s signalled by the EOFI flag in MMINT regis- ter. This flag may generate an MMC interrupt request as detailed in Section "Interrupt", page 96. When this flag is set, two other flags in MMSTA reg ister: DATFS and CRC16S give a status on the frame received. DATFS indicates if the frame fo rmat is correct or not: a valid End bit has been received, and CRC16S indicates if the CRC16 co mputation is correct or not. In case of data stream CRC16S has no meaning and stays cleared. According to the MMC specification data transmissio n, the card starts after the access time delay (formally N AC parameter) beginning from the End bit of the read command. To avoid any locking of the MMC controller when card does not se nd its data (e.g. physically removed from the bus), the user must launch a time-out period to exit from such situation. In case of time-out Data Block Transmission Start Transmission DATEN = 1 DATEN = 0 FIFO Empty? F1EI or F2EI = 1? FIFO Filling Write 8 Data to MMDAT No More Data To Send? FIFOs Filling Write 16 Data to MMDAT a. Polling Mode Data Block Initialization Start Transmission DATEN = 1 DATEN = 0 FIFOs Filling Write 16 Data to MMDAT Data Block Transmission ISR FIFO Filling Write 8 Data to MMDAT No More Data to Send? b. Interrupt Mode FIFO Empty? F1EI or F2EI = 1? Mask FIFOs Empty F1EM = 1 F2EM = 1 Unmask FIFOs Empty F1EM = 0 F2EM = 0
4173E–USB–09/07 AT89C5132 the user may reset the data controller and its inte rnal state machine by setting and clearing the DCR bit in MMCON2 register. This time-out may be disarmed after receiving 8 dat a (F1FI flag set) or after receiving end of frame (EOFI flag set) in case of block length less than 8 data (1, 2 or 4).
16.6.4.3 Data Reading
Data is read from the FIFO by reading to MMDAT regi ster. Each time one FIFO becomes full (F1FI or F2FI set), user is requested to flush this FIFO by reading 8 data. Figure 16-18. Data Stream Reception Flows Data Stream Reception FIFO Full? F1FI or F2FI = 1? FIFO Reading read 8 data from MMDAT No More Data To Receive? a. Polling Mode Data Stream Initialization Data Stream Reception ISR FIFO Reading read 8 data from MMDAT Send STOP Command No More Data To Receive? b. Interrupt Mode FIFO Full? F1FI or F2FI = 1? Unmask FIFOs Full F1FM = 0 F2FM = 0 Send STOP Command Mask FIFOs Full F1FM = 1 F2FM = 1
4173E–USB–09/07 AT89C5132 Figure 16-19. Data Block Reception Flows
16.6.5 Flow Control
To allow transfer at high speed without taking care of CPU oscillator frequency, the FLOWC bit in MMCON2 allows control of the data flow in both transmission and reception. During transmission, setting the FLOWC bit has the following effects:
- MMCLK is stopped when both FIFOs become empty: F1E I and F2EI set.
- MMCLK is restarted when one of the FIFOs becomes f ull: F1EI or F2EI cleared. During reception, setting the FLOWC bit has the following effects:
- MMCLK is stopped when both FIFOs become full: F1FI and F2FI set.
- MMCLK is restarted when one of the FIFOs becomes e mpty: F1FI or F2FI cleared. As soon as the clock is stopped, the MMC bus is frozen and remains in its state until the clock is restored by writing or reading data in MMDAT.
16.7 Interrupt
16.7.1 Description
As shown in Figure 16-20, the MMC controller implem ents eight interrupt sources reported in MCBI, EORI, EOCI, EOFI, F2FI, F1FI, and F2EI flags in MMCINT register. These flags were detailed in the previous sections. All of these sources are maskable separately using MCBM, EORM, EOCM, EOFM, F2FM, F1FM, and F2EM mask bits, respectively, in MMMSK register. Data Block Reception Start Transmission DATEN = 1 DATEN = 0 FIFO Full? F1EI or F2EI = 1? FIFO Reading read 8 data from MMDAT No More Data To Receive? a. Polling Mode Data Block Initialization Start Transmission DATEN = 1 DATEN = 0 Data Block Reception ISR FIFO Reading read 8 data from MMDAT No More Data To Receive? b. Interrupt Mode FIFO Full? F1EI or F2EI = 1? Mask FIFOs Full F1FM = 1 F2FM = 1 Unmask FIFOs Full F1FM = 0 F2FM = 0
troller interrupt enable bit is set (EMMC in IEN1 register). not to overlook any interrupts.
16.8 Registers
Table 78. MMCON0 Register
7 DRPTR
Set to reset the read pointer of the data FIFO. Clear to release the read pointer of the data FIFO.
Table 79. MMCON1 Register Table 80. MMCON2 Register
6 DTPTR
Set to reset the write pointer of the data FIFO. Clear to release the write pointer of the data FIFO .
5 CRPTR
Set to reset the read pointer of the receive comman d FIFO. Clear to release the read pointer of the receive co mmand FIFO.
4 CTPTR
Set to reset the write pointer of the transmit comm and FIFO. Clear to release the read pointer of the transmit c ommand FIFO.
3 MBLOCK
Set to select multi-block data format. Clear to select single block data format.
2 DFMT
Set to select the block-oriented data format. Clear to select the stream data format.
1 RFMT
Set to select the 48-bit response format. Clear to select the 136-bit response format.
0 CRCDIS
Set to disable the CRC7 computation when receiving a response. Clear to enable the CRC7 computation when receiving a response. Refer to Table 77 for Bits description. Do not prog ram value > 1011b.
3 DATDIR
Set to select data transfer from host to card (writ e mode). Clear to select data transfer from card to host (re ad mode).
2 DATEN
1 RESPEN
0 CMDEN Command Transmission Enable Bit
Set and clear to enable transmission of the command FIFO to the card.
Table 81. MMSTA Register
7 MMCEN
Set to enable the MCLK clocks and activate the MMC controller. Clear to disable the MMC clocks and freeze the MMC controller.
6 DCR Data Controller Reset Bit
Set and clear to reset the data line controller in case of transfer abort.
5 CCR Command Controller Reset Bit
Set and clear to reset the command line controller in case of transfer abort. The values read from these Bits are always 0. Do no t set these Bits.
0 FLOWC
Set to enable the flow control during data transfer s. Clear to disable the flow control during data trans fers. The values read from these Bits are always 0. Do no t set these Bits.
5 CBUSY
Set by hardware when the card sends a busy state on the data line. Cleared by hardware when the card no more sends a busy state on the data line.
Table 82. MMINT Register
4 CRC16S
Set by hardware when the token response reports a g ood CRC. Cleared by hardware when the token response reports a bad CRC. Set by hardware when the CRC16 received in the data block is correct. Cleared by hardware when the CRC16 received in the data block is not correct.
3 DATFS
Set by hardware when the format of the token respon se is correct. Cleared by hardware when the format of the token re sponse is not correct. Set by hardware when the format of the frame is cor rect. Cleared by hardware when the format of the frame is not correct.
2 CRC7S
Set by hardware when the CRC7 computed in the respo nse is correct. Cleared by hardware when the CRC7 computed in the r esponse is not correct. This bit is not relevant when CRCDIS is set.
1 RESPFS
Set by hardware when the format of a response is co rrect. Cleared by hardware when the format of a response i s not correct.
0 CFLCK
7 MCBI
signal is asserted or deasserted on the data line).
Table 83. MMMSK Register
6 EORI
Set by hardware at the end of response reception.
5 EOCI
Set by hardware at the end of command transmission.
4 EOFI
Set by hardware at the end of frame (stream or bloc k) transfer.
3 F2FI
Set by hardware when second FIFO becomes full. Cleared by hardware when second FIFO becomes empty.
2 F1FI
Set by hardware when first FIFO becomes full. Cleared by hardware when first FIFO becomes empty.
1 F2EI
Set by hardware when second FIFO becomes empty. Cleared by hardware when second FIFO becomes full.
0 F1EI
Set by hardware when first FIFO becomes empty. Cleared by hardware when first FIFO becomes full.
7 MCBM
Set to prevent MCBI flag from generating an MMC int errupt. Clear to allow MCBI flag to generate an MMC interru pt.
6 EORM
Set to prevent EORI flag from generating an MMC int errupt. Clear to allow EORI flag to generate an MMC interru pt.
5 EOCM
Set to prevent EOCI flag from generating an MMC int errupt. Clear to allow EOCI flag to generate an MMC interru pt.
4 EOFM
Set to prevent EOFI flag from generating an MMC int errupt. Clear to allow EOFI flag to generate an MMC interru pt.
3 F2FM
Set to prevent F2FI flag from generating an MMC int errupt. Clear to allow F2FI flag to generate an MMC interru pt.
Table 84. MMCMD Register
2 F1FM
Set to prevent F1FI flag from generating an MMC int errupt. Clear to allow F1FI flag to generate an MMC interru pt.
1 F2EM
Set to prevent F2EI flag from generating an MMC int errupt. Clear to allow F2EI flag to generate an MMC interru pt.
0 F1EM
Set to prevent F1EI flag from generating an MMC int errupt. Clear to allow F1EI flag to generate an MMC interru pt. Output (read) register of the response FIFO. Input (write) register of the command FIFO.
Table 85. MMDAT Register Table 86. MMCLK Register Input (write) or output (read) register of the data FIFO. 8-bit divider for MMC clock generation.
4173E–USB–09/07 AT89C5132 17. IDE/ATAPI Interface The AT89C5132 provide an IDE/ATAPI interface allowi ng connection of devices such as CD- ROM reader, CompactFlash cards, hard disk drive, etc. It consists of a 16-bit data transfer (read or write) between the AT89C5132 and the IDE devices.
17.1 Description
The IDE interface mode is enabled by setting the EXT16 bit in AUXR (see Table 14 on page 27 ). As soon as this bit is set, all MOVX instructions read or write are done in a 16-bit mode compare to the standard 8-bit mode. P0 carries the low orde r multiplexed address and data bus (A7:0, D7:0) while P2 carries the high order multiplexed a ddress and data bus (A15:8, D15:8). When writing data in IDE mode, the ACC contains D7:0 dat a (as in 8-bit mode) while DAT16H register (see Table 88) contains D15:8 data. When reading da ta in IDE mode, D7:0 data is returned in ACC while D15:8 data is returned in DAT16H. Figure 17-1 shows the IDE read bus cycle while Figu re 17-2 shows the IDE write bus cycle. For simplicity, these figures depict the bus cycle waveforms in idealized form and do not provide pre- cise timing information. For IDE bus cycle timing p arameters refer to the Section “AC Characteristics”. IDE cycle takes 6 CPU clock periods which is equiva lent to 12 oscillator clock periods in stan- dard mode or 6 oscillator clock periods in X2 mode. For further information on X2 mode, refer to the Section “X2 Feature”, page 12. Slow IDE devices can be accessed by stretching the read and write cycles. This is done using the M0 bit in AUXR. Setting this bit changes the wi dth of the RD and WR signals from 3 to 15 CPU clock periods. Figure 17-1. IDE Read Waveforms Notes: 1. RD signal may be stretched using M0 bit in AUXR register. 2. When executing MOVX @Ri instruction, P2 outputs S FR content. 3. When executing MOVX @DPTR instruction, if DPHDIS is set (Page Access Mode), P2 out- puts SFR content instead of DPH. ALE RD (1) DPL or Ri D7:0 CPU Clock DPH or P2 (2),(3) D15:8 P2
4173E–USB–09/07 AT89C5132 Figure 17-2. IDE Write Waveforms Notes: 1. WR signal may be stretched using M0 bit in AUXR register. 2. When executing MOVX @Ri instruction, P2 outputs S FR content. 3. When executing MOVX @DPTR instruction, if DPHDIS is set (Page Access Mode), P2 out- puts SFR content instead of DPH.
17.1.1 IDE Device Connection
Figure 17-3 and Figure 17-4 show two examples on ho w to interface up to two IDE devices to the AT89C5132. In both examples P0 carries IDE low order data bits D7:0, P2 carries IDE high order data bits D15:8, while RD and WR signals are respectively connected to the IDE nIOR and nIOW signals. Other IDE control signals are generat ed by the external address latch outputs in the first example while they are generated by some port I/Os in the second one. Using an exter- nal latch will achieve higher transfer rate. Figure 17-3. IDE Device Connection Example 1 Figure 17-4. IDE Device Connection Example 2 ALE WR (1) DPL or Ri D7:0 CPU Clock DPH or P2 (2),(3) D15:8 P2 D15-8 A2:0 ALE nIOW nIOR RD WR D7:0 nCS1:0 nRESET D15-8 A2:0 nIOW nIOR D7:0 nCS1:0 nRESET Latch IDE Device 0 IDE Device 1 AT89C5132 Px.y P2/A15:8 P0/AD7:0 D15-8 A2:0 P4.5 nIOW nIOR RD WR D7:0 nCS1:0 nRESET D15-8 A2:0 nIOW nIOR D7:0 nCS1:0 nRESET P4.2:0 P4.4:3 IDE Device 0 AT89C5132 IDE Device 1
Table 87. External Data Memory Interface Signals
17.2 Registers
Table 88. DAT16H Register Upper address lines for the external bus. Multiplexed higher address and data lines for the I DE interface.
multiprocessor communication with automatic address recognition.
18.1 Mode Selection
gle synchronous and the three asynchronous modes according to Table 89 . Table 89. Serial I/O Port Mode Selection
18.2 Baud Rate Generator
allows higher and more accurate baud rates than Timer 1. Baud rate formulas depend on the modes selected and are given in the following mode sections.
18.2.1 Timer 1
4173E–USB–09/07 AT89C5132 Figure 18-1. Timer 1 Baud Rate Generator Block Diagram
18.2.2 Internal Baud Rate Generator
When using the Internal Baud Rate Generator, the Baud Rate is derived from the overflow of the timer. As shown in Figure 18-2, the Internal Baud R ate Generator is an 8-bit auto-reload timer feed by the peripheral clock or by the peripheral c lock divided by 6 depending on the SPD bit in BDRCON register (see Table 95). The Internal Baud R ate Generator is enabled by setting BBR bit in BDRCON register. SMOD1 bit in PCON register allows doubling of the generated baud rate. Figure 18-2. Internal Baud Rate Generator Block Diagram
18.3 Synchronous Mode (Mode 0)
Mode 0 is a half-duplex, synchronous mode, which is commonly used to expand the I/0 capabil- ities of a device with shift registers. The transmi t data (TXD) pin outputs a set of eight clock pulses while the receive data (RXD) pin transmits o r receives a byte of data. The 8-bit data are transmitted and received least-significant bit (LSB ) first. Shifts occur at a fixed Baud Rate (see Section "Baud Rate Selection (Mode 0)", page 110). Figure 18-3 shows the serial port block dia- gram in Mode 0. TR1 TCON.6 GATE1 TMOD.7 Overflow C/T1# TMOD.6 TL1 (8 bits) TH1 (8 bits) INT1 PER CLOCK ÷ 6 SMOD1 PCON.7 ÷ 2 CLOCK To serial Port Overflow SPD BDRCON.1 BRG (8 bits) BRL (8 bits) PER CLOCK ÷ 6 IBRG CLOCK BRR BDRCON.4 SMOD1 PCON.7 ÷ 2 To serial Port IBRG0 CLOCK To serial Port (M0)
4173E–USB–09/07 AT89C5132 Figure 18-3. Serial I/O Port Block Diagram (Mode 0)
18.3.1 Transmission
(Mode 0) To start a transmission mode 0, write to SCON register clearing Bits SM0, SM1. As shown in Figure 18-4, writing the byte to transm it to SBUF register starts the transmission. Hardware shifts the LSB (D0) onto the RXD pin durin g the first clock cycle composed of a high level then low level signal on TXD. During the eigh th clock cycle the MSB (D7) is on the RXD pin. Then, hardware drives the RXD pin high and ass erts TI to indicate the end of the transmission. Figure 18-4. Transmission Waveforms (Mode 0)
18.3.2 Reception
(Mode 0) To start a reception in mode 0, write to SCON regis ter clearing SM0, SM1 and RI Bits and set- ting the REN bit. As shown in Figure 18-5, Clock is pulsed and the LS B (D0) is sampled on the RXD pin. The D0 bit is then shifted into the shift register. After eight sampling, the MSB (D7) is shifted into the shift register, and hardware asserts RI bit to indicate a completed reception. Software can then read the received byte from SBUF register. TXD RXD SBUF Tx SR SBUF Rx SR SM1 SCON.6 SM0 SCON.7 Mode Decoder M3 M2 M1 M0 Mode Controller RI SCON.0 TI SCON.1 Baud Rate Controller Write to SBUF TXD RXD TI D0 D1 D2 D3 D4 D5 D6 D7
4173E–USB–09/07 AT89C5132 Figure 18-5. Reception Waveforms (Mode 0)
18.3.3 Baud Rate Selection
(Mode 0) In mode 0, the baud rate can be either fixed or variable. As shown in Figure 18-6, the selection is done using M0SRC bit in BDRCON register. Figure 18-7 gives the baud rate calculation formulas for each baud rate source. Figure 18-6. Baud Rate Source Selection (mode 0) Figure 18-7. Baud Rate Formulas (Mode 0) Write to SCON TXD RXD RI D0 D1 D2 D3 D4 D5 D6 D7 Set REN, Clear RI M0SRC BDRCON.0 PER CLOCK ÷ 6 To IBRG0 CLOCK Serial Port Baud_Rate= FPER BRL= 256 - 6(1-SPD) ⋅ 16 ⋅ Baud_Rate FPER a. Fixed Formula b. Variable Formula Baud_Rate = 6 FPER
4173E–USB–09/07 AT89C5132
18.4 Asynchronous Modes (Modes 1, 2 and 3)
The Serial Port has one 8-bit and two 9-bit asynchr onous modes of operation. Figure 18-8 shows the Serial Port block diagram in asynchronous modes. Figure 18-8. Serial I/O Port Block Diagram (Modes 1, 2 and 3)
18.4.0.1 Mode 1
Mode 1 is a full-duplex, asynchronous mode. The dat a frame (see Figure 18-9) consists of 10 Bits: one start, eight data Bits and one stop bit. Serial data is transmitted on the TXD pin and received on the RXD pin. When data is received, the stop bit is read in the RB8 bit in SCON register. Figure 18-9. Data Frame Format (Mode 1)
18.4.0.2 Modes 2 and 3
Modes 2 and 3 are full-duplex, asynchronous modes. The data frame (see Figure 18-10) con- sists of 11 Bits: one start bit, eight data Bits (t ransmitted and received LSB first), one programmable ninth data bit and one stop bit. Seria l data is transmitted on the TXD pin and received on the RXD pin. On receive, the ninth bit is read from RB8 bit in SCON register. On transmit, the ninth data bit is written to TB8 bit in SCON register. Alternatively, the ninth bit can be used as a command/data flag. Figure 18-10. Data Frame Format (Modes 2 and 3)
18.4.1 Transmission
(Modes 1, 2 and 3) To initiate a transmission, write to SCON register, setting SM0 and SM1 Bits according to Table 89, and setting the ninth bit by writing to TB8 bit. Then, writing the byte to be transmitted to SBUF register starts the transmission. TB8 SCON.3 IBRG CLOCK RXD TXD SBUF Tx SR Rx SR SM1 SCON.6 SM0 SCON.7 Mode Decoder M3 M2 M1 M0 RI SCON.0 TI SCON.1 Mode & Clock Controller SBUF Rx RB8 SCON.2 SM2 SCON.4 CLOCK PER CLOCK Mode 1 D0 D1 D2 D3 D4 D5 D6 D7 Start bit 8-bit data Stop bit D0 D1 D2 D3 D4 D5 D6 D8 Start bit 9-bit data Stop bit
4173E–USB–09/07 AT89C5132
18.4.2 Reception
(Modes 1, 2 and 3) To prepare for reception, write to SCON register, s etting SM0 and SM1 Bits according to Table 89, and set the REN bit. The actual reception is then initiated by a detected high-to-low transition on the RXD pin.
18.4.3 Framing Error Detection
(Modes 1, 2 and 3) Framing error detection is provided for the three asynchronous modes. To enable the framing bit error detection feature, set SMOD0 bit in PCON register as shown in Figure 18-11. When this feature is enabled, the receiver checks e ach incoming data frame for a valid stop bit. An invalid stop bit may result from noise on the serial lines or from simultaneous transmission by two devices. If a valid stop bit is not found, the software sets FE bit in SCON register. Software may examine FE bit after each reception to check for data errors. Once set, only soft- ware or a chip reset clears FE bit. Subsequently re ceived frames with valid stop Bits cannot clear FE bit. When the framing error detection feat ure is enabled, RI rises on stop bit instead of the last data bit as detailed in Figure 18-17. Figure 18-11. Framing Error Block Diagram
18.4.4 Baud Rate Selection (Modes 1 and 3)
In modes 1 and 3, the Baud Rate is derived either f rom the Timer 1 or the Internal Baud Rate Generator and allows different baud rate in reception and transmission. As shown in Figure 18-12, the selection is done usi ng RBCK and TBCK Bits in BDRCON register. Figure 18-13 gives the baud rate calculation formul as for each baud rate source. Table 90 details Internal Baud Rate Generator configuration for different peripheral clock frequencies and gives baud rates closer to the standard baud rates. Figure 18-12. Baud Rate Source Selection (Modes 1 and 3) SM0 SMOD0 PCON.6 SM0/FE SCON.7 Framing Error Controller FE RBCK BDRCON.2 CLOCK To Serial IBRG CLOCK Rx Port TBCK BDRCON.3 CLOCK To Serial IBRG CLOCK Tx Port ÷ 16 ÷ 16
Notes: 1. These frequencies are achieved in X1 mode, F PER = F OSC ÷ 2.
- These frequencies are achieved in X2 mode, F PER = F OSC .
18.4.5 Baud Rate Selection
As shown in Figure 18-14 the selection is done using SMOD1 bit in PCON register. Figure 18-15 gives the baud rate calculation formula depending on the selection. Table 90. Baud Rate Generator Configuration
1 BRL
4173E–USB–09/07 AT89C5132 Figure 18-14. Baud Rate Generator Selection (mode 2) Figure 18-15. Baud Rate Formula (Mode 2)
18.5 Multiprocessor Communication
(Modes 2 and 3) Modes 2 and 3 provide a ninth-bit mode to facilitat e multiprocessor communication. To enable this feature, set SM2 bit in SCON register. When th e multiprocessor communication feature is enabled, the Serial Port can differentiate between data frames (ninth bit clear) and address frames (ninth bit set). This allows the AT89C5132 to function as a slave processor in an environ- ment where multiple slave processors share a single serial line. When the multiprocessor communication feature is en abled, the receiver ignores frames with the ninth bit clear. The receiver examines frames w ith the ninth bit set for an address match. If the received address matches the slaves address, the receiver hardware sets RB8 and RI bits in SCON register, generating an interrupt. The addressed slave’s software then clears SM2 bit in SCON register and prepares to receive the data Bytes. The other slaves are unaffected by these data Bytes because they are waiting to respond to their own addresses.
18.6 Automatic Address Recognition
The automatic address recognition feature is enable d when the multiprocessor communication feature is enabled (SM2 bit in SCON register is set). Implemented in hardware, automatic address recognit ion enhances the multiprocessor commu- nication feature by allowing the Serial Port to exa mine the address of each incoming command frame. Only when the Serial Port recognizes its own address, the receiver sets RI bit in SCON register to generate an interrupt. This ensures tha t the CPU is not interrupted by command frames addressed to other devices. If desired, the automatic address recognition featu re in mode 1 may be enabled. In this configu- ration, the stop bit takes the place of the ninth d ata bit. Bit RI is set only when the received command frame address matches the device’s address and is terminated by a valid stop bit. To support automatic address recognition, a device is identified by a given address and a broad- cast address. Note: The multiprocessor communication and automatic address recognition features cannot be enabled in mode 0 (i.e, setting SM2 bit in SCON register in mode 0 has no effect).
18.6.1 Given Address
Each device has an individual address that is speci fied in SADDR register; the SADEN register is a mask byte that contains don’t care Bits (defin ed by zeros) to form the device’s given SMOD1 PCON.7 PER CLOCK ÷ 2 ÷ 16 To Serial Port Baud_Rate = 32 2SMOD1 ⋅ FPER
4173E–USB–09/07 AT89C5132 address. The don’t care Bits provide the flexibilit y to address one or more slaves at a time. The following example illustrates how a given address is formed. To address a device by its individual address, the SADEN mask byte must be 1111 1111b . For example: SADDR = 0101 0110b SADEN = 1111 1100b Given = 0101 01XXb The following is an example of how to use given addresses to address different slaves: Slave A: SADDR = 1111 0001b SADEN = 1111 1010b Given = 1111 0X0Xb Slave B: SADDR = 1111 0011b SADEN = 1111 1001b Given = 1111 0XX1b Slave C: SADDR = 1111 0011b SADEN = 1111 1101b Given = 1111 00X1b The SADEN byte is selected so that each slave may be addressed separately. For slave A, bit 0 (the LSB) is a don’t-care bit; f or slaves B and C, bit 0 is a 1. To communicate with slave A only, the master must send an address where bit 0 is clear (e.g. 1111 0000B ). For slave A, bit 1 is a 0; for slaves B and C, bit 1 is a don’t care bit. To communicate with slaves A and B, but not slave C, the master must send an a ddress with bits 0 and 1 both set (e.g. 1111 0011B ). To communicate with slaves A, B and C, the master m ust send an address with bit 0 set, bit 1 clear, and bit 2 clear (e.g. 1111 0001B ).
18.6.2 Broadcast Address
A broadcast address is formed from the logical OR o f the SADDR and SADEN registers with zeros defined as don’t-care bits, e.g.: SADDR = 0101 0110b SADEN = 1111 1100b (SADDR | SADEN)=1111 111Xb The use of don’t-care bits provides flexibility in defining the broadcast address, however in most applications, a broadcast address is FFh. The following is an example of using broadcast addresses: Slave A: SADDR = 1111 0001b SADEN = 1111 1010b Given = 1111 1X11b, Slave B: SADDR = 1111 0011b SADEN = 1111 1001b Given = 1111 1X11b, Slave C: SADDR = 1111 0010b SADEN = 1111 1101b Given = 1111 1111b, For slaves A and B, bit 2 is a don’t care bit; for slave C, bit 2 is set. To communicate with all of the slaves, the master must send the address FFh. To communicate with slaves A and B, but not slave C, the master must send the address FBh.
18.6.3 Reset Address
compatible with the 80C51 microcontrollers that do not support automatic address recognition.
18.7 Interrupt
software when executing the serial interrupt service routine. bally enabled by setting EA bit in IEN0 register. flag is set during the stop bit or during the ninth bit as detailed in Figure 18-17.
18.8 Registers
Table 91. SCON Register
Table 92. SBUF Register To select this function, set SMOD0 bit in PCON regi ster. Set by hardware to indicate an invalid stop bit. Must be cleared by software. Refer to Table 89 for mode selection.
6 SM1 Serial Port Mode Bit 1
Refer to Table 89 for mode selection.
5 SM2
4 REN
3 TB8
Modes 2 and 3: Software writes the ninth data bit t o be transmitted to TB8.
2 RB8
Mode 1 (SM2 cleared): Set or cleared by hardware to reflect the stop bit received. Modes 2 and 3 (SM2 set): Set or cleared by hardware to reflect the ninth bit received. Set by the transmitter after the last data bit is t ransmitted. Must be cleared by software. Set by the receiver after the stop bit of a frame h as been received. Must be cleared by software. Read the last data received by the Serial I/O Port. Write the data to be transmitted by the Serial I/O Port.
Table 93. SADDR Register Table 94. SADEN Register Table 95. BDRCON Register 7 - 0 SAD7:0 Slave Individual Address. 7 - 0 SAE7:0 Slave Address Mask Byte. The value read from these bits is indeterminate. Do not set these bits.
4 BRR
Set to enable the baud rate generator. Clear to disable the baud rate generator.
3 TBCK
Set to select the baud rate generator as transmissi on baud rate generator. Clear to select the Timer 1 as transmission baud ra te generator.
2 RBCK
Set to select the baud rate generator as reception baud rate generator. Clear to select the Timer 1 as reception baud rate generator.
1 SPD
Set to select high speed baud rate generation. Clear to select low speed baud rate generation.
0 M0SRC
Set to select the variable baud rate generator in M ode 0. Clear to select fixed baud rate in Mode 0.
Table 96. BRL Register 7-0 BRL7:0 Baud Rate Reload Value.
4173E–USB–09/07 AT89C5132
19.1 Description
The SPI controller interfaces with the C51 core through three special function registers: SPCON, the SPI control register (see Table 98); SPSTA, the SPI status register (see Table 99); and SPDAT, the SPI data register (see Table 100).
19.1.1 Master Mode
The SPI operates in master mode when the MSTR bit in SPCON is set. Figure 19-3 shows the SPI block diagram in master mode. Only a master SPI module can initiate transmissions. Software begins the transmission by writing to SPDAT. Writing to SPDAT writes to the shift register while reading SPDAT reads an intermediate register updated at the end of each transfer. The byte begins shifting out on the MOSI pin under the control of the bit rate generator. This generator also controls the shift register of the s lave peripheral through the SCK output pin. As the byte shifts out, another byte shifts in from th e slave peripheral on the MISO pin. The byte is transmitted most significant bit (MSB) first. The end of transfer is signalled by SPIF being set. In case of the AT89C5132 is the only master on the bus, it can be useful not to use SS pin and get it back to I/O functionality. This is achieved by setting SSDIS bit in SPCON. Figure 19-3. SPI Master Mode Block Diagram Note: MSTR bit in SPCON is set to select master mode .
19.1.2 Slave Mode
The SPI operates in slave mode when the MSTR bit in SPCON is cleared and data has been loaded in SPDAT. Figure 19-4 shows the SPI block diagram in slave mo de. In slave mode, before data transmis- sion occurs, the SS pin of the slave SPI must be asserted to low level . SS must remain low until the transmission of the byte is complete. In the sl ave SPI module, data enters the shift register through the MOSI pin under the control of the serial clock provided by the master SPI module on the SCK input pin. When the master starts a transmi ssion, the data in the shift register begins shifting out on the MISO pin. The end of transfer is signaled by SPIF being set. Bit Rate Generator SPR2:0 SPCON MOSI/P4.1 MISO/P4.0 SCK/P4.2 CPOL SPCON.3 SPEN SPCON.6 CPHA SPCON.2 PER CLOCK 8-bit Shift Register SPDAT WR I Q Internal BusSPDAT RD Control and Clock Logic MODF SPSTA.4 SS /P4.3 SSDIS SPCON.5 WCOL SPSTA.6 SPIF SPSTA.7
when CPHA is cleared (see Section "SS Management", page 123). Note: MSTR bit in SPCON is cleared to select slave m ode.
19.1.3 Bit Rate
Table 97. Serial Bit Rates Notes: 1. These frequencies are achieved in X1 mode, F PER = F OSC ÷ 2.
- These frequencies are achieved in X2 mode, F PER = F OSC .
19.1.4 Data Transfer
4173E–USB–09/07 AT89C5132 AT89C5132 captures data from the SI line while the selected slave captures data from the SO line. For simplicity, the following figures depict the SP I waveforms in idealized form and do not pro- vide precise timing information. For timing parameters refer to the Section “AC Characteristics”. Note: 1. When the peripheral is disabled (SPEN = 0), default SCK line is high level. Figure 19-5. Data Transmission Format (CPHA = 0) Figure 19-6. Data Transmission Format (CPHA = 1)
19.1.5 SS Management
Figure 19-5 shows an SPI transmission with CPHA = 0 , where the first SCK edge is the MSB capture point. Therefore the slave starts to output its MSB as soon as it is selected: SS asserted to low level. SS must then be deasserted between each byte transmis sion (see Figure 19-7). SPDAT must be loaded with data before SS is asserted again. 1 2 3 4 5 6 7 8 MSB bit 1 LSB bit 2 bit 4 bit 3 bit 6 bit 5 bit 1 bit 2 bit 4 bit 3 bit 6 bit 5 MSB LSB MOSI (from Master) MISO (from Slave) SCK (CPOL = 1) SCK (CPOL = 0) SPEN (Internal) SCK Cycle Number SS (to Slave) to Capture Point 1 2 3 4 5 6 7 8 MSB bit 1 LSB bit 2 bit 4 bit 3 bit 6 bit 5 bit 1 bit 2 bit 4 bit 3 bit 6 bit 5 MSB LSB MOSI (from Master) MISO (from Slave) SCK (CPOL = 1) SCK (CPOL = 0) SPEN (Internal) SCK Cycle Number SS (to Slave) Capture Point
4173E–USB–09/07 AT89C5132 Figure 19-6 shows an SPI transmission with CPHA = 1, where the first SCK edge is used by the slave as a start of transmission signal. Therefore SS may remain asserted between each byte transmission (see Figure 19-7). Figure 19-7. SS Timing Diagram
19.1.6 Error Conditions
The following flags signal the SPI error conditions:
- MODF in SPSTA signals a mode fault. MODF flag is relevant only in master mode when SS usage is enabled (SSDIS bit cleared). It signals when set that another master on the bus has asserted SS pin and so, may create a conflict on the bus with two masters sending data at the same time. A mode fault automatically disables the SPI (SPEN cleared) and configures the SPI in slave mode (MSTR cleared). MODF flag can trigger an interrupt as explained in Section "Interrupt", page 124. MODF flag is cleared by reading SPSTA and re-configuring SPI by writing to SPCON.
- WCOL in SPSTA signals a write collision. WCOL flag is set when SPDAT is loaded while a transfer is on-going. In this case, data is not written to SPDAT and transfer continues uninterrupted. WCOL flag does not trigger any interrupt and is relevant jointly with SPIF flag. WCOL flag is cleared after reading SPSTA and writing new data to SPDAT while no transfer is ongoing.
19.2 Interrupt
The SPI handles two interrupt sources; the “end of transfer” and the “mode fault” flags. As shown in Figure 19-8 these flags are combined to gether to appear as a single interrupt source for the C51 core. The SPIF flag is set at the end of an 8-bit shift in and out and is cleared by reading SPSTA and then reading from or writing to SPDAT. The MODF flag is set in case of mode fault error and is cleared by reading SPSTA and then writ- ing to SPCON. The SPI interrupt is enabled by setting ESPI bit in IEN1 register. This assumes interrupts are globally enabled by setting EA bit in IEN0 register. Figure 19-8. SPI Interrupt System
19.3 Configuration
The SPI configuration is made through SPCON. SS (CPHA = 1) SS (CPHA = 0) SI/SO Byte 1 Byte 2 Byte 3 ESPI IEN1.2 SPI Controller Interrupt Request SPIF SPSTA.7 MODF SPSTA.4
4173E–USB–09/07 AT89C5132
19.3.1 Master Configuration
The SPI operates in master mode when the MSTR bit in SPCON is set.
19.3.2 Slave Configuration
The SPI operates in slave mode when the MSTR bit in SPCON is cleared and data has been loaded in SPDAT.
19.3.3 Data Exchange
There are two possible Policies to exchange data in master and slave modes:
- polling
- interrupts
19.3.4 Master Mode with Polling Policy
Figure 19-9 shows the initialization phase and the transfer phase flows using the polling policy. Using this flow prevents any overrun error occurrence.
- The bit rate is selected according to Table 97.
- The transfer format depends on the slave periphera l.
- SS may be deasserted between transfers depending also on the slave peripheral.
- SPIF flag is cleared when reading SPDAT (SPSTA has been read before by the “end of transfer” check). This policy provides the fastest effective transmis sion and is well adapted when communicating at high speed with other Microcontrollers. However, the procedure may then be interrupted at any time by higher priority tasks.
4173E–USB–09/07 AT89C5132 Figure 19-9. Master SPI Polling Policy Flows
19.3.5 Master Mode with Interrupt Policy
Figure 19-10 shows the initialization phase and the transfer phase flows using the interrupt pol- icy. Using this flow prevents any overrun error occurrence.
- The bit rate is selected according to Table 97.
- The transfer format depends on the slave periphera l.
- SS may be deasserted between transfers depending also on the slave peripheral. Reading SPSTA at the beginning of the ISR is mandat ory for clearing the SPIF flag. Clear is effective when reading SPDAT. SPI Initialization Polling Policy Disable Interrupt SPIE = 0 SPI Transfer Polling Policy End Of Transfer? SPIF = 1? Select Master Mode MSTR = 1 Select Bit Rate program SPR2:0 Select Format program CPOL & CPHA Enable SPI SPEN = 1 Select Slave Pn.x = L Start Transfer Write Data in SPDAT Last Transfer? Get Data Received Read SPDAT Deselect Slave Pn.x = H
4173E–USB–09/07 AT89C5132 Figure 19-10. Master SPI Interrupt Policy Flows
19.3.6 Slave Mode with Polling Policy
Figure 19-11 shows the initialization phase and the transfer phase flows using the polling policy. The transfer format depends on the master controller. SPIF flag is cleared when reading SPDAT (SPSTA has been read before by the “end of recep- tion” check). This policy provides the fastest effective transmis sion and is well adapted when communicating at high speed with other Microcontrollers. However, the procedure may be interrupted at any time by higher priority tasks. SPI Initialization Interrupt Policy Enable Interrupt ESPI =1 SPI Interrupt Service Routine Select Master Mode MSTR = 1 Select Bit Rate Program SPR2:0 Select Format Program CPOL & CPHA Enable SPI SPEN = 1 Read Status Read SPSTA Start New Transfer Write Data in SPDAT Last Transfer? Get Data Received Read SPDAT Disable Interrupt SPIE = 0 Select Slave Pn.x = L Start Transfer Write Data in SPDAT Deselect Slave Pn.x = H
4173E–USB–09/07 AT89C5132 Figure 19-11. Slave SPI Polling Policy Flows
19.3.7 Slave Mode with Interrupt Policy
Figure 19-10 shows the initialization phase and the transfer phase flows using the interrupt policy. The transfer format depends on the master controller. Reading SPSTA at the beginning of the ISR is mandat ory for clearing the SPIF flag. Clear is effective when reading SPDAT. SPI Initialization Polling Policy Disable interrupt SPIE = 0 SPI Transfer Polling Policy Data Received? SPIF = 1? Select Slave Mode MSTR = 0 Select Format Program CPOL & CPHA Enable SPI SPEN = 1 Prepare Next Transfer Write Data in SPDAT Get Data Received Read SPDAT Prepare Transfer write data in SPDAT
19.4 Registers
Table 98. SPCON Register
7 SPR2 SPI Rate Bit 2
Refer to Table 97 for bit rate description.
6 SPEN
Set to enable the SPI interface. Clear to disable the SPI interface.
5 SSDIS
Clear to enable SS in both master and slave modes.
4 MSTR
Set to select the master mode. Clear to select the slave mode.
3 CPOL
Set to have the clock output set to high level in i dle state. Clear to have the clock output set to low level in idle state.
2 CPHA
Set to have the data sampled when the clock returns to idle state (see CPOL). Clear to have the data sampled when the clock leave s the idle state (see CPOL).
Note: 1. When the SPI is disabled, SCK outputs high l evel. Table 99. SPSTA Register Table 100. SPDAT Register Refer to Table 97 for bit rate description.
7 SPIF
Set by hardware when an 8-bit shift is completed. Cleared by hardware when reading or writing SPDAT a fter reading SPSTA.
6 WCOL
Set by hardware to indicate that a collision has be en detected. Cleared by hardware to indicate that no collision h as been detected. The values read from this bit is indeterminate. Do not set this bit.
4 MODF
Set by hardware to indicate that the SS pin is at an appropriate level. Cleared by hardware to indicate that the SS pin is at an inappropriate level. The values read from these Bits are indeterminate. Do not set these Bits.
4173E–USB–09/07 AT89C5132 20. Two-wire Interface (TWI) Controller The AT89C5132 implements a TWI controller supportin g the four standard master and slave modes with multimaster capability. Thus, it allows connection of slave devices like LCD control- ler, audio DAC, etc., but also external master cont rolling where the AT89C5132 is used as a peripheral of a host. The TWI bus is a bi-directional TWI serial communic ation standard. It is designed primarily for simple but efficient integrated circuit control. Th e system is comprised of 2 lines, SCL (Serial Clock) and SDA (Serial Data) that carry information between the ICs connected to them. The serial data transfer is limited to 100 Kbit/s in lo w speed mode, however, some higher bit rates can be achieved depending on the oscillator frequen cy. Various communication configurations can be designed using this bus. Figure 20-1 shows a typical TWI bus configuration using the AT89C5132 in master and slave modes. All the devices connected to the bus can be master and slave. Figure 20-1. Typical TWI Bus Configuration
20.1 Description
The CPU interfaces to the TWI logic via the followi ng four 8-bit special function registers: the Synchronous Serial Control register (SSCON SFR, see Table 26), the Synchronous Serial Data register (SSDAT SFR, see Table 28), the Synchronous Serial Status register (SSSTA SFR, see Table 27) and the Synchronous Serial Address register (SSADR SFR, see Table 29). SSCON is used to enable the controller, to program the bit rate (see Table 26), to enable slave modes, to acknowledge or not a received data, to se nd a START or a STOP condition on the TWI bus, and to acknowledge a serial interrupt. A hardware reset disables the TWI controller. SSSTA contains a status code which reflects the sta tus of the TWI logic and the TWI bus. The three least significant bits are always zero. The f ive most significant bits contains the status code. There are 26 possible status codes. When SSST A contains F8h, no relevant state infor- mation is available and no serial interrupt is requested. A valid status code is available in SSSTA after SSI is set by hardware and is still present until SSI has been reset by software. Table 20 to Table 20-6 give the status for both master and slave modes and miscellaneous states. SSDAT contains a Byte of serial data to be transmitted or a Byte which has just been received. It is addressable while it is not in process of shifti ng a Byte. This occurs when TWI logic is in a defined state and the serial interrupt flag is set. Data in SSDAT remains stable as long as SSI is set. While data is being shifted out, data on the b us is simultaneously shifted in; SSDAT always contains the last Byte present on the bus. SSADR may be loaded with the 7 - bit slave address (7 most significant bits) to which the con- troller will respond when programmed as a slave tra nsmitter or receiver. The LSB is used to enable general call address (00h) recognition. Figure 20-2 shows how a data transfer is accomplished on the TWI bus. AT89C5132 Master/Slave LCD Display Audio DAC P1.6/SCL P1.7/SDA Rp Rp HOST Microprocessor SCL SDA
4173E–USB–09/07 AT89C5132 Figure 20-2. Complete Data Transfer on TWI Bus The four operating modes are:
- Master transmitter
- Master receiver
- Slave transmitter
- Slave receiver Data transfer in each mode of operation are shown i n Figure 20-3 through Figure 20-6. These figures contain the following abbreviations: A Acknowledge bit (low level at SDA) A Not acknowledge bit (high level on SDA) Data 8-bit data Byte S START condition P STOP condition MR Master Receive MT Master Transmit SLA Slave Address GCA General Call Address (00h) R Read bit (high level at SDA) W Write bit (low level at SDA) In Figure 20-3 through Figure 20-6, circles are use d to indicate when the serial interrupt flag is set. The numbers in the circles show the status cod e held in SSSTA. At these points, a service routine must be executed to continue or complete th e serial transfer. These service routines are not critical since the serial transfer is suspended until the serial interrupt flag is cleared by software. When the serial interrupt routine is entered, the s tatus code in SSSTA is used to branch to the appropriate service routine. For each status code, the required software action and details of the following serial transfer are given in Table 20 through Table 20-6.
20.1.1 Bit Rate
The bit rate can be selected from seven predefined bit rates or from a programmable bit rate generator using the SSCR2, SSCR1, and SSCR0 control bits in SSCON (see Table 26). The predefined bit rates are derived from the peripheral clock (F PER ) issued from the Clock Controller block as detailed in Section "Oscillator", page 12, while bit rate generator is based on timer 1 overflow output. S Slave Address SCL SDA MSB R/W direction ACK signal Nth data Byte ACK signal P/S bit from receiver from receiver 1 2 8 9 1 2 8 9 Clock Line Held Low While Serial Interrupts Are Serviced
be used with high speed TWI components limited to 400 kHz.
20.1.2 Master Transmitter Mode
SSCR2:0 define the serial bit rate (see Table 19). SSPE must be set to enable the controller. SSSTA, SSSTO and SSI must be cleared. now monitor the TWI bus and generate a START condit ion as soon as the bus becomes free. (SSI) must then be cleared before the serial transfer can continue. detailed in Table 20. This scheme is repeated until a STOP condition is transmitted. SSPE and SSCR2:0 are not affected by the serial tra nsfer and are not referred to in Table 20. mode by loading SSDAT with SLA+R.
20.1.3 Master Receiver Mode
the serial transfer can continue. Table 19. Serial Clock Rates
4173E–USB–09/07 AT89C5132 When the slave address and the direction bit have been transmitted and an acknowledgment bit has been received, the serial interrupt flag is set again and a number of status code in SSSTA are possible. There are 40h, 48h or 38h for the mas ter mode and also 68h, 78h or B0h if the slave mode was enabled (SSAA = logic 1). The approp riate action to be taken for each of these status code is detailed in Table 20-6. This scheme is repeated until a STOP condition is transmitted. SSPE and SSCR2:0 are not affected by the serial tra nsfer and are not referred to in Table 20-6. After a repeated START condition (state 10h) the controller may switch to the master transmitter mode by loading SSDAT with SLA+W.
20.1.4 Slave Receiver Mode
In the slave receiver mode, a number of data Bytes are received from a master transmitter (see Figure 20-5). To initiate the slave receiver mode, SSADR and SSCON must be loaded as follows: The upper 7 bits are the addresses to which the con troller will respond when addressed by a master. If the LSB (SSGC) is set, the controller wi ll respond to the general call address (00h); otherwise, it ignores the general call address. SSCR2:0 have no effect in the slave mode. SSPE must be set to enable the controller. The SSAA bit must be set to enable the own slave addres s or the general call address acknowledg- ment. SSSTA, SSSTO and SSI must be cleared. When SSADR and SSCON have been initialized, the con troller waits until it is addressed by its own slave address followed by the data direction bi t which must be logic 0 (W) for operating in the slave receiver mode. After its own slave address and the W bit has been received, the serial interrupt flag is set and a valid status code can be read from SSSTA. This status code is used to vector to an interrupt service routine, and the app ropriate action to be taken for each of these status code is detailed in Table 20-6 and Table 24. The slave receiver mode may also be entered if arbitration is lost while the controller is in the master mode (see states 68h and 78h). If the SSAA bit is reset during a transfer, the con troller will return a not acknowledge (logic 1) to SDA after the next received data Byte. While SSAA i s reset, the controller does not respond to its own slave address. However, the TWI bus is stil l monitored and address recognition may be resumed at any time by setting SSAA. This means that the SSAA bit may be used to temporarily isolate the controller from the TWI bus.
20.1.5 Slave Transmitter Mode
In the slave transmitter mode, a number of data Byt es are transmitted to a master receiver (see Figure 20-6). Data transfer is initialized as in th e slave receiver mode. When SSADR and SSCON have been initialized, the controller waits u ntil it is addressed by its own slave address followed by the data direction bit which must be lo gic 1 (R) for operating in the slave transmitter mode. After its own slave address and the R bit hav e been received, the serial interrupt flag is set and a valid status code can be read from SSSTA. This status code is used to vector to an interrupt service routine, and the appropriate acti on to be taken for each of these status code is detailed in Table 24. The slave transmitter mode ma y also be entered if arbitration is lost while the controller is in the master mode (see state B0h). SSA6 SSA5 SSA4 SSA3 SSA2 SSA1 SSA0 SSGC SSCR2 SSPE SSSTA SSSTO SSI SSAA SSCR1 SSCR0 X 1 0 0 0 1 X X
4173E–USB–09/07 AT89C5132 If the SSAA bit is reset during a transfer, the con troller will transmit the last Byte of the transfer and enter state C0h or C8h. The controller is switched to the not addressed slave mode and will ignore the master receiver if it continues the tran sfer. Thus the master receiver receives all 1’s as serial data. While SSAA is reset, the controller does not respond to its own slave address. However, the TWI bus is still monitored and address recognition may be resumed at any time by setting SSAA. This means that the SSAA bit may be u sed to temporarily isolate the controller from the TWI bus.
20.1.6 Miscellaneous States
There are 2 SSSTA codes that do not correspond to a defined TWI hardware state (see Table 25). These are discussed below. Status F8h indicates that no relevant information i s available because the serial interrupt flag is not yet set. This occurs between other states and w hen the controller is not involved in a serial transfer. Status 00h indicates that a bus error has occurred during a serial transfer. A bus error is caused when a START or a STOP condition occurs at an illeg al position in the format frame. Examples of such illegal positions are during the serial tra nsfer of an address Byte, a data Byte, or an acknowledge bit. When a bus error occurs, SSI is se t. To recover from a bus error, the SSSTO flag must be set and SSI must be cleared. This caus es the controller to enter the not addressed slave mode and to clear the SSSTO flag (no other bi ts in S1CON are affected). The SDA and SCL lines are released and no STOP condition is transmitted. Note: The TWI controller interfaces to the external TWI bus via 2 port 1 pins: P1.6/SCL (serial clock line) and P1.7/SDA (serial data line). To avoid low level asserting and conflict on these lines when the TWI controller is enabled, the output latches of P1.6 and P1.7 must be set to logic 1.
4173E–USB–09/07 AT89C5132 Figure 20-3. Format and States in the Master Transmitter Mode Data 20h ASLA 08h MT MR Successful transmis- sion to a slave receiver Next transfer started with a repeated start condition Not acknowledge received after the slave address Arbitration lost in slave address or data Byte Arbitration lost and addressed as slave Not acknowledge received Data AFrom master to slave From slave to master Any number of data Bytes and their associated acknowledge bits This number (contained in SSSTA) corresponds to a defined state of the TWI bus S W 18h A P 28h SLA S W R A P 10h 30h A P 38h A or A continues Other master 38h A or A continues Other master 68h A continues Other master 78h B0h nnh after a data Byte To corresponding states in slave mode
4173E–USB–09/07 AT89C5132 Figure 20-4. Format and States in the Master Receiver Mode AData 48h ASLA 08h MR MT Successful reception from a slave transmitter Next transfer started with a repeated start condition Not acknowledge received after the slave address Arbitration lost in slave address or data Byte Arbitration lost and addressed as slave Data AFrom master to slave From slave to master Any number of data Bytes and their associated acknowledge bits This number (contained in SSSTA) corresponds to a defined state of the TWI bus S R 40h A P 58h SLA S R W A P 10h 38h A continues Other master 38h A or A continues Other master 68h A continues Other master 78h B0h nnh To corresponding states in slave mode Data 50h
4173E–USB–09/07 AT89C5132 Figure 20-5. Format and States in the Slave Receiver Mode AData 68h ASLA Reception of the own slave address and one or more Last data Byte received is not acknowledged Arbitration lost as master and addressed as slave Reception of the general call address and one or more data Bytes Arbitration lost as master and addressed as slave by general call Data AFrom master to slave From slave to master Any number of data Bytes and their associated acknowledge bits This number (contained in SSSTA) corresponds to a defined state of the TWI bus S W 60h A P or S 80h A nnh Data 80h A0h 88h A P or S AData 78h AGeneral Call 70h A P or S 90h A Data 90h A0h 98h A P or S data Bytes. All are acknowledged Last data Byte received is not acknowledged
4173E–USB–09/07 AT89C5132 Figure 20-6. Format and States in the Slave Transmitter Mode AData B0h ASLA Data AFrom master to slave From slave to master Any number of data Bytes and their associated acknowledge bits This number (contained in SSSTA) corresponds to a defined state of the TWI bus S R A8h A P or S C0h All 1’s A P or S C8h nnh Data B8h AArbitration lost as master and addressed as slave Reception of the own slave address and transmission of one or more data Bytes. Last data Byte transmitted. Switched to not addressed slave (SSAA = 0).
Table 20. Status for Master Transmitter Mode been transmitted Write SLA+W X 0 0 X SLA+W will be transmitted. Data Byte will be transmitted. Repeated START will be transmitted. be transmitted and SSSTO flag will be reset. Data Byte will be transmitted. Repeated START will be transmitted. be transmitted and SSSTO flag will be reset. Data Byte will be transmitted. Repeated START will be transmitted. be transmitted and SSSTO flag will be reset. Data Byte will be transmitted. Repeated START will be transmitted. be transmitted and SSSTO flag will be reset.
Table 21. Status for Master Receiver Mode been transmitted Write SLA+R X 0 0 X SLA+R will be transmitted. Logic will switch to master transmitter mode. Data Byte will be received and ACK will be returned. Repeated START will be transmitted. be transmitted and SSSTO flag will be reset. Data Byte will be received and ACK will be returned. Repeated START will be transmitted. be transmitted and SSSTO flag will be reset.
Table 22. Status for Slave Receiver Mode with Own Slave Address Data Byte will be received and ACK will be returned. Data Byte will be received and ACK will be returned. Data Byte will be received and ACK will be returned. recognition of own SLA or GCA. will be transmitted when the bus becomes free. transmitted when the bus becomes free. recognition of own SLA or GCA. will be transmitted when the bus becomes free. transmitted when the bus becomes free.
Table 23. Status for Slave Receiver Mode with General Call Address Data Byte will be received and ACK will be returned. Data Byte will be received and ACK will be returned. Data Byte will be received and ACK will be returned. recognition of own SLA or GCA. will be transmitted when the bus becomes free. transmitted when the bus becomes free. recognition of own SLA or GCA. will be transmitted when the bus becomes free. transmitted when the bus becomes free.
Table 24. Status for Slave Transmitter Mode Last data Byte will be transmitted. Data Byte will be transmitted. Last data Byte will be transmitted. Data Byte will be transmitted. Last data Byte will be transmitted. Data Byte will be transmitted. recognition of own SLA or GCA. will be transmitted when the bus becomes free. transmitted when the bus becomes free. recognition of own SLA or GCA. will be transmitted when the bus becomes free. transmitted when the bus becomes free. Table 25. Status for Miscellaneous States No SSDAT action No SSCON action Wait or proceed curre nt transfer. released and SSSTO is reset.
20.2 Registers
Table 26. SSCON Register Table 27. SSSTA Register
7 SSCR2 Synchronous Serial Control Rate Bit 2
Refer to Table 19 for rate description.
6 SSPE
Set to enable the controller. Clear to disable the controller.
5 SSSTA
Set to send a START condition on the bus. Clear not to send a START condition on the bus.
4 SSSTO
Set to send a STOP condition on the bus. Clear not to send a STOP condition on the bus.
3 SSI
Set by hardware when a serial interrupt is requeste d. Must be cleared by software to acknowledge interrup t.
2 SSAA
Clear to disable slave modes. Clear to force a not acknowledge (high level on SDA ). Set to force an acknowledge (low level on SDA). This bit has no specific effect when in master tran smitter mode. Clear to force a not acknowledge (high level on SDA ). Set to force an acknowledge (low level on SDA). Clear to isolate slave from the bus after last data Byte transmission.
1 SSCR1 Synchronous Serial Control Rate Bit 1
Refer to Table 19 for rate description.
0 SSCR0 Synchronous Serial Control Rate Bit 0
Refer to Table 19 for rate description.
Table 28. SSDAT Register Table 29. SSADR Register Refer to Table 20 to Table 20-6 for status description.
0 SSD0 Synchronous Serial Address bit 0 (R/W) or Synchrono us Serial Data Bit 0
0 SSGC
Set to enable the general call address recognition. Clear to disable the general call address recogniti on.
4173E–USB–09/07 AT89C5132 21. Analog to Digital Converter The AT89C5132 implement a 2-channel 10-bit (8 true bits) analog to digital converter (ADC). First channel of this ADC can be used for battery m onitoring while the second one can be used for voice sampling at 8 kHz.
21.1 Description
The A/D converter interfaces with the C51 core thro ugh four special function registers: ADCON, the ADC control register (see Table 31 ); ADDH and ADDL, the ADC data registers (see Table 33 and Table 34 ); and ADCLK, the ADC clock register (see Table 32). As shown in Figure 21-1, the ADC is composed of a 1 0-bit cascaded potentiometric digital to analog converter, connected to the negative input o f a comparator. The output voltage of this DAC is compared to the analog voltage stored in the Sample and Hold and coming from AIN0 or AIN1 input depending on the channel selected (see T able 30). The 10-bit ADDAT converted value (see formula in Figure 21-1) is delivered in ADDH and ADDL registers, ADDH is giving the 8 most significant bits while ADDL is giving the 2 least significant bits. ADDAT Figure 21-1. ADC Structure Figure 21-2 shows the timing diagram of a complete conversion. For simplicity, the figure depicts the waveforms in idealized form and do not provide precise timing information. For ADC charac- teristics and timing parameters refer to the section “AC Characteristics”. AIN1 AIN0 ADCS ADCON.0 AVSS Sample and Hold ADDH AREFP R/2R DAC ADC CLOCK AREFN ADEN ADCON.5 ADSST ADCON.3 ADEOC ADCON.4 ADC Interrupt Request EADC IEN1.3 CONTROL ADDL 2SAR AD DAT
1023 V⋅ I N
21.1.1 Clock Generator
3 shows the ADC clock generator and its calculation formula (1) . reported in the Section “Analog to Digital Converter”, page 201.
- The ADCD value of 0 is equivalent to an ADCD valu e of 32.
21.1.2 Channel Selection
Table 30. ADC Channel Selection
21.1.3 Conversion Precision
0 AIN1
1 AIN0
4173E–USB–09/07 AT89C5132 version (see Section "End Of Conversion", page 149). This bit is cleared by hardware at the end of the conversion. Notes: 1. Only the CPU activity is frozen, peripheral s are not affected by the Pseudo-Idle mode. 2. If some interrupts occur during the Pseudo-Idle m ode, they will be delayed and processed, according to their priority after the end of the conversion. 3. Concurrently with ADSST bit.
21.1.4 Configuration
The ADC configuration consists in programming the ADC clock as detailed in the Section "Clock Generator", page 148. The ADC is enabled using the ADEN bit in ADCON register. As shown in Figure 93, user must wait the setup time (T SETUP ) before launching any conversion. Figure 21-4. ADC Configuration Flow
21.1.5 Conversion Launching
The conversion is launched by setting the ADSST bit in ADCON register, this bit remains set during the conversion. As soon as the conversion is started, it takes 11 clock periods (T CONV ) before the data is available in ADDH and ADDL registers. Figure 21-5. ADC Conversion Launching Flow
21.1.6 End Of Conversion
The end of conversion is signalled by the ADEOC flag in ADCON register becoming set or by the ADSST bit in ADCON register becoming cleared. ADEOC flag can generate an interrupt if ADC Configuration Enable ADC ADIDL = x ADEN = 1 Wait Setup Time Program ADC Clock ADCD4:0 = xxxxxb ADC Conversion Start Select Channel ADCS = 0-1 Start Conversion ADSST = 1
21.2 Registers
Table 31. ADCON Register Table 32. ADCLK Register The value read from this bit is always 0. Do not se t this bit.
6 ADIDL
Set to suspend the CPU core activity (pseudo-idle m ode) during conversion. Clear by hardware at the end of conversion.
5 ADEN
Set to enable the A to D converter. Clear to disable the A to D converter and put it in low power stand by mode.
4 ADEOC
Must be cleared by software.
3 ADSST
Set to start an A to D conversion on the selected c hannel. Cleared by hardware at the end of conversion. The value read from these bits is always 0. Do not set these bits.
0 ADCS
Set to select channel 0 for conversion. Clear to select channel 1 for conversion. The value read from these bits is always 0. Do not set these bits. 5-bit divider for ADC clock generation.
Table 33. ADDH Register Table 34. ADDL Register 8 Most Significant Bits of the 10-bit ADC data. The value read from these bits is always 0. Do not set these bits. 2 Least Significant Bits of the 10-bit ADC data.
board. It is based on 4 inputs with programmable in terrupt capability on both high or low level.
22.1 Description
capability to detect a programmable level according to KINL3:0 bit value in KBCON register. Level detection is then reported in interrupt flags KINF3:0 in KBSTA register. KBSTA which automatically clears KINF3:0 flags. inputs for any other purposes.
22.1.1 Power Reduction Mode
agement”, page 44. To enable this feature, KPDE bit in KBSTA register must be set to logic 1.
22.2 Registers
Table 101. KBCON Register
Table 102. KBSTA Register Set to enable a high level detection on the respect ive KIN3:0 input. Clear to enable a low level detection on the respec tive KIN3:0 input. Set to prevent the respective KINF3:0 flag from gen erating a keyboard interrupt. Clear to allow the respective KINF3:0 flag to gener ate a keyboard interrupt.
7 KPDE
Set to enable exit of power down mode by the keyboa rd interrupt. Clear to disable exit of power down mode by the key board interrupt. The values read from these Bits are always 0. Do no t set these Bits. Set by hardware when the respective KIN3:0 input de tects a programmed level.
- Electrical Characteristics
23.1 Absolute Maximum Ratings
23.2 DC Characteristics
23.2.1 Digital Logic
mum Ratings” may cause permanent damage. Conditions” may affect device reliability. Table 103. Digital DC Characteristics
0.45 V I
- Flash retention is guaranteed with the same formu la for V DD min down to 0V.
- See Table 154 for typical consumption in player m ode.
23.2.2 I DD, IDL and I PD Test Conditions
12 MHz
16 MHz
20 MHz
23.2.3 A-to-D Converter
Table 104. A-to-D Converter DC Characteristics
2.4 A VDD
23.2.4 Oscillator and Crystal
23.2.4.1 Schematic
pF). X1 and X2 may not be used to drive other circuits.
23.2.4.2 Parameters
Table 105. Oscillator and Crystal Characteristics
23.2.5 Phase Lock Loop
23.2.5.1 Schematic
23.2.5.2 Parameters
Table 106. PLL Filter Characteristics
23.2.6 USB Connection
23.2.6.1 Schematic
23.2.6.2 Parameters
Table 35. USB Characteristics
23.2.7 In-system Programming
23.2.7.1 Schematic
23.2.7.2 Parameters
Table 107. ISP Pull-Down Characteristics
23.3 AC Characteristics
23.3.1 External 8-bit Bus Cycles
23.3.1.1 Definition of Symbols
Table 108. External 8-bit Bus Cycles Timing Symbol Definitions
23.3.1.2 Timings
Test conditions: capacitive load on all pins = 50 pF. Table 109. External 8-bit Bus Cycle – Data Read AC Timings
Table 110. External 8-bit Bus Cycle – Data Write AC Timings
23.3.1.3 Waveforms
23.3.2 External IDE 16-bit Bus Cycles
23.3.2.1 Definition of Symbols
Table 111. External IDE 16-bit Bus Cycles Timing Symbol Definitions
23.3.2.2 Timings
Test conditions: capacitive load on all pins = 50 pF.
Table 112. External IDE 16-bit Bus Cycle – Data Read AC Timing s Table 113. External IDE 16-bit Bus Cycle – Data Write AC Timin gs
23.3.2.3 Waveforms
Note: D15:8 is written in DAT16H SFR. Note: D15:8 is the content of DAT16H SFR.
23.3.3 SPI Interface
23.3.3.1 Definition of Symbols
Table 114. SPI Interface Timing Symbol Definitions
23.3.3.2 Timings
Table 115. SPI Interface Master AC Timing Notes: 1. Value of this parameter depends on software .
- Test conditions: capacitive load on all pins = 10 0 pF
4173E–USB–09/07 AT89C5132
23.3.3.3 Waveforms
Figure 23-12. SPI Slave Waveforms (SSCPHA = 0) Note: 1. Not Defined but generally the MSB of the cha racter which has just been received. Figure 23-13. SPI Slave Waveforms (SSCPHA = 1) Note: 1. Not Defined but generally the LSB of the cha racter which has just been received. TSLCL TSLCH TCHCL TCLCH MOSI (input) SCK (SSCPOL = 0) (input) SS (input) SCK (SSCPOL = 1) (input) MISO (output) TCHCH TCLCX TCHCX TIVCL TCLIX TCHIX TIVCH TCHOV TCLOV TCHOX TCLOX MSB IN BIT 6 LSB IN SLAVE MSB OUT SLAVE LSB OUT BIT 6 TSLOV TSHOX TSHSL TCHSH TCLSH SI (input) SCK (SSCPOL = 0) (output) SS 1 (output) SCK (SSCPOL = 1) (output) SO (output) TCHCH TCLCX TCHCX TIVCL TCLIX TCHIX TIVCH TCHOV TCLOV TCHOX TCLOX MSB IN BIT 6 LSB IN MSB OUT Port Data LSB OUT Port Data BIT 6 TCHCL TCLCH
Note: 1. SS handled by software using general purpose port pin. Note: 1. SS handled by software using general purpose port pin.
23.3.4 Two-wire Interface
23.3.4.1 Timings
Table 36. TWI Interface AC Timing
4173E–USB–09/07 AT89C5132 VDD = 2.7 to 3.3 V, T A = -40 to +85 °C Notes: 1. At 100 kbit/s. At other bit-rates this valu e is inversely proportional to the bit-rate of 100 kbit/s. 2. Determined by the external bus-line capacitance a nd the external bus-line pull-up resistor, this must be < 1 µ s. 3. Spikes on the SDA and SCL lines with a duration o f less than 3·TCLCL will be filtered out. Maxi- mum capacitance on bus-lines SDA and SCL= 400 pF. 4. T CLCL= TOSC = one oscillator clock period.
23.3.4.2 Waveforms
Figure 23-16. Two Wire Waveforms Symbol Parameter INPUT Min Max OUTPUT Min Max THD; STA Start condition hold time 14·TCLCL(4) 4.0 µ s(1) TLOW SCL low time 16·TCLCL(4) 4.7 µ s(1) THIGH SCL high time 14·TCLCL(4) 4.0 µ s(1) TRC SCL rise time 1 µ s - (2) TFC SCL fall time 0.3 µ s 0.3 µ s(3) TSU; DAT1 Data set-up time 250 ns 20·T CLCL(4) - TRD TSU; DAT2 SDA set-up time (before repeated START condit ion) 250 ns 1 µ s(1) TSU; DAT3 SDA set-up time (before STOP condition) 250 ns 8·TCLCL(4) THD; DAT Data hold time 0 ns 8·T CLCL(4) - TFC TSU; STA Repeated START set-up time 14·T CLCL(4) 4.7 µ s(1) TSU; STO STOP condition set-up time 14·TCLCL(4) 4.0 µ s(1) TBUF Bus free time 14·TCLCL(4) 4.7 µ s(1) TRD SDA rise time 1 µ s - (2) TFD SDA fall time 0.3 µ s 0.3 µ s(3) Tsu;DAT1 Tsu ;STA Tsu;DAT 2Thd ;STA Thigh Tlow SDA (INPUT/OUTPUT) 0.3 VDD
0.7 VDD
Tbuf Tsu ;STO
0.3 VDD
(INPUT/OUTPUT) Thd; DAT Tsu; DAT3 START or Repeated START condition START condition STOP condition Repeated START condition
23.3.5 MMC Interface
23.3.5.1 Definition of Symbols
Table 116. MMC Interface Timing Symbol Definitions
23.3.5.2 Timings
Table 117. MMC Interface AC Timings
23.3.5.3 Waveforms
23.3.6 Audio Interface
23.3.6.1 Definition of Symbols
Table 118. Audio Interface Timing Symbol Definitions
23.3.6.2 Timings
Table 119. Audio Interface AC timings Note: 32-bit format with Fs = 48 kHz.
23.3.6.3 Waveforms
23.3.7 Analog to Digital Converter
23.3.7.1 Definition of Symbols
Table 120. Analog to Digital Converter Timing Symbol Definitions
23.3.7.2 Characteristics
Table 37. Analog to Digital Converter AC Characteristics Notes: 1. AV DD = AV REFP = 3.0 V, AV SS = AV REFN = 0 V. ADC is monotonic with no missing code.
- The differential non-linearity is the difference between the actual step width and the ideal step
- The integral non-linearity is the peak difference between the center of the actual step and the
ideal transfer curve after appropriate adjustment of gain and offset errors (see Figure 23-20).
- The offset error is the absolute difference betwe en the straight line which fits the actual trans-
- The gain error is the relative difference in perc ent between the straight line which fits the actual
4173E–USB–09/07 AT89C5132
23.3.7.3 Waveforms
Figure 23-19. Analog-to-Digital Converter Internal Waveforms Figure 23-20. Analog-to-Digital Converter Characteristics ADEN Bit ADSST Bit TEHSH TSHSL CLK TCLCL 1 2 3 4 5 6 7 1018 1019 1020 1021 1022 1023 1024 1018 1019 1020 1021 1022 1023 Offset Error Code Out AVIN (LSBideal) OSe Offset Error OSe Gain Error Ge Ideal Transfer Curve
1 LSB
(Ideal) Integral Non-linearity (ILe) Differential Non-linearity (DLe) Center of a Step Example of an Actual Transfer Curve
23.3.8 Flash Memory
23.3.8.1 Definition of Symbols
Table 121. Flash Memory Timing Symbol Definitions
23.3.8.2 Timings
Table 122. Flash Memory AC Timing
23.3.8.3 Waveforms
23.3.9 External Clock Drive and Logic Level Referenc es
23.3.9.1 Definition of Symbols
Table 123. External Clock Timing Symbol Definitions
23.3.9.2 Timings
Table 124. External Clock AC Timings
23.3.9.3 Waveforms
Notes: 1. During AC testing, all inputs are driven at VDD -0.5V for a logic 1 and 0.45V for a logic 0.
- Timing measurements are made on all outputs at V IH min for a logic 1 and V IL max for a logic 0.
100 mV change from the loading V OH /V OL level occurs with I OL /I OH = ±20 mA.
4173E–USB–09/07 AT89C5132 24. Ordering Information Note: 1. PLCC84 package only available for developmen t board. Possible Order Entries (1) Part Number Memory Size (Bytes) Supply Voltage Temperature Range Max Frequency (MHz) Package Packing Product Marking AT89C5132-ROTIL 64K Flash 3V Industrial 40 TQFP80 Tray 89 5132-IL AT89C5132-ROTUL 64K Flash 3V Industrial & Green 40 TQFP80 Tray 895132-UL
4173E–USB–09/07 AT89C5132 25. Package Information
25.1 TQFP80
4173E–USB–09/07 AT89C5132
25.2 PLCC84
4173E–USB–09/07 AT89C5132 26. Datasheet Revision History for AT89C5132
26.1 Changes from 4173A-08/02 to 4173B-03/04
- Suppression of ROM product version. 2. Suppression of TQFP64 package.
26.2 Changes from 4173B-03/04 - 4173C - 07/04
- Add USB connection schematic in USB section. 2. Add USB termination characteristics in DC Charact eristics section. 3. Page access mode clarification in Data Memory sec tion.
26.3 Changes from 4173C-07/04 - 4173D - 01/05
- Interrupt priority number clarification to match number defined by development tools.
26.4 Changes from to 4317D - 01/05 to 4173E - 09/07
- Added green product ordering information. 2. Removed ‘Preliminary’ status. Product now fully Industrialised.
i 4173E–USB–09/07 AT89C5132
4173E–USB–09/07 AT89C5132
4173E–USB–09/07 AT89C5132 (Modes 2 and 3) 114
4173E–USB–09/07 AT89C5132
Printed on recycled paper. 4173E–USB–09/07 © Atmel Corporation 2007 . All rights reserved. Atmel ®, logo and combinations thereof, are registered tra demarks, and Everywhere You Are ® are the trademarks of Atmel Corporation or its subs idiaries. Other terms and product names may be trad emarks of others. Disclaimer: The information in this document is provided in co nnection with Atmel products. No license, express o r implied, by estoppel or otherwise, to any intellectual property right is granted by this docu ment or in connection with the sale of Atmel produc ts. EXCEPT AS SET FORTH IN ATMEL’S TERMS AND CONDI- TIONS OF SALE LOCATED ON ATMEL’S WEB SITE, ATMEL AS SUMES NO LIABILITY WHATSOEVER AND DISCLAIMS ANY EXP RESS, IMPLIED OR STATUTORY WARRANTY RELATING TO ITS PRODUCTS INCLUDING, BUT NO T LIMITED TO, THE IMPLIED WARRANTY OF MERCHANTABILI TY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL ATM EL BE LIABLE FOR ANY DIRECT, INDIRECT, CONSEQUENTIA L, PUNITIVE, SPECIAL OR INCIDEN- TAL DAMAGES (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF PROFITS, BUSINESS INTERRUPTION, OR LOS S OF INFORMATION) ARISING OUT OF THE USE OR INABILITY TO USE THIS DOCUMENT, EVEN IF ATMEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUC H DAMAGES. Atmel makes no representations or warranties with respect to the a ccuracy or completeness of the contents of this doc ument and reserves the right to make changes to spe cifications and product descriptions at any time without notice . Atmel does not make any commitment to update the information contained herein. Unless specifically p rovidedot- herwise, Atmel products are not suitable for, and s hall not be used in, automotive applications. Atmel ’sAtmel’s products are not intended, authorized, or warranted for use as components in applications intended to support or sustain life. Atmel Corporation Atmel Operations
2325 Orchard Parkway
San Jose, CA 95131, USA Tel: 1(408) 441-0311 Fax: 1(408) 487-2600 Regional Headquarters Europe Atmel Sarl Route des Arsenaux 41 Case Postale 80 CH-1705 Fribourg Switzerland Tel: (41) 26-426-5555 Fax: (41) 26-426-5500 Asia Room 1219 Chinachem Golden Plaza
77 Mody Road Tsimshatsui
Tel: (852) 2721-9778 Fax: (852) 2722-1369 Japan 9F, Tonetsu Shinkawa Bldg. 1-24-8 Shinkawa Chuo-ku, Tokyo 104-0033 Japan Tel: (81) 3-3523-3551 Fax: (81) 3-3523-7581 Memory San Jose, CA 95131, USA Tel: 1(408) 441-0311 Fax: 1(408) 436-4314 Microcontrollers San Jose, CA 95131, USA Tel: 1(408) 441-0311 Fax: 1(408) 436-4314 La Chantrerie BP 70602
44306 Nantes Cedex 3, France
13106 Rousset Cedex, France
1150 East Cheyenne Mtn. Blvd. Colorado Springs, CO 80906, USA Tel: 1(719) 576-3300 Fax: 1(719) 540-1759 Scottish Enterprise Technology Park Maxwell Building East Kilbride G75 0QR, Scotland Tel: (44) 1355-803-000 Fax: (44) 1355-242-743 RF/Automotive Theresienstrasse 2 Postfach 3535
74025 Heilbronn, Germany
1150 East Cheyenne Mtn. Blvd. Colorado Springs, CO 80906, USA Tel: 1(719) 576-3300 Fax: 1(719) 540-1759 Biometrics/Imaging/Hi-Rel MPU/ High Speed Converters/RF Datacom Avenue de Rochepleine BP 123
38521 Saint-Egreve Cedex, France
www.atmel.com/literature