0
登录后你可以
  • 下载海量资料
  • 学习在线课程
  • 观看技术视频
  • 写文章/发帖/加入社区
会员中心
创作中心
发布
  • 发文章

  • 发资料

  • 发帖

  • 提问

  • 发视频

创作活动
AT83SND2CXXX-7FTUL

AT83SND2CXXX-7FTUL

  • 厂商:

    ATMEL(爱特梅尔)

  • 封装:

  • 描述:

    AT83SND2CXXX-7FTUL - Single-Chip Flash Microcontroller with MP3 Decoder with Full Audio Interface - ...

  • 数据手册
  • 价格&库存
AT83SND2CXXX-7FTUL 数据手册
Features • MPEG I/II-Layer 3 Hardwired Decoder – Stand-alone MP3 Decoder – 48, 44.1, 32, 24, 22.05, 16 kHz Sampling Frequency – Separated Digital Volume Control on Left and Right Channels (Software Control using 31 Steps) – Bass, Medium, and Treble Control (31 Steps) – Bass Boost Sound Effect – Ancillary Data Extraction – CRC Error and MPEG Frame Synchronization Indicators 20-bit Stereo Audio DAC – 93 dB SNR playback stereo channel – 32 Ohm/ 20 mW stereo headset drivers – Stereo Line Level Input, Differential Mono Auxiliary Input Programmable Audio Output for Interfacing with External Audio System – PCM Format Compatible – I2S Format Compatible Mono Audio Power Amplifier – 440mW on 8 Ohms Load 8-bit MCU C51 Core Based (FMAX = 20 MHz) 2304 Bytes of Internal RAM 64K Bytes of Code Memory – AT89C51SND2C: Flash (100K Erase/Write Cycles) – AT83SND2C: ROM 4K Bytes of Boot Flash Memory (AT89C51SND2C) – ISP: Download from USB (standard) or UART (option) USB Rev 1.1 Controller – Full Speed Data Transmission Built-in PLL – MP3 Audio Clocks – USB Clock MultiMedia Card® Interface Compatibility Atmel DataFlash® SPI Interface Compatibility IDE/ATAPI Interface Up to 32 Bits of General-purpose I/Os – 1 Interrupt Keyboard – SmartMedia® Software Interface 2 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 – Power amplifier supply 3.2V to 5.5V Packages – CTBGA100 • • • • • • • • • • • • • • • • • • • Single-Chip Flash Microcontroller with MP3 Decoder with Full Audio Interface AT83SND2C AT89C51SND2C Preliminary • • Rev. 4341D–MP3–04/05 Description The AT8xC51SND2C has been developed for handling MP3 ringing tones in mobile phones and can replace sound generators while adding SD/MMC card reader, MP3 music decoding, and connection of the cell phone to a PC through USB. Cell phones can also be used as a thumb drive extending cell phone capabilities. The AT8xC51SND2C are fully integrated stand-alone hardwired MPEG I/II-Layer 3 decoder with a C51 microcontroller core handling data flow, MP3-player control, Stereo Audio DAC and Mono Audio Power Amplifier for speaker control. The AT89C51SND2C includes 64K Bytes of Flash memory and allows In-System Programming through an embedded 4K Bytes of Boot Flash memory. The AT83SND2C includes 64K Bytes of ROM memory. The AT8xC51SND2C include 2304 Bytes of RAM memory. The AT8xC51SND2C provides the necessary features for human interface like timers, keyboard port, serial or parallel interface (USB, TWI, SPI, IDE), I2S output, and all external memory interface (NAND or NOR Flash, SmartMedia, MultiMedia, DataFlash cards). Typical Applications • • • • MP3-Player PDA, Camera, Mobile Phone MP3 Car Audio/Multimedia MP3 Home Audio/Multimedia MP3 2 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Block Diagram Figure 1. AT8xC51SND2C Block Diagram ISP ALE VDD VSS UVDD UVSS FILT X1 X2 RST Clock and PLL Unit C51 (X2 Core) Interrupt Handler Unit 3 3 INT0 INT1 D+ D- USB Controller I/OPorts IDE Interface MP3 Decoder Unit 8-Bit Internal Bus RAM 2304Bytes P0-P4 Flash ROM 64 KBytes Flash Boot 4 KBytes Keyboard Interface 3 3 KIN0 DOUT DCLK DSEL SCLK I2S/PCM Audio Interface UART and BRG Timers 0/1 Watchdog TXD RXD 3 3 4 4 4 4 T0 T1 HSR HSL AUXP AUXN LINEL LINER MONOP MONON Audio DAC SPI/DataFlash Controller SS MISO MOSI SCK SCL SDA TWI Controller MCLK PAINP PAINN HPP HPN Audio PA MMC Interface MDAT MCMD 3 Alternate function of Port 3 4 Alternate function of Port 4 3 4341D–MP3–04/05 Pin Description Pinouts Figure 2. AT8xC51SND2C 100-pin BGA Package 10 NC 9 NC 8 P2.0/ A8 7 P4.1/ MOSI 6 VDD 5 VSS 4 NC 3 AUXP 2 AUXN 1 ALE A B C D E F G H J K VDD P2.2/ A10 P2.1/ A9 P4.0/ MISO P4.2/ SCK MONON MONOP P0.0/ AD0 KIN0 ISP/ NC P2.4/ A12 P2.3/ A11 P2.5/ A13 P4.3/ SS P0.6/ AD6 P0.4/ AD4 P0.3/ AD3 P0.2/ AD2 P0.1/ AD1 NC P2.6/ A14 P2.7/ A15 MCLK NC P0.7/ AD7 P0.5/ AD5 NC NC NC NC EA VSS VDD ESDVSS VDD SDA AUDVREF SCL HSL AUDVDD MCMD MDAT NC P3.2/ INT0 P3.1/ TXD VSS FILT PVDD HSR HSVDD RST AUDRST SCLK DSEL P3.4/ T0 P3.0/ RXD LINER LINEL PVSS HSVSS NC VSS DOUT DCLK P3.5/ T1 TST X1 X2 INGND AUDVSS VDD AUDVSS CBP LPHN P3.7/ RD P3.6/ WR VSS D- D+ AUDVCM PAINP PAINN HPP AUDVBAT HPN AUDVSS P3.3/ INT1 VDD UVDD UVSS Notes: 1. ISP pin is only available in AT89C51SND2C product. Do not connect this pin on AT83SND2C product. 2. NC is Do Not Connect 4 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Signals All the AT8xC51SND2C signals are detailed by functionality in Table 1 to Table 14. Table 1. Ports Signal Description Signal Name Type Description Port 0 P0 is an 8-bit open-drain bidirectional I/O port. Port 0 pins that have 1s written to them float and can be used as high impedance inputs. To avoid any parasitic current consumption, floating P0 inputs must be polarized to VDD or VSS. Port 2 P2 is an 8-bit bidirectional I/O port with internal pull-ups. Alternate Function P0.7:0 I/O AD7:0 P2.7:0 I/O A15:8 RXD TXD P3.7:0 I/O Port 3 P3 is an 8-bit bidirectional I/O port with internal pull-ups. INT0 INT1 T0 T1 WR RD MISO MOSI SCK SS P4.3:0 I/O Port 4 P4 is an 8-bit bidirectional I/O port with internal pull-ups. Table 2. Clock Signal Description Signal Name Type Description Input to the on-chip inverting oscillator amplifier To use the internal oscillator, a crystal/resonator circuit is connected to this pin. If an external oscillator is used, its output is connected to this pin. X1 is the clock source for internal timing. Output of the on-chip inverting oscillator amplifier To use the internal oscillator, a crystal/resonator circuit is connected to this pin. If an external oscillator is used, leave X2 unconnected. PLL Low Pass Filter input FILT receives the RC network of the PLL low pass filter. Alternate Function X1 I - X2 O - FILT I - Table 3. Timer 0 and Timer 1 Signal Description Signal Name Type Description Timer 0 Gate Input INT0 serves as external run control for timer 0, when selected by GATE0 bit in TCON register. INT0 I External Interrupt 0 INT0 input sets IE0 in the TCON register. If bit IT0 in this register is set, bit IE0 is set by a falling edge on INT0#. If bit IT0 is cleared, bit IE0 is set by a low level on INT0#. P3.2 Alternate Function 5 4341D–MP3–04/05 Signal Name Type Description Timer 1 Gate Input INT1 serves as external run control for timer 1, when selected by GATE1 bit in TCON register. Alternate Function INT1 I External Interrupt 1 INT1 input sets IE1 in the TCON register. If bit IT1 in this register is set, bit IE1 is set by a falling edge on INT1#. If bit IT1 is cleared, bit IE1 is set by a low level on INT1#. Timer 0 External Clock Input When timer 0 operates as a counter, a falling edge on the T0 pin increments the count. Timer 1 External Clock Input When timer 1 operates as a counter, a falling edge on the T1 pin increments the count. P3.3 T0 I P3.4 T1 I P3.5 Table 4. Audio Interface Signal Description Signal Name DCLK DOUT DSEL Type O O O Description DAC Data Bit Clock DAC Audio Data Output DAC Channel Select Signal DSEL is the sample rate clock output. DAC System Clock SCLK is the oversampling clock synchronized to the digital audio data (DOUT) and the channel selection signal (DSEL). Alternate Function - SCLK O - Table 5. USB Controller Signal Description Signal Name D+ DType I/O I/O Description USB Positive Data Upstream Port This pin requires an external 1.5 KΩ pull-up to VDD for full speed operation. USB Negative Data Upstream Port Alternate Function - Table 6. MutiMediaCard Interface Signal Description Signal Name MCLK Type O Description MMC Clock output Data or command clock transfer. MMC Command line Bidirectional command channel used for card initialization and data transfer commands. To avoid any parasitic current consumption, unused MCMD input must be polarized to VDD or VSS. MMC Data line Bidirectional data channel. To avoid any parasitic current consumption, unused MDAT input must be polarized to VDD or VSS. Alternate Function - MCMD I/O - MDAT I/O - 6 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Table 7. UART Signal Description Signal Name RXD Type I/O Description Receive Serial Data RXD sends and receives data in serial I/O mode 0 and receives data in serial I/O modes 1, 2 and 3. Transmit Serial Data TXD outputs the shift clock in serial I/O mode 0 and transmits data in serial I/O modes 1, 2 and 3. Alternate Function P3.0 TXD O P3.1 Table 8. SPI Controller Signal Description Signal Name MISO Type I/O Description SPI Master Input Slave Output Data Line When in master mode, MISO receives data from the slave peripheral. When in slave mode, MISO outputs data to the master controller. SPI Master Output Slave Input Data Line When in master mode, MOSI outputs data to the slave peripheral. When in slave mode, MOSI receives data from the master controller. SPI Clock Line When in master mode, SCK outputs clock to the slave peripheral. When in slave mode, SCK receives clock from the master controller. SPI Slave Select Line When in controlled slave mode, SS enables the slave mode. Alternate Function P4.0 MOSI I/O P4.1 SCK I/O P4.2 SS I P4.3 Table 9. TWI Controller Signal Description Signal Name Type Description TWI Serial Clock When TWI controller is in master mode, SCL outputs the serial clock to the slave peripherals. When TWI controller is in slave mode, SCL receives clock from the master controller. TWI Serial Data SDA is the bidirectional Two Wire data line. Alternate Function SCL I/O - SDA I/O - Table 10. Keypad Interface Signal Description Signal Name KIN0 Type I Description Keypad Input Line Holding this pin high or low for 24 oscillator periods triggers a keypad interrupt. Alternate Function - 7 4341D–MP3–04/05 Table 11. External Access Signal Description Signal Name A15:8 Type I/O Description Address Lines Upper address lines for the external bus. Multiplexed higher address and data lines for the IDE interface. Address/Data Lines Multiplexed lower address and data lines for the external memory or the IDE interface. Address Latch Enable Output ALE signals the start of an external bus cycle and indicates that valid address information is available on lines A7:0. An external latch is used to demultiplex the address from address/data bus. ISP Enable Input (AT89C51SND2C Only) This signal must be held to GND through a pull-down resistor at the falling reset to force execution of the internal bootloader. Read Signal Read signal asserted during external data memory read operation. Write Signal Write signal asserted during external data memory write operation. External Access Enable: EA must be externally held low to enable the device to fetch code from external program memory locations 0000H to FFFFH (RD). Alternate Function P2.7:0 AD7:0 I/O P0.7:0 ALE O - ISP I/O - RD WR O O P3.7 P3.6 EA(1) I - Note: 1. For ROM/Flash/ROMless Dice product versions only. Table 12. System Signal Description Signal Name Type Description Reset Input Holding this pin high for 64 oscillator periods while the oscillator is running resets the device. The Port pins are driven to their reset conditions when a voltage lower than VIL is applied, whether or not the oscillator is running. This pin has an internal pull-down resistor which allows the device to be reset by connecting a capacitor between this pin and VDD. Asserting RST when the chip is in Idle mode or Power-Down mode returns the chip to normal operation. Test Input Test mode entry signal. This pin must be set to VDD. Alternate Function RST I - TST I - Table 13. Power Signal Description Signal Name VDD VSS Type PWR GND Description Digital Supply Voltage Connect these pins to +3V supply voltage. Circuit Ground Connect these pins to ground. Alternate Function - 8 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Signal Name PVDD PVSS UVDD UVSS Type PWR GND PWR GND Description PLL Supply voltage Connect this pin to +3V supply voltage. PLL Circuit Ground Connect this pin to ground. USB Supply Voltage Connect this pin to +3V supply voltage. USB Ground Connect this pin to ground. Alternate Function - Table 14. Audio Power Signal Description Signal Name AUDVDD AUDVSS Type PWR GND Description Audio Digital Supply Voltage Audio Circuit Ground Connect these pins to ground. Audio Analog Circuit Ground for Electrostatic Discharge. Connect this pin to ground. Audio Voltage Reference pin for decoupling. Headset Driver Power Supply. Headset Driver Ground. Connect this pin to ground. Audio Amplifier Supply. Alternate Function - ESDVSS AUDVREF HSVDD HSVSS AUDVBAT GND PWR PWR GND PWR - Table 15. Stereo Audio Dac and Mono Power Amplifier Signal Description Signal Name LPHN HPN HPP CBP PAINN PAINP AUDRST MONON MONOP AUXP AUXN HSL Type O O O O I I I O O I I O Description Low Power Audio Stage Output Negative Speaker Output Positivie Speaker Output Audio Amplifier Common Mode Voltage Decoupling Audio Amplifier Negative Input Audio Amplifier Positive Input Audio Reset (Active Low) Audio Negative Monaural Driver Output Audio Positive Monaural Driver Output Audio Mono Auxiliary Positive Input Audio Mono Auxiliary Negative Input Audio Left Channel Headset Driver Output Alternate Function - 9 4341D–MP3–04/05 Signal Name HSR LINEL LINER INGND AUDVCM Type O I I I I Description Audio Right Channel Headset Driver Output Audio Left Channel Line In Audio Right Channel Line In Audio Line Signal Ground Pin for decoupling. Audio Common Mode reference for decoupling Alternate Function - 10 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Internal Pin Structure Table 16. Detailed Internal Pin Structure Circuit(1) VDD Type Pins RTST Input TST VDD Watchdog Output P Input/Output RRST RST VSS 2 osc periods Latch Output VDD VDD VDD P1 P2 P3 Input/Output P3 P4 N VSS VDD P Input/Output N VSS VDD P0 MCMD MDAT ISP PSEN P Output N VSS ALE SCLK DCLK DOUT DSEL MCLK D+ D- Input/Output D+ D- Notes: 1. For information on resistors value, input/output levels, and drive capability, refer to the Section “DC Characteristics”, page 201. 2. When the Two Wire controller is enabled, P3 transistors are disabled allowing pseudo open-drain structure. 11 4341D–MP3–04/05 Clock Controller The AT8xC51SND2C clock controller is based on an on-chip oscillator feeding an onchip Phase Lock Loop (PLL). All internal clocks to the peripherals and CPU core are generated by this controller. The AT8xC51SND2C X1 and X2 pins are the input and the output of a single-stage onchip inverter (see Figure 3) that can be configured with off-chip components such as a Pierce oscillator (see Figure 4). Value of capacitors and crystal characteristics 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 3. These clocks are either enabled or disabled, depending on the power reduction mode as detailed in the section “Power Management” on page 46. The peripheral clock is used to generate the Timer 0, Timer 1, MMC, SPI, and Port sampling clocks. Figure 3. Oscillator Block Diagram and Symbol X1 X2 X2 CKCON.0 Oscillator ÷2 0 1 Peripheral Clock CPU Core Clock IDL PCON.0 PD PCON.1 Oscillator Clock OSC CLOCK PER CLOCK CPU CLOCK Peripheral Clock Symbol CPU Core Clock Symbol Oscillator Clock Symbol Figure 4. Crystal Connection X1 C1 Q C2 VSS X2 X2 Feature Unlike standard C51 products that require 12 oscillator clock periods per machine cycle, the AT8xC51SND2C need 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 17) and allows the AT8xC51SND2C to operate in 6 or 12 oscillator clock periods per machine cycle. As shown in Figure 3, both CPU and peripheral clocks are affected by this feature. Figure 5 shows the X2 mode switching waveforms. After reset the standard mode is activated. In standard mode the CPU and peripheral clock frequency is the oscillator frequency divided by 2 while in X2 mode, it is the oscillator frequency. Note: 1. The X2 bit reset value depends on the X2B bit in the Hardware Security Byte (see Table 23 on page 22). Using the AT89C51SND2C (Flash Version) the system can boot either in standard or X2 mode depending on the X2B value. Using AT83SND2C (ROM Version) the system always boots in standard mode. X2B bit can be changed to X2 mode later by software. 12 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Figure 5. Mode Switching Waveforms X1 X1 ÷ 2 X2 Bit Clock STD Mode X2 Mode(1) STD Mode Note: 1. In order to prevent any incorrect operation while operating in X2 mode, user must be aware that all peripherals using clock frequency as time reference (timers, etc.) will have their time reference divided by 2. For example, a free running timer generating an interrupt every 20 ms will then generate an interrupt every 10 ms. PLL PLL Description The AT8xC51SND2C PLL is used to generate internal high frequency clock (the PLL Clock) synchronized with an external low-frequency (the Oscillator Clock). The PLL clock provides the MP3 decoder, the audio interface, and the USB interface clocks. Figure 6 shows the internal structure of the PLL. The PFLD block is the Phase Frequency Comparator and Lock Detector. This block makes the comparison between the reference clock coming from the N divider and the reverse clock coming 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 in PLLCON register is used to enable the clock generation. When the PLL is locked, the bit PLOCK in PLLCON register (see Table 18) is set. The CHP block is the Charge Pump that generates the voltage reference for the VCO by injecting or extracting charges from the external filter connected on PFILT pin (see Figure 7). Value of the filter components are detailed in the Section “DC Characteristics”. The VCO block is the Voltage Controlled Oscillator controlled by the voltage Vref produced by the charge pump. It generates a square wave signal: the PLL clock. Figure 6. PLL Block Diagram and Symbol PLLCON.1 PFILT Up PLLEN OSC CLOCK N divider N6:0 PFLD CHP Down Vref VCO PLL Clock PLOCK PLLCON.0 R divider R9:0 PLL CLOCK OSCclk × ( R + 1 ) PLLclk = ---------------------------------------------N+1 PLL Clock Symbol 13 4341D–MP3–04/05 Figure 7. PLL Filter Connection FILT R C1 VSS VSS C2 PLL Programming The PLL is programmed using the flow shown in Figure 8. As soon as clock generation is enabled, the user must wait until the lock indicator is set to ensure the clock output is stable. The PLL clock frequency will depend on MP3 decoder clock and audio interface clock frequencies. Figure 8. PLL Programming Flow PLL Programming Configure Dividers N6:0 = xxxxxxb R9:0 = xxxxxxxxxxb Enable PLL PLLRES = 0 PLLEN = 1 PLOCK = 1? PLL Locked? 14 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Registers Table 17. CKCON Register CKCON (S:8Fh) – Clock Control Register 7 TWIX2 Bit Number 6 WDX2 5 4 SIX2 3 2 T1X2 1 T0X2 0 X2 Bit Mnemonic Description Two-Wire Clock Control Bit Set to select the oscillator clock divided by 2 as TWI clock input (X2 independent). Clear to select the peripheral clock as TWI clock input (X2 dependent). Watchdog Clock Control Bit Set to select the oscillator clock divided by 2 as watchdog clock input (X2 independent). Clear to select the peripheral clock as watchdog clock input (X2 dependent). Reserved The values read from this bit is indeterminate. Do not set this bit. Enhanced UART Clock (Mode 0 and 2) Control Bit 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).. Reserved The values read from this bit is indeterminate. Do not set this bit. Timer 1 Clock Control Bit Set to select the oscillator clock divided by 2 as timer 1 clock input (X2 independent). Clear to select the peripheral clock as timer 1 clock input (X2 dependent). Timer 0 Clock Control Bit Set to select the oscillator clock divided by 2 as timer 0 clock input (X2 independent). Clear to select the peripheral clock as timer 0 clock input (X2 dependent). System Clock Control Bit Clear to select 12 clock periods per machine cycle (STD mode, FCPU = FPER = FOSC/2). Set to select 6 clock periods per machine cycle (X2 mode, FCPU = FPER = FOSC). 7 TWIX2 6 WDX2 5 - 4 SIX2 3 - 2 T1X2 1 T0X2 0 X2 Reset Value = 0000 000Xb (AT89C51SND2C) or 0000 0000b (AT83SND2C) Table 18. PLLCON Register PLLCON (S:E9h) – PLL Control Register 7 R1 Bit Number 7-6 5-4 6 R0 5 4 3 PLLRES 2 1 PLLEN 0 PLOCK Bit Mnemonic Description R1:0 PLL Least Significant Bits R Divider 2 LSB of the 10-bit R divider. Reserved The values read from these bits are always 0. Do not set these bits. 15 4341D–MP3–04/05 Bit Number 3 Bit Mnemonic Description PLLRES PLL Reset Bit Set this bit to reset the PLL. Clear this bit to free the PLL and allow enabling. Reserved The value read from this bit is always 0. Do not set this bit. PLL Enable Bit Set to enable the PLL. Clear to disable the PLL. PLL Lock Indicator Set by hardware when PLL is locked. Clear by hardware when PLL is unlocked. 2 - 1 PLLEN 0 PLOCK Reset Value = 0000 1000b Table 19. PLLNDIV Register PLLNDIV (S:EEh) – PLL N Divider Register 7 Bit Number 7 6-0 6 N6 5 N5 4 N4 3 N3 2 N2 1 N1 0 N0 Bit Mnemonic Description N6:0 Reserved The value read from this bit is always 0. Do not set this bit. PLL N Divider 7 - bit N divider. Reset Value = 0000 0000b Table 20. PLLRDIV Register PLLRDIV (S:EFh) – PLL R Divider Register 7 R9 Bit Number 7-0 6 R8 5 R7 4 R6 3 R5 2 R4 1 R3 0 R2 Bit Mnemonic Description R9:2 PLL Most Significant Bits R Divider 8 MSB of the 10-bit R divider. Reset Value = 0000 0000b 16 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Program/Code Memory The AT8xC51SND2C execute up to 64K Bytes of program/code memory. Figure 9 shows the split of internal and external program/code memory spaces depending on the product. The AT83SND2C product provides the internal program/code memory in ROM memory while the AT89C51SND2C product provides it in Flash memory. These 2 products do not allow external code memory execution. The Flash memory increases EPROM and ROM functionality by in-circuit electrical erasure and programming. The high voltage needed for programming or erasing Flash cells is generated on-chip using the standard VDD voltage, made possible by the internal charge pump. Thus, the AT89C51SND2C can be programmed using only one voltage and allows In-application software programming. Hardware programming mode is also available using common programming tools. See the application note ‘Programming T89C51x and AT89C51x with Device Programmers’. The AT89C51SND2C implements an additional 4K Bytes of on-chip boot Flash memory provided in Flash memory. This boot memory is delivered programmed with a standard boot loader software allowing In-System Programming (ISP). It also contains some Application Programming Interface routines named API routines allowing In Application Programming (IAP) by using user’s own boot loader. Figure 9. Program/Code Memory Organization FFFFh FFFFh F000h FFFFh F000h 4K Bytes Boot Flash 64K Bytes Code ROM 64K Bytes Code Flash 0000h AT83SND2C 0000h AT89C51SND2C ROM Memory Architecture As shown in Figure 10 the AT83SND2C ROM memory is composed of one space detailed in the following paragraph. Figure 10. AT83SND2C Memory Architecture FFFFh 64K Bytes ROM Memory User 0000h 17 4341D–MP3–04/05 User Space This space is composed of a 64K Bytes ROM memory programmed during the manufacturing process. It contains the user’s application code. As shown in Figure 11 the AT89C51SND2C Flash memory is composed of four spaces detailed in the following paragraphs. Figure 11. AT89C51SND2C Memory Architecture Hardware Security Extra Row FFFFh FFFFh F000h Flash Memory Architecture 4K Bytes Flash Memory Boot 64K Bytes Flash Memory User 0000h User Space This space is composed of a 64K Bytes Flash memory organized in 512 pages of 128 Bytes. It contains the user’s application code. This space can be read or written by both software and hardware modes. Boot Space This space is composed of a 4K Bytes Flash memory. It contains the boot loader for InSystem Programming and the routines for In Application Programming. This space can only be read or written by hardware mode using a parallel programming tool. Hardware Security Space This space is composed of one Byte: the Hardware Security Byte (HSB see Table 23) divided in 2 separate nibbles. The MSN contains the X2 mode configuration bit and the Boot Loader Jump Bit as detailed in Section “Boot Memory Execution”, page 19 and can be written by software while the LSN contains the lock system level to protect the memory content against piracy as detailed in Section “Hardware Security System”, page 19 and can only be written by hardware. This space is composed of 2 Bytes: • • The Software Boot Vector (SBV, see Table 24). This Byte is used by the software boot loader to build the boot address. The Software Security Byte (SSB, see Table 25). This Byte is used to lock the execution of some boot loader commands. Extra Row Space 18 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Hardware Security System The AT89C51SND2C implements three lock bits LB2:0 in the LSN of HSB (see Table 23) providing three levels of security for user’s program as described in Table 21 while the AT83SND2C is always set in read disabled mode. Level 0 is the level of an erased part and does not enable any security feature. Level 1 locks the hardware programming of both user and boot memories. Level 2 locks also hardware verifying of both user and boot memories Level 3 locks also the external execution. Table 21. Lock Bit Features(1) Level 0 1 2 3 (3) LB2 U U U P LB1 U U P X LB0 U P X X Internal Execution Enable Enable Enable Enable External Execution Enable Enable Enable Disable Hardware Verifying Enable Enable Disable Disable Hardware Software Programming Programming Enable Disable Disable Disable Enable Enable Enable Enable Notes: 1. U means unprogrammed, P means programmed and X means don’t care (programmed or unprogrammed). 2. AT89C51SND2C products are delivered with third level programmed to ensure that the code programmed by software using ISP or user’s boot loader is secured from any hardware piracy. 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 bit in AUXR1 (see Figure 22). The three ways to set this bit are detailed in the following sections. The software way to set ENBOOT consists in writing to AUXR1 from the user’s software. This enables boot loader or API routines execution. 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 instead of 0000h in order to execute the boot loader software. As shown in Figure 12 the hardware condition always allows in-system recovery when user’s memory has been corrupted. Software Boot Mapping Hardware Condition Boot Mapping Programmed Condition Boot Mapping The programmed condition is based on the Boot Loader Jump Bit (BLJB) in HSB. As shown in Figure 12 when this bit is programmed (by hardware or software programming mode), the chip reset set ENBOOT and forces the reset vector to F000h instead of 0000h, in order to execute the boot loader software. 19 4341D–MP3–04/05 Figure 12. Hardware Boot Process Algorithm RESET Hard Cond? ISP = L? Hardware Process Prog Cond? BLJB = P? Hard Cond Init ENBOOT = 1 PC = F000h FCON = 00h Standard Init ENBOOT = 0 PC = 0000h FCON = F0h Prog Cond Init ENBOOT = 1 PC = F000h FCON = F0h Software Process User’s Application Atmel’s Boot Loader The software process (boot loader) is detailed in the “Boot Loader Datasheet” Document. Preventing Flash Corruption See Section “Reset Recommendation to Prevent Flash Corruption”, page 47. 20 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Registers Table 22. AUXR1 Register AUXR1 (S:A2h) – Auxiliary Register 1 7 Bit Number 7-6 6 5 ENBOOT 4 3 GF3 2 0 1 0 DPS Bit Mnemonic Description Reserved The value read from these bits are indeterminate. Do not set these bits. Enable Boot Flash Set this bit to map the boot Flash in the code space between at addresses F000h to FFFFh. Clear this bit to disable boot Flash. Reserved The value read from this bit is indeterminate. Do not set this bit. General Flag This bit is a general-purpose user flag. Always Zero This bit is stuck to logic 0 to allow INC AUXR1 instruction without affecting GF3 flag. Reserved for Data Pointer Extension. Data Pointer Select Bit Set to select second data pointer: DPTR1. Clear to select first data pointer: DPTR0. 5 ENBOOT 1 4 3 GF3 2 1 0 0 DPS Reset Value = XXXX 00X0b Note: 1. ENBOOT bit is only available in AT89C51SND2C product. 21 4341D–MP3–04/05 Hardware Bytes Table 23. HSB Byte – Hardware Security Byte 7 X2B Bit Number 7 6 BLJB 5 4 3 2 LB2 1 LB1 0 LB0 Bit Mnemonic Description X2B(1) X2 Bit Program this bit to start in X2 mode. Unprogram (erase) this bit to start in standard mode. Boot Loader Jump Bit Program this bit to execute the boot loader at address F000h on next reset. Unprogram (erase) this bit to execute user’s application at address 0000h on next reset. Reserved The value read from these bits is always unprogrammed. Do not program these bits. Reserved The value read from this bit is always unprogrammed. Do not program this bit. Hardware Lock Bits Refer to for bits description. 6 BLJB (2) 5-4 - 3 - 2-0 LB2:0 Reset Value = XXUU UXXX, UUUU UUUU after an hardware full chip erase. Note: 1. X2B initializes the X2 bit in CKCON during the reset phase. 2. In order to ensure boot loader activation at first power-up, AT89C51SND2C products are delivered with BLJB programmed. 3. Bits 0 to 3 (LSN) can only be programmed by hardware mode. Table 24. SBV Byte – Software Boot Vector 7 ADD15 Bit Number 7-0 6 ADD14 5 ADD13 4 ADD12 3 ADD11 2 ADD10 1 ADD9 0 ADD8 Bit Mnemonic Description ADD15:8 MSB of the user’s boot loader 16-bit address location Refer to the boot loader datasheet for usage information (boot loader dependent) Reset Value = XXXX XXXX, UUUU UUUU after an hardware full chip erase. Table 25. SSB Byte – Software Security Byte 7 SSB7 Bit Number 7-0 6 SSB6 5 SSB5 4 SSB4 3 SSB3 2 SSB2 1 SSB1 0 SSB0 Bit Mnemonic Description SSB7:0 Software Security Byte Data Refer to the boot loader datasheet for usage information (boot loader dependent) Reset Value = XXXX XXXX, UUUU UUUU after an hardware full chip erase. 22 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Data Memory The AT8xC51SND2C provides data memory access in 2 different spaces: 1. The internal space mapped in three separate segments: – – – The lower 128 Bytes RAM segment The upper 128 Bytes RAM segment The expanded 2048 Bytes RAM segment 2. The external space. A fourth internal segment is available but dedicated to Special Function Registers, SFRs, (addresses 80h to FFh) accessible by direct addressing mode. For information on this segment, refer to the Section “Special Function Registers”, page 30. Figure 13 shows the internal and external data memory spaces organization. Figure 13. Internal and External Data Memory Organization FFFFh 64K Bytes External XRAM 7FFh FFh FFh 2K Bytes Internal ERAM EXTRAM = 0 Upper 128 Bytes Internal RAM Indirect Addressing Lower 128 Bytes Internal RAM Direct or Indirect Addressing Special Function Registers Direct Addressing 80h 7Fh 80h 0800h 0000h EXTRAM = 1 00h 00h Internal Space Lower 128 Bytes RAM The lower 128 Bytes of RAM (see Figure 14) are accessible from address 00h to 7Fh using direct or indirect addressing modes. The lowest 32 Bytes are grouped into 4 banks of 8 registers (R0 to R7). 2 bits RS0 and RS1 in PSW register (see Table 29) select which bank is in use according to Table 26. This allows more efficient use of code space, since register instructions are shorter than instructions that use direct addressing, and can be used for context switching in interrupt service routines. Table 26. Register Bank Selection RS1 0 0 1 1 RS0 0 1 0 1 Description Register bank 0 from 00h to 07h Register bank 1 from 08h to 0Fh Register bank 2 from 10h to 17h Register bank 3 from 18h to 1Fh The next 16 Bytes above the register banks form a block of bit-addressable memory space. The C51 instruction set includes a wide selection of single-bit instructions, and the 128 bits in this area can be directly addressed by these instructions. The bit addresses in this area are 00h to 7Fh. 23 4341D–MP3–04/05 Figure 14. Lower 128 Bytes Internal RAM Organization 7Fh 30h 20h 18h 10h 08h 00h 2Fh 1Fh 17h 0Fh 07h Bit-Addressable Space (Bit Addresses 0-7Fh) 4 Banks of 8 Registers R0-R7 Upper 128 Bytes RAM Expanded RAM The upper 128 Bytes of RAM are accessible from address 80h to FFh using only indirect addressing mode. The on-chip 2K Bytes of expanded RAM (ERAM) are accessible from address 0000h to 07FFh using indirect addressing mode through MOVX instructions. In this address range, EXTRAM bit in AUXR register (see Table 30) is used to select the ERAM (default) or the XRAM. As shown in Figure 13 when EXTRAM = 0, the ERAM is selected and when EXTRAM = 1, the XRAM is selected (see Section “External Space”). The ERAM memory can be resized using XRS1:0 bits in AUXR register to dynamically increase external access to the XRAM space. Table 27 details the selected ERAM size and address range. Table 27. ERAM Size Selection XRS1 0 0 1 1 XRS0 0 1 0 1 ERAM Size 256 Bytes 512 Bytes 1K Byte 2K Bytes Address 0 to 00FFh 0 to 01FFh 0 to 03FFh 0 to 07FFh Note: Lower 128 Bytes RAM, Upper 128 Bytes RAM, and expanded RAM are made of volatile memory cells. This means that the RAM content is indeterminate after power-up and must then be initialized properly. 24 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C External Space Memory Interface The external memory interface comprises the external bus (port 0 and port 2) as well as the bus control signals (RD, WR, and ALE). Figure 15 shows the structure of the external address bus. P0 carries address A7:0 while P2 carries address A15:8. Data D7:0 is multiplexed with A7:0 on P0. Table 28 describes the external memory interface signals. Figure 15. External Data Memory Interface Structure AT8xC51SND2C P2 ALE P0 AD7:0 A15:8 RAM PERIPHERAL A15:8 A7:0 Latch A7:0 D7:0 RD WR OE WR Table 28. External Data Memory Interface Signals Signal Name A15:8 AD7:0 Type O I/O Description Address Lines Upper address lines for the external bus. Address/Data Lines Multiplexed lower address lines and data for the external memory. Address Latch Enable ALE signals indicates that valid address information are available on lines AD7:0. Read Read signal output to external data memory. Write Write signal output to external memory. Alternate Function P2.7:0 P0.7:0 ALE O - RD WR O O P3.7 P3.6 Page Access Mode The AT8xC51SND2C implement a feature called Page Access that disables the output of DPH on P2 when executing MOVX @DPTR instruction. Page Access is enable by setting the DPHDIS bit in AUXR register. Page Access is useful when application uses both ERAM and 256 Bytes of XRAM. In this case, software modifies intensively EXTRAM bit to select access to ERAM or XRAM and must save it if used in interrupt service routine. Page Access allows external access above 00FFh address without generating DPH on P2. Thus ERAM is accessed using MOVX @Ri or MOVX @DPTR with DPTR < 0100h, < 0200h, < 0400h or < 0800h depending on the XRS1:0 bits value. Then XRAM is accessed using MOVX @DPTR with DPTR ≥ 0800h regardless of XRS1:0 bits value while keeping P2 for general I/O usage. 25 4341D–MP3–04/05 External Bus Cycles This section describes the bus cycles the AT8xC51SND2C executes to read (see Figure 16), and write data (see Figure 17) in the external data memory. External memory cycle takes 6 CPU clock periods. This is equivalent to 12 oscillator clock period in standard mode or 6 oscillator clock periods in X2 mode. For further information on X2 mode, refer to the Section “X2 Feature”, page 12. Slow peripherals can be accessed by stretching the read and write cycles. This is done using the M0 bit in AUXR register. Setting this bit changes the width of the RD and WR signals from 3 to 15 CPU clock periods. For simplicity, Figure 16 and Figure 17 depict the bus cycle waveforms in idealized form and do not provide precise timing information. For bus cycle timing parameters refer to the Section “AC Characteristics”. Figure 16. External Data Read Waveforms CPU Clock ALE RD(1) P0 P2 Notes: P2 DPL or Ri DPH or P2(2),(3) D7:0 1. RD signal may be stretched using M0 bit in AUXR register. 2. When executing MOVX @Ri instruction, P2 outputs SFR content. 3. When executing MOVX @DPTR instruction, if DPHDIS is set (Page Access Mode), P2 outputs SFR content instead of DPH. Figure 17. External Data Write Waveforms CPU Clock ALE WR(1) P0 P2 P2 DPL or Ri D7:0 DPH or P2(2),(3) Notes: 1. WR signal may be stretched using M0 bit in AUXR register. 2. When executing MOVX @Ri instruction, P2 outputs SFR content. 3. When executing MOVX @DPTR instruction, if DPHDIS is set (Page Access Mode), P2 outputs SFR content instead of DPH. 26 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Dual Data Pointer Description The AT8xC51SND2C 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 22) is used to select whether DPTR is the data pointer 0 or the data pointer 1 (see Figure 18). Figure 18. Dual Data Pointer Implementation DPL0 DPL1 DPTR0 DPTR1 0 1 DPL DPS DPH0 DPH1 0 1 AUXR1.0 DPTR DPH Application Software can take advantage of the additional data pointers to both increase speed and reduce code size, for example, block operations (copy, compare, search …) are well served by using one data pointer as a “source” pointer and the other one as a “destination” pointer. Below is an example of block move implementation using the 2 pointers and coded in assembler. 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 instruction does not directly force the DPS bit to a particular state, but simply toggles it. In simple routines, such as the block move example, only the fact that DPS is toggled in the proper sequence 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 EQU 0A2h DPTR,#SOURCE AUXR1 DPTR,#DEST AUXR1 A,@DPTR DPTR AUXR1 @DPTR,A DPTR mv_loop ; ; ; ; ; ; ; ; ; ; address of SOURCE switch data pointers address of DEST switch data pointers get a Byte from SOURCE increment SOURCE address switch data pointers write the Byte to DEST increment DEST address check for NULL terminator AUXR1 move: mov inc mov mv_loop: inc movx inc inc movx inc jnz end_move: 27 4341D–MP3–04/05 Registers Table 29. PSW Register PSW (S:8Eh) – Program Status Word Register 7 CY Bit Number 7 6 5 4-3 2 1 0 6 AC 5 F0 4 RS1 3 RS0 2 OV 1 F1 0 P Bit Mnemonic Description CY AC F0 RS1:0 OV F1 P Carry Flag Carry out from bit 1 of ALU operands. Auxiliary Carry Flag Carry out from bit 1 of addition operands. User Definable Flag 0 Register Bank Select Bits Refer to Table 26 for bits description. Overflow Flag Overflow set by arithmetic operations. User Definable Flag 1 Parity Bit Set when ACC contains an odd number of 1’s. Cleared when ACC contains an even number of 1’s. Reset Value = 0000 0000b 28 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Table 30. AUXR Register AUXR (S:8Eh) – Auxiliary Control Register 7 Bit Number 7 6 EXT16 5 M0 4 DPHDIS 3 XRS1 2 XRS0 1 EXTRAM 0 AO Bit Mnemonic Description Reserved The value read from this bit is indeterminate. Do not set this bit. External 16-bit Access Enable Bit Set to enable 16-bit access mode during MOVX instructions. Clear to disable 16-bit access mode and enable standard 8-bit access mode during MOVX instructions. External Memory Access Stretch Bit 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. DPH Disable Bit Set to disable DPH output on P2 when executing MOVX @DPTR instruction. Clear to enable DPH output on P2 when executing MOVX @DPTR instruction. Expanded RAM Size Bits Refer to Table 27 for ERAM size description. External RAM Enable Bit Set to select the external XRAM when executing MOVX @Ri or MOVX @DPTR instructions. Clear to select the internal expanded RAM when executing MOVX @Ri or MOVX @DPTR instructions. ALE Output Enable Bit Set to output the ALE signal only during MOVX instructions. Clear to output the ALE signal at a constant rate of FCPU/3. 6 EXT16 5 M0 4 DPHDIS 3-2 XRS1:0 1 EXTRAM 0 AO Reset Value = X000 1101b 29 4341D–MP3–04/05 Special Function Registers The Special Function Registers (SFRs) of the AT8xC51SND2C derivatives fall into the categories detailed in Table 31 to Table 19. The relative addresses of these SFRs are provided together with their reset values in Table 49. In this table, the bit-addressable registers are identified by Note 1. Table 31. C51 Core SFRs Mnemonic Add Name ACC B PSW SP DPL DPH E0h Accumulator F0h B Register D0h Program Status Word 81h Stack Pointer 82h Data Pointer Low Byte 83h Data Pointer High Byte CY AC F0 RS1 RS0 OV F1 P 7 6 5 4 3 2 1 0 Table 32. System Management SFRs Mnemonic Add Name PCON AUXR AUXR1 NVERS 87h Power Control 8Eh Auxiliary Register 0 A2h Auxiliary Register 1 FBh Version Number 7 SMOD1 NV7 6 SMOD0 EXT16 NV6 5 M0 ENBOOT(1) NV5 4 DPHDIS NV4 3 GF1 XRS1 GF3 NV3 2 GF0 XRS0 0 NV2 1 PD EXTRAM NV1 0 IDL AO DPS NV0 Note: 1. ENBOOT bit is only available in AT89C51SND2C product. Table 33. PLL and System Clock SFRs Mnemonic Add Name CKCON PLLCON PLLNDIV PLLRDIV 8Fh Clock Control E9h PLL Control EEh PLL N Divider EFh PLL R Divider 7 R1 R9 6 R0 N6 R8 5 N5 R7 4 N4 R6 3 PLLRES N3 R5 2 N2 R4 1 PLLEN N1 R3 0 X2 PLOCK N0 R2 Table 34. Interrupt SFRs Mnemonic Add Name IEN0 IEN1 IPH0 IPL0 IPH1 IPL1 A8h Interrupt Enable Control 0 B1h Interrupt Enable Control 1 B7h Interrupt Priority Control High 0 B8h Interrupt Priority Control Low 0 B3h Interrupt Priority Control High 1 B2h Interrupt Priority Control Low 1 7 EA 6 EAUD EUSB IPHAUD IPLAUD IPHUSB IPLUSB 5 EMP3 IPHMP3 IPLMP3 4 ES EKB IPHS IPLS IPHKB IPLKB 3 ET1 IPHT1 IPLT1 2 EX1 ESPI IPHX1 IPLX1 IPHSPI IPLSPI 1 ET0 EI2C IPHT0 IPLT0 IPHI2C IPLI2C 0 EX0 EMMC IPHX0 IPLX0 IPHMMC IPLMMC 30 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Table 35. Port SFRs Mnemonic Add Name P0 P2 P3 P4 80h 8-bit Port 0 A0h 8-bit Port 2 B0h 8-bit Port 3 C0h 4-bit Port 4 7 6 5 4 3 2 1 0 Table 36. Auxiliary SFRs Mnemonic Add Name AUXCON 90h Auxiliary Control 7 SDA 6 SCL 5 4 3 2 1 0 KIN0 AUDCDOUT AUDCDIN AUDCCLK AUDCCS Table 37. Flash Memory SFR Mnemonic Add Name FCON(1) D1h Flash Control 7 FPL3 6 FPL2 5 FPL1 4 FPL0 3 FPS 2 FMOD1 1 FMOD0 0 FBUSY Note: 1. FCON register is only available in AT89C51SND2C product. Table 38. Timer SFRs Mnemonic Add Name TCON TMOD TL0 TH0 TL1 TH1 WDTRST WDTPRG 88h Timer/Counter 0 and 1 Control 89h Timer/Counter 0 and 1 Modes 8Ah Timer/Counter 0 Low Byte 8Ch Timer/Counter 0 High Byte 8Bh Timer/Counter 1 Low Byte 8Dh Timer/Counter 1 High Byte A6h Watchdog Timer Reset A7h Watchdog Timer Program WTO2 WTO1 WTO0 7 TF1 GATE1 6 TR1 C/T1# 5 TF0 M11 4 TR0 M01 3 IE1 GATE0 2 IT1 C/T0# 1 IE0 M10 0 IT0 M00 31 4341D–MP3–04/05 Table 39. MP3 Decoder SFRs Mnemonic Add Name MP3CON MP3STA MP3STA1 MP3DAT MP3ANC MP3VOL MP3VOR MP3BAS MP3MED MP3TRE MP3CLK AAh MP3 Control C8h MP3 Status AFh MP3 Status 1 ACh MP3 Data ADh MP3 Ancillary Data 9Eh MP3 Audio Volume Control Left 9Fh MP3 Audio Volume Control Right B4h MP3 Audio Bass Control B5h MP3 Audio Medium Control B6h MP3 Audio Treble Control EBh MP3 Clock Divider 7 MPEN MPANC MPD7 AND7 6 MPBBST MPREQ MPD6 AND6 5 CRCEN ERRLAY MPD5 AND5 4 MSKANC ERRSYN MPFREQ MPD4 AND4 VOL4 VOR4 BAS4 MED4 TRE4 MPCD4 3 MSKREQ ERRCRC MPBREQ MPD3 AND3 VOL3 VOR3 BAS3 MED3 TRE3 MPCD3 2 MSKLAY MPFS1 MPD2 AND2 VOL2 VOR2 BAS2 MED2 TRE2 MPCD2 1 MSKSYN MPFS0 MPD1 AND1 VOL1 VOR1 BAS1 MED1 TRE1 MPCD1 0 MSKCRC MPVER MPD0 AND0 VOL0 VOR0 BAS0 MED0 TRE0 MPCD0 Table 40. Audio Interface SFRs Mnemonic Add Name AUDCON0 AUDCON1 AUDSTA AUDDAT AUDCLK 9Ah Audio Control 0 9Bh Audio Control 1 9Ch Audio Status 9Dh Audio Data ECh Audio Clock Divider 7 JUST4 SRC SREQ AUD7 6 JUST3 DRQEN UDRN AUD6 5 JUST2 MSREQ AUBUSY AUD5 4 JUST1 MUDRN AUD4 AUCD4 3 JUST0 AUD3 AUCD3 2 POL DUP1 AUD2 AUCD2 1 DSIZ DUP0 AUD1 AUCD1 0 HLR AUDEN AUD0 AUCD0 32 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Table 41. USB Controller SFRs Mnemonic Add Name USBCON USBADDR USBINT USBIEN UEPNUM BCh USB Global Control C6h USB Address BDh USB Global Interrupt BEh USB Global Interrupt Enable C7h USB Endpoint Number 7 USBE FEN EPEN DIR FDAT7 FNUM7 6 5 4 UADD4 EORINT 3 UPRSM UADD3 SOFINT ESOFINT DTGL STLCRC FDAT3 BYCT3 FNUM3 2 RMWUPE UADD2 EPDIR 1 CONFG UADD1 EPNUM1 0 FADDEN UADD0 SPINT ESPINT EPNUM0 SUSPCLK SDRMWUP UADD6 NAKIEN UADD5 WUPCPU EWUPCPU EEORINT NAKOUT NAKIN TXRDY FDAT4 BYCT4 FNUM4 CRCERR - UEPCONX D4h USB Endpoint X Control UEPSTAX UEPRST UEPINT UEPIEN UEPDATX UBYCTX UFNUML UFNUMH USBCLK CEh USB Endpoint X Status D5h USB Endpoint Reset F8h USB Endpoint Interrupt C2h USB Endpoint Interrupt Enable CFh USB Endpoint X FIFO Data E2h USB Endpoint X Byte Counter BAh USB Frame Number Low BBh USB Frame Number High EAh USB Clock Divider EPTYPE1 EPTYPE0 TXCMP EP0RST EP0INT EP0INTE FDAT0 BYCT0 FNUM0 FNUM8 USBCD0 RXOUTB1 STALLRQ FDAT6 BYCT6 FNUM6 FDAT5 BYCT5 FNUM5 CRCOK - RXSETUP RXOUTB0 EP2RST EP2INT EP2INTE FDAT2 BYCT2 FNUM2 FNUM10 EP1RST EP1INT EP1INTE FDAT1 BYCT1 FNUM1 FNUM9 USBCD1 Table 42. Audio Interface SFRs Mnemonic Add Name AUDCON0 AUDCON1 AUDSTA AUDDAT AUDCLK 9Ah Audio Control 0 9Bh Audio Control 1 9Ch Audio Status 9Dh Audio Data ECh Audio Clock Divider 7 JUST4 SRC SREQ AUD7 6 JUST3 DRQEN UDRN AUD6 5 JUST2 MSREQ AUBUSY AUD5 4 JUST1 MUDRN AUD4 AUCD4 3 JUST0 AUD3 AUCD3 2 POL DUP1 AUD2 AUCD2 1 DSIZ DUP0 AUD1 AUCD1 0 HLR AUDEN AUD0 AUCD0 Table 43. MMC Controller SFRs Mnemonic Add Name MMCON0 MMCON1 MMCON2 MMSTA MMINT MMMSK MMCMD MMDAT MMCLK E4h MMC Control 0 E5h MMC Control 1 E6h MMC Control 2 DEh MMC Control and Status E7h MMC Interrupt DFh MMC Interrupt Mask DDh MMC Command DCh MMC Data EDh MMC Clock Divider 7 DRPTR BLEN3 MMCEN MCBI MCBM MC7 MD7 MMCD7 6 DTPTR BLEN2 DCR EORI EORM MC6 MD6 MMCD6 5 CRPTR BLEN1 CCR CBUSY EOCI EOCM MC5 MD5 MMCD5 4 CTPTR BLEN0 CRC16S EOFI EOFM MC4 MD4 MMCD4 3 MBLOCK DATDIR DATFS F2FI F2FM MC3 MD3 MMCD3 2 DFMT DATEN DATD1 CRC7S F1FI F1FM MC2 MD2 MMCD2 1 RFMT RESPEN DATD0 RESPFS F2EI F2EM MC1 MD1 MMCD1 0 CRCDIS CMDEN FLOWC CFLCK F1EI F1EM MC0 MD0 MMCD0 33 4341D–MP3–04/05 Table 44. IDE Interface SFR Mnemonic Add Name DAT16H F9h High Order Data Byte 7 D15 6 D14 5 D13 4 D12 3 D11 2 D10 1 D9 0 D8 Table 45. Serial I/O Port SFRs Mnemonic Add Name SCON SBUF SADEN SADDR BDRCON BRL 98h Serial Control 99h Serial Data Buffer B9h Slave Address Mask A9h Slave Address 92h Baud Rate Control 91h Baud Rate Reload BRR TBCK RBCK SPD SRC 7 FE/SM0 6 SM1 5 SM2 4 REN 3 TB8 2 RB8 1 TI 0 RI Table 46. SPI Controller SFRs Mnemonic Add Name SPCON SPSTA SPDAT C3h SPI Control C4h SPI Status C5h SPI Data 7 SPR2 SPIF SPD7 6 SPEN WCOL SPD6 5 SSDIS SPD5 4 MSTR MODF SPD4 3 CPOL SPD3 2 CPHA SPD2 1 SPR1 SPD1 0 SPR0 SPD0 Table 47. Two Wire Controller SFRs Mnemonic Add Name SSCON SSSTA SSDAT SSADR 93h Synchronous Serial Control 94h Synchronous Serial Status 95h Synchronous Serial Data 96h Synchronous Serial Address 7 SSCR2 SSC4 SSD7 SSA7 6 SSPE SSC3 SSD6 SSA6 5 SSSTA SSC2 SSD5 SSA5 4 SSSTO SSC1 SSD4 SSA4 3 SSI SSC0 SSD3 SSA3 2 SSAA 0 SSD2 SSA2 1 SSCR1 0 SSD1 SSA1 0 SSCR0 0 SSD0 SSGC Table 48. Keyboard Interface SFRs Mnemonic Add Name KBCON KBSTA A3h Keyboard Control A4h Keyboard Status 7 KPDE 6 5 4 KINL0 3 2 1 0 KINM0 KINF0 34 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Table 49. SFR Addresses and Reset Values 0/8 F8h F0h E8h ACC(1) 0000 0000 P5(1) XXXX 1111 PSW(1) 0000 0000 MP3STA(1) 0000 0001 P4(1) 1111 1111 IPL0(1) X000 0000 P3(1) 1111 1111 IEN0(1) 0000 0000 P2(1) 1111 1111 SCON 0000 0000 AUXCON(1) 1111 1111 TCON(1) 0000 0000 P0(1) 1111 1111 0/8 SBUF XXXX XXXX BRL 0000 0000 TMOD 0000 0000 SP 0000 0111 1/9 SADEN 0000 0000 IEN1 0000 0000 SADDR 0000 0000 UEPIEN 0000 0000 UFNUML 0000 0000 IPL1 0000 0000 MP3CON 0011 1111 AUXR1 XXXX 00X0 AUDCON0 0000 1000 BDRCON XXX0 0000 TL0 0000 0000 DPL 0000 0000 2/A KBCON 0000 1111 AUDCON1 1011 0010 SSCON 0000 0000 TL1 0000 0000 DPH 0000 0000 3/B 4/C 5/D 6/E SPCON 0001 0100 UFNUMH 0000 0000 IPH1 0000 0000 SPSTA 0000 0000 USBCON 0000 0000 MP3BAS 0000 0000 MP3DAT 0000 0000 KBSTA 0000 0000 AUDSTA 1100 0000 SSSTA 1111 1000 TH0 0000 0000 AUDDAT 1111 1111 SSDAT 1111 1111 TH1 0000 0000 SPDAT XXXX XXXX USBINT 0000 0000 MP3MED 0000 0000 MP3ANC 0000 0000 WDTRST XXX XXXX MP3VOL 0000 0000 SSADR 1111 1110 AUXR X000 1101 CKCON 0000 000X(5) PCON 00XX 0000 7/F FCON(3) 1111 0000(4) UEPINT 0000 0000 B(1) 0000 0000 PLLCON 0000 1000 USBCLK 0000 0000 UBYCTLX 0000 0000 MP3CLK 0000 0000 AUDCLK 0000 0000 MMCON0 0000 0000 MMDAT 1111 1111 UEPCONX 1000 0000 MMCLK 0000 0000 MMCON1 0000 0000 MMCMD 1111 1111 UEPRST 0000 0000 UEPSTAX 0000 0000 USBADDR 0000 0000 USBIEN 0001 0000 MP3TRE 0000 0000 IPH0 X000 0000 MP3STA1 0100 0001 WDTPRG XXXX X000 MP3VOR 0000 0000 UEPDATX XXXX XXXX UEPNUM 0000 0000 PLLNDIV 0000 0000 MMCON2 0000 0000 MMSTA 0000 0000 PLLRDIV 0000 0000 MMINT 0000 0011 MMMSK 1111 1111 1/9 DAT16H XXXX XXXX 2/A 3/B NVERS XXXX XXXX(2) 4/C 5/D 6/E 7/F FFh F7h EFh E0h E7h D8h D0h C8h C0h B8h B0h A8h A0h 98h 90h DFh D7h CFh C7h BFh B7h AFh A7h 9Fh 97h 88h 8Fh 80h 87h Reserved Notes: 1. SFR registers with least significant nibble address equal to 0 or 8 are bit-addressable. 2. NVERS reset value depends on the silicon version: 1000 0100 for AT89C51SND2C product and 0000 0001 for AT83SND2C product. 3. FCON register is only available in AT89C51SND2C product. 4. FCON reset value is 00h in case of reset with hardware condition. 5. CKCON reset value depends on the X2B bit (programmed or unprogrammed) in the Hardware Byte. 35 4341D–MP3–04/05 Interrupt System The AT8xC51SND2C, like other control-oriented computer architectures, employ a program interrupt method. This operation branches to a subroutine and performs some service in response to the interrupt. When the subroutine completes, execution resumes at the point where the interrupt occurred. Interrupts may occur as a result of internal AT8xC51SND2C activity (e.g., timer overflow) or at the initiation of electrical signals external to the microcontroller (e.g., keyboard). In all cases, interrupt operation is programmed by the system designer, who determines priority of interrupt service relative to normal code execution and other interrupt service routines. All of the interrupt sources are enabled or disabled by the system designer and may be manipulated dynamically. A typical interrupt event chain occurs as follows: • • • An internal or external device initiates an interrupt-request signal. The AT8xC51SND2C, latches this event into a flag buffer. The priority of the flag is compared to the priority of other interrupts by the interrupt handler. A high priority causes the handler to set an interrupt flag. This signals the instruction execution unit to execute a context switch. This context switch breaks the current flow of instruction sequences. The execution unit completes the current instruction prior to a save of the program counter (PC) and reloads the PC with the start address of a software service routine. The software service routine executes assigned tasks and as a final activity performs a RETI (return from interrupt) instruction. This instruction signals completion of the interrupt, resets the interrupt-in-progress priority and reloads the program counter. Program operation then continues from the original point of interruption. • Table 50. Interrupt System Signals Signal Name INT0 INT1 KIN0 Type I I I Description External Interrupt 0 See section "External Interrupts", page 39. External Interrupt 1 See section “External Interrupts”, page 39. Keyboard Interrupt Input See section “Keyboard Interface”, page 198. Alternate Function P3.2 P3.3 - Six interrupt registers are used to control the interrupt system. 2 8-bit registers are used to enable separately the interrupt sources: IEN0 and IEN1 registers (see Table 53 and Table 54). Four 8-bit registers are used to establish the priority level of the different sources: IPH0, IPL0, IPH1 and IPL1 registers (see Table 55 to Table 58). Interrupt System Priorities Each of the interrupt sources on the AT8xC51SND2C can be individually programmed to one of four priority levels. This is accomplished by one bit in the Interrupt Priority High registers (IPH0 and IPH1) and one bit in the Interrupt Priority Low registers (IPL0 and IPL1). This provides each interrupt source four possible priority levels according to Table 51. 36 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Table 51. Priority Levels IPHxx 0 0 1 1 IPLxx 0 1 0 1 Priority Level 0 Lowest 1 2 3 Highest A low-priority interrupt is always interrupted by a higher priority interrupt but not by another interrupt of lower or equal priority. Higher priority interrupts are serviced before lower priority interrupts. The response to simultaneous occurrence of equal priority interrupts is determined by an internal hardware polling sequence detailed in Table 52. Thus, within each priority level there is a second priority structure determined by the polling sequence. The interrupt control system is shown in Figure 19. Table 52. Priority within Same Level Interrupt Address Vectors C:0003h C:000Bh C:0013h C:001Bh C:0023h C:002Bh C:0033h C:003Bh C:0043h C:004Bh C:0053h C:005Bh C:0063h C:006Bh C:0073h Interrupt Request Flag Cleared by Hardware (H) or by Software (S) INT0 Timer 0 INT1 Timer 1 Serial Port MP3 Decoder Audio Interface MMC Interface Two Wire Controller SPI Controller Reserved Keyboard Reserved USB Reserved Interrupt Name INT0 Timer 0 INT1 Timer 1 Serial Port MP3 Decoder Audio Interface MMC Interface Two Wire Controller SPI Controller Reserved Keyboard Reserved USB Reserved Priority Number 0 (Highest Priority) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 (Lowest Priority) 37 4341D–MP3–04/05 Figure 19. Interrupt Control System INT0 External Interrupt 0 EX0 IEN0.0 00 01 10 11 00 01 10 11 00 01 10 11 00 01 10 11 00 01 10 11 00 01 10 11 00 01 10 11 00 01 10 11 00 01 10 11 00 01 10 11 Highest Priority Interrupts Timer 0 ET0 INT1 External Interrupt 1 IEN0.1 EX1 IEN0.2 Timer 1 ET1 TXD RXD Serial Port IEN0.3 ES MP3 Decoder IEN0.4 EMP3 Audio Interface MCLK MDAT MCMD SCL SDA SCK SI SO IEN0.5 EAUD MMC Controller IEN0.6 EMMC TWI Controller IEN1.0 EI2C SPI Controller IEN1.1 ESPI IEN1.2 KIN0 Keyboard EKB 00 01 10 11 D+ D- USB Controller IEN1.4 00 01 10 11 EUSB IEN1.6 EA IEN0.7 Interrupt Enable IPH/L Priority Enable Lowest Priority Interrupts 38 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C External Interrupts INT1:0 Inputs External interrupts INT0 and INT1 (INTn, n = 0 or 1) pins may each be programmed to be level-triggered or edge-triggered, dependent upon bits IT0 and IT1 (ITn, n = 0 or 1) in TCON register as shown in Figure 20. 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 register. If the interrupt is edge-triggered, the request flag is cleared by hardware when vectoring to the interrupt service routine. If the interrupt is level-triggered, the interrupt service routine must clear the request flag 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 signals as detailed in section “Exiting Power-down Mode”, page 48. Figure 20. INT1:0 Input Circuitry INT0/1 0 1 IE0/1 TCON.1/3 INT0/1 Interrupt Request EX0/1 IEN0.0/2 IT0/1 TCON.0/2 KIN0 Inputs Input Sampling External interrupts KIN0 provides the capability to connect a keyboard. For detailed information on this inputs, refer to section “Keyboard Interface”, page 198. External interrupt pins (INT1:0 and KIN0) are sampled once per peripheral cycle (6 peripheral clock periods) (see Figure 21). 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 interrupts must hold the request pin low for at least 6 peripheral clock periods. Figure 21. Minimum Pulse Timings Level-Triggered Interrupt > 1 Peripheral Cycle 1 cycle Edge-Triggered Interrupt > 1 Peripheral Cycle 1 cycle 1 cycle 39 4341D–MP3–04/05 Registers Table 53. IEN0 Register IEN0 (S:A8h) – Interrupt Enable Register 0 7 EA Bit Number 6 EAUD 5 EMP3 4 ES 3 ET1 2 EX1 1 ET0 0 EX0 Bit Mnemonic Description Enable All Interrupt Bit Set to enable all interrupts. Clear to disable all interrupts. If EA = 1, each interrupt source is individually enabled or disabled by setting or clearing its interrupt enable bit. 7 EA 6 EAUD Audio Interface Interrupt Enable Bit Set to enable audio interface interrupt. Clear to disable audio interface interrupt. MP3 Decoder Interrupt Enable Bit Set to enable MP3 decoder interrupt. Clear to disable MP3 decoder interrupt. Serial Port Interrupt Enable Bit Set to enable serial port interrupt. Clear to disable serial port interrupt. Timer 1 Overflow Interrupt Enable Bit Set to enable timer 1 overflow interrupt. Clear to disable timer 1 overflow interrupt. External Interrupt 1 Enable bit Set to enable external interrupt 1. Clear to disable external interrupt 1. Timer 0 Overflow Interrupt Enable Bit Set to enable timer 0 overflow interrupt. Clear to disable timer 0 overflow interrupt. External Interrupt 0 Enable Bit Set to enable external interrupt 0. Clear to disable external interrupt 0. 5 EMP3 4 ES 3 ET1 2 EX1 1 ET0 0 EX0 Reset Value = 0000 0000b 40 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Table 54. IEN1 Register IEN1 (S:B1h) – Interrupt Enable Register 1 7 Bit Number 7 6 EUSB 5 4 EKB 3 2 ESPI 1 EI2C 0 EMMC Bit Mnemonic Description Reserved The value read from this bit is always 0. Do not set this bit. USB Interface Interrupt Enable Bit Set this bit to enable USB interrupts. Clear this bit to disable USB interrupts. Reserved The value read from this bit is always 0. Do not set this bit. Keyboard Interface Interrupt Enable Bit Set to enable Keyboard interrupt. Clear to disable Keyboard interrupt. Reserved The value read from this bit is always 0. Do not set this bit. SPI Controller Interrupt Enable Bit Set to enable SPI interrupt. Clear to disable SPI interrupt. Two Wire Controller Interrupt Enable Bit Set to enable Two Wire interrupt. Clear to disable Two Wire interrupt. MMC Interface Interrupt Enable Bit Set to enable MMC interrupt. Clear to disable MMC interrupt. 6 EUSB 5 - 4 EKB 3 - 2 ESPI 1 EI2C 0 EMMC Reset Value = 0000 0000b 41 4341D–MP3–04/05 Table 55. IPH0 Register IPH0 (S:B7h) – Interrupt Priority High Register 0 7 Bit Number 7 6 5 4 3 2 1 0 6 IPHAUD 5 IPHMP3 4 IPHS 3 IPHT1 2 IPHX1 1 IPHT0 0 IPHX0 Bit Mnemonic Description IPHAUD IPHMP3 IPHS IPHT1 IPHX1 IPHT0 IPHX0 Reserved The value read from this bit is indeterminate. Do not set this bit. Audio Interface Interrupt Priority Level MSB Refer to Table 51 for priority level description. MP3 Decoder Interrupt Priority Level MSB Refer to Table 51 for priority level description. Serial Port Interrupt Priority Level MSB Refer to Table 51 for priority level description. Timer 1 Interrupt Priority Level MSB Refer to Table 51 for priority level description. External Interrupt 1 Priority Level MSB Refer to Table 51 for priority level description. Timer 0 Interrupt Priority Level MSB Refer to Table 51 for priority level description. External Interrupt 0 Priority Level MSB Refer to Table 51 for priority level description. Reset Value = X000 0000b 42 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Table 56. IPH1 Register IPH1 (S:B3h) – Interrupt Priority High Register 1 7 Bit Number 7 6 5 4 3 2 1 0 6 IPHUSB 5 4 IPHKB 3 2 IPHSPI 1 IPHI2C 0 IPHMMC Bit Mnemonic Description IPHUSB IPHKB IPHSPI IPHI2C IPHMMC Reserved The value read from this bit is always 0. Do not set this bit. USB Interrupt Priority Level MSB Refer to Table 51 for priority level description. Reserved The value read from this bit is always 0. Do not set this bit. Keyboard Interrupt Priority Level MSB Refer to Table 51 for priority level description. Reserved The value read from this bit is always 0. Do not set this bit. SPI Interrupt Priority Level MSB Refer to Table 51 for priority level description. Two Wire Controller Interrupt Priority Level MSB Refer to Table 51 for priority level description. MMC Interrupt Priority Level MSB Refer to Table 51 for priority level description. Reset Value = 0000 0000b 43 4341D–MP3–04/05 Table 57. IPL0 Register IPL0 (S:B8h) - Interrupt Priority Low Register 0 7 Bit Number 7 6 5 4 3 2 1 0 6 IPLAUD 5 IPLMP3 4 IPLS 3 IPLT1 2 IPLX1 1 IPLT0 0 IPLX0 Bit Mnemonic Description IPLAUD IPLMP3 IPLS IPLT1 IPLX1 IPLT0 IPLX0 Reserved The value read from this bit is indeterminate. Do not set this bit. Audio Interface Interrupt Priority Level LSB Refer to Table 51 for priority level description. MP3 Decoder Interrupt Priority Level LSB Refer to Table 51 for priority level description. Serial Port Interrupt Priority Level LSB Refer to Table 51 for priority level description. Timer 1 Interrupt Priority Level LSB Refer to Table 51 for priority level description. External Interrupt 1 Priority Level LSB Refer to Table 51 for priority level description. Timer 0 Interrupt Priority Level LSB Refer to Table 51 for priority level description. External Interrupt 0 Priority Level LSB Refer to Table 51 for priority level description. Reset Value = X000 0000b 44 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Table 58. IPL1 Register IPL1 (S:B2h) – Interrupt Priority Low Register 1 7 Bit Number 7 6 5 4 3 2 1 0 6 IPLUSB 5 4 IPLKB 3 2 IPLSPI 1 IPLI2C 0 IPLMMC Bit Mnemonic Description IPLUSB IPLKB IPLSPI IPLI2C IPLMMC Reserved The value read from this bit is always 0. Do not set this bit. USB Interrupt Priority Level LSB Refer to Table 51 for priority level description. Reserved The value read from this bit is always 0. Do not set this bit. Keyboard Interrupt Priority Level LSB Refer to Table 51 for priority level description. Reserved The value read from this bit is always 0. Do not set this bit. SPI Interrupt Priority Level LSB Refer to Table 51 for priority level description. Two Wire Controller Interrupt Priority Level LSB Refer to Table 51 for priority level description. MMC Interrupt Priority Level LSB Refer to Table 51 for priority level description. Reset Value = 0000 0000b 45 4341D–MP3–04/05 Power Management 2 power reduction modes are implemented in the AT8xC51SND2C: the Idle mode and the Power-down mode. These modes are detailed in the following sections. In addition to these power reduction modes, the clocks of the core and peripherals can be dynamically divided by 2 using the X2 mode detailed in section “X2 Feature”, page 12. In order to start-up (cold reset) or to restart (warm reset) properly the microcontroller, an high level has to be applied on the RST pin. A bad level leads to a wrong initialization of the internal registers like SFRs, Program Counter… and to unpredictable behavior of the microcontroller. A proper device reset initializes the AT8xC51SND2C and vectors the CPU to address 0000h. RST input has a pull-down resistor allowing power-on reset by simply connecting an external capacitor to VDD as shown in Figure 22. A warm reset can be applied either directly on the RST pin or indirectly by an internal reset source such as the watchdog timer. Resistor value and input characteristics are discussed in the Section “DC Characteristics” of the AT8xC51SND2C datasheet. The status of the Port pins during reset is detailed in Table 59. Figure 22. Reset Circuitry and Power-On Reset VDD Reset P From Internal Reset Source To CPU Core and Peripherals VDD RST RRST + RST VSS RST input circuitry Power-on Reset Table 59. Pin Conditions in Special Operating Modes Mode Reset Idle Power-down Port 0 Floating Data Data Port 1 High Data Data Port 2 High Data Data Port 3 High Data Data Port 4 High Data Data Port 5 High Data Data MMC Floating Data Data Audio 1 Data Data Note: 1. Refer to section “Audio Output Interface”, page 73. Cold Reset 2 conditions are required before enabling a CPU start-up: • • VDD must reach the specified VDD range The level on X1 input pin must be outside the specification (VIH, VIL) If one of these 2 conditions are not met, the microcontroller does not start correctly and can execute an instruction fetch from anywhere in the program space. An active level applied on the RST pin must be maintained till both of the above conditions are met. A reset is active when the level VIH1 is reached and when the pulse width covers the period of time where VDD and the oscillator are not stabilized. 2 parameters have to be taken into account to determine the reset pulse width: • • VDD rise time, Oscillator startup time. To determine the capacitor value to implement, the highest value of these 2 parameters has to be chosen. Table 60 gives some capacitor values examples for a minimum RRST of 50 KΩ and different oscillator startup and VDD rise times. 46 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Table 60. Minimum Reset Capacitor Value for a 50 kΩ Pull-down Resistor(1) Oscillator Start-Up Time 5 ms 20 ms Note: VDD Rise Time 1 ms 820 nF 2.7 µF 10 ms 1.2 µF 3.9 µF 100 ms 12 µF 12 µF 1. These values assume VDD starts from 0V to the nominal value. If the time between 2 on/off sequences is too fast, the power-supply de-coupling capacitors may not be fully discharged, leading to a bad reset sequence. Warm Reset To achieve a valid reset, the reset signal must be maintained for at least 2 machine cycles (24 oscillator clock periods) while the oscillator is running. The number of clock periods is mode independent (X2 or X1). As detailed in section “Watchdog Timer”, page 59, the WDT generates a 96-clock period pulse on the RST pin. In order to properly propagate this pulse to the rest of the application in case of external capacitor or power-supply supervisor circuit, a 1 kΩ resistor must be added as shown in Figure 23. Figure 23. Reset Circuitry for WDT Reset-out Usage VDD Watchdog Reset + VDD RST VDD 1K P From WDT Reset Source To CPU Core and Peripherals RST RRST VSS VSS To Other On-board Circuitry Reset Recommendation to Prevent Flash Corruption An example of bad initialization situation may occur in an instance where the bit ENBOOT in AUXR1 register is initialized from the hardware bit BLJB upon reset. Since this bit allows mapping of the bootloader in the code area, a reset failure can be critical. If one wants the ENBOOT cleared in order to unmap the boot from the code area (yet due to a bad reset) the bit ENBOOT in SFRs may be set. If the value of Program Counter is accidently in the range of the boot memory addresses then a Flash access (write or erase) may corrupt the Flash on-chip memory. It is recommended to use an external reset circuitry featuring power supply monitoring to prevent system malfunction during periods of insufficient power supply voltage (power supply failure, power supply switched off). Idle Mode Idle mode is a power reduction mode that reduces the power consumption. In this mode, program execution halts. Idle mode freezes the clock to the CPU at known states while the peripherals continue to be clocked (refer to section “Oscillator”, page 12). The CPU status before entering Idle mode is preserved, i.e., the program counter and program status word register retain their data for the duration of Idle mode. The contents of the SFRs and RAM are also retained. The status of the Port pins during Idle mode is detailed in Table 59. 47 4341D–MP3–04/05 Entering Idle Mode To enter Idle mode, the user must set the IDL bit in PCON register (see Table 61). The AT8xC51SND2C enters Idle mode upon execution of the instruction 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 AT8xC51SND2C enter Power-down mode. Then it does not go in Idle mode when exiting Power-down mode. Exiting Idle Mode There are 2 ways to exit Idle mode: 1. Generate an enabled interrupt. – Hardware clears IDL bit in PCON register which restores 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. 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 AT8xC51SND2C and vectors the CPU to address C:0000h. During the time that execution resumes, the internal RAM cannot be accessed; however, it is possible for the Port pins to be accessed. To avoid unexpected outputs at the Port pins, the instruction immediately following the instruction that activated Idle mode should not write to a Port pin or to the external RAM. 2. Generate a reset. – Note: Power-down Mode The Power-down mode places the AT8xC51SND2C in a very low power state. Powerdown mode stops the oscillator and freezes all clocks at known states (refer to the Section "Oscillator", page 12). The CPU status prior to entering Power-down 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 59. Note: VDD may be reduced to as low as VRET during Power-down mode to further reduce power dissipation. Notice, however, that VDD is not reduced until Power-down mode is invoked. Entering Power-down Mode To enter Power-down mode, set PD bit in PCON register. The AT8xC51SND2C enters the Power-down mode upon execution of the instruction that sets PD bit. The instruction that sets PD bit is the last instruction executed. If VDD was reduced during the Power-down mode, do not exit Power-down mode until VDD is restored to the normal operating level. There are 2 ways to exit the Power-down mode: 1. Generate an enabled external interrupt. – The AT8xC51SND2C provides capability to exit from Power-down using INT0, INT1, and KIN0 inputs. In addition, using KIN input provides high or low level exit capability (see section “Keyboard Interface”, page 198). Hardware clears PD bit in PCON register which starts the oscillator and restores the clocks to the CPU and peripherals. Using INTn input, execution Exiting Power-down Mode 48 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C resumes when the input is released (see Figure 24) while using KINx input, execution resumes after counting 1024 clock ensuring the oscillator is restarted properly (see Figure 25). 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-down mode must be configured as level sensitive (INT0 and INT1) and must be assigned the highest priority. In addition, the duration of the interrupt must be long enough to allow the oscillator to stabilize. The execution will only resume when the interrupt is deasserted. 2. Exit from power-down by external interrupt does not affect the SFRs nor the internal RAM content. Figure 24. Power-down Exit Waveform Using INT1:0 INT1:0 OSC Active phase Power-down Phase Oscillator Restart Phase Active Phase Figure 25. Power-down Exit Waveform Using KIN0 KIN01 OSC Active phase Power-down Phase 1024 clock count Active phase Note: 1. KIN0 can be high or low-level triggered. 2. Generate a reset. – A logic high on the RST pin clears PD bit in PCON register directly and asynchronously. This starts the oscillator and restores the clock to the CPU and peripherals. Program execution momentarily resumes with the instruction immediately following the instruction that activated Power-down mode and may continue for a number of clock cycles before the internal reset algorithm takes control. Reset initializes the AT8xC51SND2C and vectors the CPU to address 0000h. 1. During the time that execution resumes, the internal RAM cannot be accessed; however, it is possible for the Port pins to be accessed. To avoid unexpected outputs at the Port pins, the instruction immediately following the instruction that activated the Power-down mode should not write to a Port pin or to the external RAM. 2. Exit from power-down by reset redefines all the SFRs, but does not affect the internal RAM content. Notes: 49 4341D–MP3–04/05 Registers Table 61. PCON Register PCON (S:87h) – Power Configuration Register 7 SMOD1 Bit Number 7 6 SMOD0 5 4 3 GF1 2 GF0 1 PD 0 IDL Bit Mnemonic Description SMOD1 Serial Port Mode Bit 1 Set to select double baud rate in mode 1,2 or 3. Serial Port Mode Bit 0 Set to select FE bit in SCON register. Clear to select SM0 bit in SCON register. Reserved The value read from these bits is indeterminate. Do not set these bits. General-Purpose Flag 1 One use is to indicate whether an interrupt occurred during normal operation or during Idle mode. General-Purpose Flag 0 One use is to indicate whether an interrupt occurred during normal operation or during Idle mode. Power-Down Mode Bit Cleared by hardware when an interrupt or reset occurs. Set to activate the Power-down mode. If IDL and PD are both set, PD takes precedence. Idle Mode Bit Cleared by hardware when an interrupt or reset occurs. Set to activate the Idle mode. If IDL and PD are both set, PD takes precedence. 6 SMOD0 5-4 - 3 GF1 2 GF0 1 PD 0 IDL Reset Value = 00XX 0000b 50 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Timers/Counters The AT8xC51SND2C implement 2 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 Timer, the Timer/Counter runs for a programmed length of time, then issues an interrupt request. When operating as a Counter, the Timer/Counter counts negative transitions on an external 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. 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 62) turns the Timer on by allowing the selected input to increment 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. Timer registers can be accessed to obtain the current count or to enter preset values. They can be 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 Counter operation by selecting the divided-down peripheral clock or external pin Tx as the source for the counted signal. TRx bit must be cleared when changing the mode of operation, otherwise 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 peripheral cycle (6 peripheral clock periods). The Timer clock rate is FPER/6, i.e., FOSC/12 in standard mode or FOSC/6 in X2 mode. For Counter operation (C/Tx# = 1), the Timer register counts the negative transitions on the Tx external input pin. The external input is sampled every 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 transition, the maximum count rate is FPER/12, i.e., FOSC/24 in standard mode or FOSC/12 in X2 mode. There are no restrictions on the duty 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. Timer Clock Controller As shown in Figure 26, the Timer 0 (FT0) and Timer 1 (FT1) clocks are derived from either the peripheral clock (FPER) or the oscillator clock (FOSC) depending on the T0X2 and T1X2 bits in CKCON register. These clocks are issued from the Clock Controller block as detailed in Section “Clock Controller”, page 12. When T0X2 or T1X2 bit is set, the Timer 0 or Timer 1 clock frequency 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. 51 4341D–MP3–04/05 Figure 26. Timer 0 and Timer 1 Clock Controller and Symbols PER CLOCK OSC CLOCK 0 1 Timer 0 Clock PER CLOCK OSC CLOCK 0 1 Timer 1 Clock ÷2 T0X2 CKCON.1 ÷2 T1X2 CKCON.2 TIM0 CLOCK TIM1 CLOCK Timer 0 Clock Symbol Timer 1 Clock Symbol Timer 0 Timer 0 functions as either a Timer or event Counter in four modes of operation. Figure 27 through Figure 33 show the logical configuration of each mode. Timer 0 is controlled by the four lower bits of TMOD register (see Table 63) and bits 0, 1, 4 and 5 of TCON register (see Table 62). TMOD register selects the method of Timer gating (GATE0), Timer or Counter operation (C/T0#) and mode of operation (M10 and M00). TCON register provides 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 all 0s) sets TF0 flag generating an interrupt request. It is important to stop Timer/Counter before changing mode. 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 five bits of TL0 register (see Figure 27). The upper three bits of TL0 register are indeterminate and should be ignored. Prescaler overflow increments TH0 register. Figure 28 gives the overflow period calculation formula. Figure 27. Timer/Counter x (x = 0 or 1) in Mode 0 TIMx CLOCK Tx ÷6 0 1 C/Tx# TMOD Reg INTx GATEx TMOD Reg TRx TCON Reg TLx (5 Bits) THx (8 Bits) Overflow Timer x Interrupt Request TFx TCON reg Figure 28. Mode 0 Overflow Period Formula TFxPER= 6 ⋅ (16384 – (THx, TLx)) FTIMx 52 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Mode 1 (16-bit Timer) Mode 1 configures Timer 0 as a 16-bit Timer with TH0 and TL0 registers connected in cascade (see Figure 29). The selected input increments TL0 register. Figure 30 gives the overflow period calculation formula when in timer mode. Figure 29. Timer/Counter x (x = 0 or 1) in Mode 1 TIMx CLOCK ÷6 0 1 THx (8 bits) TLx (8 bits) Overflow TFx TCON Reg Tx Timer x Interrupt Request C/Tx# TMOD Reg INTx GATEx TMOD Reg TRx TCON Reg Figure 30. Mode 1 Overflow Period Formula TFxPER= 6 ⋅ (65536 – (THx, TLx)) FTIMx Mode 2 (8-bit Timer with AutoReload) Mode 2 configures Timer 0 as an 8-bit Timer (TL0 register) that automatically reloads from TH0 register (see Table 64). 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 next reload value may be changed at any time by writing it to TH0 register. Figure 32 gives the autoreload period calculation formula when in timer mode. Figure 31. Timer/Counter x (x = 0 or 1) in Mode 2 TIMx CLOCK ÷6 0 1 TLx (8 bits) Overflow TFx TCON reg Tx Timer x Interrupt Request C/Tx# TMOD reg INTx GATEx TMOD reg TRx TCON reg THx (8 bits) Figure 32. Mode 2 Autoreload Period Formula TFxPER= 6 ⋅ (256 – THx) FTIMx Mode 3 (2 8-bit Timers) Mode 3 configures Timer 0 such that registers TL0 and TH0 operate as separate 8-bit Timers (see Figure 33). This mode is provided for applications requiring an additional 8bit Timer or Counter. TL0 uses the Timer 0 control bits C/T0# and GATE0 in TMOD register, and TR0 and TF0 in TCON register in the normal manner. TH0 is locked into a Timer function (counting FTF1/6) and takes over use of the Timer 1 interrupt (TF1) and run control (TR1) bits. Thus, operation of Timer 1 is restricted when Timer 0 is in mode 53 4341D–MP3–04/05 3. Figure 32 gives the autoreload period calculation formulas for both TF0 and TF1 flags. Figure 33. Timer/Counter 0 in Mode 3: 2 8-bit Counters TIM0 CLOCK ÷6 0 1 TL0 (8 bits) Overflow TF0 TCON.5 T0 Timer 0 Interrupt Request C/T0# TMOD.2 INT0 GATE0 TMOD.3 TR0 TCON.4 TIM0 CLOCK ÷6 TH0 (8 bits) TR1 TCON.6 Overflow TF1 TCON.7 Timer 1 Interrupt Request Figure 34. Mode 3 Overflow Period Formula TF0PER = 6 ⋅ (256 – TL0) FTIM0 TF1PER = 6 ⋅ (256 – TH0) FTIM0 Timer 1 Timer 1 is identical to Timer 0 except for Mode 3 which is a hold-count mode. The following comments help to understand the differences: • Timer 1 functions as either a Timer or event Counter in three modes of operation. Figure 27 through Figure 31 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 Figure 63) and bits 2, 3, 6 and 7 of TCON register (see Figure 62). 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 the Serial Port. Mode 2 is best suited for this purpose. For normal Timer operation (GATE1 = 0), setting TR1 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 overflow 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 changing modes. • • • • • • 54 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C 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 27). The upper 3 bits of TL1 register are ignored. Prescaler overflow increments TH1 register. Mode 1 configures Timer 1 as a 16-bit Timer with TH1 and TL1 registers connected in cascade (see Figure 29). The selected input increments TL1 register. Mode 2 configures Timer 1 as an 8-bit Timer (TL1 register) with automatic reload from TH1 register on overflow (see Figure 31). TL1 overflow sets TF1 flag in TCON register and reloads TL1 with the contents of TH1, which is preset by software. The reload leaves TH1 unchanged. Placing Timer 1 in mode 3 causes it to halt and hold 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. 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 cleared when vectoring to the Timer interrupt routine. Interrupts are enabled by setting ETx bit in IEN0 register. This assumes interrupts are globally enabled by setting EA bit in IEN0 register. Mode 1 (16-bit Timer) Mode 2 (8-bit Timer with AutoReload) Mode 3 (Halt) Interrupt Figure 35. Timer Interrupt System TF0 TCON.5 Timer 0 Interrupt Request ET0 IEN0.1 TF1 TCON.7 Timer 1 Interrupt Request ET1 IEN0.3 55 4341D–MP3–04/05 Registers Table 62. TCON Register TCON (S:88h) – Timer/Counter Control Register 7 TF1 Bit Number 7 6 TR1 5 TF0 4 TR0 3 IE1 2 IT1 1 IE0 0 IT0 Bit Mnemonic Description TF1 Timer 1 Overflow Flag Cleared by hardware when processor vectors to interrupt routine. Set by hardware on Timer/Counter overflow, when Timer 1 register overflows. Timer 1 Run Control Bit Clear to turn off Timer/Counter 1. Set to turn on Timer/Counter 1. Timer 0 Overflow Flag Cleared by hardware when processor vectors to interrupt routine. Set by hardware on Timer/Counter overflow, when Timer 0 register overflows. Timer 0 Run Control Bit Clear to turn off Timer/Counter 0. Set to turn on Timer/Counter 0. Interrupt 1 Edge Flag Cleared by hardware when interrupt is processed if edge-triggered (see IT1). Set by hardware when external interrupt is detected on INT1 pin. Interrupt 1 Type Control Bit 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. Interrupt 0 Edge Flag Cleared by hardware when interrupt is processed if edge-triggered (see IT0). Set by hardware when external interrupt is detected on INT0 pin. Interrupt 0 Type Control Bit 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. 6 TR1 5 TF0 4 TR0 3 IE1 2 IT1 1 IE0 0 IT0 Reset Value = 0000 0000b 56 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Table 63. TMOD Register TMOD (S:89h) – Timer/Counter Mode Control Register 7 GATE1 6 C/T1# 5 M11 4 M01 3 GATE0 2 C/T0# 1 M10 0 M00 Bit Bit Number Mnemonic Description 7 GATE1 Timer 1 Gating Control Bit 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. Timer 1 Counter/Timer Select Bit Clear for Timer operation: Timer 1 counts the divided-down system clock. Set for Counter operation: Timer 1 counts negative transitions on external pin T1. Timer 1 Mode Select Bits M11 M01 Operating mode 0 0 Mode 0: 8-bit Timer/Counter (TH1) with 5-bit prescaler (TL1). 0 1 Mode 1: 16-bit Timer/Counter. 1 0 Mode 2: 8-bit auto-reload Timer/Counter (TL1).(1) 1 3 GATE0 1 Mode 3: Timer 1 halted. Retains count. 6 5 C/T1# M11 4 M01 Timer 0 Gating Control Bit Clear to enable Timer 0 whenever TR0 bit is set. Set to enable Timer/Counter 0 only while INT0 pin is high and TR0 bit is set. Timer 0 Counter/Timer Select Bit Clear for Timer operation: Timer 0 counts the divided-down system clock. Set for Counter operation: Timer 0 counts negative transitions on external pin T0. Timer 0 Mode Select Bit M10 M00 Operating mode 0 0 Mode 0: 8-bit Timer/Counter (TH0) with 5-bit prescaler (TL0). 0 1 Mode 1: 16-bit Timer/Counter. 1 0 Mode 2: 8-bit auto-reload Timer/Counter (TL0).(2) 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. 2 C/T0# M10 1 0 M00 Notes: 1. Reloaded from TH1 at overflow. 2. Reloaded from TH0 at overflow. Reset Value = 0000 0000b Table 64. TH0 Register TH0 (S:8Ch) – Timer 0 High Byte Register 7 Bit Number 7:0 6 5 4 3 2 1 0 - Bit Mnemonic Description High Byte of Timer 0 Reset Value = 0000 0000b 57 4341D–MP3–04/05 Table 65. TL0 Register TL0 (S:8Ah) – Timer 0 Low Byte Register 7 Bit Number 7:0 6 5 4 3 2 1 0 - Bit Mnemonic Description Low Byte of Timer 0 Reset Value = 0000 0000b Table 66. TH1 Register TH1 (S:8Dh) – Timer 1 High Byte Register 7 Bit Number 7:0 6 5 4 3 2 1 0 - Bit Mnemonic Description High Byte of Timer 1 Reset Value = 0000 0000b Table 67. TL1 Register TL1 (S:8Bh) – Timer 1 Low Byte Register 7 Bit Number 7:0 6 5 4 3 2 1 0 - Bit Mnemonic Description Low Byte of Timer 1 Reset Value = 0000 0000b 58 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Watchdog Timer The AT8xC51SND2C 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. The WDT consists of a 14-bit prescaler followed by a 7-bit programmable counter. As shown in Figure 36, the 14-bit prescaler is fed by the WDT clock detailed in Section “Watchdog Clock Controller”, page 59. The Watchdog Timer Reset register (WDTRST, see Table 69) provides control access to the WDT, while the Watchdog Timer Program register (WDTPRG, see Figure 39) provides time-out period programming. Three operations control the WDT: • • • Figure 36. WDT Block Diagram WDT CLOCK ÷6 Description Chip reset clears and disables the WDT. Programming the time-out value to the WDTPRG register. Writing a specific 2-Byte sequence to the WDTRST register clears and enables the WDT. 14-bit Prescaler RST 7-bit Counter OV RST SET To internal reset 1Eh-E1h Decoder System Reset RST WTO2:0 EN WDTPRG.2:0 MATCH OSC CLOCK Pulse Generator RST WDTRST Watchdog Clock Controller As shown in Figure 37 the WDT clock (FWDT) is derived from either the peripheral clock (FPER) or the oscillator clock (FOSC) depending on the WTX2 bit in CKCON register. These 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 and 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 37. WDT Clock Controller and Symbol PER CLOCK OSC CLOCK 0 1 WDT CLOCK WDT Clock ÷2 WTX2 CKCON.6 WDT Clock Symbol 59 4341D–MP3–04/05 Watchdog Operation After reset, the WDT is disabled. The WDT is enabled by writing the sequence 1Eh and E1h into the WDTRST register. As soon as it is enabled, there is no way except the chip reset to disable it. If it is not cleared using the previous sequence, the WDT overflows and forces a chip reset. This overflow generates a high level 96 oscillator periods pulse on the RST pin to globally reset the application (refer to Section “Power Management”, page 46). The WDT time-out period can be adjusted using WTO2:0 bits located in the WDTPRG register accordingly to the formula shown in Figure 38. In this formula, WTOval represents the decimal value of WTO2:0 bits. Table 68 reports the time-out period depending on the WDT frequency. Figure 38. WDT Time-Out Formula WDTTO= 6 ⋅ ((214 ⋅ 2WTOval) – 1) FWDT Table 68. WDT Time-Out Computation FWDT (ms) WTO2 0 0 0 0 1 1 1 1 WTO1 0 0 1 1 0 0 1 1 WTO0 0 1 0 1 0 1 0 1 6 MHz(1) 16.38 32.77 65.54 131.07 262.14 524.29 1049 2097 8 MHz(1) 12.28 24.57 49.14 98.28 196.56 393.1 786.24 1572 10 MHz(1) 9.83 19.66 39.32 78.64 157.29 314.57 629.15 1258 12 MHz(2) 8.19 16.38 32.77 65.54 131.07 262.14 524.29 1049 16 MHz(2) 6.14 12.28 24.57 49.14 98.28 196.56 393.12 786.24 20 MHz(2) 4.92 9.83 19.66 39.32 78.64 157.29 314.57 629.15 Notes: 1. These frequencies are achieved in X1 mode or in X2 mode when WTX2 = 1: FWDT = FOSC ÷ 2. 2. These frequencies are achieved in X2 mode when WTX2 = 0: FWDT = FOSC. WDT Behavior during Idle and Power-down Modes Operation of the WDT during power reduction modes deserves special attention. The WDT continues to count while the AT8xC51SND2C is in Idle mode. This means that you must dedicate some internal or external hardware to service the WDT during Idle mode. One approach is to use a peripheral Timer to generate an interrupt request when the Timer overflows. The interrupt service routine then clears the WDT, reloads the peripheral Timer for the next service period and puts the AT8xC51SND2C back into Idle mode. The Power-down mode stops all phase clocks. This causes the WDT to stop counting and to hold its count. The WDT resumes counting from where it left off if the Powerdown mode is terminated by INT0, INT1 or keyboard interrupt. To ensure that the WDT does not overflow shortly after exiting the Power-down mode, it is recommended to clear the WDT just before entering Power-down mode. The WDT is cleared and disabled if the Power-down mode is terminated by a reset. 60 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Registers Table 69. WDTRST Register WDTRST (S:A6h Write only) – Watchdog Timer Reset Register 7 Bit Number 7-0 6 5 4 3 2 1 0 - Bit Mnemonic Description Watchdog Control Value Reset Value = XXXX XXXXb Figure 39. WDTPRG Register WDTPRG (S:A7h) – Watchdog Timer Program Register 7 Bit Number 7-3 2-0 6 5 4 3 2 WTO2 1 WTO1 0 WTO0 Bit Mnemonic Description WTO2:0 Reserved The value read from these bits is indeterminate. Do not set these bits. Watchdog Timer Time-Out Selection Bits Refer to Table 68 for time-out periods. Reset Value = XXXX X000b 61 4341D–MP3–04/05 MP3 Decoder The AT8xC51SND2C implement a MPEG I/II audio layer 3 decoder better known as MP3 decoder. In MPEG I (ISO 11172-3) three layers of compression have been standardized supporting three sampling frequencies: 48, 44.1, and 32 kHz. Among these layers, layer 3 allows highest compression rate of about 12:1 while still maintaining CD audio quality. For example, 3 minutes of CD audio (16-bit PCM, 44.1 kHz) data, which needs about 32M bytes of storage, can be encoded into only 2.7M bytes of MPEG I audio layer 3 data. In MPEG II (ISO 13818-3), three additional sampling frequencies: 24, 22.05, and 16 kHz are supported for low bit rates applications. The AT8xC51SND2C can decode in real-time the MPEG I audio layer 3 encoded data into a PCM audio data, and also supports MPEG II audio layer 3 additional frequencies. Additional features are supported by the AT8xC51SND2C MP3 decoder such as volume control, bass, medium, and treble controls, bass boost effect and ancillary data extraction. Decoder Description The C51 core interfaces to the MP3 decoder through nine special function registers: MP3CON, the MP3 Control register (see Table 74); MP3STA, the MP3 Status register (see Table 75); MP3DAT, the MP3 Data register (see Table 76); MP3ANC, the Ancillary Data register (see Table 78); MP3VOL and MP3VOR, the MP3 Volume Left and Right Control registers (see Table 79 and Table 80); MP3BAS, MP3MED, and MP3TRE, the MP3 Bass, Medium, and Treble Control registers (see Table 81, Table 82, and Table 83); and MPCLK, the MP3 Clock Divider register (see Table 84). Figure 40 shows the MP3 decoder block diagram. Figure 40. MP3 Decoder Block Diagram Audio Data From C51 8 1K Bytes Frame Buffer MP3DAT MPxREQ MP3STA1.n Header Checker Huffman Decoder Dequantizer Stereo Processor Side Information MP3 CLOCK ERRxxx MPFS1:0 MPVER MP3STA.5:3 MP3STA.2:1 MP3STA.0 Ancillary Buffer MP3ANC MPEN MP3CON.7 Anti-Aliasing IMDCT Sub-band Synthesis 16 Decoded Data To Audio Interface MPBBST MP3CON.6 MP3VOL MP3VOR MP3BAS MP3MED MP3TRE 62 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C MP3 Data The MP3 decoder does not start any frame decoding before having a complete frame in its input buffer(1). In order to manage the load of MP3 data in the frame buffer, a hardware handshake consisting of data request and data acknowledgment is implemented. Each time the MP3 decoder needs MP3 data, it sets the MPREQ, MPFREQ and MPBREQ flags respectively in MP3STA and MP3STA1 registers. MPREQ flag can generate an interrupt if enabled as explained in Section “Interrupt”. The CPU must then load data in the buffer by writing it through MP3DAT register thus acknowledging the previous request. As shown in Figure 41, the MPFREQ flag remains set while data (i.e a frame) is requested by the decoder. It is cleared when no more data is requested and set again when new data are requested. MPBREQ flag toggles at every Byte writing. Note: 1. The first request after enable, consists in 1024 Bytes of data to fill in the input buffer. Figure 41. Data Timing Diagram MPREQ Flag MPFREQ Flag MPBREQ Flag Write to MP3DAT Cleared when Reading MP3STA MP3 Clock The MP3 decoder clock is generated by division of the PLL clock. The division factor is given by MPCD4:0 bits in MP3CLK register. Figure 42 shows the MP3 decoder clock generator and its calculation formula. The MP3 decoder clock frequency depends only on the incoming MP3 frames. Figure 42. MP3 Clock Generator and Symbol PLL CLOCK MP3CLK MPCD4:0 MP3 Decoder Clock MP3 CLOCK MP3 Clock Symbol PLLclk MP3clk = ---------------------------MPCD + 1 As soon as the frame header has been decoded and the MPEG version extracted, the minimum MP3 input frequency must be programmed according to Table 70. Table 70. MP3 Clock Frequency MPEG Version I II Minimum MP3 Clock (MHz) 21 10.5 63 4341D–MP3–04/05 Audio Controls Volume Control The MP3 decoder implements volume control on both right and left channels. The MP3VOR and MP3VOL registers allow a 32-step volume control according to Table 71. Table 71. Volume Control VOL4:0 or VOR4:0 00000 00001 00010 11110 11111 Volume Gain (dB) Mute -33 -27 -1.5 0 Equalization Control Sound can be adjusted using a 3-band equalizer: a bass band under 750 Hz, a medium band from 750 Hz to 3300 Hz and a treble band over 3300 Hz. The MP3BAS, MP3MED, and MP3TRE registers allow a 32-step gain control in each band according to Table 72. Table 72. Bass, Medium, Treble Control BAS4:0 or MED4:0 or TRE4:0 00000 00001 00010 11110 11111 Gain (dB) -∞ -14 -10 +1 +1.5 Special Effect The MPBBST bit in MP3CON register allows enabling of a bass boost effect with the following characteristics: gain increase of +9 dB in the frequency under 375 Hz. The three different errors that can appear during frame processing are detailed in the following sections. All these errors can trigger an interrupt as explained in Section "Interrupt", page 66. The ERRSYN flag in MP3STA is set when a non-supported layer is decoded in the header of the frame that has been sent to the decoder. The ERRSYN flag in MP3STA is set when no synchronization pattern is found in the data that have been sent to the decoder. When the CRC of a frame does not match the one calculated, the flag ERRCRC in MP3STA is set. In this case, depending on the CRCEN bit in MP3CON, the frame is played or rejected. In both cases, noise may appear at audio output. Decoding Errors Layer Error Synchronization Error CRC Error 64 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Frame Information The MP3 frame header contains information on the audio data contained in the frame. These informations is made available in the MP3STA register for you information. MPVER and MPFS1:0 bits allow decoding of the sampling frequency according to Table 73. MPVER bit gives the MPEG version (2 or 1). Table 73. MP3 Frame Frequency Sampling MPVER 0 0 0 0 1 1 1 1 MPFS1 0 0 1 1 0 0 1 1 MPFS0 0 1 0 1 0 1 0 1 Fs (kHz) 22.05 (MPEG II) 24 (MPEG II) 16 (MPEG II) Reserved 44.1 (MPEG I) 48 (MPEG I) 32 (MPEG I) Reserved Ancillary Data MP3 frames also contain data bits called ancillary data. These data are made available in the MP3ANC register for each frame. As shown in Figure 43, the ancillary data are available by Bytes when MPANC flag in MP3STA register is set. MPANC flag is set when the ancillary buffer is not empty (at least one ancillary data is available) and is cleared only when there is no more ancillary data in the buffer. This flag can generate an interrupt as explained in Section "Interrupt", page 66. When set, software must read all Bytes to empty the ancillary buffer. Figure 43. Ancillary Data Block Diagram Ancillary Data To C51 8 MP3ANC 8 7-Byte Ancillary Buffer MPANC MP3STA.7 65 4341D–MP3–04/05 Interrupt Description As shown in Figure 44, the MP3 decoder implements five interrupt sources reported in ERRCRC, ERRSYN, ERRLAY, MPREQ, and MPANC flags in MP3STA register. All these sources are maskable separately using MSKCRC, MSKSYN, MSKLAY, MSKREQ, and MSKANC mask bits respectively in MP3CON register. The MP3 interrupt is enabled by setting EMP3 bit in IEN0 register. This assumes interrupts are globally enabled by setting EA bit in IEN0 register. All interrupt flags but MPREQ and MPANC are cleared when reading MP3STA register. The MPREQ flag is cleared by hardware when no more data is requested (see Figure 41) and MPANC flag is cleared by hardware when the ancillary buffer becomes empty. Figure 44. MP3 Decoder Interrupt System MPANC MP3STA.7 MSKANC MPREQ MP3STA.6 MP3CON.4 MSKREQ ERRLAY MP3STA.5 MP3CON.3 MP3 Decoder Interrupt Request MSKLAY EMP3 IEN0.5 ERRSYN MP3STA.4 MP3CON.2 MSKSYN ERRCRC MP3STA.3 MP3CON.1 MSKCRC MP3CON.0 Management Reading the MP3STA register automatically clears the interrupt flags (acknowledgment) except the MPREQ and MPANC flags. This implies that register content must be saved and tested, interrupt flag by interrupt flag to be sure not to forget any interrupts. 66 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Figure 45. MP3 Interrupt Service Routine Flow MP3 Decoder ISR Read MP3STA Data Request? MPFREQ = 1? Data Request Handler Ancillary Data?(1) MPANC = 1? Write MP3 Data to MP3DAT Ancillary Data Handler Sync Error?(1) ERRSYN = 1? Read ANN2:0 Ancillary Bytes From MP3ANC Synchro Error Handler Layer Error?(1) ERRSYN = 1? Reload MP3 Frame Through MP3DAT Layer Error Handler CRC Error Handler Load New MP3 Frame Through MP3DAT Note: 1. Test these bits only if needed (unmasked interrupt). 67 4341D–MP3–04/05 Registers Table 74. MP3CON Register MP3CON (S:AAh) – MP3 Decoder Control Register 7 MPEN Bit Number 7 6 MPBBST 5 CRCEN 4 MSKANC 3 MSKREQ 2 MSKLAY 1 MSKSYN 0 MSKCRC Bit Mnemonic Description MPEN MP3 Decoder Enable Bit Set to enable the MP3 decoder. Clear to disable the MP3 decoder. Bass Boost Bit Set to enable the bass boost sound effect. Clear to disable the bass boost sound effect. CRC Check Enable Bit Set to enable processing of frame that contains CRC error. Frame is played whatever the error. Clear to disable processing of frame that contains CRC error. Frame is skipped. MPANC Flag Mask Bit Set to prevent the MPANC flag from generating a MP3 interrupt. Clear to allow the MPANC flag to generate a MP3 interrupt. MPREQ Flag Mask Bit Set to prevent the MPREQ flag from generating a MP3 interrupt. Clear to allow the MPREQ flag to generate a MP3 interrupt. ERRLAY Flag Mask Bit Set to prevent the ERRLAY flag from generating a MP3 interrupt. Clear to allow the ERRLAY flag to generate a MP3 interrupt. ERRSYN Flag Mask Bit Set to prevent the ERRSYN flag from generating a MP3 interrupt. Clear to allow the ERRSYN flag to generate a MP3 interrupt. ERRCRC Flag Mask Bit Set to prevent the ERRCRC flag from generating a MP3 interrupt. Clear to allow the ERRCRC flag to generate a MP3 interrupt. 6 MPBBST 5 CRCEN 4 MSKANC 3 MSKREQ 2 MSKLAY 1 MSKSYN 0 MSKCRC Reset Value = 0011 1111b 68 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Table 75. MP3STA Register MP3STA (S:C8h Read Only) – MP3 Decoder Status Register 7 MPANC Bit Number 7 6 MPREQ 5 ERRLAY 4 ERRSYN 3 ERRCRC 2 MPFS1 1 MPFS0 0 MPVER Bit Mnemonic Description MPANC Ancillary Data Available Flag Set by hardware as soon as one ancillary data is available (buffer not empty). Cleared by hardware when no more ancillary data is available (buffer empty). MP3 Data Request Flag Set by hardware when MP3 decoder request data. Cleared when reading MP3STA. Invalid Layer Error Flag Set by hardware when an invalid layer is encountered. Cleared when reading MP3STA. Frame Synchronization Error Flag Set by hardware when no synchronization pattern is encountered in a frame. Cleared when reading MP3STA. CRC Error Flag Set by hardware when a frame handling CRC is corrupted. Cleared when reading MP3STA. Frequency Sampling Bits Refer to Table 73 for bits description. MPEG Version Bit Set by the MP3 decoder when the loaded frame is a MPEG I frame. Cleared by the MP3 decoder when the loaded frame is a MPEG II frame. 6 MPREQ 5 ERRLAY 4 ERRSYN 3 ERRCRC 2-1 MPFS1:0 0 MPVER Reset Value = 0000 0001b Table 76. MP3DAT Register MP3DAT (S:ACh) – MP3 Data Register 7 MPD7 Bit Number 7-0 6 MPD6 5 MPD5 4 MPD4 3 MPD3 2 MPD2 1 MPD1 0 MPD0 Bit Mnemonic Description MPD7:0 Input Stream Data Buffer 8-bit MP3 stream data input buffer. Reset Value = 0000 0000b 69 4341D–MP3–04/05 Table 77. MP3STA1 Register MP3STA1 (S:AFh) – MP3 Decoder Status Register 1 7 Bit Number 7-5 6 5 4 MPFREQ 3 MPFREQ 2 1 0 - Bit Mnemonic Description Reserved The value read from these bits is always 0. Do not set these bits. MP3 Frame Data Request Flag Set by hardware when MP3 decoder request data. Cleared when MP3 decoder no more request data . MP3 Byte Data Request Flag Set by hardware when MP3 decoder request data. Cleared when writing to MP3DAT. Reserved The value read from these bits is always 0. Do not set these bits. 4 MPFREQ 3 MPBREQ 2-0 - Reset Value = 0001 0001b Table 78. MP3ANC Register MP3ANC (S:ADh Read Only) – MP3 Ancillary Data Register 7 AND7 Bit Number 7-0 6 AND6 5 AND5 4 AND4 3 AND3 2 AND2 1 AND1 0 AND0 Bit Mnemonic Description AND7:0 Ancillary Data Buffer MP3 ancillary data Byte buffer. Reset Value = 0000 0000b Table 79. MP3VOL Register MP3VOL (S:9Eh) – MP3 Volume Left Control Register 7 Bit Number 7-5 4-0 6 5 4 VOL4 3 VOL3 2 VOL2 1 VOL1 0 VOL0 Bit Mnemonic Description VOL4:0 Reserved The value read from these bits is always 0. Do not set these bits. Volume Left Value Refer to Table 71 for the left channel volume control description. Reset Value = 0000 0000b 70 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Table 80. MP3VOR Register MP3VOR (S:9Fh) – MP3 Volume Right Control Register 7 Bit Number 7-5 4-0 6 5 4 VOR4 3 VOR3 2 VOR2 1 VOR1 0 VOR0 Bit Mnemonic Description VOR4:0 Reserved The value read from these bits is always 0. Do not set these bits. Volume Right Value Refer to Table 71 for the right channel volume control description. Reset Value = 0000 0000b Table 81. MP3BAS Register MP3BAS (S:B4h) – MP3 Bass Control Register 7 Bit Number 7-5 4-0 6 5 4 BAS4 3 BAS3 2 BAS2 1 BAS1 0 BAS0 Bit Mnemonic Description BAS4:0 Reserved The value read from these bits is always 0. Do not set these bits. Bass Gain Value Refer to Table 72 for the bass control description. Reset Value = 0000 0000b Table 82. MP3MED Register MP3MED (S:B5h) – MP3 Medium Control Register 7 Bit Number 7-6 5-0 6 5 MED5 4 MED4 3 MED3 2 MED2 1 MED1 0 MED0 Bit Mnemonic Description MED5:0 Reserved The value read from these bits is always 0. Do not set these bits. Medium Gain Value Refer to Table 72 for the medium control description. Reset Value = 0000 0000b 71 4341D–MP3–04/05 Table 83. MP3TRE Register MP3TRE (S:B6h) – MP3 Treble Control Register 7 Bit Number 7-6 5-0 6 5 TRE5 4 TRE4 3 TRE3 2 TRE2 1 TRE1 0 TRE0 Bit Mnemonic Description TRE5:0 Reserved The value read from these bits is always 0. Do not set these bits. Treble Gain Value Refer to Table 72 for the treble control description. Reset Value = 0000 0000b Table 84. MP3CLK Register MP3CLK (S:EBh) – MP3 Clock Divider Register 7 Bit Number 7-5 4-0 6 5 4 MPCD4 3 MPCD3 2 MPCD2 1 MPCD1 0 MPCD0 Bit Mnemonic Description MPCD4:0 Reserved The value read from these bits is always 0. Do not set these bits. MP3 Decoder Clock Divider 5-bit divider for MP3 decoder clock generation. Reset Value = 0000 0000b 72 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Audio Output Interface The AT8xC51SND2C implement an audio output interface allowing the audio bitstream to be output in various formats. It is compatible with right and left justification PCM and I2S formats and thanks to the on-chip PLL (see Section “Clock Controller”, page 12) allows connection of almost all of the commercial audio DAC families available on the market. The audio bitstream can be from 2 different types: • • The MP3 decoded bitstream coming from the MP3 decoder for playing songs. The audio bitstream coming from the MCU for outputting voice or sounds. Description The C51 core interfaces to the audio interface through five special function registers: AUDCON0 and AUDCON1, the Audio Control registers (see Table 86 and Table 87); AUDSTA, the Audio Status register (see Table 88); AUDDAT, the Audio Data register (see Table 89); and AUDCLK, the Audio Clock Divider register (see Table 90). Figure 46 shows the audio interface block diagram, blocks are detailed in the following sections. Figure 46. Audio Interface Block Diagram SCLK AUD CLOCK Clock Generator 0 DCLK DSEL AUDEN AUDCON1.0 1 HLR Data Ready Audio Data From MP3 Decoder Sample Request To MP3 Decoder AUDCON0.0 DSIZ AUDCON0.1 POL AUDCON0.2 16 MP3 Buffer 16 16 0 1 Data Converter DOUT DRQEN AUDCON1.6 JUST4:0 SRC AUDCON1.7 AUDCON0.7:3 SREQ Audio Data From C51 8 Audio Buffer AUDDAT AUDSTA.7 UDRN AUDSTA.6 AUBUSY DUP1:0 AUDCON1.2:1 AUDSTA.5 73 4341D–MP3–04/05 Clock Generator The audio interface clock is generated by division of the PLL clock. The division factor is given by AUCD4:0 bits in CLKAUD register. Figure 47 shows the audio interface clock generator and its calculation formula. The audio interface clock frequency depends on the incoming MP3 frames and the audio DAC used. Figure 47. Audio Clock Generator and Symbol PLL CLOCK AUDCLK AUCD4:0 Audio Interface Clock AUD CLOCK PLLclk AUDclk = --------------------------AU C D + 1 Audio Clock Symbol As soon as audio interface is enabled by setting AUDEN bit in AUDCON1 register, the master clock generated by the PLL is output on the SCLK pin which is the DAC system clock. This clock is output at 256 or 384 times the sampling frequency depending on the DAC capabilities. HLR bit in AUDCON0 register must be set according to this rate for properly generating the audio bit clock on the DCLK pin and the word selection clock on the DSEL pin. These clocks are not generated when no data is available at the data converter input. For DAC compatibility, the bit clock frequency is programmable for outputting 16 bits or 32 bits per channel using the DSIZ bit in AUDCON0 register (see Section "Data Converter", page 74), and the word selection signal is programmable for outputting left channel on low or high level according to POL bit in AUDCON0 register as shown in Figure 48. Figure 48. DSEL Output Polarity POL = 0 POL = 1 Left Channel Left Channel Right Channel Right Channel Data Converter The data converter block converts the audio stream input from the 16-bit parallel format to a serial format. For accepting all PCM formats and I2 S format, JUST4:0 bits in AUDCON0 register are used to shift the data output point. As shown in Figure 49, these bits allow MSB justification by setting JUST4:0 = 00000, LSB justification by setting JUST4:0 = 10000, I2S Justification by setting JUST4:0 = 00001, and more than 16-bit LSB justification by filling the low significant bits with logic 0. 74 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Figure 49. Audio Output Format DSEL DCLK DOUT 1 2 3 Left Channel 13 14 15 16 1 2 3 Right Channel 13 14 15 16 LSB MSB B14 B1 LSB MSB B14 B1 I2S Format with DSIZ = 0 and JUST4:0 = 00001. DSEL DCLK DOUT 1 2 3 Left Channel 17 18 32 1 2 3 Right Channel 17 18 32 MSB B14 LSB MSB B14 LSB I2S Format with DSIZ = 1 and JUST4:0 = 00001. DSEL DCLK DOUT 1 2 3 Left Channel 13 14 15 16 1 2 3 Right Channel 13 14 15 16 MSB B14 B1 LSB MSB B15 B1 LSB MSB/LSB Justified Format with DSIZ = 0 and JUST4:0 = 00000. DSEL DCLK DOUT 1 Left Channel 16 17 18 31 32 1 Right Channel 16 17 18 31 32 MSB B14 B1 LSB MSB B14 B1 LSB 16-bit LSB Justified Format with DSIZ = 1 and JUST4:0 = 10000. DSEL DCLK DOUT 1 Left Channel 15 16 30 31 32 1 Right Channel 15 16 30 31 32 MSB B16 B2 B1 LSB MSB B16 B2 B1 LSB 18-bit LSB Justified Format with DSIZ = 1 and JUST4:0 = 01110. The data converter receives its audio stream from 2 sources selected by the SRC bit in AUDCON1 register. When cleared, the audio stream comes from the MP3 decoder (see Section “MP3 Decoder”, page 62) for song playing. When set, the audio stream is coming from the C51 core for voice or sound playing. As soon as first audio data is input to the data converter, it enables the clock generator for generating the bit and word clocks. Audio Buffer In voice or sound playing mode, the audio stream comes 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 16 bits by filling the LSB to 00h. Rate is adapted to the DAC rate by duplicating the data using DUP1:0 bits in AUDCON1 register according to Table 85. 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 AUDSTA register) and the busy flag (AUBUSY in AUDSTA register). SREQ and UNDR can generate an interrupt request as explained in Section "Interrupt Request", page 76. The buffer size is 8 Bytes large. SREQ is set when the samples number switches from 4 to 3 and reset when the samples number switches from 4 to 5; UNDR is set when the buffer becomes empty signaling that the audio interface ran out of samples; and AUBUSY is set when the buffer is full. 75 4341D–MP3–04/05 Table 85. Sample Duplication Factor DUP1 0 0 1 1 DUP0 0 1 0 1 Factor No sample duplication, DAC rate = 8 kHz (C51 rate). One sample duplication, DAC rate = 16 kHz (2 x C51 rate). 2 samples duplication, DAC rate = 32 kHz (4 x C51 rate). Three samples duplication, DAC rate = 48 kHz (6 x C51 rate). MP3 Buffer In song playing mode, the audio stream comes from the MP3 decoder through a buffer. The MP3 buffer is used to store the decoded MP3 data and interfaces to the decoder through a 16-bit data input and data request signal. This signal asks for data when the buffer has enough space to receive new data. Data request is conditioned by the DREQEN bit in AUDCON1 register. When set, the buffer requests data to the MP3 decoder. When cleared no more data is requested but data are output until the buffer is empty. This bit can be used to suspend the audio generation (pause mode). The audio interrupt request can be generated by 2 sources when in C51 audio mode: a sample request when SREQ flag in AUDSTA register is set to logic 1, and an under-run condition when UDRN flag in AUDSTA register is set to logic 1. Both sources can be enabled separately by masking one of them using the MSREQ and MUDRN bits in AUDCON1 register. A global enable of the audio interface is provided by setting the EAUD bit in IEN0 register. The interrupt is requested each time one of the 2 sources is set to one. The source flags are cleared by writing some data in the audio buffer through AUDDAT, but the global audio interrupt flag is cleared by hardware when the interrupt service routine is executed. Figure 50. Audio Interface Interrupt System UDRN AUDSTA.6 Interrupt Request MUDRN AUDCON1.4 Audio Interrupt Request EAUD IEN0.6 SREQ AUDSTA.7 MSREQ AUDCON1.5 MP3 Song Playing In MP3 song playing mode, the operations to do are to configure the PLL and the audio interface according to the DAC selected. The audio clock is programmed to generate the 256·Fs or 384·Fs as explained in Section "Clock Generator", page 74. Figure 51 shows the configuration flow of the audio interface when in MP3 song mode. 76 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Figure 51. MP3 Mode Audio Configuration Flow MP3 Mode Configuration Enable DAC System Clock AUDEN = 1 Program Audio Clock Configure Interface HLR = X DSIZ = X POL = X JUST4:0 = XXXXXb SRC = 0 Wait For DAC Set-up Time Enable Data Request DRQEN = 1 Voice or Sound Playing In voice or sound playing mode, the operations required are to configure the PLL and the audio interface according to the DAC selected. The audio clock is programmed to generate the 256·Fs or 384·Fs as for the MP3 playing mode. The data flow sent by the C51 is then regulated by interrupt and data is loaded 4 Bytes by 4 Bytes. Figure 52 shows the configuration flow of the audio interface when in voice or sound mode. Figure 52. Voice or Sound Mode Audio Flows Voice/Song Mode Configuration Audio Interrupt Service Routine Program Audio Clock Wait for DAC Enable Time Sample Request? SREQ = 1? Configure Interface HLR = X DSIZ = X POL = X JUST4:0 = XXXXXb DUP1:0 = XX Select Audio SRC = 1 Load 4 Samples in the Audio Buffer Load 8 Samples in the Audio Buffer Under-run Condition1 Enable DAC System Clock AUDEN = 1 Enable Interrupt Set MSREQ & MUDRN1 EAUD = 1 Note: 1. An under-run occurrence signifies that C51 core did not respond to the previous sample request interrupt. It may never occur for a correct voice/sound generation. It is the user’s responsibility to mask it or not. 77 4341D–MP3–04/05 Registers Table 86. AUDCON0 Register AUDCON0 (S:9Ah) – Audio Interface Control Register 0 7 JUST4 Bit Number 7-3 6 JUST3 5 JUST2 4 JUST1 3 JUST0 2 POL 1 DSIZ 0 HLR Bit Mnemonic Description JUST4:0 Audio Stream Justification Bits Refer to Section "Data Converter", page 74 for bits description. DSEL Signal Output Polarity Set to output the left channel on high level of DSEL output (PCM mode). Clear to output the left channel on the low level of DSEL output (I2S mode). Audio Data Size Set to select 32-bit data output format. Clear to select 16-bit data output format. High/Low Rate Bit Set by software when the PLL clock frequency is 384·Fs. Clear by software when the PLL clock frequency is 256·Fs. 2 POL 1 DSIZ 0 HLR Reset Value = 0000 1000b Table 87. AUDCON1 Register AUDCON1 (S:9Bh) – Audio Interface Control Register 1 7 SRC Bit Number 7 6 DRQEN 5 MSREQ 4 MUDRN 3 2 DUP1 1 DUP0 0 AUDEN Bit Mnemonic Description SRC Audio Source Bit Set to select C51 as audio source for voice or sound playing. Clear to select the MP3 decoder output as audio source for song playing. MP3 Decoded Data Request Enable Bit Set to enable data request to the MP3 decoder and to start playing song. Clear to disable data request to the MP3 decoder. Audio Sample Request Flag Mask Bit Set to prevent the SREQ flag from generating an audio interrupt. Clear to allow the SREQ flag to generate an audio interrupt. Audio Sample Under-run Flag Mask Bit Set to prevent the UDRN flag from generating an audio interrupt. Clear to allow the UDRN flag to generate an audio interrupt. Reserved The value read from this bit is always 0. Do not set this bit. Audio Duplication Factor Refer to Table 85 for bits description. Audio Interface Enable Bit Set to enable the audio interface. Clear to disable the audio interface. 6 DRQEN 5 MSREQ 4 MUDRN 3 2-1 DUP1:0 0 AUDEN Reset Value = 1011 0010b 78 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Table 88. AUDSTA Register AUDSTA (S:9Ch Read Only) – Audio Interface Status Register 7 SREQ Bit Number 6 UDRN 5 AUBUSY 4 3 2 1 0 - Bit Mnemonic Description Audio Sample Request Flag Set in C51 audio source mode when the audio interface request samples (buffer half empty). This bit generates an interrupt if not masked and if enabled in IEN0. Cleared by hardware when samples are loaded in AUDDAT. Audio Sample Under-run Flag Set in C51 audio source mode when the audio interface runs out of samples (buffer empty). This bit generates an interrupt if not masked and if enabled in IEN0. Cleared by hardware when samples are loaded in AUDDAT. Audio Interface Busy Bit Set in C51 audio source mode when the audio interface can not accept more sample (buffer full). Cleared by hardware when buffer is no more full. Reserved The value read from these bits is always 0. Do not set these bits. 7 SREQ 6 UDRN 5 AUBUSY 4-0 - Reset Value = 1100 0000b Table 89. AUDDAT Register AUDDAT (S:9Dh) – Audio Interface Data Register 7 AUD7 Bit Number 7-0 6 AUD6 5 AUD5 4 AUD4 3 AUD3 2 AUD2 1 AUD1 0 AUD0 Bit Mnemonic Description AUD7:0 Audio Data 8-bit sampling data for voice or sound playing. Reset Value = 1111 1111b Table 90. AUDCLK Register AUDCLK (S:ECh) – Audio Clock Divider Register 7 Bit Number 7-5 4-0 6 5 4 AUCD4 3 AUCD3 2 AUCD2 1 AUCD1 0 AUCD0 Bit Mnemonic Description AUCD4:0 Reserved The value read from these bits is always 0. Do not set these bits. Audio Clock Divider 5-bit divider for audio clock generation. Reset Value = 0000 0000b 79 4341D–MP3–04/05 DAC and PA Interface The AT8xC51SND2C implements a stereo Audio Digital-to-Analog Converter and Audio Power Amplifier targeted for Li-Ion or Ni-Mh battery powered devices. Figure 53. Audio Interface Block Diagram MP3 Decoder Unit DOUT DCLK DSEL SCLK I2S/PCM Audio Interface Serial Audio Interface HSR HSL AUXP AUXN LINEL LINER MONOP MONON Audio DAC AUDCDIN AUDCDOUT AUDCCLK AUDCCS PAINP PAINN HPP HPN Audio PA DAC The Stereo DAC section is a complete high performance, stereo, audio digital-to-analog converter delivering 93 dB Dynamic Range. It comprises a multibit sigma-delta modulator with dither, continuous time analog filters and analog output drive circuitry. This architecture provides a high insensitivity to clock jitter. The digital interpolation filter increases the sample rate by a factor of 8 using 3 linear phase half-band filters cascaded, followed by a first order SINC interpolator with a factor of 8. This filter eliminates the images of baseband audio, remaining only the image at 64x the input sample rate, which is eliminated by the analog post filter. Optionally, a dither signal can be added that may reduce eventual noise tones at the output. However, the use of a multibit sigmadelta modulator already provides extremely low noise tones energy. Master clock is 128 up to 512 times the input data rate allowing choice of input data rate up to 50 kHz, including standard audio rates of 48, 44.1, 32, 16 and 8 kHz. The DAC section is followed by a volume and mute control and can be simultaneously played back directly through a Stereo 32Ω Headset pair of drivers. The Stereo 32Ω Headset pair of drivers also includes a mixer of a LINEL and LINER pair of stereo inputs as well as a differential monaural auxiliary input (line level). 80 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C DAC Features • 20 bit D/A Conversion • 72dB Dynamic Range, -75dB THD Stereo line-in or microphone interface with 20dB • • • • • • amplification 93dB Dynamic Range, -80dB THD Stereo D/A conversion 74dB Dynamic Range / -65dB THD for 20mW output power over 32 Ohm loads Stereo, Mono and Reverse Stereo Mixer Left/Right speaker short-circuit detection flag Differential mono auxiliary input amplifier and PA driver Audio sampling rates (Fs): 16, 22.05, 24, 32, 44.1 and 48 kHz. Figure 54. Stereo DAC functional diagram PA Gain MONOP PADRV MONON + AUXP AUX AUXN AUXG Gain LINEL PGA LLIG,RLIG Gain 20,12 to -33 dB (3dB) LINER PGA Line Out Gain LLOG, RLOG 0 to -46.5dB (1.5dB) Master Playback Gain 12 to -34dB (1.5dB) DSEL HSL SPKR DRV 32 DAC_OLC Gain 6 to -6dB (3dB) SPKR DRV 32 + DAC Volume Control + Volume Control Digital Filter SCLK Serial to Parallel Interface DCLK DOUT HSR + DAC Volume Control + Volume Control Digital Filter Digital Signals Timing Data Interface To avoid noises at the output, the reset state is maintained until proper synchronism is achieved in the DAC serial interface: • • • • DSEL SCLK DCLK DOUT The data interface allows three different data transfer modes: 81 4341D–MP3–04/05 Figure 55. 20 bit I2S justified mode SCLK DSEL DOUT R1 R0 L(N-1) L(N-2) L(N-3) ... L2 L1 L0 R(N-1) R(N-2) R(N-3) ... R2 R1 R0 Figure 56. 20 bit MSB justified mode SCLK DSEL DOUT R0 L(N-1) L(N-2) L(N-3) ... L2 L1 L0 R(N-1) R(N-2) R(N-3) ... R2 R1 R0 L(N-1) Figure 57. 20 bit LSB justified mode SCLK DSEL DOUT R0 L(N-1) L(N-2) ... L1 L0 R(N-1) R(N-2) ... R1 R0 L(N-1) The selection between modes is done using the DINTSEL 1:0 in DAC_MISC register (Table 112.) according with the following table: DINTSEL 1:0 00 01 1x Format I2S Justified MSB Justified LSB Justified The data interface always works in slave mode. This means that the DSEL and the DCLK signals are provided by microcontroller audio data interface. Serial Audio DAC Interface The serial audio DAC interface is a Synchronous Peripheral Interface (SPI) in slave mode: • • • AUDCDIN: is used to transfer data in series from the master to the slave DAC. It is driven by the master. AUDCDOUT: is used to transfer data in series from the slave DAC to the master. It is driven by the selected slave DAC. Serial Clock (AUDCCLK): it is used to synchronize the data transmission both in and out the devices through the AUDCDIN and AUDCDOUT lines. Refer to Table 101. for DAC SPI Interface Description Note: 82 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Figure 58. Serial Audio Interface Serial Audio Interface Audio DAC AUDCDIN AUDCDOUT AUDCCLK AUDCCS Audio PA Protocol is as following to access DAC registers: Figure 59. Dac SPI Interface AUDCCS AUDCCLK AUDCDIN rw a6 a5 a4 a3 a2 a1 a0 d7 d6 d5 d4 d3 d2 d1 d0 AUDCDOUT d7 d6 d5 d4 d3 d2 d1 d0 DAC Interface SPI Protocol On AUDCDIN, the first bit is a read/write bit. 0 indicates a write operation while 1 is for a read operation. The 7 following bits are used for the register address and the 8 last ones are the write data. For both address and data, the most significant bit is the first one. In case of a read operation, AUDCDOUT provides the contents of the read register, MSB first. The transfer is enabled by the AUDCCS signal active low. The interface is resetted at every rising edge of AUDCCS in order to come back to an idle state, even if the transfer does not succeed. The DAC Interface SPI is synchronized with the serial clock AUDC- 83 4341D–MP3–04/05 CLK. Falling edge latches AUDCDIN input and rising edge shifts AUDCDOUT output bits. Note that the DLCK must run during any DAC SPI interface access (read or write). Figure 60. DAC SPI Interface Timings AUDCCS Tssen Twl Tc Thsen AUDCCLK Twh Tssdi Thsdi AUDCDIN Thsdo Tdsdo AUDCDOUT Table 91. Dac SPI Interface Timings Timing parameter Tc Twl Twh Tssen Thsen Tssdi Thsdi Tdsdo Thsdo Description AUDCCLK min period AUDCCLK min pulse width low AUDCCLK min pulse width high Setup time AUDCCS falling to AUDCCLK rising Hold time AUDCCLK falling to AUDCCS rising Setup time AUDCDIN valid to AUDCCLK falling Hold time AUDCCLK falling to AUDCDIN not valid Delay time AUDCCLK rising to AUDCDOUT valid Hold time AUDCCLK rising to AUDCDOUT not valid Min 150 ns 50 ns 50 ns 50 ns 50 ns 20 ns 20 ns 0 ns Max 20 ns - 84 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C DAC Register Tables Table 92. DAC Register Address Address 00h 01h 02h 03h 04h 05h 06h 07h 08h 09h 0Ah 0Ch 0Dh 10h 11h Register DAC_CTRL DAC_LLIG DAC_RLIG DAC_LPMG DAC_RPMG DAC_LLOG DAC_RLOG DAC_OLC DAC_MC DAC_CSFC DAC_MISC DAC_PRECH DAC_AUXG DAC_RST PA_CRTL Name Dac Control Dac Left Line in Gain Dac Right Line in Gain Dac Left Master Playback Gain Dac Right Master Playback Gain Dac Left Line Out Gain Dac Right Line Out Gain Dac Output Level Control Dac Mixer Control Dac Clock and Sampling Frequency Control Dac Miscellaneous Dac Precharge Control Dac Auxilary input gain Control Dac Reset Power Amplifier Control Access Read/Write Read/Write Read/Write Read/Write Read/Write Read/Write Read/Write Read/Write Read/Write Read/Write Read/Write Read/Write Read/Write Read/Write Read/Write Reset state 00h 05h 05h 08h 08h 00h 00h 22h 09h 00h 00h 00h 05h 00h 00h DAC Gain The DAC implements severals gain control: line-in (Table 93.), master playback (), lineout (Table 96.). Table 93. Line-in gain LLIG 4:0 RLIG 4:0 00000 00001 00010 00011 00100 00101 00110 00111 01000 01001 01010 01011 01100 Gain (dB) 20 12 9 6 3 0 -3 -6 -9 -12 -15 -18 -21 85 4341D–MP3–04/05 Table 93. Line-in gain (Continued) 01101 01110 01111 10000 10001 -24 -27 -30 -33 < -60 Table 94. Master Playback Gain LMPG 5:0 RMPG 5:0 000000 000001 000010 000011 000100 000101 000110 000111 001000 001001 001010 001011 001100 001101 001110 001111 010000 010001 010010 010011 010100 010101 010110 010111 011000 011001 Gain (dB) 12.0 10.5 9.0 7.5 6.0 4.5 3.0 1.5 0.0 -1.5 -3.0 -4.5 -6.0 -7.5 -9.0 -10.5 -12.0 -13.5 -15.0 -16.5 -18.0 -19.5 -21.0 -22.5 -24.0 -25.5 86 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Table 94. Master Playback Gain (Continued) LMPG 5:0 RMPG 5:0 011010 011011 011100 011101 011110 011111 100000 Gain (dB) -27.0 -28.5 -30.0 -31.5 -33.0 -34.5 mute Table 95. Line-out Gain LLOG 5:0 RLOG 5:0 000000 000001 000010 000011 000100 000101 000110 000111 001000 001001 001010 001011 001100 001101 001110 001111 010000 010001 010010 010011 010100 010101 010110 Gain (dB) 0.0 -1.5 -3.0 -4.5 -6.0 -7.5 -9.0 -10.5 -12.0 -13.5 -15.0 -16.5 -18.0 -19.5 -21.0 -22.5 -24.0 -25.5 -27.0 -28.5 -30.0 -31.5 -33.0 87 4341D–MP3–04/05 Table 95. Line-out Gain (Continued) 010111 011000 011001 011010 011011 011100 011101 011110 011111 100000 -34.5 -36.0 -37.5 -39.0 -40.5 -42.0 -43.5 -45.0 -46.5 mute Table 96. DAC Output Level Control LOLC 2:0 ROLC 2:0 000 001 010 011 100 Gain (dB) 6 3 0 -3 -6 Digital Mixer Control The Audio DAC features a digital mixer that allows the mixing and selection of multiple input sources. The mixing / multiplexing functions are described in the following table according with the next figure: Figure 61. Mixing / Multiplexing functions Left channel Volume Control + 2 1 Volume Control From digital filters To DACs 1 Volume Control + 2 Volume Control Right channel Note: Whenever the two mixer inputs are selected, a –6 dB gain is applied to the output signal. Whenever only one input is selected, no gain is applied. 88 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Signal LMSMIN1 LMSMIN2 RMSMIN1 RMSMIN2 Description Left Channel Mono/Stereo Mixer Left Mixed input enable – High to enable, Low to disable Left Channel Mono/Stereo Mixer Right Mixed input enable – High to enable, Low to disable Right Channel Mono/Stereo Mixer Left Mixed input enable – High to enable, Low to disable Right Channel Mono/Stereo Mixer Right Mixed input enable – High to enable, Low to disable Note: Refer to DAC_MC register Table 110. for signal description Master Clock and Sampling Frequency Selection The following table describes the different modes available for master clock and sampling frequency selection by setting OVRSEL bit in DAC_CSFC register (refer to Table 111.). Table 97. Master Clock selection OVRSEL 0 1 Master Clock 256 x FS 384 x FS The selection of input sample size is done using the NBITS 1:0 in DAC_MISC register (refer to Table 112.) according to Table 98. Table 98. Input Sample Size Selection NBITS 1:0 00 01 10 Format 16 bits 18 bits 20 bits The selection between modes is done using DINTSEL 1:0 in DAC_MISC register (refer to Table 112.) according to Table 99. Table 99. Format Selection DINTSEL 1:0 00 01 1x Format I2S Justified MSB Justified LSB Justified De-emphasis and dither enable The circuit features a de-emphasis filter for the playback channel. To enable the deemphasis filtering, DEEMPEN must be set to high. Likewise, the dither option (added in the playback channel) is enabled by setting the DITHEN signal to High. 89 4341D–MP3–04/05 Table 100. DAC Auxlilary Input Gain AUXG 4:0 00000 00001 00010 00011 00100 00101 00110 00111 01000 01001 01010 01011 01100 01101 01110 01111 10000 10001 Gain (dB) 20 12 9 6 3 0 -3 -6 -9 -12 -15 -18 -21 -24 -27 -30 -33 Serial CRC7 Generator CTPTR MMCON0.4 TX COMMAND Line Finished State Machine CFLCK MMSTA.0 MMINT.5 EOCI MCMD CMDEN MMCON1.0 MMSTA.2 MMSTA.1 Command Transmitter CRC7S RX Pointer RESPFS 17 - Byte FIFO MMCMD Read Data Converter Serial -> // CRC7 and Format Checker CRPTR MMCON0.5 RX COMMAND Line Finished State Machine RESPEN Command Receiver MMINT.6 EORI RFMT CRCDIS MMCON1.1 MMCON0.1 MMCON0.0 Command Transmitter For sending a command to the card, user must load the command index (1 Byte) and argument (4 Bytes) in the command transmit FIFO using the MMCMD register. Before starting transmission by setting and clearing the CMDEN bit in MMCON1 register, 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 response 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 response that do not include CRC7. Figure 94 summarizes the command transmission flow. As soon as command transmission is enabled, the CFLCK flag in MMSTA is set indicating that write to the FIFO is locked. This mechanism is implemented to avoid command overrun. The end of the command transmission is signalled to you by the EOCI flag in MMINT register becoming set. This flag may generate an MMC interrupt request as detailed in Section "Interrupt", page 150. The end of the command transmission also resets the CFLCK flag. 142 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C User may abort command loading by setting and clearing the CTPTR bit in MMCON0 register which resets the write pointer to the transmit FIFO. Figure 94. Command Transmission Flow Command Transmission Load Command in Buffer MMCMD = index MMCMD = argument Configure Response RESPEN = X RFMT = X CRCDIS = X Transmit Command CMDEN = 1 CMDEN = 0 Command Receiver The end of the response reception is signalled to you by the EORI flag in MMINT register. This flag may generate an MMC interrupt request as detailed in Section "Interrupt", page 150. When this flag is set, 2 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 cleared when a command is sent to the card and updated when the response has been received. User may abort response reading by setting and clearing the CRPTR bit in MMCON0 register which resets the read pointer to the receive FIFO. According to the MMC specification delay between a command and a response (formally NCR parameter) can not exceed 64 MMC clock periods. To avoid any locking of the MMC controller when card does not send its response (e.g. physically removed from the bus), user must launch a time-out period to exit from such situation. In case of timeout user may reset the command controller and its internal state machine by setting and clearing the CCR bit in MMCON2 register. This time-out may be disarmed when receiving the response. 143 4341D–MP3–04/05 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. Figure 95. Data Line Controller Block Diagram MMINT.0 MMINT.2 MMSTA.3 MMSTA.4 F1EI F1FI DATFS CRC16S Data Converter Serial -> // CRC16 and Format Checker TX Pointer 8-Byte FIFO 1 16-Byte FIFO MMDAT 8-Byte FIFO 2 DATA Line Finished State Machine DFMT F2EI MMINT.1 MMINT.4 MCBI MMINT.1 CBUSY MMSTA.5 DTPTR MMCON0.6 MDAT CRC16 Generator RX Pointer Data Converter // -> Serial DRPTR MMCON0.7 EOFI MBLOCK MMCON0.3 DATEN MMCON1.2 DATDIR BLEN3:0 F2FI MMINT.3 MMCON0.2 MMCON1.3 MMCON1.7:4 FIFO Implementation The 16-Byte FIFO is based on a dual 8-Byte FIFOs managed using 2 pointers and four flags indicating the status full and empty of each FIFO. Pointers are not accessible to user but can be reset at any time by setting and clearing DRPTR and DTPTR bits in MMCON0 register. Resetting the pointers is equivalent to abort the writing or reading of data. F1EI and F2EI flags in MMINT register signal when set that respectively FIFO1 and FIFO2 are empty. F1FI and F2FI flags in MMINT register signal when set that respectively FIFO1 and FIFO2 are full. These flags may generate an MMC interrupt request as detailed in Section “Interrupt”. Before sending or receiving any data, the data line controller must be configured according to the type of the data transfer considered. This is achieved using the Data Format bit: DFMT in MMCON0 register. Clearing DFMT bit enables the data stream format while setting DFMT bit enables the data block format. In data block format, user must also configure the single or multi-block mode by clearing or setting the MBLOCK bit in MMCON0 register and the block length using BLEN3:0 bits in MMCON1 according to Table 144. Figure 96 summarizes the data modes configuration flows. Table 144. Block Length Programming BLEN3:0 BLEN = 0000 to 1011 > 1011 Block Length (Byte) Length = 2BLEN: 1 to 2048 Reserved: do not program BLEN3:0 > 1011 Data Configuration 144 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Figure 96. Data Controller Configuration Flows Data Stream Configuration Data Single Block Configuration Data Multi-Block Configuration Configure Format DFMT = 0 Configure Format DFMT = 1 MBLOCK = 0 BLEN3:0 = XXXXb Configure Format DFMT = 1 MBLOCK = 1 BLEN3:0 = XXXXb Data Transmitter 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 97 summarizes the data stream transmission flows in both polling and interrupt modes while Figure 98 summarizes the data block transmission flows in both polling and interrupt modes, these flows assume that block length is greater than 16 data. Data Loading Data is loaded in the FIFO by writing to MMDAT register. Number of data loaded may vary from 1 to 16 Bytes. Then if necessary (more than 16 Bytes to send) user must wait that one FIFO becomes empty (F1EI or F2EI set) before loading 8 new data. 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 transfer from the host to the card may not start sooner than 2 MMC clock periods after the card response was received (formally N WR p arameter). 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 DATD1:0 bits are set, by step of 2 MMC clock periods. End of Transmission The end of a data frame (block or stream) transmission is signalled to you by the EOFI flag in MMINT register. This flag may generate an MMC interrupt request as detailed in Section "Interrupt", page 150. In data stream mode, EOFI flag is set, after reception of the End bit. This assumes user has previously 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 reception of the CRC status token (see Figure 88). 2 other flags in MMSTA register: DATFS and CRC16S report a status on the frame sent. DATFS indicates if the CRC status token format is correct or not, and CRC16S indicates if the card has found the CRC16 of the block correct or not. Busy Status As shown in Figure 88 the card uses a busy token during a block write operation. This busy status is reported to you by the CBUSY flag in MMSTA register 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 150. Data Transmission 145 4341D–MP3–04/05 Figure 97. Data Stream Transmission Flows Data Stream Transmission Data Stream Initialization Data Stream Transmission ISR FIFOs Filling write 16 data to MMDAT FIFOs Filling write 16 data to MMDAT FIFO Empty? F1EI or F2EI = 1? Start Transmission DATEN = 1 DATEN = 0 Unmask FIFOs Empty F1EM = 0 F2EM = 0 FIFO Filling write 8 data to MMDAT FIFO Empty? F1EI or F2EI = 1? Start Transmission DATEN = 1 DATEN = 0 No More Data To Send? FIFO Filling write 8 data to MMDAT Mask FIFOs Empty F1EM = 1 F2EM = 1 No More Data To Send? Send STOP Command Send STOP Command b. Interrupt mode a. Polling mode 146 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Figure 98. Data Block Transmission Flows Data Block Transmission Data Block Initialization Data Block Transmission ISR FIFOs Filling write 16 data to MMDAT FIFOs Filling write 16 data to MMDAT FIFO Empty? F1EI or F2EI = 1? Start Transmission DATEN = 1 DATEN = 0 Unmask FIFOs Empty F1EM = 0 F2EM = 0 FIFO Filling write 8 data to MMDAT FIFO Empty? F1EI or F2EI = 1? Start Transmission DATEN = 1 DATEN = 0 No More Data To Send? FIFO Filling write 8 data to MMDAT Mask FIFOs Empty F1EM = 1 F2EM = 1 No More Data To Send? b. Interrupt mode a. Polling mode Data Receiver Configuration To receive data from the card you must first configure the data controller in reception mode by clearing the DATDIR bit in MMCON1 register. Figure 99 summarizes the data stream reception flows in both polling and interrupt modes while Figure 100 summarizes the data block reception flows in both polling and interrupt modes, these flows assume that block length is greater than 16 Bytes. Data Reception The end of a data frame (block or stream) reception is signalled to you by the EOFI flag in MMINT register. This flag may generate an MMC interrupt request as detailed in Section "Interrupt", page 150. When this flag is set, 2 other flags in MMSTA register: DATFS and CRC16S give a status on the frame received. DATFS indicates if the frame format is correct or not: a valid End bit has been received, and CRC16S indicates if the CRC16 computation is correct or not. In case of data stream CRC16S has no meaning and stays cleared. According to the MMC specification data transmission from the card starts after the access time delay (formally NAC parameter) beginning from the End bit of the read command. To avoid any locking of the MMC controller when card does not send its data (e.g. physically removed from the bus), you must launch a time-out period to exit from such situation. In case of time-out you may reset the data controller and its internal state machine by setting and clearing the DCR bit in MMCON2 register. 147 4341D–MP3–04/05 This time-out may be disarmed after receiving 8 data (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). Data Reading Data is read from the FIFO by reading to MMDAT register. Each time one FIFO becomes full (F1FI or F2FI set), user is requested to flush this FIFO by reading 8 data. Figure 99. Data Stream Reception Flows Data Stream Reception Data Stream Initialization Data Stream Reception ISR FIFO Full? F1FI or F2FI = 1? Unmask FIFOs Full F1FM = 0 F2FM = 0 FIFO Full? F1FI or F2FI = 1? FIFO Reading read 8 data from MMDAT FIFO Reading read 8 data from MMDAT No More Data To Receive? No More Data To Receive? Send STOP Command Mask FIFOs Full F1FM = 1 F2FM = 1 a. Polling mode Send STOP Command b. Interrupt mode 148 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Figure 100. Data Block Reception Flows Data Block Reception Data Block Initialization Data Block Reception ISR Start Transmission DATEN = 1 DATEN = 0 Unmask FIFOs Full F1FM = 0 F2FM = 0 FIFO Full? F1EI or F2EI = 1? FIFO Full? F1EI or F2EI = 1? Start Transmission DATEN = 1 DATEN = 0 FIFO Reading read 8 data from MMDAT FIFO Reading read 8 data from MMDAT No More Data To Receive? No More Data To Receive? Mask FIFOs Full F1FM = 1 F2FM = 1 a. Polling mode b. Interrupt mode 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: F1EI and F2EI set. MMCLK is restarted when one of the FIFOs becomes full: F1EI or F2EI cleared. MMCLK is stopped when both FIFOs become full: F1FI and F2FI set. MMCLK is restarted when one of the FIFOs becomes empty: F1FI or F2FI cleared. During reception, setting the FLOWC bit has the following effects: 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. 149 4341D–MP3–04/05 Interrupt Description As shown in Figure 101, the MMC controller implements eight interrupt sources reported in MCBI, EORI, EOCI, EOFI, F2FI, F1FI, and F2EI flags in MMCINT register. These flags are detailed in the previous sections. All these sources are maskable separately using MCBM, EORM, EOCM, EOFM, F2FM, F1FM, and F2EM mask bits respectively in MMMSK register. The interrupt request is generated each time an unmasked flag is set, and the global MMC controller interrupt enable bit is set (EMMC in IEN1 register). Reading the MMINT register automatically clears the interrupt flags (acknowledgment). This implies that register content must be saved and tested interrupt flag by interrupt flag to be sure not to forget any interrupts. Figure 101. MMC Controller Interrupt System MCBI MMINT.7 MCBM EORI MMINT.6 MMMSK.7 EORM EOCI MMINT.5 MMMSK.6 EOCM EOFI MMINT.4 MMMSK.5 EOFM F2FI MMINT.3 MMMSK.4 MMC Interface Interrupt Request EMMC F2FM IEN1.0 MMMSK.3 F1FI MMINT.2 F1FM F2EI MMINT.1 MMMSK.2 F2EM F1EI MMINT.0 MMMSK.1 F1EM MMMSK.0 150 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Registers Table 145. MMCON0 Register MMCON0 (S:E4h) – MMC Control Register 0 7 DRPTR Bit Number 7 6 DTPTR 5 CRPTR 4 CTPTR 3 MBLOCK 2 DFMT 1 RFMT 0 CRCDIS Bit Mnemonic Description DRPTR Data Receive Pointer Reset Bit Set to reset the read pointer of the data FIFO. Clear to release the read pointer of the data FIFO. Data Transmit Pointer Reset Bit Set to reset the write pointer of the data FIFO. Clear to release the write pointer of the data FIFO. Command Receive Pointer Reset Bit Set to reset the read pointer of the receive command FIFO. Clear to release the read pointer of the receive command FIFO. Command Transmit Pointer Reset Bit Set to reset the write pointer of the transmit command FIFO. Clear to release the read pointer of the transmit command FIFO. Multi-block Enable Bit Set to select multi-block data format. Clear to select single block data format. Data Format Bit Set to select the block-oriented data format. Clear to select the stream data format. Response Format Bit Set to select the 48-bit response format. Clear to select the 136-bit response format. CRC7 Disable Bit Set to disable the CRC7 computation when receiving a response. Clear to enable the CRC7 computation when receiving a response. 6 DTPTR 5 CRPTR 4 CTPTR 3 MBLOCK 2 DFMT 1 RFMT 0 CRCDIS Reset Value = 0000 0000b 151 4341D–MP3–04/05 Table 146. MMCON1 Register MMCON1 (S:E5h) – MMC Control Register 1 7 BLEN3 Bit Number 7-4 6 BLEN2 5 BLEN1 4 BLEN0 3 DATDIR 2 DATEN 1 RESPEN 0 CMDEN Bit Mnemonic Description BLEN3:0 Block Length Bits Refer to Table 144 for bits description. Do not program value > 1011b Data Direction Bit Set to select data transfer from host to card (write mode). Clear to select data transfer from card to host (read mode). Data Transmission Enable Bit Set and clear to enable data transmission immediately or after response has been received. Response Enable Bit Set and clear to enable the reception of a response following a command transmission. Command Transmission Enable Bit Set and clear to enable transmission of the command FIFO to the card. 3 DATDIR 2 DATEN 1 RESPEN 0 CMDEN Reset Value = 0000 0000b Table 147. MMCON2 Register MMCON2 (S:E6h) – MMC Control Register 2 7 MMCEN Bit Number 7 6 DCR 5 CCR 4 3 2 DATD1 1 DATD0 0 FLOWC Bit Mnemonic Description MMCEN MMC Clock Enable Bit Set to enable the MCLK clocks and activate the MMC controller. Clear to disable the MMC clocks and freeze the MMC controller. Data Controller Reset Bit Set and clear to reset the data line controller in case of transfer abort. Command Controller Reset Bit Set and clear to reset the command line controller in case of transfer abort. Reserved The value read from these bits is always 0. Do not set these bits. Data Transmission Delay Bits Used to delay the data transmission after a response from 3 MMC clock periods (all bits cleared) to 9 MMC clock periods (all bits set) by step of 2 MMC clock periods. MMC Flow Control Bit Set to enable the flow control during data transfers. Clear to disable the flow control during data transfers. 6 5 4-3 DCR CCR - 2-1 DATD1:0 0 FLOWC Reset Value = 0000 0000b 152 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Table 148. MMSTA Register MMSTA (S:DEh Read Only) – MMC Control and Status Register 7 Bit Number 7-6 6 5 CBUSY 4 CRC16S 3 DATFS 2 CRC7S 1 RESPFS 0 CFLCK Bit Mnemonic Description Reserved The value read from these bits is always 0. Do not set these bits. Card Busy Flag 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. CRC16 Status Bit Transmission mode Set by hardware when the token response reports a good CRC. Cleared by hardware when the token response reports a bad CRC. Reception mode 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. Data Format Status Bit Transmission mode Set by hardware when the format of the token response is correct. Cleared by hardware when the format of the token response is not correct. Reception mode Set by hardware when the format of the frame is correct. Cleared by hardware when the format of the frame is not correct. CRC7 Status Bit Set by hardware when the CRC7 computed in the response is correct. Cleared by hardware when the CRC7 computed in the response is not correct. This bit is not relevant when CRCDIS is set. 5 CBUSY 4 CRC16S 3 DATFS 2 CRC7S 1 RESPFS Response Format Status Bit Set by hardware when the format of a response is correct. Cleared by hardware when the format of a response is not correct. Command FIFO Lock Bit Set by hardware to signal user not to write in the transmit command FIFO: busy state. Cleared by hardware to signal user the transmit command FIFO is available: idle state. 0 CFLCK Reset Value = 0000 0000b 153 4341D–MP3–04/05 Table 149. MMINT Register MMINT (S:E7h Read Only) – MMC Interrupt Register 7 MCBI Bit Number 6 EORI 5 EOCI 4 EOFI 3 F2FI 2 F1FI 1 F2EI 0 F1EI Bit Mnemonic Description MMC Card Busy Interrupt Flag Set by hardware when the card enters or exits its busy state (when the busy signal is asserted or deasserted on the data line). Cleared when reading MMINT. End of Response Interrupt Flag Set by hardware at the end of response reception. Cleared when reading MMINT. End of Command Interrupt Flag Set by hardware at the end of command transmission. Clear when reading MMINT. End of Frame Interrupt Flag Set by hardware at the end of frame (stream or block) transfer. Clear when reading MMINT. FIFO 2 Full Interrupt Flag Set by hardware when second FIFO becomes full. Cleared by hardware when second FIFO becomes empty. FIFO 1 Full Interrupt Flag Set by hardware when first FIFO becomes full. Cleared by hardware when first FIFO becomes empty. FIFO 2 Empty Interrupt Flag Set by hardware when second FIFO becomes empty. Cleared by hardware when second FIFO becomes full. FIFO 1 Empty Interrupt Flag Set by hardware when first FIFO becomes empty. Cleared by hardware when first FIFO becomes full. 7 MCBI 6 EORI 5 EOCI 4 EOFI 3 F2FI 2 F1FI 1 F2EI 0 F1EI Reset Value = 0000 0011b 154 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Table 150. MMMSK Register MMMSK (S:DFh) – MMC Interrupt Mask Register 7 MCBM Bit Number 7 6 EORM 5 EOCM 4 EOFM 3 F2FM 2 F1FM 1 F2EM 0 F1EM Bit Mnemonic Description MCBM MMC Card Busy Interrupt Mask Bit Set to prevent MCBI flag from generating an MMC interrupt. Clear to allow MCBI flag to generate an MMC interrupt. End Of Response Interrupt Mask Bit Set to prevent EORI flag from generating an MMC interrupt. Clear to allow EORI flag to generate an MMC interrupt. End Of Command Interrupt Mask Bit Set to prevent EOCI flag from generating an MMC interrupt. Clear to allow EOCI flag to generate an MMC interrupt. End Of Frame Interrupt Mask Bit Set to prevent EOFI flag from generating an MMC interrupt. Clear to allow EOFI flag to generate an MMC interrupt. FIFO 2 Full Interrupt Mask Bit Set to prevent F2FI flag from generating an MMC interrupt. Clear to allow F2FI flag to generate an MMC interrupt. FIFO 1 Full Interrupt Mask Bit Set to prevent F1FI flag from generating an MMC interrupt. Clear to allow F1FI flag to generate an MMC interrupt. FIFO 2 Empty Interrupt Mask Bit Set to prevent F2EI flag from generating an MMC interrupt. Clear to allow F2EI flag to generate an MMC interrupt. FIFO 1 Empty Interrupt Mask Bit Set to prevent F1EI flag from generating an MMC interrupt. Clear to allow F1EI flag to generate an MMC interrupt. 6 EORM 5 EOCM 4 EOFM 3 F2FM 2 F1FM 1 F2EM 0 F1EM Reset Value = 1111 1111b Table 151. MMCMD Register MMCMD (S:DDh) – MMC Command Register 7 MC7 Bit Number 6 MC6 5 MC5 4 MC4 3 MC3 2 MC2 1 MC1 0 MC0 Bit Mnemonic Description MMC Command Receive Byte Output (read) register of the response FIFO. MMC Command Transmit Byte Input (write) register of the command FIFO. 7-0 MC7:0 Reset Value = 1111 1111b 155 4341D–MP3–04/05 Table 152. MMDAT Register MMDAT (S:DCh) – MMC Data Register 7 MD7 Bit Number 7-0 6 MD6 5 MD5 4 MD4 3 MD3 2 MD2 1 MD1 0 MD0 Bit Mnemonic Description MD7:0 MMC Data Byte Input (write) or output (read) register of the data FIFO. Reset Value = 1111 1111b Table 153. MMCLK Register MMCLK (S:EDh) – MMC Clock Divider Register 7 MMCD7 Bit Number 7-0 6 MMCD6 5 MMCD5 4 MMCD4 3 MMCD3 2 MMCD2 1 MMCD1 0 MMCD0 Bit Mnemonic Description MMCD7:0 MMC Clock Divider 8-bit divider for MMC clock generation. Reset Value = 0000 0000b 156 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Synchronous Peripheral Interface The AT8xC51SND2C implements a Synchronous Peripheral Interface with master and slave modes capability. Figure 102 shows an SPI bus configuration using the AT8xC51SND2C as master connected to slave peripherals while Figure 103 shows an SPI bus configuration using the AT8xC51SND2C as slave of an other master. The bus is made of three wires connecting all the devices together: • Master Output Slave Input (MOSI): it is used to transfer data in series from the master to a slave. It is driven by the master. Master Input Slave Output (MISO): it is used to transfer data in series from a slave to the master. It is driven by the selected slave. Serial Clock (SCK): it is used to synchronize the data transmission both in and out the devices through their MOSI and MISO lines. It is driven by the master for eight clock cycles which allows to exchange one Byte on the serial lines. • • Each slave peripheral is selected by one Slave Select pin (SS). If there is only one slave, it may be continuously selected with SS t ied to a low level. Otherwise, the AT8xC51SND2C may select each device by software through port pins (Pn.x). Special care should be taken not to select 2 slaves at the same time to avoid bus conflicts. Figure 102. Typical Master SPI Bus Configuration Pn.z Pn.y Pn.x SS SO DataFlash 1 SI SCK SS DataFlash 2 SO SI SCK SS SO LCD Controller SI SCK AT8xC51SND2C MISO MOSI SCK P4.0 P4.1 P4.2 Figure 103. Typical Slave SPI Bus Configuration SSn SS1 SS0 SS SO SS Slave 1 SI SCK SS SO Slave 2 SI SCK AT8xC51SND2C Slave n MISO MOSI SCK MASTER MISO MOSI SCK 157 4341D–MP3–04/05 Description The SPI controller interfaces with the C51 core through three special function registers: SPCON, the SPI control register (see Table 155); SPSTA, the SPI status register (see Table 156); and SPDAT, the SPI data register (see Table 157). The SPI operates in master mode when the MSTR bit in SPCON is set. Figure 104 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 slave peripheral through the SCK output pin. As the Byte shifts out, another Byte shifts in from the slave peripheral on the MISO pin. The Byte is transmitted most significant bit (MSB) first. The end of transfer is signaled by SPIF being set. When the AT8xC51SND2C 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. Master Mode Figure 104. SPI Master Mode Block Diagram MOSI/P4.1 MISO/P4.0 SCK/P4.2 SPDAT RD SS#/P4.3 SSDIS SPCON.5 I 8-bit Shift Register SPDAT WR Q Internal Bus 4341D–MP3–04/05 MODF Control and Clock Logic SPSTA.4 WCOL SPSTA.6 PER CLOCK Bit Rate Generator SPEN SPCON.6 SPIF SPSTA.7 SPR2:0 SPCON CPHA SPCON.2 CPOL SPCON.3 Note: MSTR bit in SPCON is set to select master mode. 158 AT8xC51SND2C AT8xC51SND2C Slave Mode The SPI operates in slave mode when the MSTR bit in SPCON is cleared and data has been loaded in SPDAT. Figure 105 shows the SPI block diagram in slave mode. In slave mode, before a data transmission 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 slave 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 transmission, the data in the shift register begins shifting out on the MISO pin. The end of transfer is signaled by SPIF being set. When the AT8xC51SND2C is the only slave 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. This bit has no effect when CPHA is cleared (see Section "SS Management", page 161). Figure 105. SPI Slave Mode Block Diagram MISO/P4.2 MOSI/P4.1 I Q Internal Bus 8-bit Shift Register SPDAT WR SCK/P4.2 Control and Clock Logic SS/P4.3 SSDIS SPCON.5 SPDAT RD SPIF SPSTA.7 CPHA SPCON.2 CPOL SPCON.3 Note: 1. MSTR bit in SPCON is cleared to select slave mode. Bit Rate The bit rate can be selected from seven predefined bit rates using the SPR2, SPR1 and SPR0 control bits in SPCON according to Table 154. These bit rates are derived from the peripheral clock (FPER) issued from the Clock Controller block as detailed in Section "Oscillator", page 12. 159 4341D–MP3–04/05 Table 154. Serial Bit Rates Bit Rate (kHz) Vs FPER SPR2 0 0 0 0 1 1 1 1 SPR1 0 0 1 1 0 0 1 1 SPR0 0 1 0 1 0 1 0 1 6 MHz(1) 8 MHz(1) 10 MHz(1) 12 MHz(2) 16 MHz(2) 20 MHz(2) 3000 1500 750 375 187.5 93.75 46.875 6000 4000 2000 1000 500 250 125 62.5 8000 5000 2500 1250 625 312.5 156.25 78.125 10000 6000 3000 1500 750 375 187.5 93.75 12000 8000 4000 2000 1000 500 250 125 16000 10000 5000 2500 1250 625 312.5 156.25 20000 FPER Divider 2 4 8 16 32 64 128 1 Notes: 1. These frequencies are achieved in X1 mode, FPER = FOSC ÷ 2. 2. These frequencies are achieved in X2 mode, FPER = FOSC. Data Transfer The Clock Polarity bit (CPOL in SPCON) defines the default SCK line level in idle state(1) while the Clock Phase bit (CPHA in SPCON) defines the edges on which the input data are sampled and the edges on which the output data are shifted (see Figure 106 and Figure 107). The SI signal is output from the selected slave and the SO signal is the output from the master. The AT8xC51SND2C captures data from the SI line while the selected slave captures data from the SO line. For simplicity, Figure 106 and Figure 107 depict the SPI waveforms in idealized form and do not provide 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 106. Data Transmission Format (CPHA = 0) SCK Cycle Number SPEN (Internal) SCK (CPOL = 0) SCK (CPOL = 1) MOSI (From Master) MISO (From Slave) SS (to slave) Capture point MSB MSB bit 6 bit 6 bit 5 bit 5 bit 4 bit 4 bit 3 bit 3 bit 2 bit 2 bit 1 bit 1 LSB LSB 1 2 3 4 5 6 7 8 160 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Figure 107. Data Transmission Format (CPHA = 1) SCK cycle number SPEN (internal) SCK (CPOL = 0) SCK (CPOL = 1) MOSI (from master) MISO (from slave) SS (to slave) Capture point MSB MSB bit 6 bit 6 bit 5 bit 5 bit 4 bit 4 bit 3 bit 3 bit 2 bit 2 bit 1 bit 1 LSB LSB 1 2 3 4 5 6 7 8 SS Management Figure 106 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 transmission (see Figure 108). SPDAT must be loaded with a data before SS i s asserted again. Figure 107 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 m ay remain asserted between each Byte transmission (see Figure 108). Figure 108. SS Timing Diagram SI/SO SS (CPHA = 0) SS (CPHA = 1) Byte 1 Byte 2 Byte 3 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 an other master on the bus has asserted SS pin and so, may create a conflict on the bus with 2 master 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 162. 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 continue 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 on-going. 161 • • 4341D–MP3–04/05 Interrupt The SPI handles 2 interrupt sources that are the “end of transfer” and the “mode fault” flags. As shown in Figure 109, these flags are combined toghether 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 writing 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 109. SPI Interrupt System SPIF SPSTA.7 MODF SPSTA.4 SPI Controller Interrupt Request ESPI IEN1.2 162 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Configuration Master Configuration Slave Configuration Data Exchange The SPI configuration is made through SPCON. The SPI operates in master mode when the MSTR bit in SPCON is set. The SPI operates in slave mode when the MSTR bit in SPCON is cleared and data has been loaded is SPDAT. There are 2 possible methods to exchange data in master and slave modes: • • Master Mode with Polling Policy polling interrupts Figure 110 shows the initialization phase and the transfer phase flows using the polling method. Using this flow prevents any overrun error occurrence. The bit rate is selected according to Table 154. The transfer format depends on the slave peripheral. 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 polling method provides the fastest effective transmission 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. Figure 110. Master SPI Polling Flows SPI Initialization Polling Policy SPI Transfer Polling Policy Disable interrupt SPIE = 0 Select Slave Pn.x = L Select Master Mode MSTR = 1 Start Transfer write data in SPDAT Select Bit Rate program SPR2:0 End Of Transfer? SPIF = 1? Select Format program CPOL & CPHA Get Data Received read SPDAT Enable SPI SPEN = 1 Last Transfer? Deselect Slave Pn.x = H 163 4341D–MP3–04/05 Master Mode with Interrupt Figure 111 shows the initialization phase and the transfer phase flows using the interrupt. Using this flow prevents any overrun error occurrence. The bit rate is selected according to Table 154. The transfer format depends on the slave peripheral. SS may be deasserted between transfers depending also on the slave peripheral. Reading SPSTA at the beginning of the ISR is mandatory for clearing the SPIF flag. Clear is effective when reading SPDAT. Figure 111. Master SPI Interrupt Flows SPI Initialization Interrupt Policy SPI Interrupt Service Routine Select Master Mode MSTR = 1 Read Status Read SPSTA Select Bit Rate program SPR2:0 Get Data Received read SPDAT Select Format program CPOL & CPHA Start New Transfer write data in SPDAT Enable interrupt ESPI =1 Last Transfer? Enable SPI SPEN = 1 Deselect Slave Pn.x = H Select Slave Pn.x = L Disable interrupt SPIE = 0 Start Transfer write data in SPDAT 164 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Slave Mode with Polling Policy Figure 112 shows the initialization phase and the transfer phase flows using the polling. The transfer format depends on the master controller. SPIF flag is cleared when reading SPDAT (SPSTA has been read before by the “end of reception” check). This provides the fastest effective transmission and is well adapted when communicating at high speed with other Microcontrollers. However, the process may then be interrupted at any time by higher priority tasks. Figure 112. Slave SPI Polling Flows SPI Initialization Polling Policy SPI Transfer Polling Policy Disable interrupt SPIE = 0 Data Received? SPIF = 1? Select Slave Mode MSTR = 0 Get Data Received read SPDAT Select Format program CPOL & CPHA Prepare Next Transfer write data in SPDAT Enable SPI SPEN = 1 Prepare Transfer write data in SPDAT 165 4341D–MP3–04/05 Slave Mode with Interrupt Policy Figure 111 shows the initialization phase and the transfer phase flows using the interrupt. The transfer format depends on the master controller. Reading SPSTA at the beginning of the ISR is mandatory for clearing the SPIF flag. Clear is effective when reading SPDAT. Figure 113. Slave SPI Interrupt Policy Flows SPI Initialization Interrupt Policy SPI Interrupt Service Routine Select Slave Mode MSTR = 0 Get Status Read SPSTA Select Format program CPOL & CPHA Get Data Received read SPDAT Enable interrupt ESPI =1 Prepare New Transfer write data in SPDAT Enable SPI SPEN = 1 Prepare Transfer write data in SPDAT 166 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Registers Table 155. SPCON Register SPCON (S:C3h) – SPI Control Register 7 SPR2 Bit Number 7 6 SPEN 5 SSDIS 4 MSTR 3 CPOL 2 CPHA 1 SPR1 0 SPR0 Bit Mnemonic Description SPR2 SPI Rate Bit 2 Refer to Table 154 for bit rate description. SPI Enable Bit Set to enable the SPI interface. Clear to disable the SPI interface. Slave Select Input Disable Bit Set to disable SS in both master and slave modes. In slave mode this bit has no effect if CPHA = 0. Clear to enable SS in both master and slave modes. Master Mode Select Set to select the master mode. Clear to select the slave mode. SPI Clock Polarity Bit(1) 6 SPEN 5 SSDIS 4 MSTR 3 CPOL Set to have the clock output set to high level in idle state. Clear to have the clock output set to low level in idle state. SPI Clock Phase Bit Set to have the data sampled when the clock returns to idle state (see CPOL). Clear to have the data sampled when the clock leaves the idle state (see CPOL). SPI Rate Bits 0 and 1 Refer to Table 154 for bit rate description. 2 CPHA 1-0 SPR1:0 Reset Value = 0001 0100b Note: 1. When the SPI is disabled, SCK outputs high level. 167 4341D–MP3–04/05 Table 156. SPSTA Register SPSTA (S:C4h) – SPI Status Register 7 SPIF Bit Number 7 6 WCOL 5 4 MODF 3 2 1 0 - Bit Mnemonic Description SPIF SPI Interrupt Flag Set by hardware when an 8-bit shift is completed. Cleared by hardware when reading or writing SPDAT after reading SPSTA. Write Collision Flag Set by hardware to indicate that a collision has been detected. Cleared by hardware to indicate that no collision has been detected. Reserved The value read from this bit is indeterminate. Do not set this bit. Mode Fault 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. Reserved The value read from these bits is indeterminate. Do not set these bits. 6 WCOL 5 - 4 MODF 3-0 - Reset Value = 00000 0000b Table 157. SPDAT Register SPDAT (S:C5h) – Synchronous Serial Data Register 7 SPD7 Bit Number 7-0 6 SPD6 5 SPD5 4 SPD4 3 SPD3 2 SPD2 1 SPD1 0 SPD0 Bit Mnemonic Description SPD7:0 Synchronous Serial Data. Reset Value = XXXX XXXXb 168 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Serial I/O Port The serial I/O port in the AT8xC51SND2C provides both synchronous and asynchronous communication modes. It operates as a Synchronous Receiver and Transmitter in one single mode (Mode 0) and operates as an Universal Asynchronous Receiver and Transmitter (UART) in three full-duplex modes (Modes 1, 2 and 3). Asynchronous modes support framing error detection and multiprocessor communication with automatic address recognition. SM0 and SM1 bits in SCON register (see Figure 160) are used to select a mode among the single synchronous and the three asynchronous modes according to Table 158. Table 158. Serial I/O Port Mode Selection SM0 0 0 1 1 SM1 0 1 0 1 Mode 0 1 2 3 Description Synchronous Shift Register 8-bit UART 9-bit UART 9-bit UART Baud Rate Fixed/Variable Variable Fixed Variable Mode Selection Baud Rate Generator Depending on the mode and the source selection, the baud rate can be generated from either the Timer 1 or the Internal Baud Rate Generator. The Timer 1 can be used in Modes 1 and 3 while the Internal Baud Rate Generator can be used in Modes 0, 1 and 3. The addition of the Internal Baud Rate Generator allows freeing of the Timer 1 for other purposes in the application. It is highly recommended to use the Internal Baud Rate Generator as it 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. Timer 1 When using Timer 1, the Baud Rate is derived from the overflow of the timer. As shown in Figure 114 Timer 1 is used in its 8-bit auto-reload mode (detailed in Section "Mode 2 (8-bit Timer with Auto-Reload)", page 53). SMOD1 bit in PCON register allows doubling of the generated baud rate. Figure 114. Timer 1 Baud Rate Generator Block Diagram PER CLOCK ÷6 0 1 TL1 (8 bits) Overflow ÷2 0 1 T1 To serial Port C/T1# TMOD.6 INT1 GATE1 TMOD.7 SMOD1 PCON.7 TH1 (8 bits) TR1 TCON.6 T1 CLOCK 169 4341D–MP3–04/05 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 115 the Internal Baud Rate Generator is an 8-bit auto-reload timer fed by the peripheral clock or by the peripheral clock divided by 6 depending on the SPD bit in BDRCON register (see Table 164). The Internal Baud Rate Generator is enabled by setting BBR bit in BDRCON register. SMOD1 bit in PCON register allows doubling of the generated baud rate. Figure 115. Internal Baud Rate Generator Block Diagram PER CLOCK ÷6 0 1 BRG (8 bits) BRR BDRCON.4 Overflow ÷2 0 1 To serial Port SPD BDRCON.1 SMOD1 PCON.7 BRL (8 bits) IBRG CLOCK Synchronous Mode (Mode 0) Mode 0 is a half-duplex, synchronous mode, which is commonly used to expand the I/0 capabilities of a device with shift registers. The transmit data (TXD) pin outputs a set of eight clock pulses while the receive data (RXD) pin transmits or 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 171). Figure 116 shows the serial port block diagram in Mode 0. Figure 116. Serial I/O Port Block Diagram (Mode 0) SCON.6 SCON.7 SM1 SM0 SBUF Tx SR RXD Mode Decoder M3 M2 M1 M0 SBUF Rx SR Mode Controller PER CLOCK TI SCON.1 RI SCON.0 BRG CLOCK Baud Rate Controller TXD Transmission (Mode 0) To start a transmission mode 0, write to SCON register clearing bits SM0, SM1. As shown in Figure 117, writing the Byte to transmit to SBUF register starts the transmission. Hardware shifts the LSB (D0) onto the RXD pin during the first clock cycle composed of a high level then low level signal on TXD. During the eighth clock cycle the MSB (D7) is on the RXD pin. Then, hardware drives the RXD pin high and asserts TI to indicate the end of the transmission. 170 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Figure 117. Transmission Waveforms (Mode 0) TXD Write to SBUF RXD TI D0 D1 D2 D3 D4 D5 D6 D7 Reception (Mode 0) To start a reception in mode 0, write to SCON register clearing SM0, SM1 and RI bits and setting the REN bit. As shown in Figure 118, Clock is pulsed and the LSB (D0) is sampled on the RXD pin. The D0 bit is then shifted into the shift register. After eight samplings, 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. Figure 118. Reception Waveforms (Mode 0) TXD Write to SCON RXD RI Set REN, Clear RI D0 D1 D2 D3 D4 D5 D6 D7 Baud Rate Selection (Mode 0) In mode 0, the baud rate can be either, fixed or variable. As shown in Figure 119, the selection is done using M0SRC bit in BDRCON register. Figure 120 gives the baud rate calculation formulas for each baud rate source. Figure 119. Baud Rate Source Selection (mode 0) PER CLOCK IBRG CLOCK ÷6 0 1 To Serial Port M0SRC BDRCON.0 Figure 120. Baud Rate Formulas (Mode 0) Baud_Rate= Baud_Rate= FPER 6 6 (1-SPD) 2SMOD1 ⋅ FPER ⋅ 32 ⋅ (256 -BRL) BRL= 256 - 6 (1-SPD) 2SMOD1 ⋅ FPER ⋅ 32 ⋅ Baud_Rate a. Fixed Formula b. Variable Formula 171 4341D–MP3–04/05 Asynchronous Modes (Modes 1, 2 and 3) The Serial Port has one 8-bit and 2 9-bit asynchronous modes of operation. Figure 121 shows the Serial Port block diagram in such asynchronous modes. Figure 121. Serial I/O Port Block Diagram (Modes 1, 2 and 3) SCON.6 SCON.7 SCON.3 SM1 SM0 TB8 SBUF Tx SR TXD Mode Decoder M3 M2 M1 M0 T1 CLOCK IBRG CLOCK PER CLOCK Rx SR Mode & Clock Controller SBUF Rx SM2 SCON.4 RXD RB8 SCON.2 TI SCON.1 RI SCON.0 Mode 1 Mode 1 is a full-duplex, asynchronous mode. The data frame (see Figure 122) 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 a data is received, the stop bit is read in the RB8 bit in SCON register. Figure 122. Data Frame Format (Mode 1) Mode 1 Start bit D0 D1 D2 D3 D4 D5 D6 D7 Stop bit 8-bit data Modes 2 and 3 Modes 2 and 3 are full-duplex, asynchronous modes. The data frame (see Figure 123) consists of 11 bits: one start bit, eight data bits (transmitted and received LSB first), one programmable ninth data bit and one stop bit. Serial 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, you can use the ninth bit can be used as a command/data flag. Figure 123. Data Frame Format (Modes 2 and 3) D0 Start bit D1 D2 D3 D4 9-bit data D5 D6 D7 D8 Stop bit Transmission (Modes 1, 2 and 3) Reception (Modes 1, 2 and 3) To initiate a transmission, write to SCON register, set the SM0 and SM1 bits according to Table 158, and set the ninth bit by writing to TB8 bit. Then, writing the Byte to be transmitted to SBUF register starts the transmission. To prepare for reception, write to SCON register, set the SM0 and SM1 bits according to Table 158, and set the REN bit. The actual reception is then initiated by a detected highto-low transition on the RXD pin. 172 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C 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 124. When this feature is enabled, the receiver checks each 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 2 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 software or a chip reset clear FE bit. Subsequently received frames with valid stop bits cannot clear FE bit. When the framing error detection feature is enabled, RI rises on stop bit instead of the last data bit as detailed in Figure 130. Figure 124. Framing Error Block Diagram Framing Error Controller FE 1 0 SM0/FE SCON.7 SM0 SMOD0 PCON.6 Baud Rate Selection (Modes 1 and 3) In modes 1 and 3, the Baud Rate is derived either from the Timer 1 or the Internal Baud Rate Generator and allows different baud rate in reception and transmission. As shown in Figure 125 the selection is done using RBCK and TBCK bits in BDRCON register. Figure 126 gives the baud rate calculation formulas for each baud rate source while Table 159 details Internal Baud Rate Generator configuration for different peripheral clock frequencies and giving baud rates closer to the standard baud rates. Figure 125. Baud Rate Source Selection (Modes 1 and 3) T1 CLOCK IBRG CLOCK T1 CLOCK IBRG CLOCK 0 1 ÷ 16 To Serial Rx Port 0 1 ÷ 16 To Serial Tx Port RBCK BDRCON.2 TBCK BDRCON.3 Figure 126. Baud Rate Formulas (Modes 1 and 3) Baud_Rate= 2SMOD1 ⋅ FPER 6(1-SPD) ⋅ 32 ⋅ (256 -BRL) 2SMOD1 ⋅ FPER ⋅ 32 ⋅ Baud_Rate Baud_Rate= 2SMOD1 ⋅ FPER 6 ⋅ 32 ⋅ (256 -TH1) 2SMOD1 ⋅ FPER 192 ⋅ Baud_Rate BRL= 256 - 6 (1-SPD) TH1= 256 - a. IBRG Formula b. T1 Formula 173 4341D–MP3–04/05 Table 159. Internal Baud Rate Generator Value FPER = 6 MHz(1) Baud Rate 115200 57600 38400 19200 9600 4800 SPD 1 1 1 1 SMOD1 1 1 1 1 BRL 246 236 217 178 Error % 2.34 2.34 0.16 0.16 SPD 1 1 1 1 1 FPER = 8 MHz(1) SMOD1 1 1 1 1 1 BRL 247 243 230 204 152 Error % 3.55 0.16 0.16 0.16 0.16 SPD 1 1 1 1 1 FPER = 10 MHz(1) SMOD1 1 1 1 1 1 BRL 245 240 223 191 126 Error % 1.36 1.73 1.36 0.16 0.16 FPER = 12 MHz(2) Baud Rate 115200 57600 38400 19200 9600 4800 SPD 1 1 1 1 1 SMOD1 1 1 1 1 1 BRL 243 236 217 178 100 Error % 0.16 2.34 0.16 0.16 0.16 SPD 1 1 1 1 1 1 FPER = 16 MHz(2) SMOD1 1 1 1 1 1 1 BRL 247 239 230 204 152 48 Error % 3.55 2.12 0.16 0.16 0.16 0.16 SPD 1 1 1 1 1 1 FPER = 20 MHz(2) SMOD1 1 1 1 1 1 0 BRL 245 234 223 191 126 126 Error % 1.36 1.36 1.36 0.16 0.16 0.16 Notes: 1. These frequencies are achieved in X1 mode, FPER = FOSC ÷ 2. 2. These frequencies are achieved in X2 mode, FPER = FOSC. Baud Rate Selection (Mode 2) In mode 2, the baud rate can only be programmed to 2 fixed values: 1/16 or 1/32 of the peripheral clock frequency. As shown in Figure 127 the selection is done using SMOD1 bit in PCON register. Figure 128 gives the baud rate calculation formula depending on the selection. Figure 127. Baud Rate Generator Selection (Mode 2) PER CLOCK ÷2 0 1 ÷ 16 To Serial Port SMOD1 PCON.7 174 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Figure 128. Baud Rate Formula (Mode 2) Baud_Rate= 2SMOD1 ⋅ FPER 32 Multiprocessor Communication (Modes 2 and 3) Modes 2 and 3 provide a ninth-bit mode to facilitate multiprocessor communication. To enable this feature, set SM2 bit in SCON register. When the 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 AT8xC51SND2C to function as a slave processor in an environment where multiple slave processors share a single serial line. When the multiprocessor communication feature is enabled, the receiver ignores frames with the ninth bit clear. The receiver examines frames with 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. Automatic Address Recognition The automatic address recognition feature is enabled when the multiprocessor communication feature is enabled (SM2 bit in SCON register is set). Implemented in hardware, automatic address recognition enhances the multiprocessor communication feature by allowing the Serial Port to examine 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 that the CPU is not interrupted by command frames addressed to other devices. If desired, the automatic address recognition feature in mode 1 may be enabled. In this configuration, the stop bit takes the place of the ninth data 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 broadcast 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). Given Address Each device has an individual address that is specified in SADDR register; the SADEN register is a mask Byte that contains don’t care bits (defined by zeros) to form the device’s given address. The don’t care bits provide the flexibility 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 175 4341D–MP3–04/05 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; for 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 address with bits 0 and 1 both set (e.g. 1111 0011B). To communicate with slaves A, B and C, the master must send an address with bit 0 set, bit 1 clear, and bit 2 clear (e.g. 1111 0001B). Broadcast Address A broadcast address is formed from the logical OR of 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. Reset Address On reset, the SADDR and SADEN registers are initialized to 00h, i.e. the given and broadcast addresses are XXXX XXXXb (all don’t care bits). This ensures that the Serial Port is backwards compatible with the 80C51 microcontrollers that do not support automatic address recognition. 176 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Interrupt The Serial I/O Port handles 2 interrupt sources that are the “end of reception” (RI in SCON) and “end of transmission” (TI in SCON) flags. As shown in Figure 129 these flags are combined together to appear as a single interrupt source for the C51 core. Flags must be cleared by software when executing the serial interrupt service routine. The serial interrupt is enabled by setting ES bit in IEN0 register. This assumes interrupts are globally enabled by setting EA bit in IEN0 register. Depending on the selected mode and weather the framing error detection is enabled or disabled, RI flag is set during the stop bit or during the ninth bit as detailed in Figure 130. Figure 129. Serial I/O Interrupt System SCON.0 RI Serial I/O Interrupt Request TI SCON.1 ES IEN0.4 Figure 130. Interrupt Waveforms a. Mode 1 RXD Start Bit RI SMOD0 = X FE SMOD0 = 1 b. Mode 2 and 3 RXD Start bit RI SMOD0 = 0 RI SMOD0 = 1 FE SMOD0 = 1 D0 D1 D2 D3 D4 9-bit data D5 D6 D7 D8 Stop bit D0 D1 D2 D3 D4 D5 D6 D7 Stop Bit 8-bit Data 177 4341D–MP3–04/05 Registers Table 160. SCON Register SCON (S:98h) – Serial Control Register 7 FE/SM0 Bit Number 6 OVR/SM1 5 SM2 4 REN 3 TB8 2 RB8 1 TI 0 RI Bit Mnemonic Description Framing Error Bit To select this function, set SMOD0 bit in PCON register. Set by hardware to indicate an invalid stop bit. Must be cleared by software. Serial Port Mode Bit 0 Refer to Table 158 for mode selection. Serial Port Mode Bit 1 Refer to Table 158 for mode selection. Serial Port Mode Bit 2 Set to enable the multiprocessor communication and automatic address recognition features. Clear to disable the multiprocessor communication and automatic address recognition features. Receiver Enable Bit Set to enable reception. Clear to disable reception. Transmit Bit 8 Modes 0 and 1: Not used. Modes 2 and 3: Software writes the ninth data bit to be transmitted to TB8. Receiver Bit 8 Mode 0: Not used. 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. Transmit Interrupt Flag Set by the transmitter after the last data bit is transmitted. Must be cleared by software. Receive Interrupt Flag Set by the receiver after the stop bit of a frame has been received. Must be cleared by software. FE 7 SM0 6 SM1 5 SM2 4 REN 3 TB8 2 RB8 1 TI 0 RI Reset Value = 0000 0000b 178 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Table 161. SBUF Register SBUF (S:99h) – Serial Buffer Register 7 SD7 Bit Number 7-0 6 SD6 5 SD5 4 SD4 3 SD3 2 SD2 1 SD1 0 SD0 Bit Mnemonic Description SD7:0 Serial Data Byte Read the last data received by the serial I/O Port. Write the data to be transmitted by the serial I/O Port. Reset value = XXXX XXXXb Table 162. SADDR Register SADDR (S:A9h) – Slave Individual Address Register 7 SAD7 Bit Number 7-0 6 SAD6 5 SAD5 4 SAD4 3 SAD3 2 SAD2 1 SAD1 0 SAD0 Bit Mnemonic Description SAD7:0 Slave Individual Address Reset Value = 0000 0000b Table 163. SADEN Register SADEN (S:B9h) – Slave Individual Address Mask Byte Register 7 SAE7 Bit Number 7-0 6 SAE6 5 SAE5 4 SAE4 3 SAE3 2 SAE2 1 SAE1 0 SAE0 Bit Mnemonic Description SAE7:0 Slave Address Mask Byte Reset Value = 0000 0000b 179 4341D–MP3–04/05 Table 164. BDRCON Register BDRCON (S:92h) – Baud Rate Generator Control Register 7 Bit Number 7-5 6 5 4 BRR 3 TBCK 2 RBCK 1 SPD 0 M0SRC Bit Mnemonic Description Reserved The value read from these bits are indeterminate. Do not set these bits. Baud Rate Run Bit Set to enable the baud rate generator. Clear to disable the baud rate generator. Transmission Baud Rate Selection Bit Set to select the baud rate generator as transmission baud rate generator. Clear to select the Timer 1 as transmission baud rate generator. Reception Baud Rate Selection Bit Set to select the baud rate generator as reception baud rate generator. Clear to select the Timer 1 as reception baud rate generator. Baud Rate Speed Bit Set to select high speed baud rate generation. Clear to select low speed baud rate generation. Mode 0 Baud Rate Source Bit Set to select the variable baud rate generator in Mode 0. Clear to select fixed baud rate in Mode 0. 4 BRR 3 TBCK 2 RBCK 1 SPD 0 M0SRC Reset Value = XXX0 0000b Table 165. BRL Register BRL (S:91h) – Baud Rate Generator Reload Register 7 BRL7 Bit Number 7-0 6 BRL6 5 BRL5 4 BRL4 3 BRL3 2 BRL2 1 BRL1 0 BRL0 Bit Mnemonic Description BRL7:0 Baud Rate Reload Value Reset Value = 0000 0000b 180 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Two-wire Interface (TWI) Controller The AT8xC51SND2C implements a TWI controller supporting the four standard master and slave modes with multimaster capability. Thus, it allows connection of slave devices like LCD controller, audio DAC, etc., but also external master controlling where the AT8xC51SND2C is used as a peripheral of a host. The TWI bus is a bi-directional TWI serial communication standard. It is designed primarily for simple but efficient integrated circuit control. The 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 low speed mode, however, some higher bit rates can be achieved depending on the oscillator frequency. Various communication configurations can be designed using this bus. Figure 131 shows a typical TWI bus configuration using the AT8xC51SND2C in master and slave modes. All the devices connected to the bus can be master and slave. Figure 131. Typical TWI Bus Configuration AT8xC51SND2C Master/Slave Rp SCL SDA Rp SCL SDA LCD Display Audio DAC HOST Microprocessor Description The CPU interfaces to the TWI logic via the following four 8-bit special function registers: the Synchronous Serial Control register (SSCON SFR, see Table 174), the Synchronous Serial Data register (SSDAT SFR, see Table 176), the Synchronous Serial Status register (SSSTA SFR, see Table 175) and the Synchronous Serial Address register (SSADR SFR, see Table 177). SSCON is used to enable the controller, to program the bit rate (see Table 174), to enable slave modes, to acknowledge or not a received data, to send 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 status of the TWI logic and the TWI bus. The three least significant bits are always zero. The five most significant bits contains the status code. There are 26 possible status codes. When SSSTA contains F8h, no relevant state information 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 167 to Table 136 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 shifting 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 bus 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 controller will respond when programmed as a slave transmitter or receiver. The LSB is used to enable general call address (00h) recognition. Figure 132 shows how a data transfer is accomplished on the TWI bus. 181 4341D–MP3–04/05 Figure 132. Complete Data Transfer on TWI Bus SDA MSB Slave Address R/W ACK direction signal bit from receiver 8 9 1 Nth data Byte ACK signal from receiver 8 9 P/S SCL S 1 2 2 Clock Line Held Low While Serial Interrupts Are Serviced The four operating modes are: • • • • Master transmitter Master receiver Slave transmitter Slave receiver Data transfer in each mode of operation are shown in Figure 133 through Figure 136. These figures contain the following abbreviations: A A Data S P MR MT SLA GCA R W Acknowledge bit (low level at SDA) Not acknowledge bit (high level on SDA) 8-bit data Byte START condition STOP condition Master Receive Master Transmit Slave Address General Call Address (00h) Read bit (high level at SDA) Write bit (low level at SDA) In Figure 133 through Figure 136, circles are used to indicate when the serial interrupt flag is set. The numbers in the circles show the status code held in SSSTA. At these points, a service routine must be executed to continue or complete the 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 status 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 167 through Table 136. 182 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C 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 174). The predefined bit rates are derived from the peripheral clock (FPER) issued from the Clock Controller block as detailed in section "Oscillator", page 12, while bit rate generator is based on timer 1 overflow output. Table 166. Serial Clock Rates SSCRx 2 0 0 0 0 1 1 1 1 1 0 0 1 1 0 0 1 1 0 0 1 0 1 0 1 0 1 FPER = 6 MHz 47 53.5 62.5 75 12.5 100 200(1) 0.5 < ⋅ < 125(1) Bit Frequency (kHz) FPER = 8 MHz 62.5 71.5 83 100 16.5 133.3(1) 266.7(1) FPER = 10 MHz 78.125 89.3 104.2(1) 125(1) 20.83 166.7(1) 333.3(1) FPER Divided By 128 112 96 80 480 60 30 96 ⋅ (256 – reload value Timer 1) 0.67 < ⋅ < 166.7(1) 0.81 < ⋅ < 208.3(1) Note: 1. These bit rates are outside of the low speed standard specification limited to 100 kHz but can be used with high speed TWI components limited to 400 kHz. Master Transmitter Mode In the master transmitter mode, a number of data Bytes are transmitted to a slave receiver (see Figure 133). Before the master transmitter mode can be entered, SSCON must be initialized as follows: SSCR2 Bit Rate SSPE 1 SSSTA 0 SSSTO 0 SSI 0 SSAA X SSCR1 Bit Rate SSCR0 Bit Rate SSCR2:0 define the serial bit rate (see Table 166). SSPE must be set to enable the controller. SSSTA, SSSTO and SSI must be cleared. The master transmitter mode may now be entered by setting the SSSTA bit. The TWI logic will now monitor the TWI bus and generate a START condition as soon as the bus becomes free. When a START condition is transmitted, the serial interrupt flag (SSI bit in SSCON) is set, and the status code in SSSTA is 08h. This status must be used to vector to an interrupt routine that loads SSDAT with the slave address and the data direction bit (SLA+W). The serial interrupt flag (SSI) must then be cleared before the serial transfer can continue. When the slave address and the direction bit have been transmitted and an acknowledgment bit has been received, SSI is set again and a number of status code in SSSTA are possible. There are 18h, 20h or 38h for the master mode and also 68h, 78h or B0h if the slave mode was enabled (SSAA = logic 1). The appropriate action to be taken for each of these status code is detailed in Table 167. This scheme is repeated until a STOP condition is transmitted. SSPE and SSCR2:0 are not affected by the serial transfer and are not referred to in Table 167. After a repeated START condition (state 10h) the controller may switch to the master receiver mode by loading SSDAT with SLA+R. 183 4341D–MP3–04/05 Master Receiver Mode In the master receiver mode, a number of data Bytes are received from a slave transmitter (see Figure 134). The transfer is initialized as in the master transmitter mode. When the START condition has been transmitted, the interrupt routine must load SSDAT with the 7 - bit slave address and the data direction bit (SLA+R). The serial interrupt flag (SSI) must then be cleared before the serial transfer can continue. 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 master mode and also 68h, 78h or B0h if the slave mode was enabled (SSAA = logic 1). The appropriate action to be taken for each of these status code is detailed in Table 136. This scheme is repeated until a STOP condition is transmitted. SSPE and SSCR2:0 are not affected by the serial transfer and are not referred to in Table 136. After a repeated START condition (state 10h) the controller may switch to the master transmitter mode by loading SSDAT with SLA+W. Slave Receiver Mode In the slave receiver mode, a number of data Bytes are received from a master transmitter (see Figure 135). To initiate the slave receiver mode, SSADR and SSCON must be loaded as follows: SSA6 SSA5 SSA4 SSA3 Own Slave Address SSA2 SSA1 SSA0 SSGC X ←⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯→ The upper 7 bits are the addresses to which the controller will respond when addressed by a master. If the LSB (SSGC) is set, the controller will respond to the general call address (00h); otherwise, it ignores the general call address. SSCR2 X SSPE 1 SSSTA 0 SSSTO 0 SSI 0 SSAA 1 SSCR1 X SSCR0 X 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 address or the general call address acknowledgment. SSSTA, SSSTO and SSI must be cleared. When SSADR and SSCON have been initialized, the controller waits until it is addressed by its own slave address followed by the data direction bit 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 appropriate action to be taken for each of these status code is detailed in Table 136 and Table 171. 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 controller will return a not acknowledge (logic 1) to SDA after the next received data Byte. 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 used to temporarily isolate the controller from the TWI bus. 184 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Slave Transmitter Mode In the slave transmitter mode, a number of data Bytes are transmitted to a master receiver (see Figure 136). Data transfer is initialized as in the slave receiver mode. When SSADR and SSCON have been initialized, the controller waits until it is addressed by its own slave address followed by the data direction bit which must be logic 1 (R) for operating in the slave transmitter mode. After its own slave address and the R bit have 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 action to be taken for each of these status code is detailed in Table 171. The slave transmitter mode may also be entered if arbitration is lost while the controller is in the master mode (see state B0h). If the SSAA bit is reset during a transfer, the controller 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 transfer. 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 used to temporarily isolate the controller from the TWI bus. Miscellaneous States There are 2 SSSTA codes that do not correspond to a defined TWI hardware state (see Table 172). These are discussed below. Status F8h indicates that no relevant information is available because the serial interrupt flag is not yet set. This occurs between other states and when 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 illegal position in the format frame. Examples of such illegal positions are during the serial transfer of an address Byte, a data Byte, or an acknowledge bit. When a bus error occurs, SSI is set. To recover from a bus error, the SSSTO flag must be set and SSI must be cleared. This causes the controller to enter the not addressed slave mode and to clear the SSSTO flag (no other bits 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. 185 4341D–MP3–04/05 Figure 133. Format and States in the Master Transmitter Mode MT Successful transmission to a slave receiver S SLA W A Data A P 08h Next transfer started with a repeated start condition 18h 28h S SLA W 10h R Not acknowledge received after the slave address A P 20h Not acknowledge received after a data Byte A P MR 30h Arbitration lost in slave address or data Byte A or A Other master continues A or A Other master continues 38h Arbitration lost and addressed as slave A Other master continues 38h 68h 78h B0h To corresponding states in slave mode From master to slave From slave to master Data A Any number of data Bytes and their associated acknowledge bits This number (contained in SSSTA) corresponds to a defined state of the TWI bus nnh 186 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Figure 134. Format and States in the Master Receiver Mode MR Successful reception from a slave transmitter S SLA R A Data A Data A P 08h Next transfer started with a repeated start condition 40h 50h 58h S SLA R 10h W Not acknowledge received after the slave address A P 48h Arbitration lost in slave address or data Byte A or A Other master continues MT A Other master continues 38h Arbitration lost and addressed as slave A Other master continues 38h 68h 78h B0h To corresponding states in slave mode From master to slave From slave to master Data A Any number of data Bytes and their associated acknowledge bits This number (contained in SSSTA) corresponds to a defined state of the TWI bus nnh 187 4341D–MP3–04/05 Figure 135. Format and States in the Slave Receiver Mode Reception of the own slave address and one or more data Bytes. All are acknowledged S SLA W A Data A Data A P or S 60h Last data Byte received is not acknowledged 80h 80h A A0h P or S 88h Arbitration lost as master and addressed as slave A 68h Reception of the general call address and one or more data Bytes General Call A Data A Data A P or S 70h Last data Byte received is not acknowledged 90h 90h A A0h P or S 98h Arbitration lost as master and addressed as slave by general call A 78h From master to slave From slave to master Data A Any number of data Bytes and their associated acknowledge bits This number (contained in SSSTA) corresponds to a defined state of the TWI bus nnh 188 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Figure 136. Format and States in the Slave Transmitter Mode Reception of the own slave address and transmission of one or more data Bytes. S SLA R A Data A Data A P or S A8h Arbitration lost as master and addressed as slave A B8h C0h B0h Last data Byte transmitted. Switched to not addressed slave (SSAA = 0). A All 1’s P or S C8h From master to slave From slave to master Data A Any number of data Bytes and their associated acknowledge bits This number (contained in SSSTA) corresponds to a defined state of the TWI bus nnh 189 4341D–MP3–04/05 Table 167. Status for Master Transmitter Mode Application Software Response Status Code SSSTA 08h Status of the TWI Bus and TWI Hardware To/From SSDAT A START condition has Write SLA+W been transmitted A repeated START condition has been transmitted Write SLA+W Write SLA+R Write data Byte 18h SLA+W has been transmitted; ACK has been received No SSDAT action No SSDAT action No SSDAT action Write data Byte 20h SLA+W has been transmitted; NOT ACK has been received No SSDAT action No SSDAT action No SSDAT action Write data Byte 28h Data Byte has been transmitted; ACK has been received No SSDAT action No SSDAT action No SSDAT action Write data Byte 30h Data Byte has been transmitted; NOT ACK has been received No SSDAT action No SSDAT action No SSDAT action No SSDAT action 38h Arbitration lost in SLA+W or data Bytes No SSDAT action To SSCON SSSTA X X X 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 SSSTO 0 0 0 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 SSI 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 SSAA X X X X X X X X X X X X X X X X X X X X X Next Action Taken by TWI Hardware SLA+W will be transmitted. SLA+W will be transmitted. SLA+R will be transmitted. Logic will switch to master receiver mode Data Byte will be transmitted. Repeated START will be transmitted. STOP condition will be transmitted and SSSTO flag will be reset. STOP condition followed by a START condition will be transmitted and SSSTO flag will be reset. Data Byte will be transmitted. Repeated START will be transmitted. STOP condition will be transmitted and SSSTO flag will be reset. STOP condition followed by a START condition will be transmitted and SSSTO flag will be reset. Data Byte will be transmitted. Repeated START will be transmitted. STOP condition will be transmitted and SSSTO flag will be reset. STOP condition followed by a START condition will be transmitted and SSSTO flag will be reset. Data Byte will be transmitted. Repeated START will be transmitted. STOP condition will be transmitted and SSSTO flag will be reset. STOP condition followed by a START condition will be transmitted and SSSTO flag will be reset. TWI bus will be released and not addressed slave mode will be entered. A START condition will be transmitted when the bus becomes free. 10h 190 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Table 168. Status for Master Receiver Mode Application Software Response Status Code SSSTA 08h Status of the TWI Bus and TWI Hardware To/From SSDAT A START condition has Write SLA+R been transmitted A repeated START condition has been transmitted Write SLA+R Write SLA+W No SSDAT action No SSDAT action No SSDAT action No SSDAT action No SSDAT action 48h SLA+R has been transmitted; NOT ACK has been received No SSDAT action No SSDAT action Read data Byte Read data Byte Read data Byte 58h Data Byte has been received; NOT ACK has been returned Read data Byte Read data Byte To SSCON SSSTA X X X 0 1 0 0 1 0 1 0 0 1 0 1 SSSTO 0 0 0 0 0 0 0 0 1 1 0 0 0 1 1 SSI 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 SSAA X X X X X 0 1 X X X 0 1 X X X Next Action Taken by TWI Hardware SLA+R will be transmitted. SLA+R will be transmitted. SLA+W will be transmitted. Logic will switch to master transmitter mode. TWI bus will be released and not addressed slave mode will be entered. A START condition will be transmitted when the bus becomes free. Data Byte will be received and NOT ACK will be returned. Data Byte will be received and ACK will be returned. Repeated START will be transmitted. STOP condition will be transmitted and SSSTO flag will be reset. STOP condition followed by a START condition will be transmitted and SSSTO flag will be reset. Data Byte will be received and NOT ACK will be returned. Data Byte will be received and ACK will be returned. Repeated START will be transmitted. STOP condition will be transmitted and SSSTO flag will be reset. STOP condition followed by a START condition will be transmitted and SSSTO flag will be reset. 10h 38h Arbitration lost in SLA+R or NOT ACK bit SLA+R has been transmitted; ACK has been received 40h 50h Data Byte has been received; ACK has been returned 191 4341D–MP3–04/05 Table 169. Status for Slave Receiver Mode with Own Slave Address Application Software Response Status Code SSSTA Status of the TWI Bus and TWI Hardware To/From SSDAT Own SLA+W has been No SSDAT action received; ACK has been returned No SSDAT action Arbitration lost in SLA+R/W as master; own SLA+W has been received; ACK has been returned Previously addressed with own SLA+W; data has been received; ACK has been returned No SSDAT action X No SSDAT action X Read data Byte X Read data Byte X Read data Byte Read data Byte Previously addressed with own SLA+W; data has been received; NOT ACK has been returned 0 0 Read data Byte 1 Read data Byte 1 0 0 1 0 0 0 0 0 0 0 0 1 0 0 1 Switched to the not addressed slave mode; no recognition of own SLA or GCA. Switched to the not addressed slave mode; own SLA will be recognized; GCA will be recognized if SSGC = logic 1. Switched to the not addressed slave mode; no recognition of own SLA or GCA. A START condition will be transmitted when the bus becomes free. Switched to the not addressed slave mode; own SLA will be recognized; GCA will be recognized if SSGC = logic 1. A START condition will be transmitted when the bus becomes free. Switched to the not addressed slave mode; no recognition of own SLA or GCA. Switched to the not addressed slave mode; own SLA will be recognized; GCA will be recognized if SSGC = logic 1. Switched to the not addressed slave mode; no recognition of own SLA or GCA. A START condition will be transmitted when the bus becomes free. Switched to the not addressed slave mode; own SLA will be recognized; GCA will be recognized if SSGC = logic 1. A START condition will be transmitted when the bus becomes free. 0 0 0 0 0 1 Data Byte will be received and NOT ACK will be returned. Data Byte will be received and ACK will be returned. 0 0 0 To SSCON SSSTA X X SSSTO 0 0 SSI 0 0 SSAA 0 1 Next Action Taken by TWI Hardware Data Byte will be received and NOT ACK will be returned. Data Byte will be received and ACK will be returned. Data Byte will be received and NOT ACK will be returned. Data Byte will be received and ACK will be returned. 60h 68h 80h 88h No SSDAT action No SSDAT action A STOP condition or repeated START condition has been received while still addressed as slave 0 0 No SSDAT action 1 No SSDAT action 1 0 0 1 0 0 0 0 0 0 0 0 1 A0h 192 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Table 170. Status for Slave Receiver Mode with General Call Address Application Software Response Status Code SSSTA Status of the TWI Bus and TWI Hardware To/From SSDAT General call address has been received; ACK has been returned Arbitration lost in SLA+R/W as master; general call address has been received; ACK has been returned Previously addressed with general call; data has been received; ACK has been returned No SSDAT action No SSDAT action No SSDAT action No SSDAT action X X 0 0 0 0 0 1 To SSCON SSSTA X X SSSTO 0 0 SSI 0 0 SSAA 0 1 Next Action Taken by TWI Hardware Data Byte will be received and NOT ACK will be returned. Data Byte will be received and ACK will be returned. Data Byte will be received and NOT ACK will be returned. Data Byte will be received and ACK will be returned. 70h 78h Read data Byte X Read data Byte X Read data Byte Read data Byte 0 0 Read data Byte 1 Read data Byte 1 0 0 1 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 Data Byte will be received and NOT ACK will be returned. Data Byte will be received and ACK will be returned. 90h Switched to the not addressed slave mode; no recognition of own SLA or GCA. Switched to the not addressed slave mode; own SLA will be recognized; GCA will be recognized if SSGC = logic 1. Switched to the not addressed slave mode; no recognition of own SLA or GCA. A START condition will be transmitted when the bus becomes free. Switched to the not addressed slave mode; own SLA will be recognized; GCA will be recognized if SSGC = logic 1. A START condition will be transmitted when the bus becomes free. Switched to the not addressed slave mode; no recognition of own SLA or GCA. Switched to the not addressed slave mode; own SLA will be recognized; GCA will be recognized if SSGC = logic 1. Switched to the not addressed slave mode; no recognition of own SLA or GCA. A START condition will be transmitted when the bus becomes free. Switched to the not addressed slave mode; own SLA will be recognized; GCA will be recognized if SSGC = logic 1. A START condition will be transmitted when the bus becomes free. 98h Previously addressed with general call; data has been received; NOT ACK has been returned No SSDAT action No SSDAT action A STOP condition or repeated START condition has been received while still addressed as slave 0 0 No SSDAT action 1 No SSDAT action 1 0 0 1 0 0 0 0 0 0 0 0 1 A0h 193 4341D–MP3–04/05 Table 171. Status for Slave Transmitter Mode Application Software Response Status Code SSSTA Status of the TWI Bus and TWI Hardware To/From SSDAT Own SLA+R has been received; ACK has been returned Arbitration lost in SLA+R/W as master; own SLA+R has been received; ACK has been returned Data Byte in SSDAT has been transmitted; ACK has been received Write data Byte Write data Byte Write data Byte X Write data Byte X Write data Byte Write data Byte No SSDAT action No SSDAT action Data Byte in SSDAT has been transmitted; NOT ACK has been received 0 0 No SSDAT action 1 No SSDAT action 1 0 0 1 0 0 0 0 0 0 0 0 1 0 0 1 Last data Byte will be transmitted. Data Byte will be transmitted. Switched to the not addressed slave mode; no recognition of own SLA or GCA. Switched to the not addressed slave mode; own SLA will be recognized; GCA will be recognized if SSGC = logic 1. Switched to the not addressed slave mode; no recognition of own SLA or GCA. A START condition will be transmitted when the bus becomes free. Switched to the not addressed slave mode; own SLA will be recognized; GCA will be recognized if SSGC = logic 1. A START condition will be transmitted when the bus becomes free. Switched to the not addressed slave mode; no recognition of own SLA or GCA. Switched to the not addressed slave mode; own SLA will be recognized; GCA will be recognized if SSGC = logic 1. Switched to the not addressed slave mode; no recognition of own SLA or GCA. A START condition will be transmitted when the bus becomes free. Switched to the not addressed slave mode; own SLA will be recognized; GCA will be recognized if SSGC = logic 1. A START condition will be transmitted when the bus becomes free. 0 0 0 Data Byte will be transmitted. SSSTA X X To SSCON SSSTO 0 0 SSI 0 0 SSAA 0 1 Next Action Taken by TWI Hardware Last data Byte will be transmitted. Data Byte will be transmitted. Last data Byte will be transmitted. A8h B0h X X 0 0 0 0 0 1 B8h C0h No SSDAT action No SSDAT action Last data Byte in SSDAT has been transmitted (SSAA= 0); ACK has been received 0 0 No SSDAT action 1 No SSDAT action 1 0 0 1 0 0 0 0 0 0 0 0 1 C8h Table 172. Status for Miscellaneous States Application Software Response Status Code SSSTA F8h Status of the TWI Bus and TWI Hardware To/From SSDAT No relevant state information available; SSI = 0 No SSDAT action No SSCON action Only the internal hardware is affected, no STOP condition is sent on the bus. In all cases, the bus is released and SSSTO is reset. To SSCON SSSTA SSSTO SSI SSAA Next Action Taken by TWI Hardware Wait or proceed current transfer. 00h No SSDAT action Bus error due to an illegal START or STOP condition 0 1 0 X 194 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Registers Table 173. AUXCON Register AUXCON (S:90h) – Auxiliary Control Register 7 SDA Bit Number 7 6 SCL Bit Mnemonic SDA 5 4 AUDCDOUT 3 AUDCDIN 2 AUDCCLK 1 AUDCCS 0 KIN0 Description TWI Serial Data SDA is the bidirectional Two Wire data line. TWI Serial Clock When TWI controller is in master mode, SCL outputs the serial clock to the slave peripherals. When TWI controller is in slave mode, SCL receives clock from the master controller. Audio DAC Control Refer to Audio DAC interface section 6 SCL 5:1 0 KIN0 Keyboard Input Line Reset Value = 1111 1111b Table 174. SSCON Register SSCON (S:93h) – Synchronous Serial Control Register 7 SSCR2 6 SSPE 5 SSSTA 4 SSSTO 3 SSI 2 SSAA 1 SSCR1 0 SSCR0 195 4341D–MP3–04/05 Bit Number 7 Bit Mnemonic Description SSCR2 Synchronous Serial Control Rate Bit 2 Refer to Table 166 for rate description. Synchronous Serial Peripheral Enable Bit Set to enable the controller. Clear to disable the controller. Synchronous Serial Start Flag Set to send a START condition on the bus. Clear not to send a START condition on the bus. Synchronous Serial Stop Flag Set to send a STOP condition on the bus. Clear not to send a STOP condition on the bus. Synchronous Serial Interrupt Flag Set by hardware when a serial interrupt is requested. Must be cleared by software to acknowledge interrupt. Synchronous Serial Assert Acknowledge Flag Set to enable slave modes. Slave modes are entered when SLA or GCA (if SSGC set) is recognized. Clear to disable slave modes. Master Receiver Mode in progress Clear to force a not acknowledge (high level on SDA). Set to force an acknowledge (low level on SDA). Master Transmitter Mode in progress This bit has no specific effect when in master transmitter mode. Slave Receiver Mode in progress Clear to force a not acknowledge (high level on SDA). Set to force an acknowledge (low level on SDA). Slave Transmitter Mode in progress Clear to isolate slave from the bus after last data Byte transmission. Set to enable slave mode. Synchronous Serial Control Rate Bit 1 Refer to Table 166 for rate description. Synchronous Serial Control Rate Bit 0 Refer to Table 166 for rate description. 6 SSPE 5 SSSTA 4 SSSTO 3 SSI 2 SSAA 1 0 SSCR1 SSCR0 Reset Value = 0000 0000b 196 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Table 175. SSSTA Register SSSTA (S:94h) – Synchronous Serial Status Register 7 SSC4 Bit Number 7:3 2:0 6 SSC3 5 SSC2 4 SSC1 3 SSC0 2 0 1 0 0 0 Bit Mnemonic Description SSC4:0 0 Synchronous Serial Status Code Bits 0 to 4 Refer to Table 167 to Table 136 for status description. Always 0. Reset Value = F8h Table 176. SSDAT Register SSDAT (S:95h) – Synchronous Serial Data Register 7 SSD7 Bit Number 7:1 0 6 SSD6 5 SSD5 4 SSD4 3 SSD3 2 SSD2 1 SSD1 0 SSD0 Bit Mnemonic Description SSD7:1 SSD0 Synchronous Serial Address bits 7 to 1 or Synchronous Serial Data Bits 7 to 1 Synchronous Serial Address bit 0 (R/W) or Synchronous Serial Data Bit 0 Reset Value = 1111 1111b Table 177. SSADR Register SSADR (S:96h) – Synchronous Serial Address Register 7 SSA7 Bit Number 7:1 0 6 SSA6 5 SSA5 4 SSA4 3 SSA3 2 SSA2 1 SSA1 0 SSGC Bit Mnemonic Description SSA7:1 SSGC Synchronous Serial Slave Address Bits 7 to 1 Synchronous Serial General Call Bit Set to enable the general call address recognition. Clear to disable the general call address recognition. Reset Value = 1111 1110b 197 4341D–MP3–04/05 Keyboard Interface The AT8xC51SND2C implement a keyboard interface allowing the connection of a keypad. It is based on one input with programmable interrupt capability on both high or low level. This input allows exit from idle and power down modes. The keyboard interfaces with the C51 core through 2 special function registers: KBCON, the keyboard control register (see Table 179); and KBSTA, the keyboard control and status register (see Table 180). An interrupt enable bit (EKB in IEN1 register) allows global enable or disable of the keyboard interrupt (see Figure 137). As detailed in Figure 138 this keyboard input has the capability to detect a programmable level according to KINL0 bit value in KBCON register. Level detection is then reported in interrupt flag KINF0 in KBSTA register. A keyboard interrupt is requested each time this flag is set. This flag can be masked by software using KINM0 bits in KBCON register and is cleared by reading KBSTA register. Figure 137. Keyboard Interface Block Diagram Description KIN0 Input Circuitry EKB IEN1.4 Keyboard Interface Interrupt Request Figure 138. Keyboard Input Circuitry 0 1 KIN0 KINF0 KBSTA.0 KINM0 KINL0 KBCON.4 KBCON.0 Power Reduction Mode KIN0 inputs allow exit from idle and power-down modes as detailed in section “Power Management”, page 46. To enable this feature, KPDE bit in KBSTA register must be set to logic 1. Due to the asynchronous keypad detection in power down mode (all clocks are stopped), exit may happen on parasitic key press. In this case, no key is detected and software must enter power down again. 198 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Registers Table 178. AUXCON Register AUXCON (S:90h) – Auxiliary Control Register 7 SDA Bit Number 7:6 6 SCL Bit Mnemonic 5 4 AUDCDOUT 3 AUDCDIN 2 AUDCCLK 1 AUDCCS 0 KIN0 Description TWI Lines Refer to TWI section. 5:1 0 KIN0 Audio DAC Control Refer to Audio DAC section. Keyboard Input Interrupt. Reset Value = 1111 1111b Table 179. KBCON Register KBCON (S:A3h) – Keyboard Control Register 7 Bit Number 7-5 6 5 4 KINL0 3 2 1 0 KINM0 Bit Mnemonic Description Reserved Do not set these bits. Keyboard Input Level Bit Set to enable a high level detection on the respective KIN0 input. Clear to enable a low level detection on the respective KIN0 input. Reserved Do not reset these bits. Keyboard Input Mask Bit Set to prevent the respective KINF3:0 flag from generating a keyboard interrupt. Clear to allow the respective KINF3:0 flag to generate a keyboard interrupt. 4 KINL0 3-1 - 0 KINM0 Reset Value = 0000 1111b Table 180. KBSTA Register KBSTA (S:A4h) – Keyboard Control and Status Register 7 KPDE Bit Number 7 6 5 4 3 2 1 0 KINF0 Bit Mnemonic Description KPDE Keyboard Power Down Enable Bit Set to enable exit of power down mode by the keyboard interrupt. Clear to disable exit of power down mode by the keyboard interrupt. 199 4341D–MP3–04/05 Bit Number 6-1 Bit Mnemonic Description Reserved The value read from these bits is always 0. Do not set these bits. Keyboard Input Interrupt Flag Set by hardware when the KIN0 input detects a programmed level. Cleared when reading KBSTA. 0 KINF0 Reset Value = 0000 0000b 200 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Electrical Characteristics Absolute Maximum Rating Storage Temperature ......................................... -65 to +150°C Voltage on any other Pin to VSS .................................... -0.3 *NOTICE: to +4.0 V IOL per I/O Pin ................................................................. 5 mA Power Dissipation ............................................................. 1 W Operating Conditions Ambient Temperature Under Bias........................ -40 to +85°C VDD ......................................................................................................... 2.7 to 3.3V Stressing the device beyond the “Absolute Maximum Ratings” may cause permanent damage. These are stress ratings only. Operation beyond the “operating conditions” is not recommended and extended exposure beyond the “Operating Conditions” may affect device reliability. DC Characteristics Digital Logic Table 181. Digital DC Characteristics VDD = 2.7 to 3.3 V, TA = -40 to +85°C Symbol VIL VIH1(2) VIH2 VOL1 Parameter Input Low Voltage Input High Voltage (except RST, X1) Input High Voltage (RST, X1) Output Low Voltage (except P0, ALE, MCMD, MDAT, MCLK, SCLK, DCLK, DSEL, DOUT) Output Low Voltage (P0, ALE, MCMD, MDAT, MCLK, SCLK, DCLK, DSEL, DOUT) Output High Voltage (P1, P2, P3, P4 and P5) Output High Voltage (P0, P2 address mode, ALE, MCMD, MDAT, MCLK, SCLK, DCLK, DSEL, DOUT, D+, D-) Logical 0 Input Current (P1, P2, P3, P4 and P5) Input Leakage Current (P0, ALE, MCMD, MDAT, MCLK, SCLK, DCLK, DSEL, DOUT) Logical 1 to 0 Transition Current (P1, P2, P3, P4 and P5) Pull-Down Resistor Pin Capacitance VDD Data Retention Limit 50 90 10 1.8 VDD - 0.7 Min -0.5 0.2·VDD + 1.1 0.7·VDD Typ(1) Max 0.2·VDD - 0.1 VDD VDD + 0.5 0.45 Units V V V V IOL= 1.6 mA Test Conditions VOL2 0.45 V IOL= 3.2 mA VOH1 V IOH= -30 µA VOH2 VDD - 0.7 V IOH= -3.2 mA IIL -50 µA VIN= 0.45 V ILI 10 µA 0.45< VIN< VDD ITL RRST CIO VRET -650 200 µA kΩ pF V VIN= 2.0 V TA= 25°C 201 4341D–MP3–04/05 Table 181. Digital DC Characteristics VDD = 2.7 to 3.3 V, TA = -40 to +85°C Symbol Parameter Min Typ(1) Max X1 / X2 mode 7/ 11.5 9/ 14.5 10.5 / 18 X1 / X2 mode 7/ 11.5 9/ 14.5 10.5 / 18 X1 / X2 mode 6.3 / 9.1 7.4 / 11.3 8.5 / 14 X1 / X2 mode 6.3 / 9.1 7.4 / 11.3 8.5 / 14 20 20 500 500 +15 Units Test Conditions VDD < 3.3 V mA 12 MHz 16 MHz 20 MHz VDD < 3.3 V mA 12 MHz 16 MHz 20 MHz VDD < 3.3 V mA 12 MHz 16 MHz 20 MHz VDD < 3.3 V mA 12 MHz 16 MHz 20 MHz VRET < VDD < 3.3 V VRET < VDD < 3.3 V VDD < 3.3 V AT89C51SND2C Operating Current IDD AT83SND2C Operating Current (3) AT89C51SND2C Idle Mode Current IDL AT83SND2C Idle Mode Current (3) AT89C51SND2C Power-Down Mode Current IPD AT83SND2C Power-Down Mode Current AT89C51SND2C Flash Programming Current µA µA mA IFP Notes: 1. Typical values are obtained using VDD= 3 V and TA= 25°C. They are not tested and there is no guarantee on these values. 2. Flash retention is guaranteed with the same formula for VDD min down to 0V. 3. See Table 182 for typical consumption in player mode. Table 182. Typical Reference Design AT89C51SND2C Power Consumption Player Mode IDD 10 mA Test Conditions AT89C51SND2C at 16 MHz, X2 mode, VDD= 3 V No song playing. This consumption does not include AUDVBAT current. AT89C51SND2C at 16 MHz, X2 mode, VDD= 3 V MP3 Song with Fs= 44.1 KHz, at any bit rates (Variable Bit Rate) This consumption does not include AUDVBAT current. Stop Playing 37 mA 202 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C IDD, IDL and IPD Test Conditions Figure 139. IDD Test Condition, Active Mode VDD VDD RST VDD PVDD UVDD AUDVDD IDD (NC) Clock Signal X2 X1 P0 VSS PVSS UVSS AUDVSS TST VDD VSS All other pins are unconnected Figure 140. IDL Test Condition, Idle Mode VDD RST VSS VDD PVDD UVDD AUDVDD IDL (NC) Clock Signal X2 X1 P0 VSS PVSS UVSS AUDVSS TST VDD VSS All other pins are unconnected Figure 141. IPD Test Condition, Power-Down Mode VDD RST VSS VDD PVDD UVDD AUDVDD P0 MCMD MDAT TST IPD VDD (NC) X2 X1 VSS PVSS UVSS AUDVSS VSS All other pins are unconnected 203 4341D–MP3–04/05 Oscillator & Crystal Schematic Figure 142. Crystal Connection X1 C1 Q C2 VSS X2 Note: For operation with most standard crystals, no external components are needed on X1 and X2. It may be necessary to add external capacitors on X1 and X2 to ground in special cases (max 10 pF). X1 and X2 may not be used to drive other circuits. Parameters Table 183. Oscillator & Crystal Characteristics VDD = 2.7 to 3.3 V, TA = -40 to +85°C Symbol CX1 CX2 CL DL F RS CS Parameter Internal Capacitance (X1 - VSS) Internal Capacitance (X2 - VSS) Equivalent Load Capacitance (X1 - X2) Drive Level Crystal Frequency Crystal Series Resistance Crystal Shunt Capacitance Min Typ 10 10 5 50 20 40 6 Max Unit pF pF pF µW MHz Ω pF Phase Lock Loop Schematic Figure 143. PLL Filter Connection FILT R C1 VSS VSS C2 Parameters Table 184. PLL Filter Characteristics VDD = 2.7 to 3.3 V, TA = -40 to +85°C Symbol R C1 C2 Filter Resistor Filter Capacitance 1 Filter Capacitance 2 Parameter Min Typ 100 10 2.2 Max Unit Ω nF nF 204 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C USB Connection Schematic Figure 144. USB Connection VBUS D+ DGND VSS To Power Supply RUSB RUSB D+ D- Parameters Table 185. USB Termination Characteristics VDD = 2.7 to 3.3 V, TA = -40 to +85°C Symbol RUSB Parameter USB Termination Resistor Min Typ 27 Max Unit Ω DAC and PA Electrical Specifications PA AUDVBAT = 3.6V, TA = 25°C unless otherwise noted. High power mode, 100nF capacitor connected between CBP and AUDVSS, 470nF input capacitors, Load = 8 ohms. Figure 145. PA Specification Symbol AUDVBAT IDD IDDstby VCBP VOS ZIN ZLFP ZLLP CL PSRR Parameter Supply Voltage Quiescent Current Standby Current DC Reference Output differential offset Input impedance Output load Output load Capacitive load Power supply rejection ratio 200 – 2kHz Differential output 1KHz reference frequency BW Output Frequency bandwidth 3dB attenuation. 470nF input coupling capacitors tUP VN Output setup time Output noise Off to on mode. Voltage already settled. Input capacitors precharged Max gain, A weighted 120 10 500 ms µVRMS 50 20000 Hz full gain Active state Full Power mode Low-Power mode Inputs shorted, no load Capacitance Conditions Min 3.2 -20 12K 6 100 Typ 6 AUDVBAT/2 0 20k 8 150 60 Max 5.5 8 2 20 30k 32 300 100 Unit V mA µA V mV W W W pF dB 205 4341D–MP3–04/05 Symbol THDHP Parameter Output distortion Conditions High power mode, VDD = 3.2V, 1KHz, Pout=100mW, gain=0dB Low power mode, VDD = 3.2V , 1KHz, Vout= 100mVpp, Max gain, load 8 ohms in serie with 200 ohms Min - Typ 50 Max - Unit dB THDLP GACC GSTEP Output distortion Overall Gain accuracy Gain Step Accuracy -2 -0.7 1 0 0 2 0.7 % dB dB Figure 146. Maximum Dissipated Power Versus Power Supply 600 550 Dissipated Power [mW] 500 450 400 350 300 250 200 3,2 3,4 3,6 3,8 4 Supply Voltage AUDVBAT [V] 4,2 8 Ohms load 6.5 Ohms load Figure 147. Dissipated Power vs Output Power, AUDVBAT = 3.2V 600 550 500 Dissipated Power [mW] 450 400 350 300 250 200 150 100 50 0 0 100 200 300 400 500 600 700 800 Output Power [mW] 8 Ohms load 6.5 Ohms load 206 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C DAC AUDVDD, HSVDD = 2.8 V, Ta=25°C, typical case, unless otherwise noted All noise and distortion specifications are measured in the 20 Hz to 0.425xFs and Aweighted filtered. Full Scale levels scale proportionally with the analog supply voltage. Figure 148. Audio DAC Specification OVERALL Operating Temperature Analog Supply Voltage (AUDVDD, HSVDD) Digital Supply Voltage (VDD) Audio Amplifier Supply (AUDVBAT) DIGITAL INPUTS/OUTPUTS Resolution Logic Family Logic Coding 20 CMOS 2’s Complement Bits MIN -40 2.7 2.4 3.2 TYP +25 2.8 2.8 MAX +125 3.3 3.3 5.5 UNITS °C V V V ANALOG PERFORMANCE – DAC to Line-out/Headphone Output Output level for full scale input (for AUDVDD, HSVDD = 2.8 V) Output common mode voltage Output load resistance (on HSL, HSR) - Headphone load - Line load Output load capacitance (on HSL, HSR) - Headphone load - Line load Signal to Noise Ratio (–1dBFS @ 1kHz input and 0dB Gain) - Line and Headphone loads Total Harmonic Distortion (–1dBFS @ 1kHz input and 0dB Gain) - Line Load - Headphone Load - Headphone Load (16 Ohm) Dynamic Range (measured with -60 dBFS @ 1kHz input, extrapolated to full-scale) - Line Load - Headphone Load Interchannel mismatch Left-channel to right-channel crosstalk (@ 1kHz) Output Power Level Control Range Output Power Level Control Step -6 88 70 93 74 0.1 -90 3 1 -80 6 dB dB dB dB dB dB -80 -65 -40 -76 -60 dB dB dB 87 92 dB 30 30 1000 150 pF pF 16 32 10 Ohm kOhm 1.65 0.5xHSVDD Vpp V 207 4341D–MP3–04/05 OVERALL PSRR - 1kHz - 20kHz Maximum output slope at power up (100 to 220F coupling capacitor) MIN TYP MAX UNITS 55 50 3 dB dB V/s ANALOG PERFORMANCE – Line-in/Microphone Input to Line-out/Headphone Output Input level for full scale output - 0dBFS Level @ AUDVDD, HSVDD = 2.8 V and 0 dB gain @ AUDVDD, HSVDD = 2.8 V and 20 dB gain 1.65 583 0.165 58.3 0.5xAUDVD D 7 10 Vpp mVrms Vpp mVrms V kOhm Input common mode voltage Input impedance Signal to Noise Ratio -1 dBFS @ 1kHz input and 0 dB gain -21 dBFS @ 1kHz input and 20 dB gain Dynamic Range (extrapolated to full scale level) -60 dBFS @ 1kHz input and 0 dB gain -60 dBFS @ 1kHz input and 20 dB gain Total Harmonic Distortion –1dBFS @ 1kHz input and 0 dB gain –1dBFS @ 1kHz input and 20 dB gain Interchannel mismatch Left-channel to right-channel crosstalk (@ 1kHz) ANALOG PERFORMANCE – Differential mono input amplifier Differential input level for full scale output - 0dBFS Level @ AUDVDD, HSVDD = 2.8 V and 0 dB gain 82 81 85 71 dB 86 72 dB -80 -75 0.1 -90 -76 -68 1 -80 dB dB dB 1.65 583 0.5xAUDVD D 7 76 10 80 -85 -81 Vppdif mVrms V kOhm dB dB Input common mode voltage Input impedance Signal to Noise Ratio (-1 dBFS @ 1kHz input and 0 dB gain) Total Harmonic Distortion (–1dBFS @ 1kHz input and 0 dB gain) ANALOG PERFORMANCE – PA Driver Differential output level for full scale input (for AUDVDD, HSVDD = 3 V) Output common mode voltage Output load 3.3 0.5xHSVDD 10 Vppdif V kOhm 30 pF 208 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C OVERALL Signal to Noise Ratio (–1dBFS @ 1kHz input and 0dB Gain) Total Harmonic Distortion (–1dBFS @ 1kHz input and 0dB Gain) MASTER CLOCK Master clock Maximum Long Term Jitter DIGITAL FILTER PERFORMANCE Frequency response (10 Hz to 20 kHz) Deviation from linear phase (10 Hz to 20 kHz) Passband 0.1 dB corner Stopband Stopband Attenuation DE-EMPHASIS FILTER PERFORMANCE (for 44.1kHz Fs) Frequency Pass band Transition band Stop Band Power Performance Current consumption from Audio Analog supply AVDD, HSVDD in power on Current consumption from Audio Analog supply AVDD, HSVDD in power down Power on Settling Time - From full Power Down to Full Power Up (AUDVREF and AUDVCM decoupling capacitors charge) - Linein amplifier (Line-in coupling capacitors charge) - Driver amplifier (out driver DC blocking capacitors charge) 500 50 500 ms ms ms 9.5 10 mA µA 0Hz to 3180Hz 3180Hz to 10600Hz 10600Hz to 20kHz Gain -1dB Logarithm decay -10.45dB Margin 1dB 1dB 1dB 0.5465 65 +/- 0.1 +/- 0.1 0.4535 dB deg Fs Fs dB 1.5 nspp MIN 76 TYP 80 -75 -71 MAX UNITS dB dB 209 4341D–MP3–04/05 Digital Filters Transfer Function Figure 149. Channel Filter Figure 150. De-emphasis Filter 0 -2 -4 Gain (dB) -6 -8 -10 -12 10 3 10 4 Frequency (Hz) 210 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Audio DAC and PA Connection Figure 151. DAC and PA Connection PAINN AUDVSS C16 CBP AUDVSS C7 HPP AUDVSS Audio Dac and PA Connection VDD C17 VSS 3V from LDO Battery 3.2V to 5.5V AUDVBAT AUDVDD 3V from LDO 8 Ohm Loud Speaker HPN LPHN C15 R1 PAINP MONOP MONON AUDVREF HSVDD C18 AUDVSS C19 HSVSS C9 VSS C11 AUDVCM AUDVSS R C12 C8 LINER C3 LINEL Stereo Line Input L Mono AUDVSS mono input (+) mono input C1 (-) C6 C4 Differential Input AUXP AUXN HSR C5 HSL 32 Ohm 32 Ohm Headset or Line Out 32 Ohm INGND AUDVSS AUDVSS ESDVSS C10 ESDVSS VSS VSS 211 4341D–MP3–04/05 Table 186. DAC and PA Characteristics Symbol C1 C3 C4 C5 C6 C7 C8 C9 C10 C11 C12 C15 C16 C17 C18 C19 R1 Capacitance Capacitance Capacitance Capacitance Capacitance Capacitance Capacitance Capacitance Capacitance Capacitance Capacitance Capacitance Capacitance Capacitance Capacitance Capacitance Resistor Parameter Typ 470 470 470 100 100 100 470 100n 10 10 470 470 22 100 100 100 200 Unit nF nF nF µF µF nF nF µF µF µF nF nF µF nF nF nF Ω In System Programming Schematic Figure 152. ISP Pull-Down Connection ISP RISP VSS Parameters Table 187. ISP Pull-Down Characteristics VDD = 2.7 to 3.3 V, TA = -40 to +85°C Symbol RISP Parameter ISP Pull-Down Resistor Min Typ 2.2 Max Unit KΩ 212 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C AC Characteristics External Program Bus Cycles Definition of Symbols Table 188. External Program Bus Cycles Timing Symbol Definitions Signals A I L P Address Instruction In ALE PSEN H L V X Z Conditions High Low Valid No Longer Valid Floating Timings Test conditions: capacitive load on all pins= 50 pF. Table 189. External Program Bus Cycle - Read AC Timings VDD = 2.7 to 3.3 V, TA = -40 to +85°C Variable Clock Standard Mode Symbol TCLCL TLHLL TAVLL TLLAX TLLIV TPLPH TPLIV TPXIX TPXIZ TAVIV TPLAZ Parameter Clock Period ALE Pulse Width Address Valid to ALE Low Address hold after ALE Low ALE Low to Valid Instruction PSEN Pulse Width PSEN Low to Valid Instruction Instruction Hold After PSEN High Instruction Float After PSEN High Address Valid to Valid Instruction PSEN Low to Address Float 0 TCLCL-10 5·TCLCL-35 10 Min 50 2·TCLCL-15 TCLCL-20 TCLCL-20 4·TCLCL-35 3·TCLCL-25 3·TCLCL-35 0 0.5·TCLCL-10 2.5·TCLCL-35 10 Max Variable Clock X2 Mode Min 50 TCLCL-15 0.5·TCLCL-20 0.5·TCLCL-20 2·TCLCL-35 1.5·TCLCL-25 1.5·TCLCL-35 Max Unit ns ns ns ns ns ns ns ns ns ns ns 213 4341D–MP3–04/05 Waveforms Figure 153. External Program Bus Cycle - Read Waveforms ALE TLHLL TLLPL PSEN TPLIV TPLAZ TAVLL TLLAX P0 D7:0 A7:0 TPXAV TPXIZ TPXIX D7:0 Instruction In P2 A15:8 A7:0 D7:0 Instruction In A15:8 TPLPH External Data 8-bit Bus Cycles Definition of Symbols Table 190. External Data 8-bit Bus Cycles Timing Symbol Definitions Signals A D L Q R W Address Data In ALE Data Out RD WR H L V X Z Conditions High Low Valid No Longer Valid Floating Timings Test conditions: capacitive load on all pins= 50 pF. Table 191. External Data 8-bit Bus Cycle - Read AC Timings VDD = 2.7 to 3.3 V, TA = -40 to +85°C Variable Clock Standard Mode Symbol TCLCL TLHLL TAVLL TLLAX TLLRL Parameter Clock Period ALE Pulse Width Address Valid to ALE Low Address hold after ALE Low ALE Low to RD Low Min 50 2·TCLCL-15 TCLCL-20 TCLCL-20 3·TCLCL-30 Max Variable Clock X2 Mode Min 50 TCLCL-15 0.5·TCLCL-20 0.5·TCLCL-20 1.5·TCLCL-30 Max Unit ns ns ns ns ns 214 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Variable Clock Standard Mode Symbol TRLRH TRHLH TAVDV TAVRL TRLDV TRLAZ TRHDX TRHDZ Parameter RD Pulse Width RD high to ALE High Address Valid to Valid Data In Address Valid to RD Low RD Low to Valid Data RD Low to Address Float Data Hold After RD High Instruction Float After RD High 0 2·TCLCL-25 4·TCLCL-30 5·TCLCL-30 0 0 TCLCL-25 Min 6·TCLCL-25 TCLCL-20 TCLCL+20 9·TCLCL-65 2·TCLCL-30 2.5·TCLCL-30 0 Max Variable Clock X2 Mode Min 3·TCLCL-25 0.5·TCLCL-20 0.5·TCLCL+20 4.5·TCLCL-65 Max Unit ns ns ns ns ns ns ns ns 215 4341D–MP3–04/05 Table 192. External Data 8-bit Bus Cycle - Write AC Timings VDD = 2.7 to 3.3 V, TA = -40 to +85°C Variable Clock Standard Mode Symbol TCLCL TLHLL TAVLL TLLAX TLLWL TWLWH TWHLH TAVWL TQVWH TWHQX Parameter Clock Period ALE Pulse Width Address Valid to ALE Low Address hold after ALE Low ALE Low to WR Low WR Pulse Width WR High to ALE High Address Valid to WR Low Data Valid to WR High Data Hold after WR High Min 50 2·TCLCL-15 TCLCL-20 TCLCL-20 3·TCLCL-30 6·TCLCL-25 TCLCL-20 4·TCLCL-30 7·TCLCL-20 TCLCL-15 TCLCL+20 Max Variable Clock X2 Mode Min 50 TCLCL-15 0.5·TCLCL-20 0.5·TCLCL-20 1.5·TCLCL-30 3·TCLCL-25 0.5·TCLCL-20 2·TCLCL-30 3.5·TCLCL-20 0.5·TCLCL-15 0.5·TCLCL+20 Max Unit ns ns ns ns ns ns ns ns ns ns Waveforms Figure 154. External Data 8-bit Bus Cycle - Read Waveforms ALE TLHLL TLLRL TRLRH TRHLH RD TRLDV TRLAZ TAVLL P0 TLLAX A7:0 TAVRL TAVDV P2 A15:8 D7:0 Data In TRHDZ TRHDX 216 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Figure 155. External Data 8-bit Bus Cycle - Write Waveforms ALE TLHLL TLLWL TWLWH TWHLH WR TAVWL TAVLL P0 TLLAX A7:0 TQVWH D7:0 Data Out P2 A15:8 TWHQX External IDE 16-bit Bus Cycles Definition of Symbols Table 193. External IDE 16-bit Bus Cycles Timing Symbol Definitions Signals A D L Q R W Address Data In ALE Data Out RD WR H L V X Z Conditions High Low Valid No Longer Valid Floating 217 4341D–MP3–04/05 Timings Test conditions: capacitive load on all pins= 50 pF. Table 194. External IDE 16-bit Bus Cycle - Data Read AC Timings VDD = 2.7 to 3.3 V, TA = -40 to +85°C Variable Clock Standard Mode Symbol TCLCL TLHLL TAVLL TLLAX TLLRL TRLRH TRHLH TAVDV TAVRL TRLDV TRLAZ TRHDX TRHDZ Parameter Clock Period ALE Pulse Width Address Valid to ALE Low Address hold after ALE Low ALE Low to RD Low RD Pulse Width RD high to ALE High Address Valid to Valid Data In Address Valid to RD Low RD Low to Valid Data RD Low to Address Float Data Hold After RD High Instruction Float After RD High 0 2·TCLCL-25 4·TCLCL-30 5·TCLCL-30 0 0 TCLCL-25 Min 50 2·TCLCL-15 TCLCL-20 TCLCL-20 3·TCLCL-30 6·TCLCL-25 TCLCL-20 TCLCL+20 9·TCLCL-65 2·TCLCL-30 2.5·TCLCL-30 0 Max Variable Clock X2 Mode Min 50 TCLCL-15 0.5·TCLCL-20 0.5·TCLCL-20 1.5·TCLCL-30 3·TCLCL-25 0.5·TCLCL-20 0.5·TCLCL+20 4.5·TCLCL-65 Max Unit ns ns ns ns ns ns ns ns ns ns ns ns ns Table 195. External IDE 16-bit Bus Cycle - Data Write AC Timings VDD = 2.7 to 3.3 V, TA = -40 to +85°C Variable Clock Standard Mode Symbol TCLCL TLHLL TAVLL TLLAX TLLWL TWLWH TWHLH TAVWL TQVWH TWHQX Parameter Clock Period ALE Pulse Width Address Valid to ALE Low Address hold after ALE Low ALE Low to WR Low WR Pulse Width WR High to ALE High Address Valid to WR Low Data Valid to WR High Data Hold after WR High Min 50 2·TCLCL-15 TCLCL-20 TCLCL-20 3·TCLCL-30 6·TCLCL-25 TCLCL-20 4·TCLCL-30 7·TCLCL-20 TCLCL-15 TCLCL+20 Max Variable Clock X2 Mode Min 50 TCLCL-15 0.5·TCLCL-20 0.5·TCLCL-20 1.5·TCLCL-30 3·TCLCL-25 0.5·TCLCL-20 2·TCLCL-30 3.5·TCLCL-20 0.5·TCLCL-15 0.5·TCLCL+20 Max Unit ns ns ns ns ns ns ns ns ns ns 218 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Waveforms Figure 156. External IDE 16-bit Bus Cycle - Data Read Waveforms ALE TLHLL TLLRL TRLRH TRHLH RD TRLDV TRLAZ TAVLL P0 TLLAX A7:0 TAVRL TAVDV P2 A15:8 D15:8(1) Data In D7:0 Data In TRHDZ TRHDX Note: 1. D15:8 is written in DAT16H SFR. Figure 157. External IDE 16-bit Bus Cycle - Data Write Waveforms ALE TLHLL TLLWL TWLWH TWHLH WR TAVWL TAVLL P0 TLLAX A7:0 TQVWH D7:0 Data Out P2 A15:8 D15:8(1) Data Out TWHQX Note: 1. D15:8 is the content of DAT16H SFR. SPI Interface Definition of Symbols Table 196. SPI Interface Timing Symbol Definitions Signals C I O Clock Data In Data Out H L V X Z Conditions High Low Valid No Longer Valid Floating 219 4341D–MP3–04/05 Timings Test conditions: capacitive load on all pins= 50 pF. Table 197. SPI Interface Master AC Timing VDD = 2.7 to 3.3 V, TA = -40 to +85°C Symbol Parameter Slave Mode TCHCH TCHCX TCLCX TSLCH, TSLCL TIVCL, TIVCH TCLIX, TCHIX TCLOV, TCHOV TCLOX, TCHOX TCLSH, TCHSH TSLOV TSHOX TSHSL TILIH TIHIL TOLOH TOHOL Clock Period Clock High Time Clock Low Time SS Low to Clock edge Input Data Valid to Clock Edge Input Data Hold after Clock Edge Output Data Valid after Clock Edge Output Data Hold Time after Clock Edge SS High after Clock Edge SS Low to Output Data Valid Output Data Hold after SS High SS High to SS Low Input Rise Time Input Fall Time Output Rise time Output Fall Time Master Mode TCHCH TCHCX TCLCX TIVCL, TIVCH TCLIX, TCHIX TCLOV, TCHOV TCLOX, TCHOX TILIH TIHIL TOLOH TOHOL Clock Period Clock High Time Clock Low Time Input Data Valid to Clock Edge Input Data Hold after Clock Edge Output Data Valid after Clock Edge Output Data Hold Time after Clock Edge Input Data Rise Time Input Data Fall Time Output Data Rise time Output Data Fall Time 0 2 2 50 50 2 0.8 0.8 20 20 40 TPER TPER TPER ns ns ns ns µs µs ns ns (1) Min Max Unit 2 0.8 0.8 100 40 40 40 0 0 50 50 TPER TPER TPER ns ns ns ns ns ns ns ns 2 2 100 100 µs µs ns ns Note: 1. Value of this parameter depends on software. 220 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Waveforms Figure 158. SPI Slave Waveforms (SSCPHA= 0) SS (input) TSLCH TSLCL SCK (SSCPOL= 0) (input) SCK (SSCPOL= 1) (input) TSLOV MISO (output) SLAVE MSB OUT TIVCH TCHIX TIVCL TCLIX MOSI (input) MSB IN BIT 6 LSB IN TCHCH TCLCH TCLSH TCHSH TSHSL TCHCX TCLCX TCHCL TCLOV TCHOV BIT 6 TCLOX TCHOX SLAVE LSB OUT (1) TSHOX Note: 1. Not Defined but generally the MSB of the character which has just been received. Figure 159. SPI Slave Waveforms (SSCPHA= 1) SS (input) TSLCH TSLCL SCK (SSCPOL= 0) (input) SCK (SSCPOL= 1) (input) TSLOV MISO (output) (1) TCHCH TCLCH TCLSH TCHSH TSHSL TCHCX TCLCX TCHCL TCHOV TCLOV BIT 6 TCHOX TCLOX SLAVE LSB OUT TSHOX SLAVE MSB OUT TIVCH TCHIX TIVCL TCLIX MOSI (input) MSB IN BIT 6 LSB IN Note: 1. Not Defined but generally the LSB of the character which has just been received. 221 4341D–MP3–04/05 Figure 160. SPI Master Waveforms (SSCPHA= 0) SS (output) TCHCH SCK (SSCPOL= 0) (output) SCK (SSCPOL= 1) (output) TCLCH TCHCX TCLCX TCHCL TIVCH TCHIX TIVCL TCLIX MSB IN BIT 6 TCLOV TCHOV Port Data MSB OUT BIT 6 LSB OUT LSB IN TCLOX TCHOX Port Data MOSI (input) MISO (output) Note: 1. SS handled by software using general purpose port pin. Figure 161. SPI Master Waveforms (SSCPHA= 1) SS(1) (output) TCHCH SCK (SSCPOL= 0) (output) SCK (SSCPOL= 1) (output) TCLCH TCHCX TCLCX TCHCL TIVCH TCHIX TIVCL TCLIX MOSI (input) MSB IN TCLOV TCHOV Port Data MSB OUT BIT 6 TCLOX TCHOX BIT 6 LSB IN MISO (output) LSB OUT Port Data Note: 1. SS handled by software using general purpose port pin. 222 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Two-wire Interface Timings Table 198. TWI Interface AC Timing VDD = 2.7 to 3.3 V, TA = -40 to +85°C INPUT Min Max 14·TCLCL(4) 16·TCLCL(4) 14·TCLCL(4) 1 µs 0.3 µs 250 ns 250 ns 250 ns 0 ns 14·TCLCL(4) 14·TCLCL(4) 14·TCLCL(4) 1 µs 0.3 µs OUTPUT Min Max 4.0 µs(1) 4.7 µs(1) 4.0 µs(1) -(2) 0.3 µs(3) 20·TCLCL(4)- TRD 1 µs(1) 8·TCLCL(4) 8·TCLCL(4) - TFC 4.7 µs(1) 4.0 µs(1) 4.7 µs(1) -(2) 0.3 µs(3) Symbol THD; STA TLOW THIGH TRC TFC TSU; DAT1 TSU; DAT2 TSU; DAT3 THD; DAT TSU; STA TSU; STO TBUF TRD TFD Parameter Start condition hold time SCL low time SCL high time SCL rise time SCL fall time Data set-up time SDA set-up time (before repeated START condition) SDA set-up time (before STOP condition) Data hold time Repeated START set-up time STOP condition set-up time Bus free time SDA rise time SDA fall time Notes: 1. At 100 kbit/s. At other bit-rates this value is inversely proportional to the bit-rate of 100 kbit/s. 2. Determined by the external bus-line capacitance and the external bus-line pull-up resistor, this must be < 1 µs. 3. Spikes on the SDA and SCL lines with a duration of less than 3·TCLCL will be filtered out. Maximum capacitance on bus-lines SDA and SCL= 400 pF. 4. TCLCL= TOSC= one oscillator clock period. Waveforms Figure 162. Two Wire Waveforms START or Repeated START condition Trd SDA (INPUT/OUTPUT) Tfd Trc SCL (INPUT/OUTPUT) Thd;STA Tlow Thigh Tsu;DAT1 Thd;DAT Tsu;DAT2 Tfc Tsu;STO Tsu;DAT3 0.7 VDD 0.3 VDD Tbuf Repeated START condition STOP condition Tsu;STA 0.7 VDD 0.3 VDD START condition 223 4341D–MP3–04/05 MMC Interface Definition of symbols Table 199. MMC Interface Timing Symbol Definitions Signals C D O Clock Data In Data Out H L V X Conditions High Low Valid No Longer Valid Timings Table 200. MMC Interface AC timings VDD = 2.7 to 3.3 V, TA = -40 to +85°C, CL ≤ 100pF (10 cards) Symbol TCHCH TCHCX TCLCX TCLCH TCHCL TDVCH TCHDX TCHOX TOVCH Clock Period Clock High Time Clock Low Time Clock Rise Time Clock Fall Time Input Data Valid to Clock High Input Data Hold after Clock High Output Data Hold after Clock High Output Data Valid to Clock High 3 3 5 5 Parameter Min 50 10 10 10 10 Max Unit ns ns ns ns ns ns ns ns ns Waveforms Figure 163. MMC Input-Output Waveforms TCHCH TCHCX MCLK TCHCL TCHIX MCMD Input MDAT Input TCHOX MCMD Output MDAT Output TOVCH TCLCH TIVCH TCLCX 224 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Audio Interface Definition of symbols Table 201. Audio Interface Timing Symbol Definitions Signals C O S Clock Data Out Data Select H L V X Conditions High Low Valid No Longer Valid Timings Table 202. Audio Interface AC timings VDD = 2.7 to 3.3 V, TA = -40 to +85°C, CL≤ 30pF Symbol TCHCH TCHCX TCLCX TCLCH TCHCL TCLSV TCLOV Parameter Clock Period Clock High Time Clock Low Time Clock Rise Time Clock Fall Time Clock Low to Select Valid Clock Low to Data Valid 30 30 10 10 10 10 Min Max 325.5 (1) Unit ns ns ns ns ns ns ns Note: 1. 32-bit format with Fs= 48 KHz. Waveforms Figure 164. Audio Interface Waveforms TCHCH TCHCX DCLK TCHCL TCLSV DSEL TCLOV DDAT Right Left TCLCH TCLCX 225 4341D–MP3–04/05 Flash Memory Definition of symbols Table 203. Flash Memory Timing Symbol Definitions Signals S R B ISP RST FBUSY flag L V X Conditions Low Valid No Longer Valid Timings Table 204. Flash Memory AC Timing VDD = 2.7 to 3.3 V, TA = -40 to +85°C Symbol TSVRL TRLSX TBHBL NFCY TFDR Parameter Input ISP Valid to RST Edge Input ISP Hold after RST Edge FLASH Internal Busy (Programming) Time Number of Flash Write Cycles Flash Data Retention Time 100K 10 Min 50 50 10 Typ Max Unit ns ns ms Cycle Years Waveforms Figure 165. FLASH Memory - ISP Waveforms RST TSVRL ISP (1) TRLSX Note: 1. ISP must be driven through a pull-down resistor (see Section “In System Programming”, page 212). Figure 166. FLASH Memory - Internal Busy Waveforms FBUSY bit TBHBL External Clock Drive and Logic Level References Definition of symbols Table 205. External Clock Timing Symbol Definitions Signals C Clock H L X Conditions High Low No Longer Valid Timings Table 206. External Clock AC Timings 226 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C VDD = 2.7 to 3.3 V, TA = -40 to +85°C Symbol TCLCL TCHCX TCLCX TCLCH TCHCL TCR Clock Period High Time Low Time Rise Time Fall Time Cyclic Ratio in X2 mode Parameter Min 50 10 10 3 3 40 60 Max Unit ns ns ns ns ns % Waveforms Figure 167. External Clock Waveform TCLCH VDD - 0.5 0.45 V VIH1 TCLCX TCHCL TCLCL TCHCX VIL Figure 168. AC Testing Input/Output Waveforms INPUTS VDD - 0.5 0.45 V 0.7 VDD 0.3 VDD OUTPUTS VIH min VIL max Note: 1. During AC testing, all inputs are driven at VDD -0.5 V for a logic 1 and 0.45 V for a logic 0. 2. Timing measurements are made on all outputs at VIH min for a logic 1 and VIL max for a logic 0. Figure 169. Float Waveforms VLOAD VLOAD + 0.1 V VLOAD - 0.1 V Timing Reference Points VOH - 0.1 V VOL + 0.1 V Note: For timing purposes, a port pin is no longer floating when a 100 mV change from load voltage occurs and begins to float when a 100 mV change from the loading VOH/VOL level occurs with IOL/IOH= ±20 mA. 227 4341D–MP3–04/05 Ordering Information Memory Size 64K Flash 64K Flash 64K ROM Supply Voltage 3V 3V 3V Temperature Range Industrial Industrial & ROHS Industrial & ROHS Max Frequency 40 MHz 40 MHz 40 MHz RoHS Compliant No Yes Yes Part Number AT89C51SND2C-7FTIL AT89SND2C-7FTUL AT83SND2Cxxx-7FTUL Package BGA100 BGA100 BGA100 Packing Tray Tray Tray Product Marking 89C51SND2C-IL 89C51SND2C-JL 83C51SND2C-JL 228 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Package Information CTBGA100 229 4341D–MP3–04/05 Datasheet Change Log Changes from 4341A 10/04 to 4341B - 01/05 1. Update Power Amplifier DC characteristics, Section “Electrical Characteristics”, page 201. 2. Fix minor bugs. 3. Update power consumption measures, Table 182 on page 202. Changes from 4341B 01/05 to 4341C - 03/05 Changes from 4341C 03/05 to 4341D - 04/05 1. Change to hardware security system description. Section “Hardware Security System”, page 19. 1. Update to DAC gain information, Figure 54 on page 81. 2. Correction to BGA package pinout, Figure 2 on page 4. 3. Updated Ordering Information, Green product version changed to ROHS. (Green version not yet available) 230 AT8xC51SND2C 4341D–MP3–04/05 Table of Contents Features ................................................................................................. 1 Description ............................................................................................ 2 Typical Applications ............................................................................. 2 Block Diagram ....................................................................................... 3 Pin Description ...................................................................................... 4 Pinouts ................................................................................................................. 4 Signals................................................................................................................... 5 Internal Pin Structure.......................................................................................... 11 Clock Controller .................................................................................. 12 Oscillator ............................................................................................................ 12 X2 Feature.......................................................................................................... 12 PLL ..................................................................................................................... 13 Registers ............................................................................................................. 15 Program/Code Memory ...................................................................... 17 ROM Memory Architecture ................................................................................. 17 Flash Memory Architecture ................................................................................ 18 Hardware Security System .................................................................................. 19 Boot Memory Execution ..................................................................................... 19 Preventing Flash Corruption............................................................................... 20 Registers ............................................................................................................. 21 Hardware Bytes ................................................................................................... 22 Data Memory ....................................................................................... 23 Internal Space .................................................................................................... 23 External Space .................................................................................................... 25 Dual Data Pointer ............................................................................................... 27 Registers ............................................................................................................ 28 Special Function Registers ................................................................ 30 Interrupt System ................................................................................. 36 Interrupt System Priorities .................................................................................. 36 External Interrupts .............................................................................................. 39 Registers ............................................................................................................. 40 231 Power Management ............................................................................ 46 Reset .................................................................................................................. 46 Reset Recommendation to Prevent Flash Corruption ........................................ 47 Idle Mode ............................................................................................................ 47 Power-down Mode.............................................................................................. 48 Registers..............................................................................................................50 Timers/Counters ................................................................................. 51 Timer/Counter Operations .................................................................................. 51 Timer Clock Controller ........................................................................................ 51 Timer 0................................................................................................................ 52 Timer 1................................................................................................................ 54 Interrupt .............................................................................................................. 55 Registers..............................................................................................................56 Watchdog Timer .................................................................................. 59 Description.......................................................................................................... 59 Watchdog Clock Controller ................................................................................. 59 Watchdog Operation............................................................................................60 Registers..............................................................................................................61 MP3 Decoder ....................................................................................... 62 Decoder .............................................................................................................. 62 Audio Controls .....................................................................................................64 Decoding Errors.................................................................................................. 64 Frame Information ...............................................................................................65 Ancillary Data...................................................................................................... 65 Interrupt ...............................................................................................................66 Registers..............................................................................................................68 Audio Output Interface ....................................................................... 73 Description.......................................................................................................... 73 Clock Generator...................................................................................................74 Data Converter ................................................................................................... 74 Audio Buffer ........................................................................................................ 75 MP3 Buffer.......................................................................................................... 76 Interrupt Request ................................................................................................ 76 MP3 Song Playing .............................................................................................. 76 Voice or Sound Playing ...................................................................................... 77 Registers..............................................................................................................78 DAC and PA Interface ......................................................................... 80 DAC .................................................................................................................... 80 Power Amplifier....................................................................................................98 Audio Supplies and Start-up ............................................................................... 99 232 AT8xC51SND2C 4341D–MP3–04/05 AT8xC51SND2C Universal Serial Bus ......................................................................... 102 Description.........................................................................................................103 Configuration .................................................................................................... 107 Read/Write Data FIFO ...................................................................................... 109 Bulk/Interrupt Transactions............................................................................... 110 Control Transactions......................................................................................... 114 Isochronous Transactions..................................................................................115 Miscellaneous ....................................................................................................117 Suspend/Resume Management ........................................................................118 USB Interrupt System ....................................................................................... 120 Registers............................................................................................................122 IDE/ATAPI Interface .......................................................................... 132 Description........................................................................................................ 132 Registers........................................................................................................... 134 MultiMedia Card Controller .............................................................. 135 Card Concept.................................................................................................... 135 Bus Concept ..................................................................................................... 135 Description........................................................................................................ 140 Clock Generator................................................................................................ 140 Command Line Controller................................................................................. 142 Data Line Controller...........................................................................................144 Interrupt .............................................................................................................150 Registers............................................................................................................151 Synchronous Peripheral Interface .................................................. 157 Description.........................................................................................................158 Interrupt ............................................................................................................ 162 Configuration .....................................................................................................163 Registers............................................................................................................167 Serial I/O Port .................................................................................... 169 Mode Selection ................................................................................................. 169 Baud Rate Generator........................................................................................ 169 Synchronous Mode (Mode 0) ........................................................................... 170 Asynchronous Modes (Modes 1, 2 and 3) .........................................................172 Multiprocessor Communication (Modes 2 and 3) ............................................. 175 Automatic Address Recognition........................................................................ 175 Interrupt .............................................................................................................177 Registers............................................................................................................178 Two-wire Interface (TWI) Controller ................................................ 181 Description........................................................................................................ 181 Registers........................................................................................................... 195 233 4341D–MP3–04/05 Keyboard Interface ........................................................................... 198 Description........................................................................................................ 198 Registers............................................................................................................199 Electrical Characteristics ................................................................. 201 Absolute Maximum Rating................................................................................ DC Characteristics............................................................................................ AC Characteristics ............................................................................................ SPI Interface ..................................................................................................... 201 201 213 219 Ordering Information ........................................................................ 228 Package Information ........................................................................ 229 CTBGA100 ....................................................................................................... 229 Datasheet Change Log..................................................................... 230 Changes from 4341A - 10/04 to 4341B - 01/05 ................................................ 230 Changes from 4341B - 01/05 to 4341C - 03/05................................................ 230 Changes from 4341C - 03/05 to 4341D - 04/05................................................ 230 234 AT8xC51SND2C 4341D–MP3–04/05 Atmel Corporation 2325 Orchard Parkway San Jose, CA 95131, USA Tel: 1(408) 441-0311 Fax: 1(408) 487-2600 Atmel Operations Memory 2325 Orchard Parkway San Jose, CA 95131, USA Tel: 1(408) 441-0311 Fax: 1(408) 436-4314 RF/Automotive Theresienstrasse 2 Postfach 3535 74025 Heilbronn, Germany Tel: (49) 71-31-67-0 Fax: (49) 71-31-67-2340 1150 East Cheyenne Mtn. Blvd. Colorado Springs, CO 80906, USA Tel: 1(719) 576-3300 Fax: 1(719) 540-1759 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 Microcontrollers 2325 Orchard Parkway San Jose, CA 95131, USA Tel: 1(408) 441-0311 Fax: 1(408) 436-4314 La Chantrerie BP 70602 44306 Nantes Cedex 3, France Tel: (33) 2-40-18-18-18 Fax: (33) 2-40-18-19-60 Biometrics/Imaging/Hi-Rel MPU/ High Speed Converters/RF Datacom Avenue de Rochepleine BP 123 38521 Saint-Egreve Cedex, France Tel: (33) 4-76-58-30-00 Fax: (33) 4-76-58-34-80 Asia Room 1219 Chinachem Golden Plaza 77 Mody Road Tsimshatsui East Kowloon Hong Kong Tel: (852) 2721-9778 Fax: (852) 2722-1369 ASIC/ASSP/Smart Cards Zone Industrielle 13106 Rousset Cedex, France Tel: (33) 4-42-53-60-00 Fax: (33) 4-42-53-60-01 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 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 Literature Requests www.atmel.com/literature Disclaimer: A tmel Corporation makes no warranty for the use of its products, other than those expressly contained in the Company’s standard warranty which is detailed in Atmel’s Terms and Conditions located on the Company’s web site. The Company assumes no responsibility for any errors which may appear in this document, reserves the right to change devices or specifications detailed herein at any time without notice, and does not make any commitment to update the information contained herein. No licenses to patents or other intellectual property of Atmel are granted by the Company in connection with the sale of Atmel products, expressly or by implication. Atmel’s products are not authorized for use as critical components in life support devices or systems. © Atmel Corporation 2005. All rights reserved. Atmel®, logo and combinations thereof, are registered trademarks, and Everywhere You Are(SM) are the trademarks of Atmel Corporation or its subsidiaries. Other terms and product names may be trademarks of others. Printed on recycled paper. 4341D–MP3–04/05 /0M
AT83SND2CXXX-7FTUL 价格&库存

很抱歉,暂时无法提供与“AT83SND2CXXX-7FTUL”相匹配的价格&库存,您可以联系我们找货

免费人工找货