VRS51L2070 Rev 1.2 Preliminary Datasheet High-Performance Versa 8051 MCU Overview Feature Set The VRS51L2070 is a high performance, 8051-based microcontroller coupled with a fully integrated array of peripherals for addressing a broad range of embedded design applications. o o Based on a powerful 40-MIPS, single-cycle, 8051 microprocessor, the VRS51L2070's memory sub-system features 64KB of Flash and 4352 bytes of SRAM. o o Support peripherals include a hardware based arithmetic unit capable of performing complex mathematical operations, JTAG interface used for Flash programming and non-intrusive in-circuit debugging/emulation, a precision internal oscillator (2% accuracy) and a watchdog timer. o o o o o o o o o o o o o o o o o Communication and control of external devices is facilitated via an assortment of digital peripherals such as an enhanced, fully configurable SPI bus, an IC interface, dual UARTs with dedicated baud rate generators, 8 PWM controllers, 3 16-bit timers and 2 pulse width counter modules. The VRS51L2070 is powered by a 3.3 volt supply, can function over the industrial temperature range, and is available in a QFP-64 package (See VRS51L2170 datasheet for PLCC/QFP-44 packages - pin compatible with the industry standard 8051 microcontroller footprint/pin-out). FIGURE 1: VRS51L2070 FUNCTIONAL DIAGRAM VRS51L2070 o Ports (7), I/Os (56) Flash 64K Bytes SPI External Data Bus Controller SRAM 4352 Bytes I2C Crystal Oscillator Inputs SDO-P1.5 SCK-SCL*-PC1.3-P1.6 SDI-SDA*-P1.7 RESET RXD0-PC0.1-P3.0 T0OUT-P4.5 PWM0*-P5.0 PWM1*-P5.1 PWM2*-P5.2 PWM3*-P5.3 VSS TXD0-P3.1 INT0-PC0.0-P3.2 INT1-PC1.0-P3.3 T0IN-SCL-EXBR0-PC0.3-P3.4 T1IN-SDA-EXBR1-P3.5 UARTs, Baud Rate Generators (2) Interrupt Controller Dynamic Clock Control PWMs/ Timers (8) Watch Dog Timer Pulse Width Counters (2) Power-On/ Reset Timer Capture Inputs (3) Ramtron International Corporation 1850 Ramtron Drive Colorado Springs Colorado, USA, 80921 1 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 2 47 3 46 4 45 5 44 6 43 7 8 9 10 VRS51L2070 QFP-64 42 41 40 39 11 38 12 37 13 36 14 35 15 34 16 33 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 P0.4-AD4 P0.5-AD5 P0.6-AD6 P0.7-AD7 P6.5-A5 P6.6-A6 P6.7-A7 PC1.2-T0EX-RXD1* T1EX-TXD1* P4.3-TDI P4.2-TD0 CM0-ALE P4.1-TMS P2.7-A15-PWM7-TCK P2.6-A14-PWM6-T0EX P2.5-A13-PWM5-T1EX WR-P3.6 RD-P3.7 VDD PWM4*-P5.4 PWM5*-P5.5 PWM6*-P5.6 PWM7*-P5.7 XTAL1-P4.6 XTAL2-P4.7 VSS T1OUT-P4.0 PWM0-A8-P2.0 PWM1-A9-P2.1 PWM2-A10-P2.2 TXD0*-PWM3-A11-P2.3 RXD0*-PWM4-A112-P2.4 On-Board Oscillator FIGURE 2: VRS51L2070 QFP-64 PIN OUT DIAGRAMS P1.1-CS1-T2EX P1.0-CS0-T2IN P4.4-T2OUT VDD P6.0-A0-T2EX* P6.1-A1-T2IN* P6.2-A2 P6.3-A3 P6.4-A4 P0.0-AD0 P0.1-AD1 P0.2-AD2 P0.3-AD3 JTAG w/On-Chip Emulation P1.2-CS2-PC1.1-RXD1-T2OUT* 8051 Core Single Cycle 40MHz P1.4-SS-T1OUT* P1.3-CS3-TXD1 Mult/Accu/Div w/ 32-Bit Barrel Shifter 8051 High Performance Single Cycle Processor (Operation up to 40 MIPS) 64KB Flash Program Memory (In-System/ln-Application Programmable) 4352 Bytes of SRAM (4KB + 256) (Ext. 4K Bytes can be used for program or data memory) JTAG Interface for Flash Programming and Non-Intrusive Debugging/In-Circuit Emulation MULT/DIV/ACCU Unit including Barrel Shifter 56 General Purpose I/Os (64-pin version) 2 Serial UARTs/2 Baud Rate Generators (16-bit) Enhanced SPI Interface (fully configurable word size) 2 Fully Configurable I C Interface (Master/Slave) 16 External Interrupt Pins/Interrupt On Port Pin Change 16-bit General Purpose Timer/Counters 3 Timer Capture Inputs 2 Pulse Width Counter Modules 8 PWM Controller Outputs with Individual Timers PWMs can be used as General Purpose Timers Precision Internal Oscillator Dynamic System Clock Frequency Adjustment Power Saving Features Power-On Reset/Brown-Out Detect Watchdog Timer Operating voltage: 3.1V to 3.6V Operating Temperature -40C to +85C http://www.ramtron.com MCU customer service: 1-800-943-4625, 1-514-871-2447 x 208 1-800-545-FRAM, 1-719-481-7000 page 1 of 99 VRS51L2070 Pin Descriptions for QFP-64 TABLE 1: VRS51L2070 PIN DESCRIPTIONS FOR QFP-64 PACKAGE QFP 64 1 2 3 4 5 6 7 8 9 10 11 12 13 Name I/O P1.5 I/O Port 1.5 SDO O SPI Data output P1.6 I/O Port 1.6 SCK O SPI Clock SCL* I/O IC Clock (Alternate Pin) PC1.3 I Pulse Counter PC1 input 3 P1.7 I/O Port P1.7 17 18 19 20 21 22 23 26 27 28 Function Crystal Oscillator (Output) P4.6 I/O Port 4.6 XTAL2 I Crystal Oscillator (Input) P4.7 I/O Port 4.7 VSS GND Device ground P4.0 I/O Port 4.0 T1OUT O Timer 1 Output P2.0 I/O Port 2.0 PWM0 O PWM0 Output Ext. Address Bus A8 I SPI Data Input A8 O I/O IC Data (Alternate Pin) P2.1 I/O Port 2.1 RESET I/O Reset PWM1 O PWM1 Output Ext. Address Bus A9 29 P3.0 I/O Port 3.0 A9 O RXD0 I UART0 RX pin P2.2 I/O Port 2.2 PC0.1 I Pulse Counter PC0 input 1 PWM2 O PWM2 Output Ext. Address Bus A10 30 P4.5 I/O Port 4.5 A10 O T0OUT O Timer 0 output P2.3 I/O Port 2.3 P5.0 I/O Port 5.0 PWM3 O PWM3 Output PWM0* O PWM0 Output (Alternate Pin) TXD0* O UART0 TX pin (Alternate Pin ) P5.1 I/O Port 5.1 A11 O Ext. Address Bus A11 PWM1* O PWM1 Output (Alternate Pin) P2.4 I/O Port 2.4 P5.2 I/O Port 5.2 PWM4 O PWM4 Output PWM2* O PWM2 Output (Alternate Pin) RXD0* I UART0 RX pin (Alternate Pin) P5.3 I/O Port 5.3 PC0.2 I Pulse Counter PC0 input 2 PWM3* O PWM3 Output (Alternate Pin) A12 O Ext. Address Bus A12 VSS GND Device ground P2.5 I/O Port 2.5 P3.1 I/O Port 3.1 PWM5 O PWM5 output TXD0 O UART0 TX pin T1EX I Timer 1 EX input P3.2 I/O Port 3.2 A13 O Ext. Address Bus A13 INT0 I Interrupt 0 input P2.6 I/O Port 2.6 PWM6 O PWM6 output Pulse Counter PC0 input 0 P3.3 I/O Port 3.3 INT1 I Interrupt 1 input P3.4 16 25 I/O O SDI PC1.0 15 24 Name XTAL1 SDA* PC0.0 14 Function QFP 64 I/O Port 3.4 I/O IC clock T0IN I Timer 0 Input PC0.3 I Pulse Counter PC0 input 3 EXBR0 I UART0 External Baud Rate Input P3.5 I/O Port 3.5 SDA I/O IC Data T1IN I Timer 1 Input EXBR1 I UART1 External Baud Rate input P3.6 I/O Port 3.6 WR O Ext Data memory access write signal (active low) P3.7 I/O Port 3.7 RD O Ext Data memory access read signal (active low) VDD VDD Positive supply P5.4 O P5.5 PWM5* O 34 36 37 38 39 I Timer 0 EX input O Ext. Address Bus A114 P2.7 I/O Port 2.7 PWM7 O PWM7 output TCK I JTAG TCK input A15 O Ext. Address Bus A15 P4.1 I/O Port 4.1 TMS I JTAG TMS Input JTAG Program mode CM0 I ALE O Ext Address Latch Enable P4.2 I/O Port 4.2 TDO O JTAG TDO Line P4.3 I/O Port 4.3 TDI I JTAG TDI line O UART1 TX pin (Alternate Pin) I Timer 1 EX input RXD1* I UART1 RX pin (Alternate Pin) T0EX I Timer 0 EX input Port 5.4 PC1.2 I Pulse Counter PC1 input 2 PWM4 Output (Alternate Pin) P6.7 I/O Port 6.7 A7 O Ext. Address 7 (Non-Multiplexed mode) P6.6 I/O Port 6.6 A6 O Ext. Address 6 (Non-Multiplexed mode) P6.5 I/O Port 6.5 A5 O Ext. Address 5 (Non-Multiplexed mode) PWM5 Output (Alternate Pin) PWM6 Output (Alternate Pin) Port 5.7 O 35 T0EX A14 TXD1* Port 5.6 O P5.7 PWM7* 33 T1EX Port 5.5 P5.6 PWM6* 32 Pulse Counter PC1 input 0 SCL PWM4* 31 40 41 42 43 44 PWM7 Output (Alternate Pin) ________________________________________________________________________________________________ www.ramtron.com page 2 of 99 VRS51L2070 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 AD7 I/O Ext. Address/Data Bus AD7 P0.6 I/O Port 0.6 AD6 I/O Ext. Address/Data Bus AD6 P0.5 I/O Port 0.5 AD5 I/O Ext. Address/Data Bus AD5 P0.4 I/O Port 0.4 AD4 I/O Ext. Address/Data Bus AD4 P0.3 I/O Port 0.3 AD3 I/O Ext. Address/Data Bus AD3 P0.2 I/O Port 0.2 AD2 I/O Ext. Address/Data Bus AD2 P0.1 I/O Port 0.1 AD1 I/O Ext. Address/Data Bus AD1 P0.0 I/O Port 0.0 AD0 I/O Ext. Address/Data Bus AD0 P6.4 I/O Port 6.4 A4 O Ext. Address 4 (Non-Multiplexed mode) Port 6.3 P6.3 I/O A3 O Ext. Address 3 (Non-Multiplexed mode) P6.2 I/O Port 6.2 A2 O Ext. Address 2 (Non-Multiplexed mode) P6.1 I/O Port 6.1 A1 O Ext. Address 1 (Non-Multiplexed mode) T2IN* I Timer 2 input (Alternate) P6.0 I/O Port 6.0 A0 O Ext. Address 0 (Non-Multiplexed mode) T2EX* I Timer 2 EX Input (Alternate) VDD SDO-P1.5 SCK-SCL*-PC1.3-P1.6 SDI-SDA*-P1.7 RESET RXD0-PC0.1-P3.0 T0OUT-P4.5 PWM0*-P5.0 PWM1*-P5.1 PWM2*-P5.2 PWM3*-P5.3 VSS TXD0-P3.1 INT0-PC0.0-P3.2 INT1-PC1.0-P3.3 T0IN-SCL-EXBR0-PC0.3-P3.4 T1IN-SDA-EXBR1-P3.5 P1.1-CS1-T2EX P1.0-CS0-T2IN P4.4-T2OUT VDD P6.0-A0-T2EX* P6.1-A1-T2IN* P6.2-A2 P6.3-A3 P6.4-A4 P0.0-AD0 P0.1-AD1 P0.2-AD2 P0.3-AD3 47 Function Port 0.7 P1.2-CS2-PC1.1-RXD1-T2OUT* 46 I/O I/O P1.4-SS-T1OUT* P1.3-CS3-TXD1 45 Name P0.7 1 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 2 47 3 46 4 45 5 44 43 6 7 8 9 10 VRS51L2070 QFP-64 42 41 40 39 11 38 12 37 13 36 14 35 15 34 16 33 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 P0.4-AD4 P0.5-AD5 P0.6-AD6 P0.7-AD7 P6.5-A5 P6.6-A6 P6.7-A7 PC1.2-T0EX-RXD1* T1EX-TXD1* P4.3-TDI P4.2-TD0 CM0-ALE P4.1-TMS P2.7-A15-PWM7-TCK P2.6-A14-PWM6-T0EX P2.5-A13-PWM5-T1EX WR-P3.6 RD-P3.7 VDD PWM4*-P5.4 PWM5*-P5.5 PWM6*-P5.6 PWM7*-P5.7 XTAL1-P4.6 XTAL2-P4.7 VSS T1OUT-P4.0 PWM0-A8-P2.0 PWM1-A9-P2.1 PWM2-A10-P2.2 TXD0*-PWM3-A11-P2.3 RXD0*-PWM4-A112-P2.4 QFP 64 Positive supply P4.4 I/O Port 4.4 T2OUT O Timer 2 Output P1.0 I/O Port 1.0 CS0 O SPI Chip Select 0 T2IN I Timer 2 input P1.1 I/O Port 1.1 CS1 O SPI Chip Select 1 T2EX I Timer 2 EX input P1.2 I/O Port 1.2 CS2 O SPI Chip Select 2 RXD1 I UART1 RX line PC1.1 I Pulse Counter PC1 input 1 T2OUT O Timer 2 Output Pin (Alternate Pin) P1.3 I/O Port 1.3 CS3 O SPI Chip Select 3 TXD1 O UART1 TX line P1.4 I/O Port 1.4 SS I SPI Slave Select input T1OUT* O Timer 1 Output (Alternate pin) ________________________________________________________________________________________________ www.ramtron.com page 3 of 99 VRS51L2070 P1.1-CS1-T2EX P1.0-CS0-T2IN P4.4-T2OUT VDD P6.0-A0-T2EX* P6.1-A1-T2IN* P6.2-A2 P6.3-A3 P6.4-A4 P0.0-AD0 P0.1-AD1 P0.2-AD2 P0.3-AD3 1 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 2 47 3 46 4 45 5 44 6 43 7 8 9 10 VRS51L2070 QFP-64 42 41 40 39 11 38 12 37 13 36 14 35 15 34 16 33 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 P0.4-AD4 P0.5-AD5 P0.6-AD6 P0.7-AD7 P6.5-A5 P6.6-A6 P6.7-A7 PC1.2-T0EX-RXD1* T1EX-TXD1* P4.3-TDI P4.2-TD0 CM0-ALE P4.1-TMS P2.7-A15-PWM7-TCK P2.6-A14-PWM6-T0EX P2.5-A13-PWM5-T1EX WR-P3.6 RD-P3.7 VDD PWM4*-P5.4 PWM5*-P5.5 PWM6*-P5.6 PWM7*-P5.7 XTAL1-P4.6 XTAL2-P4.7 VSS T1OUT-P4.0 PWM0-A8-P2.0 PWM1-A9-P2.1 PWM2-A10-P2.2 TXD0*-PWM3-A11-P2.3 RXD0*-PWM4-A112-P2.4 SDO-P1.5 SCK-SCL*-PC1.3-P1.6 SDI-SDA*-P1.7 RESET RXD0-PC0.1-P3.0 T0OUT-P4.5 PWM0*-P5.0 PWM1*-P5.1 PWM2*-P5.2 PWM3*-P5.3 VSS TXD0-P3.1 INT0-PC0.0-P3.2 INT1-PC1.0-P3.3 T0IN-SCL-EXBR0-PC0.3-P3.4 T1IN-SDA-EXBR1-P3.5 P1.2-CS2-PC1.1-RXD1-T2OUT* P1.4-SS-T1OUT* P1.3-CS3-TXD1 FIGURE 3: LARGER VIEW OF VRS51L2070 QFP-64 PACKAGE PINOUT ________________________________________________________________________________________________ www.ramtron.com page 4 of 99 VRS51L2070 Instruction Set The following table describes the instruction set of the VRS51L2070. The instructions are binary code-compatible and perform the same functions as industry standard 8051s. TABLE 2: LEGEND FOR INSTRUCTION SET TABLE Symbol A Rn Direct @Ri rel bit #data #data 16 addr 16 addr 11 Function Accumulator Register R0-R7 Internal register address Internal register pointed to by R0 or R1 (except MOVX) Two's complement offset byte Direct bit address 8-bit constant 16-bit constant 16-bit destination address 11-bit destination address TABLE 3: VRS51L2070 INSTRUCTION SET Mnemonic Description Arithmetic instructions Add register to A ADD A, Rn Add direct byte to A ADD A, direct Add data memory to A ADD A, @Ri Add immediate to A ADD A, #data Add register to A with carry ADDC A, Rn Add direct byte to A with carry ADDC A, direct Add data memory to A with carry ADDC A, @Ri Add immediate to A with carry ADDC A, #data Subtract register from A with borrow SUBB A, Rn Subtract direct byte from A with borrow SUBB A, direct Subtract data mem from A with borrow SUBB A, @Ri Subtract immediate from A with borrow SUBB A, #data Increment A INC A Increment register INC Rn Increment direct byte INC direct Increment data memory INC @Ri Decrement A DEC A Decrement register DEC Rn Decrement direct byte DEC direct Decrement data memory DEC @Ri Increment data pointer INC DPTR Multiply A by B MUL AB Divide A by B DIV AB Decimal adjust A DA A Logical Instructions AND register to A ANL A, Rn AND direct byte to A ANL A, direct AND data memory to A ANL A, @Ri AND immediate to A ANL A, #data AND A to direct byte ANL direct, A AND immediate data to direct byte ANL direct, #data OR register to A ORL A, Rn OR direct byte to A ORL A, direct OR data memory to A ORL A, @Ri OR immediate to A ORL A, #data OR A to direct byte ORL direct, A OR immediate data to direct byte ORL direct, #data Exclusive-OR register to A XRL A, Rn Exclusive-OR direct byte to A XRL A, direct Exclusive-OR data memory to A XRL A, @Ri Exclusive-OR immediate to A XRL A, #data Exclusive-OR A to direct byte XRL direct, A Exclusive-OR immediate to direct byte XRL direct, #data Clear A CLR A Compliment A CPL A Swap nibbles of A SWAP A Rotate A left RL A Rotate A left through carry RLC A Rotate A right RR A Rotate A right through carry RRC A Instr. Cycles Hex Code 1 2 1 2 1 2 1 2 1 2 1 2 1 1 2 1 1 1 2 1 1 1 1 1 2 3 3 2 2 3 3 2 2 3 3 2 2 2 3 3 2 2 3 3 2 2 2 4 28h-2Fh 25h 26h-27h 24h 38h-3Fh 35h 36h-37h 34h 98h-9Fh 95h 96h-97h 94h 04h 08h-0Fh 05h 06h-07h 14h 18h-1Fh 15h 16h-17h A3h A4h 84h D4h 1 2 1 2 2 3 1 2 1 2 2 3 1 2 1 2 2 3 1 1 1 1 1 1 1 2 3 3 2 3 3 2 3 3 2 3 3 2 3 3 2 3 3 1 1 1 1 1 1 1 58h-5Fh 55h 56h-57h 54h 52h 53h 48h-4Fh 45 46h-47h 44h 42h 43h 68h-6Fh 65h 66h-67h 64h 62h 63h E4h F4h C4h 23h 33h 03h 13h Size (bytes) Mnemonic Description Boolean Instruction Clear Carry bit CLR C Clear bit CLR bit Set Carry bit to 1 SETB C Set bit to 1 SETB bit Complement Carry bit CPL C Complement bit CPL bit Logical AND between Carry and bit ANL C,bit Logical AND between Carry and not bit ANL C,#bit Logical ORL between Carry and bit ORL C,bit Logical ORL between Carry and not bit ORL C,#bit Copy bit value into Carry MOV C,bit Copy Carry value into Bit MOV bit,C Data Transfer Instructions Move register to A MOV A, Rn Move direct byte to A MOV A, direct Move data memory to A MOV A, @Ri Move immediate to A MOV A, #data Move A to register MOV Rn, A Move direct byte to register MOV Rn, direct Move immediate to register MOV Rn, #data Move A to direct byte MOV direct, A Move register to direct byte MOV direct, Rn Move direct byte to direct byte MOV direct, direct Move data memory to direct byte MOV direct, @Ri Move immediate to direct byte MOV direct, #data Move A to data memory MOV @Ri, A Move direct byte to data memory MOV @Ri, direct Move immediate to data memory MOV @Ri, #data Move immediate to data pointer MOV DPTR, #data MOVC A, @A+DPTR Move code byte relative DPTR to A Move code byte relative PC to A MOVC A, @A+PC MOVX Move external data (A8) to A A,{MPAGE, @Ri} Move external data (A16) to A MOVX A, @DPTR MOVX Move A to external data (A8) {MPAGE, @Ri},A Move A to external data (A16) MOVX @DPTR, A Push direct byte onto stack PUSH direct Pop direct byte from stack POP direct Exchange A and register XCH A, Rn Exchange A and direct byte XCH A, direct Exchange A and data memory XCH A, @Ri Exchange A and data memory nibble XCHD A, @Ri Branching Instructions Absolute call to subroutine ACALL addr 11 Long call to subroutine LCALL addr 16 Return from subroutine RET Return from interrupt RETI Absolute jump unconditional AJMP addr 11 Long jump unconditional LJMP addr 16 Short jump (relative address) SJMP rel Jump on carry = 1 JC rel Jump on carry = 0 JNC rel Jump on direct bit = 1 JB bit, rel Jump on direct bit = 0 JNB bit, rel Jump on direct bit = 1 and clear JBC bit, rel Jump indirect relative DPTR JMP @A+DPTR Jump on accumulator = 0 JZ rel Jump on accumulator 1= 0 JNZ rel Compare A, direct JNE relative CJNE A, direct, rel Compare A, immediate JNE relative CJNE A, #d, rel Compare reg, immediate JNE relative CJNE Rn, #d, rel Compare ind, immediate JNE relative CJNE @Ri, #d, rel Decrement register, JNZ relative DJNZ Rn, rel Decrement direct byte, JNZ relative DJNZ direct, rel Miscellaneous Instruction No operation NOP If PCON.4 is 0 (reset Value): NOP NOP MOV @RamPtr,A MOV A,@RamPtr If MSB (@RamPtr) == 0 Accumulator value is written in SFR{1,@RamPtr[6:0]} If MSB (@RamPtr) == 1 SFR{1,@RamPtr[6:0]} is written in Accumulator Instr. Cycles Hex Code 1 2 1 2 1 2 2 2 2 2 2 2 1 4 1 4 1 4 4 4 4 4 4 3 C3h C2h D3h D2h B3h B2h 82h B0h 72h A0h A2h 92h 1 2 1 2 1 2 2 2 2 3 2 3 1 2 2 3 1 1 2 3 3 2 1 3 2 3 3 3 3 3 2 3 2 3 3+1 3+1 E8h-EFh E5h E6h-E7h 74h F8h-FFh A8h-AFh 78h-7Fh F5h 88h-8Fh 85h 86h-87h 75h F6h-F7h A6h-A7h 76h-77h 90h 93h 83h 1 3* E2h-E3h 1 2* E0h 1 2* F2h-F3h 1 2 2 1 2 1 1 1* 3 2 3 4 4 4 F0h C0h D0h C8h-CFh C5h C6h-C7h D6h-D7h 2 3 1 1 2 3 2 2 2 3 3 3 1 2 2 3 3 3 3 2 3 4+1 5+1 3+1 3+1 2+1 3+1 3+1 3+1 3+1 3 / 4 +1 3 / 4 +1 3/4+1 2+1 3+1 3+1 4 / 5 +1 3 / 4 +1 3 / 4 +1 4/5+1 3 / 4 +1 3 / 4 +1 11h-F1h 12h 22h 32h 01h-E1h 02h 80h 40h 50h 20h 30h 10h 73h 60h 70h B5h B4h B8h-BFh B6h-B7h D8h-DFh D5 1 1 1 1 00h A5h 2 3 A5h 3 4 A5h Size (bytes) Rn: Any of the register R0 to R7 @Ri: Indirect addressing using Register R0 or R1 #data: immediate Data provided with Instruction #data16: Immediate data included with instruction bit: address at the bit level rel: relative address to Program counter from +127 to -128 Addr11: 11-bit address range Addr16: 16-bit address range #d: Immediate Data supplied with instruction ________________________________________________________________________________________________ www.ramtron.com page 5 of 99 VRS51L2070 Special Function Registers (SFR) Addresses 80h to FFh of the SFR address space can be accessed in direct addressing mode only. The following table lists the VRS51L2070 special function registers. Due to the VRS51L2070's high level of integration, the SFRs have been mapped into two pages. The following tables summarize the SFR assignment. Complete functional descriptions of each register will be provided throughout the datasheet. 1.1 SFR Map Page 0 TABLE 4: SPECIAL FUNCTION REGISTERS (SFR) PAGE 0 SFR SFR Bit 7 Bit 6 Register Adrs Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Reset Value P0 80h - - - - - - - - 1111 1111b SP 81h - - - - - - - - 0000 0111b DPL0 82h - - - - - - - - 0000 0000b DPH0 83h - - - - - - - - 0000 0000b DPL1 84h 0000 0000b DPH1 85h 0000 0000b DPS 86h PCON 87h OSCSTOP INTEN1 88h T1IEN U1IEN U0IEN T0T1CFG 89h - T1GATE T0GATE TL0 8Ah TH0 8Bh 0000 0000b TL1 8Ch 0000 0000b TH1 8Dh 0000 0000b TL2 8Eh 0000 0000b TH2 8Fh P1 90h - - - - - - - - WDTCFG 91h WDTPERIOD3 WDTPERIOD2 WDTPERIOD1 WDTPERIOD0 WTIMERF ASTIMER WDTF WDTRESET RCAP0L 92h RCAP0H 93h 0000 0000b RCAP1L 94h 0000 0000b RCAP1H 95h 0000 0000b RCAP2L 96h 0000 0000b RCAP2H 97h 0000 0000b P5 98h T0T1CLKCFG 99h T1CLKCFG3 T1CLKCFG2 T1CLKCFG1 T1CLKCFG0 T0CLKCFG3 T0CLKCFG2 T0CLKCFG1 T0CLKCFG0 0000 0000b T0CON 9Ah T0OVF T0EXF T0DOWNEN T0TOGOUT T0EXTEN TR0 T0COUNTEN T0RLCAP 0000 0000b T1CON 9Bh T1OVF T1EXF T1DOWNEN T1TOGOUT T1EXTEN TR1 T1COUNTEN T1RLCAP 0000 0000b T2CON 9Ch T2OVF T2EXF T2DOWNEN T2TOGOUT T2EXTEN TR2 T2COUNTEN T2RLCAP 0000 0000b T2CLKCFG 9Dh - - T2CLKSRC T2OUTEN T2CLKCFG3 T2CLKCFG2 T2CLKCFG1 T2CLKCFG0 0000 0000b PWC0CFG 9Eh PWC0IF PWC0RST PWC0END PWC0START PWC0ENDSRC1 PWC0ENDSRC0 PWC0STSRC1 PWC0STSRC0 0000 0000b PWC1CFG 9Fh PWC1IF PWC1RST PWC1END PWC1START PWC1ENDSRC1 PWC1ENDSRC0 PWC1STSRC1 PWC1STSRC0 0000 0000b P2 A0h - - - - - - - - 1111 1111b INTMODEN DEVCFGEN SFRINDADR DPSEL 0000 0000b IDLE 0110 0000b SPITXEIEN - 0000 0000b T0OUTEN T0MODE8 0000 0000b GF1 GF0 PDOWN PCHGIEN0 T0IEN SPIRXOVIEN T1CLKSRC T1OUTEN T1MODE8 0000 0000b 0000 0000b 1111 1111b 0000 0000b 0000 0000b 1111 1111b UART0INT A1h COLEN RXOVEN RXAVAILEN TXEMPTYEN COLENF RXOVF RXAVENF TXEMPTYF 0000 0001b UART0CFG A2h BRADJ3 BRADJ2 BRADJ1 BRADJ0 BRCLKSRC B9RXTX B9EN STOP2EN 1110 0000b UART0BUF A3h UART0BRL A4h 0000 0000b UART0BRH A5h 0000 0000b UART0EXT A6h Reserved A7h 0000 0000b U0TIMERF U0TIMEREN U0RXSTATE MULTIPROC J1708PRI3 J1708PRI2 J1708PRI1 J1708PRI0 0010 0000b ________________________________________________________________________________________________ www.ramtron.com page 6 of 99 VRS51L2070 INTEN2 A8h PCHGIEN1 AUWDTIEN PWMT47IEN PWMT03IEN PWCIEN I2CUARTCI I2CIEN T2IEN 0000 0000b PWMCFG A9h - PWMWAIT PWMCLRALL PWMLSBMSB PWMMIDEND PWMCH2 PWMCH1 PWMCH0 0000 0000b PWMEN AAh PWM7EN PWM6EN PWM5EN PWM4EN PWM3EN PWM2EN PWM1EN PWM0EN 0000 0000b PWMLDPOL ABh PWM7LDPOL PWM6LDPOL PWM5LDPOL PWM4LDPOL PWM3LDPOL PWM2LDPOL PWM1LDPOL PWM0LDPOL 0000 0000b PWMDATA ACh PWMTMREN ADh PWM7TMREN PWM6TMREN PWM5TMREN PWM4TMREN PWM3TMREN PWM2TMREN PWM1TMREN PWM0TMREN 0000 0000b PWMTMRF AEh PWM7TMRF PWM6TMRF PWM5TMRF PWM4TMRF PWM3TMRF PWM2TMRF PWM1TMRF PWM0TMRF 0000 0000b PWMCLKCFG AFh U4PWMCLK3 U4PWMCLK2 U4PWMCLK1 U4PWMCLK0 L4PWMCLK3 L4PWMDCLK2 L4PWMCLK1 L4PWMCLK0 0000 0000b P3 B0h - - - - - - - - 1111 1011b 0000 0000b UART1INT B1h COLEN RXOVEN RXAVAILEN TXEMPTYEN COLENF RXOVF RXAVENF TXEMPTYF 0000 0001b UART1CFG B2h BRADJ3 BRADJ2 BRADJ1 BRADJ0 BRCLKSRC B9RXTX B9EN STOP2EN 1110 0000b UART1BUF B3h UART1BRL B4h 0000 0000b UART1BRH B5h 0000 0000b UART1EXT B6h Not used B7h 0000 0000b U1TIMERF U1TIMEREN U1RXSTATE MULTIPROC J1708PRI3 J1708PRI2 J1708PRI1 J1708PRI0 0010 0000b IPINFLAG1 B8h P37IF P36IF P35IF P34IF P31IF P30IF INT1IF INT0IF 0000 0000b PORTCHG B9h PMONFLAG1 PCHGMSK1 PCHGSEL1 PCHGSEL0 PMONFLAG0 PCHGMSK0 PCHGSEL1 PCHGSEL0 0000 0000b P4 C0h SPICTRL C1h SPICLK2 SPICLK1 SPICLK0 SPICS1 SPICS0 SPICLKPH SPICLKPOL SPIMASTER 0000 0001b SPICONFIG C2h SPIMANCS SPIUNDERC FSONCS3 SPILOADCS3 SPISLOW SPIRXOVEN SPIRXAVEN SPITXEEN 0000 0000b SPISIZE C3h 0000 0111b SPIRXTX0 C4h 0000 0000b SPIRXTX1 C5h 0000 0000b SPIRXTX2 C6h 0000 0000b SPIRXTX3 C7h 0000 0000b P6 C8h SPISTATUS C9h SPIREVERSE - SPIUNDERF SSPINVAL SPINOCS SPIRXOVF SPIRXAVF SPITXEMPF 0011 1001b PSW D0h CY AC F0 RS1 RS0 OV - P 0000 0000b I2CCONFIG D1h MASTRARB I2CRXOVEN I2CRXAVEN I2CTXEEN I2CMASTART I2CSCLLOW I2CRXSTOP I2CMODE 0000 0100b I2CTIMING D2h I2CIDCFG D3h I2CID6 I2CID5 I2CID4 I2CID3 I2CID2 I2CID1 I2CID0 I2CADVCFG 0000 0000b I2CSTATUS D4h I2CERROR I2CNOACK I2CSDASYNC I2CACKPH I2CIDLEF I2CRXOVF I2CRXAVF I2CTXEMPF I2CRXTX D5h IPININV1 D6h P37IINV P36IINV P35IINV P34IINV P33IINV P32IINV P31IINV P30IINV 0000 0000b IPININV2 D7h P07IINV P06IINV P05IINV P04IINV P03IINV P02IINV P01IINV P00IINV 0000 0000b IPINFLAG2 D8h P07IF P06IF P05IF P04IF P03IF P02IF P01IF P00IF 0000 0000b XMEMCTRL D9h EXTBUSCFG EXTBUSCS - - STRECH3 STRECH2 STRECH1 STRECH0 0000 0000b Reserved DAh - - - - - - - - 0000 0000b Reserved DBh - - - - - - - - 0000 0000b Reserved DCh - - - - - - - - 0000 0000b Reserved DDH - - - - - - - - 0000 0000b Reserved DEh - - - - - - - - 0000 0000b Reserved DFH - - - - - - - - 0000 0000b ACC E0h - - - - - - - - 0000 0000b DEVIOMAP E1h Reserved PWMALTMAP I2CALTMAP U1ALTMAP U0ALTMAP T2ALTMAP T1ALTMAP T0ALTMAP 0000 0000b INTPRI1 E2h T1P37PRI U1P36PRI U0P35PRI PC0P34PRI T0P31PRI SRP30PRI STP33PRI INT0P32PRI 0000 0000b INTPRI2 E3h PC1P00PRI AUP06PRI PTHP05PRI PTLP04PRI PWCP23PRI I10P02PRI I2CP01PRI T2P00PRI 0000 0000b INTSRC1 E4h INTSRC1.7 INTSRC1.6 INTSRC1.5 INTSRC1.4 INTSRC1.3 INTSRC1.2 INTSRC1.1 INTSRC1.0 0000 0000b INTSRC2 E5h INTSRC2.7 INTSRC2.6 INTSRC2.5 INTSRC2.4 INTSRC2.3 INTSRC2.2 INTSRC2.1 INTSRC2.0 0000 0000b INTPINSENS1 E6h P37ISENS P36ISENS P35ISENS P34ISENS P33ISENS P32ISENS P31ISENS P30ISENS 0000 0000b 1111 1111b 1111 1111b 0000 1100b 0010 1001b 0000 0000b ________________________________________________________________________________________________ www.ramtron.com page 7 of 99 VRS51L2070 INTPINSENS2 E7h P07ISENS P06ISENS P05ISENS P04ISENS P03ISENS P02ISENS GENINTEN E8h - - - - - - FPICONFIG E9h FPILOCK1 FPILOCK0 FPIIDLE FPIRDY 0 FPI8BIT FPIADDRL EAh 0000 0000b FPIADDRH EBh 0000 0000b FPIDATAL ECh 0000 0000b FPIDATAH EDh 0000 0000b FPICLKSPD EEh Reserved EFh - - - - P01ISENS FPITASK1 P00ISENS 0000 0000b GENINTEN 0000 0000b FPITASK0 0000 0100b FPICLKSPD3 FPICLKSPD2 FPICLKSPD1 FPICLKSPD0 0000 0000b - - - - 0000 0000b B F0h 0000 0000b MPAGE F1h 0000 0000b DEVCLKCFG1 F2h SOFTRESET OSCSELECT CLKDIVEN FULLSPDINT CLKDIV3 CLKDIV2 CLKDIV1 CLKDIV0 0011 0000b DEVCLKCGF2 F3h CYOSCEN INTOSCEN - - CYRANGE1 CYRANGE0 0 SYSTEMRDY 0100 1001b PERIPHEN1 F4h SPICSEN SPIEN I2CEN U1EN U0EN T2EN T1EN T0EN 0000 0000b PERIPHEN2 F5h PWC1EN PWC0EN AUEN XRAM2CODE IOPORTEN WDTEN PWMSFREN FPIEN 0000 1000b DEVMEMCFG F6h EXTBUSEN - - - - - - SFRPAGE 0000 0000b PORTINEN F7h Reserved (0) P6INPUTEN P5INPUTEN P4INPUTEN P3INPUTEN P2INPUTEN P1INPUTEN P0INPUTEN 0111 1111b USERFLAGS F8h P0PINCFG F9h P07IN1OUT0 P06IN1OUT0 P05IN1OUT0 P04IN1OUT0 P03IN1OUT0 P02IN1OUT0 P01IN1OUT0 P00IN1OUT0 1111 1111b P1PINCFG FAh P17IN1OUT0 P16IN1OUT0 P15IN1OUT0 P14IN1OUT0 P13IN1OUT0 P12IN1OUT0 P11IN1OUT0 P10IN1OUT0 1111 1111b P2PINCFG FBh P27IN1OUT0 P26IN1OUT0 P25IN1OUT0 P24IN1OUT0 P23IN1OUT0 P22IN1OUT0 P21IN1OUT0 P20IN1OUT0 1111 1111b P3PINCFG FCh P37IN1OUT0 P36IN1OUT0 P35IN1OUT0 P34IN1OUT0 P33IN1OUT0 P32IN1OUT0 P31IN1OUT0 P30IN1OUT0 1111 1111b P4PINCFG FDh P47IN1OUT0 P46IN1OUT0 P45IN1OUT0 P44IN1OUT0 P43IN1OUT0 P42IN1OUT0 P41IN1OUT0 P40IN1OUT0 1111 1111b P5PINCFG FEh P57IN1OUT0 P56IN1OUT0 P55IN1OUT0 P54IN1OUT0 P53IN1OUT0 P52IN1OUT0 P51IN1OUT0 P50IN1OUT0 1111 1111b P6PINCFG FFh P67IN1OUT0 P66IN1OUT0 P65IN1OUT0 P64IN1OUT0 P63IN1OUT0 P62IN1OUT0 P61IN1OUT0 P60IN1OUT0 1111 1111b 0000 0000b ________________________________________________________________________________________________ www.ramtron.com page 8 of 99 VRS51L2070 1.2 SFR Map Page 1 TABLE 5: SPECIAL FUNCTION REGISTERS (SFR) PAGE 1 SFR SFR Bit 7 Bit 6 Register Adrs Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Reset Value P0 80h - - - - - - - - 1111 1111b SP 81h - - - - - - - - 0000 0111b DPL0 82h - - - - - - - - 0000 0000b DPH0 83h - - - - - - - - 0000 0000b DPL1 84h 0000 0000b DPH1 85h 0000 0000b DPS 86h PCON 87h OSCSTOP INTEN1 88h T1IEN U1IEN U0IEN T0T1CFG 89h - T1GATE T0GATE TL0 8Ah TH0 8Bh 0000 0000b TL1 8Ch 0000 0000b TH1 8Dh 0000 0000b TL2 8Eh 0000 0000b TH2 8Fh P1 90h - - - - - - - - WDTCFG 91h WDTPERIOD3 WDTPERIOD2 WDTPERIOD1 WDTPERIOD0 WTIMERF ASTIMER WDTF WDTRESET RCAP0L 92h RCAP0H 93h 0000 0000b RCAP1L 94h 0000 0000b RCAP1H 95h 0000 0000b RCAP2L 96h 0000 0000b RCAP2H 97h 0000 0000b P5 98h T0T1CLKCFG 99h T1CLKCFG3 T1CLKCFG2 T1CLKCFG1 T1CLKCFG0 T0CLKCFG3 T0CLKCFG2 T0CLKCFG1 T0CLKCFG0 0000 0000b T0CON 9Ah T0OVF T0EXF T0DOWNEN T0TOGOUT T0EXTEN TR0 T0COUNTEN T0RLCAP 0000 0000b T1CON 9Bh T1OVF T1EXF T1DOWNEN T1TOGOUT T1EXTEN TR1 T1COUNTEN T1RLCAP 0000 0000b T2CON 9Ch T2OVF T2EXF T2DOWNEN T2TOGOUT T2EXTEN TR2 T2COUNTEN T2RLCAP 0000 0000b T2CLKCFG 9Dh - - T2CLKSRC T2OUTEN T2CLKCFG3 T2CLKCFG2 T2CLKCFG1 T2CLKCFG0 0000 0000b Reserved 9Eh - - - - - - - - 0000 0000b Reserved 9Fh - - - - - - - - 0000 0000b INTMODEN DEVCFGEN SFRINDADR DPSEL 0000 0000b IDLE 0110 0000b SPITXEIEN - 0000 0000b T0OUTEN T0MODE8 0000 0000b GF1 GF0 PDOWN PCHGIEN0 T0IEN SPIRXOVIEN T1CLKSRC T1OUTEN T1MODE8 0000 0000b 0000 0000b 1111 1111b 0000 0000b 0000 0000b 1111 1111b P2 A0h - - - - - - - - 1111 1111b Reserved A1h - - - - - - - - 0000 0000b AUA0 A2h* AUA1 A3h* 0010 0000b AUC0 A4h* 0010 0000b AUC1 A5h* 0010 0000b AUC2 A6h* 0010 0000b AUC3 A7h* INTEN2 A8h PCHGIEN1 AUWDTIEN PWMT47IEN PWMT03IEN PWCIEN I2CUARTCI I2CIEN T2IEN 0000 0000b P3 B0h - - - - - - - - 1111 1011b AUB0DIV B1h* 0010 0000b AUB0 B2h* 0010 0000b 0010 0000b 0010 0000b AUB1 B3h* 0010 0000b AURES0 B4h* 0010 0000b AURES1 B5h* 0010 0000b ________________________________________________________________________________________________ www.ramtron.com page 9 of 99 VRS51L2070 AURES2 B6h* AURES3 B7h* 0010 0000b IPINFLAG1 B8h P37IF P36IF P35IF P34IF P31IF P30IF INT1IF INT0IF 0000 0000b PORTCHG B9h PMONFLAG1 PCHGMSK1 PCHGSEL1 PCHGSEL0 PMONFLAG0 PCHGMSK0 PCHGSEL1 PCHGSEL0 0000 0000b Reserved BAh - - - - - - - - 0001 0000b Reserved BBh - - - - - - - - 0000 0000b Reserved BCh - - - - - - - - 0000 0000b Reserved BDh - - - - - - - - 0000 0000b Reserved BEh - - - - - - - - Reserved BFh - - - - - - - - P4 C0h AUSHIFTCFG C1h* SHIFTMODE ARITHSHIFT SHIFT5 SHIFT4 SHIFT3 SHIFT2 SHIFT1 SHIFT0 0010 0000b AUCONFIG1 C2h* CAPPREV CAPMODE OVCAPEN READCAP ADDSRC1 ADDSRC0 MULCMD1 MULCMD0 0000 0000b AUCONFIG2 C3h* AUREGCLR2 AUREGCLR1 AUREGCLR0 AUINTEN - DIVOUTRG AUOV16 AUOV32 0000 0000b AUPREV0 C4h* 0000 0000b AUPREV1 C5h* 0000 0000b AUPREV2 C6h* 0000 0000b AUPREV3 C7h* 0000 0000b P6 C8h Reserved C9h - - Reserved CAh - - Reserved CBh - - Reserved CCh - - Reserved CDh - Reserved CEh Reserved 0010 0000b 1111 1111b 0000 0000b - - - - - - 0000 0000b - - - - - - 0000 0001b - - - - - - 0000 0000b - - - - - - 0000 0000b - - - - - - - 0000 0000b - - - - - - - - 0000 0000b CFh - - - - - - - - PSW D0h CY AC F0 RS1 RS0 OV - P Reserved D1h - - - - - - - - Reserved D2h - - - - - - - - Reserved D3h - - - - - - - - Reserved D4h - - - - - - - - Reserved D5h - - - - - - - - INTPININV1 D6h P37IINV P36IINV P35IINV P34IINV P33IINV P32IINV P31IINV P30IINV 0000 0000b INTPININV2 D7h P07IINV P06IINV P05IINV P04IINV P03IINV P02IINV P01IINV P00IINV 0000 0000b IPINFLAG2 D8h P07IF P06IF P05IF P04IF P03IF P02IF P01IF P00IF 0000 0000b XMEMCTRL D9h EXTBUSCFG EXTBUSCS - - STRECH3 STRECH2 STRECH1 STRECH0 0000 0000b Reserved DAh - - - - - - - - 0000 0000b 0000 0000b Reserved DBh - - - - - - - - 0000 0000b Reserved DCh - - - - - - - - 0000 0000b Reserved DDH - - - - - - - - 0000 0000b Reserved DEh - - - - - - - - 0000 0000b Reserved DFh - - - - - - - - 0000 0000b ACC E0h - - - - - - - - 0000 0000b DEVIOMAP E1h Reserved PWMALTMAP I2CALTMAP U1ALTMAP U0ALTMAP T2ALTMAP T1ALTMAP T0ALTMAP 0000 0000b INTPRI1 E2h T1P37PRI U1P36PRI U0P35PRI PC0P34PRI T0P31PRI SRP30PRI STP33PRI INT0P32PRI 0000 0000b INTPRI2 E3h PC1P00PRI AUP06PRI PTHP05PRI PTLP04PRI PWCP23PRI I10P02PRI I2CP01PRI T2P00PRI 0000 0000b INTSRC1 E4h INTSRC1.7 INTSRC1.6 INTSRC1.5 INTSRC1.4 INTSRC1.3 INTSRC1.2 INTSRC1.1 INTSRC1.0 0000 0000b INTSRC2 E5h INTSRC2.7 INTSRC2.6 INTSRC2.5 INTSRC2.4 INTSRC2.3 INTSRC2.2 INTSRC2.1 INTSRC2.0 0000 0000b INTPINSENS1 E6h P37ISENS P36ISENS P35ISENS P34ISENS P33ISENS P32ISENS P31ISENS P30ISENS 0000 0000b INTPINSENS2 E7h P07ISENS P06ISENS P05ISENS P04ISENS P03ISENS P02ISENS P01ISENS P00ISENS 0000 0000b GENINTEN E8h - - - - - - GENINTEN 0000 0000b ________________________________________________________________________________________________ www.ramtron.com page 10 of 99 VRS51L2070 FPICONFIG E9h FPIADDRL EAh FPILOCK1 0000 0000b FPIADDRH EBh 0000 0000b FPIDATAL ECh 0000 0000b FPIDATAH EDh 0000 0000b FPICLKSPD EEh Reserved EFh - FPILOCK0 - FPIIDLE - FPIRDY - 0 FPI8BIT FPITASK1 FPITASK0 0000 0100b FPICLKSPD3 FPICLKSPD2 FPICLKSPD1 FPICLKSPD0 0000 0000b - - - - 0000 0000b B F0h 0000 0000b MPAGE F1h 0000 0000b DEVCLKCFG1 F2h SOFTRESET OSCSELECT CLKDIVEN FULLSPDINT CLKDIV3 CLKDIV2 CLKDIV1 CLKDIV0 0011 0000b DEVCLKCGF2 F3h CYOSCEN INTOSCEN - - CYRANGE1 CYRANGE0 0 SYSTEMRDY 0100 1001b PERIPHEN1 F4h SPICSEN SPIEN I2CEN U1EN U0EN T2EN T1EN T0EN 0000 0000b PERIPHEN2 F5h PWC1EN PWC0EN AUEN XRAM2CODE IOPORTEN WDTEN PWMSFREN FPIEN 0000 1000b DEVMEMCFG F6h EXTBUSEN - - - - - - SFRPAGE 0000 0000b PORTINEN F7h Reserved (0) P6INPUTEN P5INPUTEN P4INPUTEN P3INPUTEN P2INPUTEN P1INPUTEN P0INPUTEN 0111 1111b USERFLAGS F8h P0PINCFG F9h P07IN1OUT0 P06IN1OUT0 P05IN1OUT0 P04IN1OUT0 P03IN1OUT0 P02IN1OUT0 P01IN1OUT0 P00IN1OUT0 1111 1111b P1PINCFG FAh P17IN1OUT0 P16IN1OUT0 P15IN1OUT0 P14IN1OUT0 P13IN1OUT0 P12IN1OUT0 P11IN1OUT0 P10IN1OUT0 1111 1111b P2PINCFG FBh P27IN1OUT0 P26IN1OUT0 P25IN1OUT0 P24IN1OUT0 P23IN1OUT0 P22IN1OUT0 P21IN1OUT0 P20IN1OUT0 1111 1111b P3PINCFG FCh P37IN1OUT0 P36IN1OUT0 P35IN1OUT0 P34IN1OUT0 P33IN1OUT0 P32IN1OUT0 P31IN1OUT0 P30IN1OUT0 1111 1111b P4PINCFG FDh P47IN1OUT0 P46IN1OUT0 P45IN1OUT0 P44IN1OUT0 P43IN1OUT0 P42IN1OUT0 P41IN1OUT0 P40IN1OUT0 1111 1111b P5PINCFG FEh P57IN1OUT0 P56IN1OUT0 P55IN1OUT0 P54IN1OUT0 P53IN1OUT0 P52IN1OUT0 P51IN1OUT0 P50IN1OUT0 1111 1111b P6PINCFG FFh P67IN1OUT0 P66IN1OUT0 P65IN1OUT0 P64IN1OUT0 P63IN1OUT0 P62IN1OUT0 P61IN1OUT0 P60IN1OUT0 1111 1111b 1.3 0000 0000b Bit Accessible Registers As is the case in the standard 8051, all SFR registers in which the lower nibble of the address is x0 or x8 are bitaddressable. The bit-addressable registers allow bit-oriented instructions to alter individual register bit values. TABLE 6:BIT ADDRESSABLE SFR REGISTERS SFR Register SFR Adrs Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Reset Value P0 80h - - - - - - - - 1111 1111b INTEN1 88h T1IEN U1IEN U0IEN PCHGIEN0 T0IEN SPIRXOVIEN SPITXEIEN - 0000 0000b P1 90h - - - - - - - - 1111 1111b P5 98h P2 A0h - - - - - - - - 1111 1111b INTEN2 A8h PCHGIEN1 AUWDTIEN PWMT47IEN PWMT03IEN PWCIEN I2CUARTCI I2CIEN T2IEN 0000 0000b P3 B0h - - - - - - - - 1111 1011b IPINFLAG1 B8h P37IF P36IF P35IF P34IF P31IF P30IF INT1IF INT0IF 0000 0000b P6 C8h PSW D0h CY AC F0 RS1 RS0 OV - P 0000 0000b IPINFLAG2 D8h P07IF P06IF P05IF P04IF P03IF P02IF P01IF P00IF 0000 0000b ACC E0h - - - - - - - - 0000 0000b GENINTEN E8h - - - - - - GENINTEN 0000 0000b B F0h 0000 0000b USERFLAGS F8h 0000 0000b 1111 1111b 1111 1111b ________________________________________________________________________________________________ www.ramtron.com page 11 of 99 VRS51L2070 TABLE 12:THE PSW SFR REGISTER - PSW SFR D0H 1 VRS51L2070 Architecture 1.1 Data Pointers The VRS51L2070 includes two 16-bit data pointers which are described in the following tables. The active data pointer is controlled via DPS register is located at SFR address 86h (see below). TABLE 7: DATA POINTER 0 HIGH - DPH0 SFR 83H 7 6 5 4 3 2 1 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic Description 7 CY 6 AC 5 4:3 F0 RS1:RS0 2 OV 1 0 F1 P Carry Bit Flag. Indicates that the last addition/subtraction resulted in a carry or borrow. The CY bit is cleared by other arithmetic instructions, the JBC and CLR C instructions. Auxiliary Carry Bit Flag. Indicates that the last addition/subtraction resulted in a carry or borrow from the higher nibble. The AC bit is cleared by other arithmetic instructions and by the JBC instruction. User General Purpose Flag Register Select Address for R0 - R7 00 R0 to R7 From 00h to 07h 01 R0 to R7 From 08h to 0Fh 10 R0 to R7 From 10h to 17h 11 R0 to R7 From 17h to 1Fh Overflow Flag Indicates that the last addition/subtraction resulted in a carry/borrow/overflow. The OV bit is cleared by other arithmetic instructions and the JBC instruction. User General Purpose Flag Parity Flag 0 R/W, Reset = 0x00 DPTR0[15:8] TABLE 8: DATA POINTER 0 LOW - DPL0 SFR 82H 7 6 5 4 3 2 1 0 R/W, Reset = 0x00 DPTR0[7:0] TABLE 9: DATA POINTER 1 HIGH - DPH1 SFR 85H 7 6 5 4 3 2 1 0 1.3 R/W, Reset = 0x00 DPTR1[15:8] TABLE 10: DATA POINTER 1 LOW - DPL1 SFR 84H 7 6 5 4 3 2 1 0 R/W, Reset = 0x00 Accumulator, B and User Flags Register The VRS51L2070 accumulator is located at address E0h on SFR pages 0 and 1. The accumulator is the source and destination for many 8051 instructions. TABLE 13: THE ACCUMULATOR - ACC OR A SFR E0H 7 DPTR1[7:0] 6 5 TABLE 11: DATA POINTER SELECT REGISTER - DPS SFR 86H 7 6 5 4 3 2 1 0 R 0 R 0 R 0 R 0 R 0 R 0 R 0 R/W 0 Bit Mnemonic Description 7:1 0 unused DPSEL DPS value 0 : Selects DPTR 0 1 : Selects DPTR 1 1.2 PSW Register The PSW register is a bit addressable register that contains the status flags (CY, AC, OV, P), user flag (F0) and register bank select bits (RS1, RS0) of the 8051 processor 4 3 2 R/W, Reset = 0x00 ACC[7:0] 1 0 The B register is mainly used for MUL and DIV instructions, holding the MSB of the MUL instruction and the remainder of the DIV instruction. It can also be used as a general purpose register that is bitaddressable. It is accessible via both SFR pages 0 and 1 at address F0h. TABLE 14: B REGISTER - SFR F0H 7 1.4 6 5 4 3 2 R/W, Reset = 0x00 B[7:0] 1 0 User Flag Register The user flag register is a bit-addressable register used for condition testing or as a general purpose storage register. TABLE 15: USERFLAGS REGISTER - USERFLAGS SFR F8H 7 6 5 4 3 2 USERFLAGS, RESET = 0x00 USERFLAGS[7:0] 1 0 ________________________________________________________________________________________________ www.ramtron.com page 12 of 99 VRS51L2070 2 VRS51L2070 Program Memory The VRS51L2070 includes 64KB of on-chip Flash memory that can be used as program memory or as nonvolatile data storage. 2.1 Most peripherals are accessible via both SFR pages. The following peripherals are only accessible via SFR Page 0: o o o Programming the VRS51L2070 The VRS51L2070 on-board Flash memory is programmed through its JTAG interface or via the FPI interface. The VRS51L2070 cannot be programmed in parallel mode (section 21 of this datasheet explains the FPI interface operation). 3 Data Memory The VRS51L2070 has a total of 4352 bytes of on-chip SRAM memory: 256 bytes are configured as the standard internal memory structure of an 8051, while the remaining 4096 bytes can be accessed using external memory addressing (MOVX instructions). FIGURE 4: VRS51L2070 DATA AND PROGRAM MEMORY STRUCTURE FFFFh FFFFh External Data BUS Access (Upper 32KB) IC Interface SPI Interface PWC Interface The enhanced arithmetic unit is only mapped into SFR Page 1. The active SFR page is selected by using the device memory configuration register. TABLE 16:DEVICE MEMORY CONFIGURATION REGISTER - DEVMEMCFG SFR F6H 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic Description 7 EXTBUSEN When set this bit activates the External data bus access through Port 0, port 2, P3.6 and P3.7 6:2 0 Not used SFRPAGE 3.3 When set, SFR Page 1 is selected. Accessing SFR Page 1 Accessing registers located on SFR Page 1 requires writing a 01h to the DEVMEMCFG register, as shown below: (DEVMEMCFG.7 = 1) 8000h 0FFFh Upper 128 bytes SRAM (indirect addressing only) FFh 80h 7Fh FFh 80h FFh 80h SFR Page 1 (DEVMEMCFG.0=1) SFR Page 0 (DEVMEMCFG.0=0) Program Memory 64KB Flash (No External Program memory access) 8000h 0FFFh 4096 bytes of SRAM (accessible using MOVX instruction) 3.4 0000h Internal Scratch Pad SRAM (256 Bytes) As is the case with standard 8051s, the VRS51L2070 includes 256 bytes of internal scratch pad SRAM: the lower 128 bytes are accessible by using either direct or indirect addressing; the upper 128 bytes are accessible by using indirect addressing only. Using direct addressing for the upper 128 bytes of scratch pad SRAM will access the SFR register area. 3.2 Indirect Addressing of the SFR 0000h The VRS51L2070 also provides external data bus memory access, enabling direct interfacing of the VRS51L2070 to external devices such as SRAM, data converters, etc. Bit 7 of the DEVMEMCFG register, when set, will activate external data bus access. 3.1 Writing 00h into the DEVMEMCFG register enables access to SFR Page 0. MOV DEVMEMCFG,#00H ;SELECT SFR PAGE 0 Lower 128 bytes SRAM 00h MOV DEVMEMCFG,#01H ;SELECT SFR PAGE 1 SFR Register Structure The VRS51L2070 peripheral registers are accessible through two SFR register pages mapped into address range 80h to FFh in the 256 bytes of memory, which can be addressed directly or indirectly. It is possible to access the SFR register in indirect addressing mode. Unique to the VRS51L2070, this feature enables efficient SFR content data transfers. When the SFRINDADR bit 4 of the PCON register is set to 1, the A5h (NOP) instruction functions as an indirect SFR access. Indirect SFR addressing uses the accumulator as well as the four bank Rn registers of SRAM memory area 00h to 1Fh to indirectly transfer the data to and from the SFR memory space. 3.4.1 Indirect SFR Register Write For an indirect SFR write operation, perform the following steps after the SFRINDADR bit of the PCON register is set to 1: o o Write the data value into the accumulator. Hold the SFR address where the write operation is performed in the internal SRAM memory from address 00h to 1Fh. The same SRAM memory area [00f to 1Fh] holds four sets of 8x Rn registers that are used for indirect ________________________________________________________________________________________________ www.ramtron.com page 13 of 99 VRS51L2070 addressing. Only one set of Rn registers is active at any given time and is defined by the value of the bits RS1 and RS0 of the PSW register. For an indirect SFR write operation, bit 7 of the SFR address written into Rn must be cleared. For example, to write to the SPITX0 register located at address C4h, 44h should be written into the Rn register. Example using the Bank 1, R0 register: MOV R0,#44 ;Target is SFR C4h (with Bit 7 stripped) Example using the Bank 1, R3 register: MOV R3,#44 3.4.2 Indirect SFR Read The indirect SFR address read functions similarly to the indirect SFR write, with the main differences being that the SFR target address stored in the Rn register is the actual SFR address (bit 7 = 1) with the accumulator containing the current SFR data. ;// Perform Indirect Read of Value in USERFLAGS SFR Address (0xF8) ;// into ACC using indirect SFR READ function ORL 0x87, #0x10; ;SET A5 for indirect SFR addressing MOV A,#0x00 ;Acc = 00h MOV R0, #0xF8 ;R0 (bank1) = address P2 with Bit 7 cleared .db 0xA5 ;Perform the indirect SFR Write .db 0x00 ;After the second .db instruction, ;Acc contain the value 0xAA ;Target is SFR C4h (with Bit 7 stripped) The next step involves calling the SFR indirect addressing function. This is a two-step process composed of the A5h instruction itself followed by the physical address of the Rn register, where the SFR address is stored. If the R0 register of Bank 1 has been used, the next instructions should be: db. 0xA5 db. 0x00 3.5 ;Set A5 for NOP operation Stack Pointer The stack pointer is a register located at address 81h of the SFR register area whose value corresponds to the address of the last item that was put on the processor stack. Each time new data is put on the processor stack, the value of the stack pointer is incremented. TABLE 17: STACK POINTER - SP SFR 81H If the R3 register of Bank 0 has been used, the next instructions should be: db. 0xA5 db. 0x03 This would also work for the Rn registers located in Bank 4. For example, if the R0 register of Bank 4 contains the target SFR address, the instruction should be: db. 0xA5 db. 0x18 Once the A5h instruction is executed, the processor will take the value stored in the accumulator and put it into the SFR address identified by the Rn register address. ;// Perform Indirect Write of Value 0xAA ;// into USERFLAGS SFR address (0xF8) using indirect SFR WRITE ORL 0x87, #0x10; ;SET A5 for indirect SFR addressing MOV 0xF8,#00 ;Clear USERFLAGS MOV A, #0xAA ;Acc = AAh MOV R0, #0x78 ;R0 (bank1) = address USERFLAGS (F8h) ;with Bit 7 cleared .db 0xA5 ;Perform the indirect SFR write .db 0x00 ;After the second .db instruction, ;P2 contain the value 0xAA ANL 0x87, #0xEF; ANL 0x87, #0xEF; 7 6 5 4 3 2 R/W, Reset = 0x07 SP[7:0] 1 0 By default, the stack pointer value is 07h. The stack can be set anywhere in the internal SRAM from address 00h to FFh. Each time a function call is performed or an interrupt is serviced, the 16-bit return address (2 bytes) is stored on the stack. Data can be manually placed on the stack by using the PUSH and POP functions. 3.6 External Data Memory Access The VRS51L2070 provides external memory bus access on the upper 32KB block of the 64KB external memory [8000h to FFFFh]. External memory bus access requires that the EXTBUSEN bit of the DEVMEMCFG register be set to 1. The external memory address range 0000h to 3FFFh provides access to a block of 4KB of SRAM memory on the device. ;Set A5 for NOP operation ________________________________________________________________________________________________ www.ramtron.com page 14 of 99 VRS51L2070 TABLE 18: XMEM CONTROL REGISTER - XMEMCTRL SFR D9H 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic Description 7 EXTBUSCFG 6 EXTBUSCS 5 4 3:0 Stretch[3:0] External Memory Bus Configuration 0 = LSB of Address/Data are Multiplexed 1 = LSB of Address/Data are not Multiplexed Ext Memory CS Function 0 = Full Address Bit Dedicated to Addressing 1 = A12: A15 Becomes CS Lines Not used Not Used Number of Stretch Cycles from 0 to 15 From a device connected to the VRS51L2070's external memory bus, the address range is seen as 0000 to 7FFFh, as P2.7/A15 is driven low. 3.7 Integrated 4KB SRAM Block The VRS51L2070 includes a 4KB block of SRAM that is mapped from address 0000h to 0FFFh on the external memory bus. This SRAM can be used for general purpose data memory or program memory. 3.7.1 Accessing the 4KB SRAM Block Access to the block of 4KB SRAM requires the use of MOVX instructions. 3.7.2 Running Programs from the External 4KB SRAM Block Here, the VRS51L2070 processor can execute code directly from the external 4KB of SRAM. Running the program from the SRAM memory can significantly save power, especially at lower operating frequencies. This is because SRAM power consumption is directly proportional to the access frequency, while power consumption of the Flash memory is less dependant of the VRS51L2070 operating frequency To execute code from the 4KB SRAM block: 1. Copy the code from the Flash to the SRAM and apply the appropriate address shifting, if required 2. Before switching to an XRAM operation, the program must execute from a Flash address higher than 0FFFh 3. Set the XRAM2CODE bit (bit 4) of the PERIPHEN2 register 4. Jump to the code copied into XRAM The following program example copies code from the Flash memory to the XRAM memory and switches the program execution to the XRAM ;--------VRS51L2070 - Running program into XRAM --------------;- DESCRIPTION: This program gives an examples on how ;to switch code execution from Flash to XRAM ;--------------------------------------------------------------include VRS51L2070_RIDE.inc ;---------- Variable definition -------------CPTR EQU 030h org LJMP 00000H INIT ;-----------------------------------------------------------------------;---------------------- MAIN PROGRAM BEGINS ----------------------------;-----------------------------------------------------------------------INIT: MOV PERIPHEN2,#08H ;ENABLE IO MOV P1PINCFG,#00H ;CONFIGURE P1 AS OUTPUT MOV PERIPHEN1,#00000000B; MOV PERIPHEN2,#00001000B ;BIT4 - XRAM2CODE = 0 ;--COPY CODE FROM FLASH INTO XRAM MEMORY CLR DPS MOV DPTR,#01000H ;SET DPTR0 (POINT TO CODE) MOV DPS,#01H ;SWITCH TO DPTR1 MOV DPTR,#0000H ;SET DPTR1 (POINT TO XRAM) COPYLOOP: MOV DPS,#00 CLR A MOVC A,@A+DPTR INC DPTR ;POINT TO DPTR0 (FLASH) ; ;INC DPTR0 (FLASH) MOV DPS,#01H MOVX @DPTR,A INC DPTR ;SWITCH TO DPTR1 (XRAM) ;WRITE VALUE INTO XRAM ;INC dptr1 (XRAM) MOV A,DPH1 CJNE A,#03,COPYLOOP LJMP OUTSIDEXRAM ;CHECK IF DPTR1 (XRAM) REACH ADDRESS 0300H ;JUMP TO FLASH LOCATION OUTSIDE XRAM AREA ;-----------------------------------------;- SECTION OF CODE OUTSIDE THE XRAM ;-----------------------------------------ORG 2000H OUTSIDEXRAM: MOV PERIPHEN2,#18H LJMP 0100H MOV P1,#00 LOOP: LJMP ;ACTIVATE XRAM2CODE BIT AND IOPORTS ;ANY JUMP TO THE 0000H - 0FFFH AREA SHOULD EXECUTE FROM XRAM ;JUMP TO THE P1 TOGGLE LOOP COPIED INTO XRAM ;FORCE P1 = 0X00H IF STUCK INTO THE FLASH LOOP ;INFINITE LOOP ;----------------------------------------------------------------------------------;- Code to be moved into XRAM from address 0000h to 02FFH ; ASSUMED CODE CONTAINED FROM 1000H TO 12FFH... ; WILL BE COPIED FROM 0000H TO 02FFH INTO XRAM ;-----------------------------------------------------------------------------------;-------------------------------------;- XRAM_Port_Toggle: ;-------------------------------------org 1100h TOGGLE: MOV LCALL MOV LCALL LJMP P1,#00H 0200H P1,#0FFH 0200H 0100H ;SET PORT 1 = 00H ;CALL DELAY FUNCTION ;SET PORT 1 = FFH ;CALL DELAY FUNCTION org 1200h ;---------------------------------------------------------------;- DELAY1MSTO : 1MS DELAY USING TIMER0 ;--------------------------------------------------------------DELAY1MS: MOV CPTR,#1 MOV ORL MOV A,PERIPHEN1 A,#00000001B PERIPHEN1,A ;LOAD PERIPHEN1 REG ;ENABLE TIMER 0 ________________________________________________________________________________________________ www.ramtron.com page 15 of 99 VRS51L2070 DELAY1MSLP: MOV TH0,#063H MOV TL0,#0C0H MOV MOV T0T1CLKCFG,#00H T0CON,#00000100B DWAITOVT0: MOV A,T0CON ANL A,#080H JZ DWAITOVT0 ; 6TIMER0 RELOAD VALUE FOR 1MS AT 40MHZ ;NO PRESCALER FOR TIMER 0 CLOCK ;START TIMER 0, COUNT UP ;READ TIMER 0 CONTROL, WAIT FOR OVERFLOW ;ISOLATE TIMER OVERFLOW FLAG ;LOOP AS LONG AS TIMER 0 DONT OVERFLOW MOV DJNZ T0CON,#00H CPTR,DELAY1MSLP ;STOP TIMER 0 ; MOV ANL MOV RET A,PERIPHEN1 A,#11111110B PERIPHEN1,A ;LOAD PERIPHEN1 REG ;DISABLE TIMER 0 3.8 The multiplexed addressing mode is the default configuration when external memory access is performed. 3.8.2 Non-Multiplexed External Data Memory Access The VRS51L2070 external address and data memory bus can operate in non-multiplexed mode. This mode is activated by setting the EXTBUSCFG bit of the XMEMCTRL register to 1. In this case: D7:D0 will be mapped into Port 0 A7:A0 will be mapped into Port 6 A15:A8 will be mapped into Port 2 o o o External Data Bus Access The VRS51L2070 provides 32KB of data memory access, which is mapped from address 8000h to FFFFh. Bit 7 of the DEVMEMCFG register, when set, activates the external data memory bus access. In this mode, Port 0 and Port 2 are dedicated to external device addressing. FIGURE 6: NON-MULTIPLEXED EXTERNAL DATA MEMORY ACCESS NON-MULTIPLEXED WRITE CLK P2:P6 A[14:0] P0 D[7:0] 3.8.1 Multiplexed External Data Memory Access Multiplexed external data memory access mode on the VRS51L2070 is similar to that on standard 8051s: address bits A0 to A7 and data bits D0 to D7 are timemultiplexed on Port 0, while Port 2 controls address bits A8 to A15. In multiplexed addressing mode, external glue logic is required to multiplex lower addresses and data. Typically, a 74x373 or 74x573 can be used for this purpose. The ALE-CM0 pin serves to latch the address. WR CE- NON-MULTIPLEXED READ CLK P2:P6 A[14:0] DATA P0 D[7:0] RD CE- FIGURE 5: MULTIPLEXED EXTERNAL DATA MEMORY ACCESS 3.8.3 Page Addressing of the External SRAM using the MPAGE Register The MPAGE register provides access to the entire external memory using indirect addressing through registers R0 and R1. When using the MOVX @Ri instructions, the MPAGE register provides the upper byte of the address pointed to. MULTIPLEXED WRITE CLK P2 A[14:8] P0 A[7:0]/D[7:0] A[7:0] D[7:0] ALE WR TABLE 19: MEMORY PAGE REGISTER - MPAGE SFR F1H 7 MULTIPLEXED READ CLK 6 5 4 3 2 1 R/W, Reset = 0x00 MPAGE[7:0] = Upper Address Byte 0 P2 A[14:8] P0 A[7:0]/D[7:0] A[7:0] DATA ALE RD ________________________________________________________________________________________________ www.ramtron.com page 16 of 99 VRS51L2070 3.9 External Bus CS Control Lines 4 Chip Configuration In some applications, the external memory access is only required to perform high speed data transfers between the microcontroller and a parallel access data converter. In this case, only a few register addresses would have to be accessed. The VRS51L2070 provides a feature that greatly simplifies the interface to parallel access peripherals such as data converters or high-speed communication devices. 4.1 When both the EXTBUSCS bit of the XMEMCTRL register and the EXTBUSGEN bit of the DEVMEMCFG register are set to 1, the VRS51L2070's external memory bus behaves as follows: Two SFR registers control the configuration of the clock source and the division ratio applied to the system clock source. The DEVCLKCFG1 register selects either the internal oscillator or the external crystal oscillator as the system clock source. When the OSCSELECT bit is cleared, the VRS51L2070 system clock derives its power from the external crystal oscillator (please see the next section). * * * * * * Address lines A15 to A12 operate as CS (chip select) outputs. They are mapped on P2.7P2.4 Address lines A11-A8 contain the rest of address Address lines A0-A7 are mapped into P6 (inaccessible in the 44-pin version of the VRS51L2070) Port 0 handles the data bus (D7:D0) when the EXTBUSCFG bit is set to 1 (non-multiplexed address/data) RD and RW lines on P3.7 and P3.6 are active ALE is set to 0 The value of bits 13 and 12 of the target address will define the active chip select line output to P2.7-P2.4. Address bits 15 and 14 are not taken into account. A11:A0 carries the rest of the address bits. This is represented at the register level as follows: A15 X A14 X A13 CS1 A12 CS0 ... ... A0 As such, when the CS bus control mode is activated, the upper 32KB of the external data memory bus is seen as two overlapping blocks of 16KB. TABLE 20: EXTERNAL MEMORY BUS CS CONTROL MODE Address range 0000h- 7FFFh I/O Pin Active as CS None 8000h-8FFFh 9000h-9FFFh A000h-AFFFh B000h-BFFFh C000h-CFFFh D000h-DFFFh E000h-EFFFh F000h-FFFFh P2.4-A12 P2.5-A13 P2.6-A14 P2.7-A15 P2.4-A12 (overlap) P2.5-A13 (overlap) P2.6-A14 (overlap) P2.7-A15 (overlap) VRS51L2070 Clock Configuration The VRS51L2070 clock system is highly configurable. The VRS51L2070 includes an internal 40MHz oscillator, eliminating the need for an external oscillator or crystal. However, an external standard parallel AT or BT cut crystal can be used (frequency range of 1MHz to 40MHz). TABLE 21:DEVICE CLOCK CONFIGURATION REGISTER 1 - DEVCLKCFG1 SFR F2H 7 6 5 4 3 2 1 0 R/W 0 R/W 1 R/W 1 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic Description 7 6 SOFTRESET OSCSELECT 5 CLKDIVEN 4 FULLSPDINT 3:0 CLKDIV[3:0] Soft reset control bit Oscillator Select 0 = External oscillator is selected 1 = Internal oscillator is selected Internal oscillator output clock divisor enable bit 0 = Disable Clock Divisor 1 = Enable Clock Division Full Speed Interrupt Mode 0 =Processor will run with selected clock division during interrupts 1 = Processor will run at full speed during interrupts CLKDIV Value/Clock Division 0 = /1 1 = /2 2 = /4 3 = /8 4 = /16 5 = /32 6 = /64 7 = /128 8 = /256 9 = /512 A = /1024 B = /2048 C = /4096 D = /8192 E = /16384 F= /32768 (4KB SRAM from 0000h to 0FFFh) ________________________________________________________________________________________________ www.ramtron.com page 17 of 99 VRS51L2070 Soft Reset Operation A software reset can be performed on the VRS51L2070. This is executed via two consecutive instruction: The first instruction is to clear the SOFTRESET bit and the second is to set SOFTRESET bit to 1: Examples of soft Reset in ASM: ANL ORL DEVCLKCFG,#7Fh DEVCLKCFG,#80h In C : active and stable at the moment the transition is made. The minimum period required for the crystal oscillator to stabilize depends on the type of crystal and the frequency used. In general, it is recommended to wait at least 1ms for the crystal oscillator to stabilize before switching to it. The stabilization time of the internal oscillator is much shorter than that of the crystal oscillator. Whenever the internal oscillator is reactivated, wait 1ms before switching the system clock back to the internal oscillator. DEVCLKCFG &= 0x7F DEVCLKCFG |= 0x80 4.1.1 The DEVCLKCFG2 register activates the on-chip oscillator and the crystal oscillator. Both oscillators can be activated independently, however, as previously mentioned, only one can be used as the VRS51L2070 system clock source. The following steps represent the recommended procedure for switching from the internal oscillator to the crystal oscillator: * TABLE 22:DEVICE CLOCK CONFIGURATION REGISTER 2 - DEVCLKCFG2 SFR F3H 7 6 5 4 3 2 1 0 R/W 0 R/W 1 R/W 0 R/W 0 R/W 1 R/W 0 R/W 0 R 0 Bit Mnemonic Description 7 CYOSCEN 6 INTOSCEN Crystal Oscillator Enable 0 = Crystal oscillator is disabled (default) 1 = Crystal oscillator is enabled Internal Oscillator Enable 0 = Internal oscillator is disabled 1 = Internal oscillator is enabled (default) 5 4 3:2 - 1 0 CYRANGE[1:0] Reserved SYSTEMRDY Crystal Oscillator Range 00 = 25MHz - 40MHz 01 = 4MHz to 25MHz 10 = 32kHz to 100KHz 11 = 32kHz to 100KHz System Ready Indicator When this bit is set to 1, it indicates that the VRS51L2070 is no longer driving the reset line The SYSTEMRDY bit of the DEVCLKCFG2 register indicates the state of the RESET driving circuit. A 0 indicates that the RESET line of the VRS51L2070 is driving the rest of the system. The SYSTEMRDY bit will be set to 1 by the reset control circuit when the RESET line no longer drives the circuit. The crystal oscillator is activated by setting the CYOSCEN bit of the DEVCLKCFG2 register to 1 and selecting the CYRANGE value according to the frequency of the crystal used. The CYRANGE parameter controls the drive of the crystal oscillator circuit. The internal oscillator is activated by setting the INTOSEN bit to 1. Before switching from one oscillator source to another, it is important to make sure that both oscillators are Switching from the Internal to the External Oscillator * * Activate the crystal oscillator and configure the frequency range, while leaving the internal oscillator active (INTOSCEN = 1) Wait at least 1ms for stabilization time Clear the OSCSELECT bit to turn off the internal oscillator Below is a code example of the above sequence: ;********************************** ;* Switching from Internal * ; to External Oscillatr * ;********************************** MOV DEVCLKCFG2,#11001001B ;ENABLE EXTERNAL CRYSTAL OSC MOV A,#1 ;WAIT 1MS FOR CRYSTAL TO STABILISE ACALL DELAY1MST0 MOV DEVCLKCFG1,#00100000B ;SET EXTERNAL CRYSTAL OSCILLATOR It is important to allow the crystal oscillator to stabilize before using it as the system clock. An instable oscillator may result in an operating frequency error or device volatility . 4.1.2 Switching from the External Oscillator Back to the Internal Oscillator It is possible to switch system clock source to the internal oscillator while the device is running from the external oscillator. Note that before switching the internal oscillator, it must be active. The following the sequence below is recommended in order to switch from the crystal oscillator back to the internal oscillator: o o o Keep the external oscillator enabled (CYOSCEN = 1), activate the internal oscillator by setting the INTOSCEN bit of the DEVCLKCFG2 register to 1 Wait at least 100 us for stabilization time Set the OSCSELECT bit of the DEVCLKCFG1 register to 1 ________________________________________________________________________________________________ www.ramtron.com page 18 of 99 VRS51L2070 Below is a code example of the above sequence: ;********************************** ;* Switching from External * ; to Internal Oscillator * ;********************************** MOV DEVCLKCFG2,#11001001B ;REACTIVATE THE INTERNAL OSCILLATOR ACALL DELAY100US ;WAIT 100us FOR Self Oscillator to Stabilize MOV ;SET EXTERNAL CRYSTAL OSCILLATOR DEVCLKCFG1,#01000000B 4.1.3 System Clock Prescaler Between the internal and the external oscillator modules and the main system clock tree, the VRS51L2070 includes a clock prescaler module enabling a dynamic division adjustment of the system clock frequency from FOSC /1 to FOSC/32768. This feature can be useful for saving power in batteryoperated applications, in which the device clock speed can be adjusted to suit the processing power requirements. After a reset, the VRS51L2070 will boot up from the internal oscillator and the selected operating speed will be set to 20MHz i.e.. CLKDIVEN is set to 1 and the CLKDIV value is 1 (CLK = Fosc/2). Clearing the CLKDIVEN bit will deactivate the main clock prescaler. 4.1.4 Interrupt Processing Speed Configuration The VRS51L2070 includes a feature that allows interrupts to be processed at full speed, while the main program executes at a lower speed, as defined by the FULLSPDINT value when the CLKDIVEN bit is set to 1.This mode of operation can be useful for applications where high processing power is required for short periods of time. Significant power saving can be achieved by dynamically adjusting the system clock frequency according to the processing power required. 4.2 Switching from Internal to External Oscillator Example Program /---------------------------------------------------------------------------------------------------------// //VRS51L2070_Int_to_ext_to_Int_osc_switching_test2-SDCC.c /---------------------------------------------------------------------------------------------------------// // // DESCRIPTION: // Test switching from internal osc to the external oscillator // then back to the internal oscillator...forever // 1) The program start from the internal oscillator with // duty = 50 / 50 for 100 cycles // 2) Then it switch to external oscillator with a // duty of 50/20for 100 cycles // 3) It then switch to internal oscillator // 4) then it execute 100 cycles with a // duty of 20/50 for 100 cycles // 5) Return to step 2 //--------------------------------------------------------------------------------------------------------// #include // --- function prototypes void delay(unsigned int); //----------------------------------------------------------------# // MAIN FUNCTION // //----------------------------------------------------------------# void main (void) { int cptr ; PERIPHEN1 = 0x01; PERIPHEN2 = 0x08; P2PINCFG = 0x00; //Enable Timer 0 //Enable IOPORT //Config port 2 as output (for Tests) for(cptr =0; cptr < 100; cptr++) //toggle P2 100 times { P2 = 0xFF; delay(50); P2 = 0x00; delay(50); }; do{ //-- Enable the external oscillator DEVCLKCFG2 = 0xC0; delay(10); DEVCLKCFG1 = 0x20; delay(1); DEVCLKCFG2 = 0x83; //Enable the external oscillator, //Keep external osc active //Crystal range = 1 to 20MHz //Stabilization Time //Select External oscillator //Stabilization Time //Keep the external oscillator, //Disable internal osc active for(cptr =0; cptr < 100; cptr++) //toggle P2 100 times { P2 = 0xFF; delay(50); P2 = 0x00; delay(20); }; //-- Return to the internal oscillator DEVCLKCFG2 = 0xC0; //Keep the external oscillator enabled //Activate the internal osc //Crystal range = 1 to 20MHz ________________________________________________________________________________________________ www.ramtron.com page 19 of 99 VRS51L2070 delay(100); // Stabilization Time (way too much) DEVCLKCFG1 = 0x60; delay(1); //Select Internal oscillator // Stabilization Time DEVCLKCFG2 = 0x40; //Disable the external oscillator, //Keep internal osc active for(cptr =0; cptr < 100; cptr++) //toggle P2 100 times { P2 = 0xFF; delay(20); P2 = 0x00; delay(50); }; }while(1); }// End of main //--------------------------------------------------------------------------// //--------- INDIVIDUALS FUNCTIONS -------------// //--------------------------------------------------------------------------// //;------------------------------------------------------------------//;- DELAY1MSTO : 1MS DELAY USING TIMER0 //; CALIBRATED FOR 40MHZ //;------------------------------------------------------------------void delay(unsigned int dlais){ idata unsigned char x=0; idata unsigned int dlaisloop; x = PERIPHEN1; x |= 0x01; PERIPHEN1 = x; dlaisloop = dlais; while ( dlaisloop > 0) { TH0 = 0x63; TL0 = 0xC0; Processor Mode Control Register The VRS51L2070 provides two power saving modes: Idle and power-down, which are controlled by the PDOWN and IDLE bits of the PCON register at address 87h. TABLE 23:POWER CONTRO L REGISTER - PCON SFR 87H 7 6 5 4 3 2 1 0 R/W 0 R/W 1 R/W 1 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic Description 7 OSCSTOP 6 INTMODEN 5 DEVCFGEN 4 SFRINDADR 3 2 1 GF1 GF0 PDOWN 0 IDLE Oscillator Stop Control When this bit is set to 1, the VRS51L2070 oscillator stops. A reset pulse or a power-on reset is required to restart the device Interrupt Module Enable 0 = Interrupt module is disabled 1 = Interrupt module is enabled (default) Device Configuration Module Enable 0 = Device configuration module is disabled 1 = Device configuration module is enabled SFR Indirect Addressing Enable 0 = NOP instruction A5h behaves normally 1 = NOP instruction A5h acts as a SFR indirect addressing instruction General Purpose Flag General Purpose Flag Power-Down Mode Enable When this bit is set to 1, the processor goes into power-down mode. A reset is required to exit power-down mode Idle Mode Enable When this bit is set to 1, the processor goes into power-idle mode. A reset or an interrupt is required to exit idle mode //LOAD PERIPHEN1 REG //ENABLE TIMER 0 T0T1CLKCFG = 0x00; T0CON = 0x04; do{ x=T0CON; x= x & 0x80; }while(x==0); T0CON = 0x00; dlaisloop = dlaisloop-1; //TIMER0 RELOAD VALUE FOR 1MS AT 40MHZ //NO PRESCALER FOR TIMER 0 CLOCK //START TIMER 0, COUNT UP //Stop Timer 0 }//end of while dlais... x = PERIPHEN1; x = x & 0xFE; PERIPHEN1 = x; }//End of function delais 4.3 //LOAD PERIPHEN1 REG //DISABLEBLE TIMER 0 4.3.1 Oscillator Stop Mode The oscillator stop mode goes one step further than the PDOWN mode. When the OSCSTOP bit is set, all the oscillators are stopped, achieving maximum power saving, while maintaining the I/Os in their current state. Note that in this mode, the watchdog timer will stop functioning. In order to stop the oscillator of the VRS51L2070, clear the OSCSTOP bit of the PCON register and then immediately set it to 1, as shown below: PCON &= 0x7F PCON |= 0x80 4.3.2 SFR Indirect Addressing Capability The SFR registers on the VRS51L2070 can be accessed via indirect addressing. This is accomplished by setting the SFRINDADR bit of the PCON register. When SFRINDADR is set, the A5h instruction functions as an SFR indirect addressing instruction (the default at reset is the NOP instruction). ________________________________________________________________________________________________ www.ramtron.com page 20 of 99 VRS51L2070 4.3.3 PDOWN and IDLE Power Saving Mode In idle mode, the processor clock is stopped, however the peripherals remain active. The contents of the SRAM, the state of the I/Os and the SFR registers are maintained, as are the timer, external interrupt and UART operations. Idle mode is useful for applications in which stopping the processor to save power is required. The processor will be activated when an external event, triggering an interrupt, occurs. In power-down mode, the VRS51L2070 oscillator is stopped. While the clock to all the peripherals is deactivated, the contents of the SRAM and the SFR registers is maintained. The only way to exit powerdown mode is via a hardware reset. In power-down and idle modes the watchdog timer continues to function. VRS51L2070 Peripheral Enable 4.4 Peripherals Enable Register The VRS51L2070 peripherals can be individually activated. The PERIPHEN1 and PERIPHEN2 registers are used for this purpose. With the exception of the I/O ports, all the VRS51L2070 peripherals and communication interfaces are in the disable state upon reset. When a given peripheral is inactive, read and write operations to its SFR registers will have no effect. To activate a given peripheral, the corresponding enable bit in the PERIPHENx registers must be set to 1. The PERIPHEN1 register controls the activation of the: * * * * SPI Interface IC Interface Two UARTs Timers TABLE 24: PERIPHERAL ENABLE REGISTER 1 - PERIPHEN1 SFR F4H 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic Description 7 SPICSEN 6 SPIEN 5 I2CEN 4 U1EN 3 U0EN 2 T2EN 1 T1EN 0 T0EN Enable SPI CS Line 0 = SPI CS lines are disabled (accessible as I/O) 1 = SPI CS lines are enabled and reserved by SPI interface SPI Interface Enable 0 = SPI interface is disabled 1 = SPI interface is enabled IC Interface Enable 0 = IC interface is disabled 1 = IC interface is enabled UART1 Interface Enable 0 = UART1 interface is disabled 1 = UART1 interface is enabled UART0 Interface Enable 0 = UART0 interface is disabled 1 = UART0 interface is enabled Timer2 Enable 0 = Timer 2 interface is disabled 1 = Timer 2 Interface is enabled Timer1 Enable 0 = Timer 1 interface is disabled 1 = Timer 1 interface is enabled Timer0 Enable 0 = Timer 0 interface is disabled 1 = Timer 0 interface is enabled When the SPI interface is enabled, the SPI CS0 line is reserved for the SPI interface, independent of the state of the SPICSEN bit. UART1 has priority over the SPICSEN bit of the PERIPHEN1 register. As such, even if the SPI CS1, CS2 and CS3 lines are activated by setting the SPICSEN bit to 1, when UART1 is used, it will override CS2 and CS3. ________________________________________________________________________________________________ www.ramtron.com page 21 of 99 VRS51L2070 Additionally, when activated, the SPI interface, has priority over the Timer 2 input, even if Timer 2 is enabled. The PERIPHEN2 register controls the activation of the: * * * * * Pulse Width Counter Modules Arithmetic Unit I/O Ports Watchdog Timer FPI Interface It also activates the XRAM into code mode, in which the processor starts executing code from the 4KB block of externally mapped SRAM memory. TABLE 26:PERIPHERAL ALTERNATE PIN CONFIGURATION Peripheral T2OUT T2EX T2IN SCL SDA RXD0 TXD0 RXD1 TXD1 PWM[7:0] Default Pin P1.2 P1.1 P1.0 P3.4 P3.5 P3.0 P3.1 P1.2 P1.3 P2[7:0] Alternate Pin P4.4 P6.0 P6.1 P1.6 P1.7 P2.4 P2.3 Pin 41 Pin 40 P5[7:0] TABLE 25: PERIPHERA2 ENABLE REGISTER 2 - PERIPHEN2 SFR F5H 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 1 R/W 0 R/W 0 R/W 0 Bit Mnemonic Description 7 PWC1EN 6 PWC0EN 5 AUEN 4 XRAM2CODE Pulse Width Counter 1 Enable 0 = PWC1 is off 1 = PWC1 is on Pulse Width Counter 0 Enable 0 = PWC0 is off 1 = PWC0 is on Arithmetic Unit Enable 0 = Arithmetic unit is off 1 = Arithmetic unit is on When set to 1, the 4KB block of SRAM is mapped into the program code area from 0000h to 3FFFh. XRAM-based variable are not permitted when the processor is running from the XRAM. The XRAM2CODE bit must be set and cleared only when the program counter is outside the abovementioned address range. 3 IOPORTEN 2 WDTEN 1 PWRSFREN 0 FPIEN 4.5 I/O Port Enable 0 = I/O Ports are deactivated 1 = I/O Ports are activated Watchdog Timer Module Enable 0 = WDT is OFF 1 = WDT is ON Pulse Width Modulators SFR Enable 0 = SFR associated with PWMs are deactivated 1 = SFR associated with PWMs are activated FPI Interface Enable 0 = FPI interface is disabled 1 = FPI interface is enabled Peripheral I/O Mapping and Priority The pin locations of the following peripherals can be remapped to alternate pin positions: o o o o o Timer 2 Output IC UART0 UART1 PWMs This feature has been included to provide access to all peripherals. The following table lists the peripherals whose I/O positions are configurable: ________________________________________________________________________________________________ www.ramtron.com page 22 of 99 VRS51L2070 5 Input/Output Ports The VRS51L2070 includes 56 I/O pins grouped into seven ports. All the VRS51L2070 I/Os are 5V-tolerant, except for P4.6 and P4.7, which can endure a maximum input voltage of VDD+0.5V. 5.1 corresponding I/O pin as an input and reading the port pin value. TABLE 27:PORT 0 PIN DIRECTION CONFIGURATION REGISTER - P0PINCFG -SFR F9H 7 6 5 4 3 2 1 0 R/W 1 R/W 1 R/W 1 R/W 1 R/W 1 R/W 1 R/W 1 R/W 1 Bit Mnemonic Description 7 P07IN1OUT0 6 5 4 3 2 1 0 P06IN1OUT0 P05IN1OUT0 P04IN1OUT0 P03IN1OUT0 P02IN1OUT0 P01IN1OUT0 P00IN1OUT0 When: 1 = I/O pin acts as a input (reset value) 0 = I/O pin acts as a output Same as bit 7 Same as bit 7 Same as bit 7 Same as bit 7 Same as bit 7 Same as bit 7 Same as bit 7 Structure of the I/O Ports All I/O ports on the VRS51L2070 have the same structure. Their main difference resides in the drive capability of the I/O ports, as shown in the following diagram: FIGURE 7: GENERAL STRUCTURE OF THE VRS51L2070 I/OS W hen I/O is con figu red as In put it w ill be p ulle d up at 2 .5V instea d of 3 .3V When the external data memory bus access is activated, Port 0 functions as D7:D0 and/or address A7:A0. TABLE 28:PORT 1 PIN DIRECTION CONFIGURATION REGISTER - P1PINCFG -SFR FAH IN P U T OEN IC P in 7 6 5 4 3 2 1 0 R/W 1 R/W 1 R/W 1 R/W 1 R/W 1 R/W 1 R/W 1 R/W 1 Bit Mnemonic Description 7 P17IN1OUT0 6 5 4 3 2 1 0 P16IN1OUT0 P15IN1OUT0 P14IN1OUT0 P13IN1OUT0 P12IN1OUT0 P11IN1OUT0 P10IN1OUT0 1 = I/O pin act as a input (reset value) 0 = I/O pin act as a output Same as bit 7 Same as bit 7 Same as bit 7 Same as bit 7 Same as bit 7 Same as bit 7 Same as bit 7 OUTPUT P rovid e 5V T oltrance When the I/O ports are configured as inputs, the pin is pulled high to a voltage of about 2.50V, instead of the device voltage, which is 3.3V. An external pull-up resistor can be added to pull the I/O pin up to 3.3 volts or to 5 volts. 5.2 Direction Configuration Registers for the I/O Ports Each I/O port on the VRS51L2070 has dedicated SFR registers for read/write operations and for I/O pin direction. The pin direction configuration registers allow the user to configure the direction of each individual I/O pin. Writing a 1 to these register bit positions configures the corresponding I/O port as an input. To configure an I/O pin as an output, the corresponding bit in the pin direction configuration register must be cleared. Because the pin direction configuration registers are not located at addresses that are multiples of x0h or x8h, they are not bit-addressable. When a peripheral is activated, it takes control of the I/O pins and the I/O pin direction is configured automatically. TABLE 29:PORT 2 PIN DIRECTION CONFIGURATION REGISTER - P2PINCFG -SFR FBH 7 6 5 4 3 2 1 0 R/W 1 R/W 1 R/W 1 R/W 1 R/W 1 R/W 1 R/W 1 R/W 1 Bit Mnemonic Description 7 P27IN1OUT0 6 5 4 3 2 1 0 P26IN1OUT0 P25IN1OUT0 P24IN1OUT0 P23IN1OUT0 P22IN1OUT0 P21IN1OUT0 P20IN1OUT0 When: 1 = I/O pin acts as a input (reset value) 0 = I/O pin act as a output Same as bit 7 Same as bit 7 Same as bit 7 Same as bit 7 Same as bit 7 Same as bit 7 Same as bit 7 When the external data memory bus is activated, except when in external bus CS mode, Port 2 functions as address bus bits A15:A8. The user can monitor the activity of any peripheral module input pin current state by configuring the ________________________________________________________________________________________________ www.ramtron.com page 23 of 99 VRS51L2070 TABLE 30:PORT 3 PIN DIRECTION CONFIGURATION REGISTER - P3PINCFG -SFR FCH 7 6 5 4 3 2 1 0 R/W 1 R/W 1 R/W 1 R/W 1 R/W 1 R/W 1 R/W 1 R/W 1 Bit Mnemonic Description 7 P37IN1OUT0 6 5 4 3 2 1 0 P36IN1OUT0 P35IN1OUT0 P34IN1OUT0 P33IN1OUT0 P32IN1OUT0 P31IN1OUT0 P30IN1OUT0 When: 1 = I/O pin act as a input (reset value) 0 = I/O pin act as a output Same as bit 7 Same as bit 7 Same as bit 7 Same as bit 7 Same as bit 7 Same as bit 7 Same as bit 7 TABLE 31:PORT 4 PIN DIRECTION CONFIGURATION REGISTER - P4PINCFG -SFR FDH 7 6 5 4 3 2 1 0 R/W 1 R/W 1 R/W 1 R/W 1 R/W 1 R/W 1 R/W 1 R/W 1 Mnemonic Description 7 P47IN1OUT0 6 5 4 3 2 1 0 P46IN1OUT0 P45IN1OUT0 P44IN1OUT0 P43IN1OUT0 P42IN1OUT0 P41IN1OUT0 P40IN1OUT0 When: 1 = I/O pin acts as a input (reset value) 0 = I/O pin acts as a output Same as bit 7 Same as bit 7 Same as bit 7 Same as bit 7 Same as bit 7 Same as bit 7 Same as bit 7 I/O Ports Input Enable Register Upon reset, all the VRS51L2070 I/Os are configured as inputs and the input control logic of all ports is activated. A given I/O port's input logic can be deactivated by clearing the corresponding bit in the PORTINEN register. TABLE 34:PORTS INPUT ENABLE When the external data memory bus is activated, P3.6 and P3.7 function as WR and RD. Bit 5.3 REGISTER - PORTINEN SFR F7H 7 6 5 4 3 2 1 0 R/W 1 R/W 1 R/W 1 R/W 1 R/W 1 R/W 1 R/W 1 R/W 1 Bit Mnemonic Description 7 6 Reserved (0) P6INPUTEN 5 P5INPUTEN 4 P4INPUTEN 3 P3INPUTEN 2 P2INPUTEN 1 P1INPUTEN 0 P0INPUTEN Keep this bit at 0 Port 6 Input Enable Register 0 = Port 6 input logic is deactivated 1 = Port 6 input logic is activated Port 5 Input Enable Register 0 = Port 5 input logic is deactivated 1 = Port 5 input logic is activated Port 4 Input Enable Register 0 = Port 4 input logic is deactivated 1 = Port 4 input logic is activated Port 3 Input Enable Register 0 = Port 3 input logic is deactivated 1 = Port 3 input logic is activated Port 2 Input Enable Register 0 = Port 2 input logic is deactivated 1 = Port 2 input logic is activated Port 1 Input Enable Register 0 = Port 1 input logic is deactivated 1 = Port 1 input logic is activated Port 0 Input Enable Register 0 = Port 0 input logic is deactivated 1 = Port 0 input logic is activated TABLE 32:PORT 5 PIN DIRECTION CONFIGURATION REGISTER - P5PINCFG -SFR FEH 7 6 5 4 3 2 1 0 R/W 1 R/W 1 R/W 1 R/W 1 R/W 1 R/W 1 R/W 1 R/W 1 Bit Mnemonic Description 7 P57IN1OUT0 6 5 4 3 2 1 0 P56IN1OUT0 P55IN1OUT0 P54IN1OUT0 P53IN1OUT0 P52IN1OUT0 P51IN1OUT0 P50IN1OUT0 When: 1 = I/O pin acts as a input (reset value) 0 = I/O pin acts as a output Same as bit 7 Same as bit 7 Same as bit 7 Same as bit 7 Same as bit 7 Same as bit 7 Same as bit 7 7 6 5 4 3 2 1 0 R/W 1 R/W 1 R/W 1 R/W 1 R/W 1 R/W 1 R/W 1 R/W 1 Mnemonic Description 7 P67IN1OUT0 6 5 4 3 2 1 0 P66IN1OUT0 P65IN1OUT0 P64IN1OUT0 P63IN1OUT0 P62IN1OUT0 P61IN1OUT0 P60IN1OUT0 When: 1 = I/O pin acts as a input (reset value) 0 = I/O pin acts as a output Same as bit 7 Same as bit 7 Same as bit 7 Same as bit 7 Same as bit 7 Same as bit 7 Same as bit 7 I/O Ports SFR Registers As is the case for standard 8051 devices, the I/O ports on the VRS51L2070 are mapped into SFR registers that are bit-addressable. At reset, the I/O ports are activated and configured as inputs. TABLE 33:PORT 6 PIN DIRECTION CONFIGURATION REGISTER - P6PINCFG -SFR FFH Bit 5.4 The VRS51L2070 I/O output drivers, unlike the original standard 8051 I/O output drivers, are of the push-pull type. The VRS51L2070 I/Os have the same output drive capability whether they are driving a logic high or a logic low, versus the standard 8051s, which feature an active low driver with a pull-up resistor. From a software point of view, the difference is that whenever the configuration of a given I/O has to be changed, the corresponding bit in the port direction configuration register must be set accordingly. ________________________________________________________________________________________________ www.ramtron.com page 24 of 99 VRS51L2070 The following tables describe the SFR registers associated with the VRS51L2070 I/O ports. TABLE 35:PORT 0 REGISTER - P0 SFR 80H 7 6 5 4 3 2 1 0 R/W 1 R/W 1 R/W 1 R/W 1 R/W 1 R/W 1 R/W 1 R/W 1 Bit Mnemonic Description 7:0 P0[7 :0] Port 0 TABLE 36:PORT 1 REGISTER - P1 SFR 90H 7 6 5 4 3 2 1 0 R/W 1 R/W 1 R/W 1 R/W 1 R/W 1 R/W 1 R/W 1 R/W 1 Bit Mnemonic Description 7:0 P1[7 :0] Port 1 5.5 The current drive capability of the VRS51L2070 I/O ports is not the same for all ports. Most can drive 2mA and others can drive more in either current source or current sink and can be used for direct LED drive. The following table summarizes the VRS51L2070 I/O port drive capabilities: TABLE 42:I/O PORTS DRIVING CAPABILITY I/O Port Port 0[7:0] Port 1[7:5] Port 1[4:0] Port 2[7:0] Port 3[7:6] Port 3[5:4] Port 3[3:0] Port 4[7:0] Port 5[7:0] Port 6[7:0] TABLE 37:PORT 2 REGISTER - P2 SFR A0H 7 6 5 4 3 2 1 0 R/W 1 R/W 1 R/W 1 R/W 1 R/W 1 R/W 1 R/W 1 R/W 1 Bit Mnemonic Description 7:0 P2[7 :0] Port 2 TABLE 38:PORT 3 REGISTER - P0 SFR B0H 7 6 5 4 3 2 1 0 R/W 1 R/W 1 R/W 1 R/W 1 R/W 1 R/W 1 R/W 1 R/W 1 Bit Mnemonic Description 7:0 P3[7 :0] Port 3 TABLE 39:PORT 4 REGISTER - P4 SFR C0H 7 6 5 4 3 2 1 0 R/W 1 R/W 1 R/W 1 R/W 1 R/W 1 R/W 1 R/W 1 R/W 1 Bit Mnemonic Description 7:0 P4[7 :0] Port 4 TABLE 40:PORT 5 REGISTER - P5 SFR 98H (VRS51L2070-64PIN ONLY) 7 6 5 4 3 2 1 0 R/W 1 R/W 1 R/W 1 R/W 1 R/W 1 R/W 1 R/W 1 R/W 1 Bit Mnemonic Description 7:0 P5[7 :0] Port 5 TABLE 41:PORT 6 REGISTER - P6 SFR C8H (VRS51L2070-64PIN ONLY) 7 6 5 4 3 2 1 0 R/W 1 R/W 1 R/W 1 R/W 1 R/W 1 R/W 1 R/W 1 R/W 1 Bit Mnemonic Description 7:0 P6[7 :0] Port 5 I/O Port Drive Capability Max Current on Individual Pin 2mA 4mA 2mA 8mA 2mA 4mA 2mA 2mA 16mA 2mA It is not recommended to exceed the sink current specified in the table above. Doing so will likely cause the low-level output voltage to exceed device specifications and affect device reliability. For the current revision of the VRS51L2070, the total DC load on the I/O ports should not exceed 100mA. 5.6 Port Software Specifics Some instructions allow the user to read the logic state of the output pin, while others allow the user to read the contents of the associated port register. These instructions are called read-modify-write instructions. A list of these instructions may be found in the following table. Upon executing these instructions, the content of the port register (at least 1 bit) is modified. The other read instructions take the present state of the input into account. For example, instruction ANL P3,#01h obtains the value in the P3 register; performs the desired logic operation with the constant 01h and recopies the result into the P3 register. In order to monitor the present state of the inputs of an I/O port bit, first, read the port, and second, perform an AND or an OR operation, as required by the program: MOV A, P3; State of the inputs in the accumulator ANL A, #01; AND operation between P3 and 01h ________________________________________________________________________________________________ www.ramtron.com page 25 of 99 VRS51L2070 When the port is used as an output, the register contains information on the state of the output pins. Measuring the state of an output directly on the pin is inaccurate because the voltage level depends mostly on the type of charge that is applied to it. The functions below perform the operation on the value of the port register rather than the actual port pin itself. TABLE 43: LIST OF INSTRUCTIONS THAT READ AND MODIFY THE PORT USING REGISTER VALUES Instruction ANL ORL XRL JBC CPL INC DEC DJNZ MOV P.,C CLR* P.x SETB P.x Function Logical AND ex: ANL P0, A Logical OR ex: ORL P2, #01110000B Exclusive OR ex: XRL P1, A Jump if the bit of the port is set to 0 Complement 1 bit of the port Increment the port register by 1 Decrement the port register by 1 Decrement by 1 and jump if the result is not equal to 0 Copy the held bit C to the port Set the port bit to 0 Set the port bit to 1 *Note: Even though the CPU does not read in this case, it is considered a read-modify-write instruction. In MOV dir, dir has an extra cycle when doing an SFR read during a debugger interrupt. The debugger memory is synchronous and is mapped into the SFR bus and, therefore, requires an extra read cycle. Instruction A5, which is considered an NOP in a standard 8051, has been redefined to perform write and read SFR indirect addressing. Therefore, during a debugger interrupt, the A5 indirect read SFR addressing requires an extra cycle. 5.7 Port Operation Timing 5.7.1 5.7.2 5.8 Writing to a Port (Output) Reading a Port (Input) I/O Port Example Programs 5.8.1 I/O Ports Toggle Example This program shows the activation and configuration of ports P0 to P4 as outputs. The program continuously toggles their values. ;************************************************* ;* VRS51L2070 I/O Ports Toggle Example * ;************************************************* START: MOV PERIPHEN2,#08H ;ENABLE IO MOV MOV MOV MOV MOV P0PINCFG,#00H P1PINCFG,#00H P2PINCFG,#00H P3PINCFG,#00H P4PINCFG,#00H ;CONFIGURE P0 AS OUTPUT ;CONFIGURE P1 AS OUTPUT ;CONFIGURE P2 AS OUTPUT ;CONFIGURE P3 AS OUTPUT ;CONFIGURE P4 AS OUTPUT MOV PERIPHEN2,#00001000B ;BIT7 - PWC1EN ;BIT6 - PWC0EN ;BIT5 - AUEN ;BIT4 - XRAM2CODE ;BIT3 - IOPORTEN ;BIT2 - WDTEN ;BIT1 - PWMSFREN ;BIT0 - FPIEN // I/O Output Toggle Loop LOOP: MOV MOV MOV MOV MOV P0,#00H P1,#00H P2,#00H P3,#00H P4,#00H ;FORCE P0 = 00H ;FORCE P1 = 00H ;FORCE P2 = 00H ;FORCE P3 = 00H ;FORCE P4 = 00H MOV A,#100 ;Wait 100ms using Timer 0 ACALL DELAY1MST0 ;See Timer section MOV P0,#0FFH MOV P1,#0FFH MOV P2,#0FFH MOV P3,#0FFH MOV P4,#0FFH MOV A,#100 ACALL DELAY1MST0 LJMP ;FORCE P0 = FFH ;FORCE P1 = FFH ;FORCE P2 = FFH ;FORCE P3 = FFH ;FORC E P4 = FFH ;Wait 100ms using Timer0 ;See Timer Section LOOP The DELAY1MS function is described in the timers section. ________________________________________________________________________________________________ www.ramtron.com page 26 of 99 VRS51L2070 5.8.2 I/O Port Read Example ;************************************************************** ;* VRS51L2070 I/O Ports Read and Write Example * ;*************************************************************** PORTREAD EQU 021H START: MOV PERIPHEN2,#08H ;ENABLE IO P0PINCFG,#00H P1PINCFG,#00H ;CONFIGURE P0 AS iNTPUT ;CONFIGURE P2 AS OUTPUT MOV MOV ;GENREAL VARIABLE ; Note that the port Input logic is activated by default MOV PERIPHEN2,#00001000B ;BIT7 - PWC1EN ;BIT6 - PWC0EN ;BIT5 - AUEN ;BIT4 - XRAM2CODE ;BIT3 - IOPORTEN ;BIT2 - WDTEN ;BIT1 - PWMSFREN ;BIT0 - FPIEN LOOP: PORTREAD, P0 P2, PORTREAD Port Pin Change Monitoring The VRS51L2070 includes an I/O port pin change monitoring subsystem. This module is used to monitor the activity on the selected I/O ports. When enabled, if a pin state changes on the selected I/O port, the PMONFLAG will be set to 1 by the system. It must be cleared manually by the software. The port pin change monitoring feature is very useful for monitoring events that can occur on a given group of I/Os without having to constantly read the I/O state. Since it is connected to the VRS51L2070 interrupt subsystem, the port pin change monitoring system frees the processor resources for other tasks. TABLE 44:PORT CHANGE MONITORING REGISTER - PORTCHG SFR B9H ;*** Read Port 0 and copy the value to P2 MOV MOV 5.9 ;Read Prt 0 and store the value in a Variable ;Write the Variable content to P2 AJMP LOOP In this example, the Port P0 value is stored in a variable before writing it to P2, but the user can also directly transfer P0 to P2 in one operation: 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic Description 7 PMONFLAG1 6 PCHGMSK1 5:4 PCHGSEL1[1:0] 3 PMONFLAG0 1 PCHGMSK0 1:0 PCHGSEL0[1:0] Port Change Monitoring Flag1 When set, monitored port state has changed Port Change Mask Register 1 0 = Port monitoring is deactivated 1 = Port monitoring is activated Port Change Monitoring Register Select 1 00 = P4 Change is monitored 01 = P5 Change is monitored 10 = P6 Change is monitored 11 = P4[3:0] Change is monitored Port Change Monitoring Flag 0 When set, monitored port state has changed Port Change Mask Register 0 0 = Port monitoring is deactivated 1 = Port monitoring is activated Port Change Monitoring Register Select 0 00 = P0 Change is monitored 01 = P1 Change is monitored 10 = P2 Change is monitored 11 = P3 Change is monitored LOOP: MOV P2,P0 AJMP LOOP ;would do the same operation more efficiently The port pin change monitoring flags, PMONFLAGx, are active at all times, even if the port change masks are not activated. The PCHGMSKx bits serve to connect the port change module to the VRS51L2070 interrupt system. The port change monitoring flags must be cleared manually. ________________________________________________________________________________________________ www.ramtron.com page 27 of 99 VRS51L2070 5.10 Port Pin Change Interrupt Example Programs 5.10.1 Numeric Keypad Interface //--------------------------------------------------------------------------------------------------------------------// // VRS51L2070_KeypadP0_LCDP1.c // //--------------------------------------------------------------------------------------------------------------------// // // DESCRIPTION: Character LCD and Numeric Keypad Interface Example Program. // // This program initialize and sends LCD strings and numeric values // to a character based LCD display. // The program also demonstrate the use of the Port Change interrupt // Feature of the VRS51L2070 to simplify the interface with a numeric Keypad // on Port 0. // The numeric keypad is a standard phone keypad which to connected to Port 0 // as shown below: // Column 3 - P0.7 // Column 2 - P0.6 // Column 1 - P0.5 // Row 4 - P0.3 // Row 3 - P0.2 // Row 2 - P0.1 // Row 1 - P0.0 // // No external pull-up / pull down resistors are required, thank to the // presence of internal pull-up on the VRS51L2070 I/O ports. // // The interface to the LCD done through the VRS51L2070 Port 1. // The LCD is initialized to operate in 4 bit data Bus Mode // // LCD interface structure: // ======================== // P1.0 = LCD RS // P1.1 = LCD RW // P1.2 = LCD E // P1.3 = (not used) // P1[7:4] = LCD Data (4 bit mode) // // Notes about standard Character LCD display interface to the VRS51L2070 // -Most LCD displays operates on a 4.5V to 5.5V Supply. // They won't work with the 3.3V supply the VRS51L2070 operate from // -On the digital side make sure the LCD module logic High level lower limit // is below 3V. // -The VRS51L2070 I/Os are 5V tolerant, so there is no need to add interface // circuit between the LCD module's I/O and the VRS51L2070 I/O // // // //--------------------------------------------------------------------------------------------------------------------// // TARGET: VRS51L2070 //--------------------------------------------------------------------------------------------------------------------// // // Rev 1.0 // Date: June 2005 //--------------------------------------------------------------------------------------------------------------------// #include bit at 0x90 LCD_RS; bit at 0x91 LCD_RW; // Global variables definitions idata unsigned char cptr = 0x00; // LCD Strings and constants definitions code char msg1[]= "VRS51L2070 \0"; code char msg2[]= "Waiting for Key.\0"; code char msgkey[]= "Last key: \0"; code char LCD_L1C1 = 0x80; code char LCD_L2C1 = 0xC0; code char LCD_L2C10 = 0xC9; code char LCD_CLEAR = 0x01; //Command LCD set CGRAM addr to Line1,column 1 //Command LCD set CGRAM addr to Line2,column 1 //Command LCD set CGRAM addr to Line2,column 10 //Command LCD Clear and return cursor home //--------------------------------------------------------------------------------------------------------------------// // MAIN FUNCTION //--------------------------------------------------------------------------------------------------------------------// void main (void) { PERIPHEN1 = 0x01; LCDPORTDIR = 0x00; //Enable Timer 0 //Config LCD port as output //--Configure Keypad Port and port Change monitor KEYPADPORTDIR = 0x0F; //KeypadPort bit 3:0 -> configured as Input (Lines) //KeypadPort bit 7:5->Configured as output (Columns) KEYPADPORT = 0x0F; //Clear the Columns driver outputs V2KDelay1ms(100); //Put a 100 milliseconds delay PORTCHG = 0x04; //Disable Port Change monitoring Module 1 //Enable Port Change monitoring Module 0 //Clear the Port Change monitoring Flag //Port 0 Change is monitored //-- Activate port change interrupt INTSRC1 &= 0xEF; INTEN1 |= 0x10; GENINTEN = 0x01; //Force Interrupt vector 4 to be routed to Port Change //module 0 //Enable the PORT CHANGE 0 Module Interrupt //Activate the Global Interrupts //--Initialize the LCD initlcd(); sendlcdcmd(LCD_L1C1); //Initialise the LCD Module //Place LCD cursor on Line 1, Column 1 cptr = 0; while( msg1[cptr] != '\0') sendlcdchar( msg1[cptr++]); //Display "VRS51L2070" on first line of LCD display sendlcdcmd(LCD_L2C1); //Place LCD cursor on Line 2, Column 1 cptr = 0; while( msg2[cptr] != '\0') sendlcdchar( msg2[cptr++]); V2KDelay1ms(1000); //Display "Waiting for Key.\0" on 2 line of LCD display //Put a 1 seconds delay //--Loop Waiting for Keys to be pressed while(1); //Infinite Loop }// End of main //----------------------------------------------------------------------------------------// //----------------------Port Change Interrupt Function(s)---------------------// //----------------------------------------------------------------------------------------// void PortChange0Int(void) interrupt 4 { unsigned char keypressed = 0x00; //var holding ASCII value of the last key //pressed (could be global) unsigned char keylines = 0x00; //variable to read the actual I/O port unsigned char keyrow = 0x00; //Row position of the pressed key unsigned char keycol = 0x00; //Column position of the pressed key //--LCD I/O definition #define LCDPORT P1 #define LCDPORTDIR P1PINCFG //--Keypad I/O definition #define KEYPADPORT P0 #define KEYPADPORTDIR P0PINCFG //---Keypad Function prototypes char KeyDecode(); void KeyDisplay(char); // rows and columns association table const char code keyrowmap[] = {0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x03,0x0F,0x0F,0x0F,0x02,0x0F,0x01,0x00,0x0F}; const char code keycolmap[]={0x0F,0x0F,0x0F,0x02,0x0F,0x01,0x00,0x0F}; //---LCD Function prototypes void lcdbusy(void); void initlcd(void); void LCDSlow(void); void int2lcd(unsigned int); void lcdstring( char code *); void sendlcdchar( char); void sendlcdcmd( unsigned char); //LCD Busy check //LCD Initialisation function //Slow Down communication with LCD display //Integer to LCD display function //String to LCD display function //Char to LCD Display function //Send LCD Command Function //---Generic Functions prototype void V2KDelay1ms(unsigned int); //Standard Delay function GENINTEN = 0x00; //LCD E Line //--Retrieve the line number KEYPADPORT = 0x00; // LCD bit variables bit at 0x92 LCD_E; //LCD RS //LCD RW // Ascii code associated with pressed key const char code keyascii[4][3] = { {'1','2','3'}, {'4','5','6'}, {'7','8','9'}, {'*','0','#'}}; //Disable the Global Interrupts //Send 0 on each column ________________________________________________________________________________________________ www.ramtron.com page 28 of 99 VRS51L2070 V2KDelay1ms(10); keylines = KEYPADPORT; keylines &=0x0F; //Put a 10 millisecond delay //Read Keypad Port //Isolate lower nibble The VRS51L2070 includes three 16-bit timers: Timer 0, Timer 1 and Timer 2. The VRS51L2070 timers include more functionality and features than standard 8051 timers: if(keylines != 0x0F) { //-retrieve the line value keyrow = keyrowmap[keylines]; //--Retrieve Column number KEYPADPORTDIR = 0xF0; KEYPADPORT = 0x00; //columns are input / rows are output //Send 0 on each row V2KDelay1ms(10); keylines = KEYPADPORT; B = keylines; //Put a 10 millisecond delay //Read Keypad Port keylines &=0xE0; keylines = (keylines >> 5); //-retrieve the line value keycol = keycolmap[keylines]; //Isolate upper 3 bit (columns) //Position columns to lower portion if((keyrow != 0x0F)&& (keycol != 0xFF)) { //--Get the ascii value of the key keypressed = keyascii[keyrow][keycol]; sendlcdcmd(LCD_L2C1); /Place LCD cursor on Line 2, Column 1 cptr = 0; while( msgkey[cptr] != '\0') //Display "Last key: \0" sendlcdchar( msgkey[cptr++]) //on second line of LCD display //Display the key value on the LCD display sendlcdcmd(LCD_L2C10); //Place LCD cursor on Line 2, Column 10 sendlcdchar(keypressed); }//end of if key row / col //--wait for the key to be released do{ B= KEYPADPORT; B &= 0xE0; }while(B != 0xE0 ); //--Set KEYPADPORT as before KEYPADPORTDIR = 0x0F; //Columns are input / rows are output KEYPADPORT = 0x0F; //Clear the Columns driver outputs V2KDelay1ms(10); }//end of if keylines != 0xFF 6 VRS51L2070 Timers o o o o o o o Timers 0, 1 can operate as one 16-bit timer or two 8-bit timers Timers can count up/count down Each timer includes a configurable divisor Timers can be chained together to form 24-, 32- or 48-bit timer/counters Each timer features an output that can generate a pulse or toggle when the timer overflows Each timer provides counter input Each timer provides a gating pin VRS51L2070 timers include a number of parameters that can be adjusted independently, enabling countless configurations to suit a diversity of timing/counting applications. The structure of the timer configuration registers has been simplified compared to standard 8051 timer control registers. The architecture of the registers controlling the VRS51L2070's three timers is the same for Timer 0 and Timer 1 and almost the same for Timer 2. // Put a 10 millisecond delay 6.1 PORTCHG = 0x04; //Disable Port Change monitoring Module 1 //Enable Port Change monitoring Module 0 //Clear the Port Change monitoring Flag //Port 0 Change is monitored GENINTEN = 0x01; //Activate the Global Interrupts }//End of Port Change Interrupt //--------------------------------------------------------------------------------------------------------------------// // INDIVIDUALS FUNCTIONS //--------------------------------------------------------------------------------------------------------------------// Timer 0, Timer 1 Configuration Timer 0 and Timer 1 operation is controlled by three registers. The configuration of timers 0/1 is essentially the same. 6.1.1 T0T1CFG Register Overview The T0T1CFG register controls the gating features of both Timer 1 and Timer 0. The TxGATE bit controls the clock gating of the timers. When this bit is set to 1, the timer will only count when the INTx pin is high. (See demonstration programs... ) ________________________________________________________________________________________________ www.ramtron.com page 29 of 99 VRS51L2070 TABLE 45: TIMER 0 / TIMER1 CONFIGURATION REGISTER - T0T1CFG SFR 89H 7 6 5 4 3 2 1 0 R 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic Description 7 6 T1GATE Not used Timer 1 Gating Enable 0 = Timer 1 gating feature is disabled 1 = Timer 1 count only when INT1 pin is high Timer 0 Gating Enable 0 = Timer 0 gating feature is disabled 1 = Timer 0 count only when INT0 pin is high Timer 1 Clock Source 0 = Timer 1 takes its clock from system clock 1 = Timer 1 takes its clock from Timer 0 output Timer 1 Output Enable 0 = Timer 1 output is deactivated 1 = Timer 1 output is connected to a pin Timer 1 8-bit Operating Mode Enable 0 = Timer 1 operates as a 16-bit timer 1 = Timer 1 operates as two 8-bit timers Timer 0 Output Enable 0 = Timer 0 output is deactivated 1 = Timer 0 output is connected to a pin Timer 1 8-bit Operating Mode Enable 0 = Timer 1 operates as a 16-bit timer 1 = Timer 1 operates as two 8-bit timers 5 T0GATE 4 T1CLKSRC 3 T1OUTEN 2 T1MODE8 1 T0OUTEN 0 T0MODE8 The T1CLKSRC bit defines which clock source will feed Timer 1 when it is configured to operate in timer mode. The Timer 1 clock source is defined as follows: o o T1CLKSRC = 0 System Clock T1CLKSRC = 1 Timer 0 Output (overflow) When configured in timer mode, Timer 0 can only derive its clock source from the system clock with the proper prescaler value. Both timers 1 and 0 can operate as two general purpose 8-bit timers. This mode is activated by setting the corresponding TxMODE8 bit of the T0T1CFG register to 1. 6.1.2 The T0CON and T1CON Registers The T0CON and T1CON SFR registers control the following: o o o o o o Timer operation mode (timer or counter) Advanced gating features of Timer 0 and Timer 1 Timer overflow flag Counting direction (up/down) Timer reload and capture Timer output mode (Pulse/Toggle) These registers are fully orthogonal, which means that for a given timer operating mode, the registers function in the same manner. TABLE 48:TIMER 0 CONFIGURATION REGISTER - T0CON SFR 9AH 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic Description 7 T0OVF 6 T0EXF 5 T0DOWNEN 4 T0TOGOUT 3 T0EXTEN 2 TR0 1 T0COUNTEN 0 T0RLCAP Timer 0 Overflow Flag Set to 1 when timer overflow from FFFFh to 0000h. Must be cleared by software. Writing 1 into this bit will trigger a timer interrupt, if enabled Timer 0 External Flag Gating Flag Set to 1 when timer reload of capture is caused by an high to low transition on the T0EX pin, if T0EXEN is set to 1 Timer 0 Count Down Enable 0 = Timer 0 count up 1 = Timer 0 counts down Timer 0 Output Toggle Enable 0 = Timer 0 output outputs a pulse when it overflow from FFFFh to 0000h 1 = Timer 0 output toggle when it overflow from FFFFh to 0000h Timer 0 External Gating Enable 0 = T0EX pin is not active 1 = Enable Timer 0 capture or reload upon a high to low transition on the T0EX pin Timer 0 Run 0 = Timer 0 is stopped 1 = Timer 0 is running Timer 0 Counter Enable 0 = Timer 0 acts as a timer 1 = Timer 0 acts as a counter that is incremented (decremented) by a high to low transition on T0IN pin Timer 0 Capture Enable 0 = Auto reload value is loaded in Timer 0, if a high to low transition occurs on T0EX, if T0EXTEN is set to 1 1 = Timer 0 current value is captured when a high to low transition occurs on the T0EX pin, if T0EXTEN is set to 1 TABLE 46:TIMER0 / TIMER 1 CLOCK CONFIG. REGISTER - T0T1CLKCFG SFR 99H 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic Description 7:4 T1CLKCFG[3:0] Timer 1 Clock Prescaler Configuration see table below 3:0 T0CLKCFG[3:0 Timer 0 Clock Prescaler Configuration see table below TABLE 47:TIMER0 / TIMER 1 CLOCK DIVISION RATIO T0/1CLKCFG (4 bit binary) 0000 0001 0010 0011 0100 0101 0110 0111 Timer Clock Div. Ratio 1 2 4 8 16 32 64 128 T0/1CLKCFG 1000 1001 1010 1011 1100 1101 1110 1111 Timer Clock Div. Ratio 256 512 1024 2048 4096 8192 16384 16384 ________________________________________________________________________________________________ www.ramtron.com page 30 of 99 VRS51L2070 TABLE 49:TIMER 1 CONFIGURATION REGISTER - T1CON SFR 9BH 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic Description 7 T1OVF Timer 1 Overflow Flag Get set to 1 when timer overflow from FFFFh to 0000h. Must be cleared by software. Writing 1 into this bit will trigger a timer interrupt, if enabled Timer 1 External Flag Gating Flag Get set to 1 when timer reload of capture is caused by an high to low transition on the T1EX pin, if T1EXEN is set to 1 Timer 1 Count Down Enable 0 = timer 1 count up 1 = Timer 1 counts down Timer 1 Output Toggle Enable 0 = Timer 1 output outputs a pulse when it overflow from FFFFh to 0000h 1 = Timer 1 output toggle when it overflow from FFFFh to 0000h Timer 1 External Gating Enable 0 = T1EX pin is not active 1 = Enable Timer 1 capture or reload upon a high to low transition on the T1EX pin Timer1 Run 0 = Timer 1 is stopped 1 = Timer 1 is running Timer 1 Counter Enable 0 = Timer 1 acts as a timer 1 = Timer 1 acts as a counter that is incremented (decremented) by a high to low transition on T1IN pin Timer 1 Capture Enable 0 = Auto reload value is loaded in Timer 1, if a high to low transition occurs on T1EX, if T1EXTEN is set to 1 1 = Timer 1 current value is captured when a high to low transition occurs on the T1EX pin, if T1EXTEN is set to 1. 6 T1EXF 5 T1DOWNEN 4 T1TOGOUT 3 T1EXTEN 2 TR1 1 T1COUNTEN 0 T1RLCAP The TxOVF bit of the TxCON register indicates that the timer count has rolled over from FFFFh to 0000h. If the corresponding timer interrupt has been enabled, the TxOVF will raise the interrupt. The TxEXF flags are set to 1 when a high to low transition occurs on the corresponding TxEX pin, provided that the TxEXEN pin is set to 1. Timer 0 and Timer 1 can count up or down. By default, the timers count up. However setting the TxDOWNEN bit to 1 will make the timer count down . The TxRLCAP bit defines the function of the timer capture/reload register upon a high to low transition on the TxEX timer trigger input pin. o o TxRLCAP = 0 : Auto reload value is loaded in Timer x TxRLCAP = 1 : Timer x current value will be captured The functions associated with the TxRLCAP bit are only activated when the corresponding TxEXTEN bit is set to 1. 6.2 Timer 0 and Timer 1 Current Value Register Two SFR registers provide access to the current 16-bit value of Timer 0 and Timer 1. TABLE 50:TIMER 0 LOW - TL0 SFR 8AH 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic 7:0 TL0[7:0] Description TABLE 51:TIMER 0 HIGH - TH0 SFR 8BH 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic 7:0 TH0[7:0] Description TABLE 52:TIMER 1 LOW - TL1 SFR 8CH 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic 7:0 TL1[7:0] Description TABLE 53:TIMER 1 HIGH - TH0 SFR 8DH 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic 7:0 TH0[7:0] Description The TxCOUNTEN bit allows the timer to be configured as an external event counter. By default, the timers derive their source from the system clock or a prescaled source. Setting the TxCOUNTEN bit to 1, will configure the corresponding timer to derive its source from the timer input pin (TxIN). A high to low transition on the timer input pin will make the timer count one step up or one step down, depending on the value of the corresponding TxDOWNEN bit. ________________________________________________________________________________________________ www.ramtron.com page 31 of 99 VRS51L2070 6.2.1 Timer 0 Reload and Capture Registers Both Timer 0 and Timer 1 have an auxiliary 16-bit reload/capture register, which is accessible through two SFR registers as follows: FIGURE 8: TIMER 0, TIMER 1 OUTPUT MODES Timer 0/1 OverFlow TABLE 54:TIMER 0 RELOAD AND CAPTURE LOW - RCAP0L SFR 92H 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic 7:0 RCAP0L[7:0] TxOUTEN = 1 TxTOGOUT = 1 Description TxOUTEN = 1 TxTOGOUT = 0 TABLE 55:TIMER 0 RELOAD AND CAPTURE HIGH - RCAP0H SFR 93H 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic 7:0 RCAP0H[7:0] 6.3 Description TABLE 56:TIMER 1 RELOAD AND CAPTURE LOW - RCAP1L SFR 94H 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Timer 0/1 Alternate Mapping Bits 0 and 1 of the DEVIOMAP register (SFR E1h) control the mapping of the Timer 0 and Timer 1 peripherals as shown in the following tables. TABLE 58: TIMER 0 PIN MAPPING Bit Mnemonic 7:0 RCAP1L[7:0] Description TABLE 57:TIMER 1 RELOAD AND CAPTURE HIGH - RCAP1H SFR 95H 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic 7:0 RCAP1H[7:0] 6.2.2 Description Timer 0/1 Output DEVIOMAP.0 Bit Value 0 (Reset) 1 T0IN mapping P3.4 - T0EX mapping P2.6 Pin 41 T0OUT mapping P4.5 - TABLE 59: TIMER 1 PIN MAPPING DEVIOMAP.1 Bit Value 0 (Reset) 1 T1IN mapping P3.5 - T1EX mapping P2.5 T1OUT mapping P4.0 Pin 40 P1.4 Timer 0 and Timer 1 outputs can be routed to an external pin. This feature is activated by setting the TxOUTEN bit of the TxCLKCFG register to 1. By default, the timer outputs, when enabled, will generate a pulse upon timer overflow. The duration of the pulse equals 1/ SYS CLK. Setting the TxTOGOUT bit of the TxCON register to 1 will configure the timer x output to toggle upon a timer overflow instead of generating a pulse. ________________________________________________________________________________________________ www.ramtron.com page 32 of 99 VRS51L2070 6.4 Timer 0, Timer 1 Functional Diagram The following diagram represents the main features of timers 0 and 1 FIGURE 9: TIMER 0, TIMER 1 FUNCTIONAL DIAGRAM TxCLKSRC SYSCL K 0 1 T(x-1)Out TxCLKCFG Div Ratio: Sys Clk / 1 Downto Sys Clk / 16384 TxDOWNEN TxMODE8 TxCOUNTEN DOWN / UP 1 TLx 0 IF x = 1 or 2 7 0 DOWN / UP 8 THx 15 TxTOGOUT CLK 0 Pulse 0 Toggle 1 TxOUT pin 1 TxIN pin TOUTEN RCAPxH RCAPxL TRx 0 0 7 7 TxOVF interrupt TxGATE INTx pin TxRLCAP 0 TxEX pin 1 Reloa d Capture Reload Capture TxEXEN ________________________________________________________________________________________________ www.ramtron.com page 33 of 99 VRS51L2070 6.5 6.5.3 Timer 0, Timer1 Examples Programs 6.5.1 Timer 0 1ms Delay Function ;******************************************************** ;* DELAY1MSTO : 1MS DELAY USING TIMER0 ;*; *CALIBRATED FOR 40MHZ ;********************************************************** DELAY1MST0: MOV CPTR,A ;GET NUMBER OF CYCLES MOV A,PERIPHEN1 ;LOAD PERIPHEN1 REG ORL A,#00000001B ;ENABLE TIMER 0 MOV PERIPHEN1,A DELAY1MSLP: MOV MOV ;MOV ;MOV DWAITOVT0: 6.5.2 TH0,#063H TL0,#0C0H TH0,#0A9H TL0,#058H T0T1CLKCFG,#00H T0CON,#00000100B MOV A,T0CON ANL JZ A,#080H DWAITOVT0 MOV DJNZ T0CON,#00H ;STOP TIMER 0 CPTR,DELAY1MSLP ;Out Loop MOV ANL MOV RET A,PERIPHEN1 A,#11111110B PERIPHEN1,A ;NO PRESCALER FOR T0 CLOCK ;START T0, COUNT UP INIT: MOV PERIPHEN1,#00000111B ;BIT7 - SPICS EN ;BIT6 - SPIEN ;BIT5 - I2CEN ;BIT4 - U1EN ;BIT3 - U0EN ;BIT2 - T2EN ;BIT1 - T1EN ;BIT0 - T0EN MOV PERIPHEN2,#00001000B ;BIT7 - PWC1EN ;BIT6 - PWC0EN ;BIT5 - AUEN ;BIT4 - XRAM2CODE ;BIT3 - IOPORTEN ;BIT2 - WDTEN ;BIT1 - PWMSFREN ;BIT0 - FPIEN ;READ T0 CONTROL, WAIT FOR ;OVERFLOW ;ISOLATE TIMER OVERFLOW FLAG ;LOOP AS LONG AS T0 DON'T OVERFLOW ;LOAD PERIPHEN1 REG ;DISABLEBLE TIMER 0 Timer 0, Timer 1 and Timer 2 Output Toggle Example PERIPHEN2,#00001000B Include ;T0 RELOAD VALUE FOR 1MS AT 22.11MHZ ;******************************************************************************* ;- TIMER 0, TIMER 1 AND TMER 2, OUTPUT TOGGLE EXAMPLE * ;******************************************************************************* Include MOV ;******************************************************************************************************** ;- TIMER 0, TIMER 1 AND TMER 2, OUTPUT TOGGLE + TIMER CHAINING EXAMPLE * ;******************************************************************************************************** ;T0 RELOAD VALUE FOR 1MS AT 40MHZ MOV MOV ;-- Enable Timer 0, Timer 1 and Timer 2 INIT: MOV PERIPHEN1,#00000111B Timer 0, Timer 1 and Timer 2 Output Toggle and Timer Chaining Example ;-- SET THE SYSTEM CLOCK PRESCALER TO MAX SPEED MOV DEVCLKCFG1,#60H ;SET DEVICE PRESCALER SPEED ;** CONFIGURE AND START TIMER 0, TIMER 1 & TIMER 2 MOV T0CON,#14H ;START TIMER0, TOGGLE OUTPUT MOV T1CON,#14H ;START TIMER1, TIMER1 TOGGLE ;OUTPUT MOV T2CON,#14H ;START TIMER2, TIMER2 TOGGLE ;OUTPUT MOV T0T1CFG,#00001000B ;CONNECT TIMER1 OUTPUT T0 P4.0 MOV T2CLKCFG,#00110000B ;TIMER 2 USES TIMER1 OUTPUT AS ;CLOCK SOURCE, T2 OUT ON P1.2, ;CLOCK PRESCALER = 1 LOOP: AJMP LOOP ;INFINITE LOOP ;BIT7 - SPICS EN ;BIT6 - SPIEN ;BIT5 - I2CEN ;BIT4 - U1EN ;BIT3 - U0EN ;BIT2 - T2EN ;BIT1 - T1EN ;BIT0 - T0EN ;BIT7 - PWC1EN ;BIT6 - PWC0EN ;BIT5 - AUEN ;BIT4 - XRAM2CODE ;BIT3 - IOPORTEN ;BIT2 - WDTEN ;BIT1 - PWMSFREN ;BIT0 - FPIEN ;-- SET THE SYSTEM CLOCK PRESCALER TO MAX SPEED MOV DEVCLKCFG1,#60H ;SET DEVICE PRESCALER SPEED ;** CONFIGURE AND START TIMER 0, TIMER 1 & TIMER 2 MOV T0T1CFG,#00001010B MOV T2CLKCFG,#00010110B MOV MOV MOV T0CON,#14H T1CON,#14H T2CON,#14H LOOP: AJMP LOOP ;CONNECT TIMER0 OUTPUT T0 P4.5 and ;TIMER1 OUTPUT T0 P4.0, TIMER SOURCE ;FROM SYS CLK ;T2 SSOURCE = SYS CLK, T2OUT ;ENABLED ON P1.2, PRESCALER = SYS ;CLK/64 ;START TIMER0, TOGGLE OUTPUT ;START TIMER1, TOGGLE OUTPUT ;START TIMER2, TOGGLE OUTPUT ;INFINITE LOOP ________________________________________________________________________________________________ www.ramtron.com page 34 of 99 VRS51L2070 6.6 Timer 2 The architecture of Timer 2 is very similar to that of timers 0 and 1, the main difference being that Timer 2 cannot operate as two 8-bit timers. 6.6.1 The T2OVF bit of the T2CON register indicates whether the timer count has rolled over from FFFFh to 0000h. If the corresponding timer interrupt has been activated, the T2OVF will raise the Timer 2 interrupt.. The T2EXF flags are set to 1 when a high to low transition occurs on the T2EX pin, provided that the T2EXE pin is set to 1. Timer 2 Configuration Registers The T2CON register controls: Timer operation mode (timer or counter) Timer 2 advanced gating features Timer 2 overflow flag Timer 2 counting direction (up/down) Timer 2 reload and capture Timer 2 output mode (pulse/toggle) As is the case for timers 0 and 1, Timer 2 can be configured to count up or down. By default, Timer 2 counts up. However setting the T2DOWNEN bit to 1 will configure Timer 2 to count down. When the timer counts downwards, the overflow flag will be set when the timer counts from 0000h to FFFFh. The T2CON register has the same structure as the T0CON and T1CON registers. The T2COUNTEN bit- enables the configuration of Timer 2 as a external event counter. By default, Timer 2 derives its source from the system clock or a prescaled system clock. Setting the T2COUNTEN bit to 1 will configure Timer 2 to derive its source from the T2IN input pin. A high to low transition on the T2IN pin will initiate a timer count one step up or down, depending on the value of the corresponding T2DOWNEN bit. o o o o o o TABLE 60:TIMER 2 CONFIGURATION REGISTER - T2CON SFR 9CH 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic Description 7 T2OVF 6 T2EXF 5 T2DOWNEN 4 T2TOGOUT 3 T2EXTEN 2 TR2 Timer 2 Overflow Flag Set to 1 when timer overflows from FFFFh to 0000h. Must be cleared by software. Writing 1 into this bit will trigger a timer interrupt, if enabled Timer 2 External Flag Gating Flag Set to 1 when timer reload of capture is caused by an high to low transition on the T2EX pin, if T2EXEN is set to 1 Timer 2 Count Down Enable 0 = Timer 2 count up 1 = Timer 2 counts down Timer 2 Output Toggle Enable 0 = Timer 2 output outputs a pulse when it overflows from FFFFh to 0000h 1 = Timer 2 output toggles when it overflows from FFFFh to 0000h Timer 2 External Gating Enable 0 = T2EX pin is not active 1 = Enable Timer 1 capture or reload upon a high to low transition on the T2EX pin Timer2 Run 0 = Timer 2 is stopped 1 = Timer 2 is running Timer 2 Counter Enable 0 = Timer 2 acts as a timer 1 = Timer 2 acts as a counter that is incremented (decremented) by a high to low transition on T2IN pin Timer 2 Capture Enable 0 = Auto reload value is loaded in Timer 2 if a high to low transition occurs on T2EX, if T2EXTEN is set to 1 1 = Timer 2 current value is captured when a high to low transition occurs on the T2EX pin, if T2EXTEN is set to 1 1 0 T2COUNTEN T2RLCAP The T2RLCAP bit controls the function of the timer capture/reload register when a high to low transition occurs on the T2EX timer trigger input pin. o o T2RLCAP = 0 : Auto reload value is loaded in Timer 2 T2RLCAP = 1 : Timer 2 current value will be captured in the RCAP2L and RCAP2H registers The functions associated with the T2RLCAP bit are only activated when the T2EXTEN bit is set to 1. TABLE 61:TIMER 2 LOW - TL2 SFR 8EH 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic 7:0 TL2[7:0] Description TABLE 62:TIMER 2 HIGH - TH2 SFR 8FH 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic 7:0 TH2[7:0] Description ________________________________________________________________________________________________ www.ramtron.com page 35 of 99 VRS51L2070 6.6.2 Timer 2 Reload and Capture Registers TABLE 63:TIMER 2 RELOAD AND CAPTURE LOW - RCAP2L SFR 96H 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic 7:0 RCAP2L[7:0] Description TABLE 64:TIMER 2 RELOAD AND CAPTURE HIGH - RCAP2H SFR 97H 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic 7:0 RCAP2H[7:0] 6.6.3 6.6.4 Timer 2 Output As is the case for timers 0 and 1, Timer 2's output can be routed to an external pin. This feature is activated by setting the T2OUTEN bit of the T2CLKCFG register to 1. By default, the Timer 2 output, when enabled, will generate a pulse upon Timer 2 overflow. The duration of the pulse is (1/ SYS CLK). Setting the T2TOGOUT bit of the T2CON register to 1 will configure Timer 2's output to toggle upon a Timer 2 overflow instead of outputting a pulse. FIGURE 10: TIMER 2 OUTPUT MODES Description Timer2 OverFlow The Timer 2 Clock Configuration Register The T2CLKCFG register is used to configure the clock source for Timer 2. The source can be either a prescaled value of the system clock or the output of Timer 1. The Timer 2 clock source is also controlled by the T2CLKSRC bit. When this bit is set to 1, Timer 2 derives its source from the Timer 1 overflow. If T2CLKSRC is set to 0, Timer 2 will derive its source from a prescaled value of the system clock. The division factor applied to the system clock is defined by T2CLKCFG[3:0] TABLE 65:TIMER2 CLOCK CONFIGURATION REGISTER - T2CLKCFG SFR 9DH 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic 7 6 5 T2CLKSRC 4 T2OUTEN 3:0 T2CLKCFG[3:0] Description Timer 2 Clock Source 0 = Timer 2 take its clock from system clock 1 = Timer 2 takes its clock from Timer 1 output Timer 2 Output Enable 0 = Timer 2 output is deactivated 1 = Timer 2 output is connected to a pin Timer 2 Clock Prescaler Configuration See Table below T2OUTEN = 1 T2TOGOUT = 1 T2OUTEN = 1 T2TOGOUT = 0 6.7 Timer 2 Alternate Mapping Bit 2 of the DEVIOMAP register (SFR E1h) controls the mapping of the Timer 2 interface as shown in the following table: TABLE 67: TIMER 2 PIN MAPPING DEVIOMAP.2 Bit Value 0 (Reset) 1 T2IN mapping P1.0 P6.1 T2EX mapping P1.1 P6.0 T2OUT mapping P1.2 P4.4 Alternate mapping allows Timer 2's output to be mapped into P4.4 instead of P1.2. This can be useful for applications where both UART0 and UART1 are required. The following table outlines the Timer 2 prescaler values according to the value of the T2CLKCFG[3:0] bits. TABLE 66:TIMER 2 CLOCK DIVISION RATIO T2CLKCFG (4 bit binary) 0000 0001 0010 0011 0100 0101 0110 0111 Timer Clock Div. Ratio 1 2 4 8 16 32 64 128 T2CLKCFG 1000 1001 1010 1011 1100 1101 1110 1111 Timer Clock Div. Ratio 256 512 1024 2048 4096 8192 16384 16384 ________________________________________________________________________________________________ www.ramtron.com page 36 of 99 VRS51L2070 6.8 Timer 2 Functional Diagram The following diagram describes the main features of Timer 2. FIGURE 11: TIMER 2 FUNCTIONAL DIAGRAM T2CLKSRC SYSCLK 0 1 T1Out T2CLKCFG Div Ratio: Sys Clk / 1 Downto Sys Clk / 16384 T2DOWNEN DOWN / UP T2COUNTEN DOWN / UP 8 7 THx 15 CLK 0 T2IN pin TLx 0 T2TOGOUT Pulse 0 Toggle 1 TxOUT pin 1 T2OUTEN RCAP2H RCAP2L TR2 0 0 7 7 T2OVF interrupt T2GATE INTx pin T2RLCAP Reload 0 T2EX pin 1 Capture Reload Capture T2EXEN ________________________________________________________________________________________________ www.ramtron.com page 37 of 99 VRS51L2070 6.9 Timer Chaining Capability 7 The three VRS51L2070 timers can be chained together to form a 24-, 32- or 48-bit timer that can be used for very long delay timing. Longer delays can be achieved by using the system clock prescalers. The following provides an example of time delays that can be achieved by timer chaining: TABLE 68: TIME DELAYS VS. TIMER SIZE FOR 40MHZ SYSTEM CLOCK Timer Size Time out period 16 bit 24 bit 32 bit 48 bit 1.638 milliseconds 419 milliseconds 107 sec-seconds 7.037x10E6 seconds (1954.6 hours) The VRS51L2070 provides two independent pulse width counter modules associated with timers 0 and 1. The pulse width counter modules provide advanced timer control, allowing the user to define which event will trigger the timer to start and stop. Contrary to standard timer capture module units, the PWC unit can be used to measure the duration of an event. The following two diagrams provide a schematic view of the PWC modules' structure and functionality. FIGURE 13: PWC0 MODULE STRUCTURE Timer 0 SYS CLK The following diagram provides representation of timer chaining. FIGURE 12: TIMER Pulse Width Counters (PWC) a schematic Timer 0 Div Ratio: Sys Clk / 1 Downto Sys Clk / 16384 0 15 PWC0RST RST CHAINING P3.2-INT0 pin 00 P3.0-RXD0 pin 01 P2.4-PWM4 pin 10 P3.4-T0IN-SCL pin 11 Edge Detec t 0 RST RST PWC0RST (Status) 1 Edge Detec t PWC0STPOL PWC0STSRC SYS CLK RST T1CLKCFG T2CLKCFG Div Ratio: SYS CLK / 1 Down To SYSCLK / 16384 Div Ratio: SYS CLK / 1 Down To SYSCLK / 16384 10 Timer 2 1 Timer 0 Out 0 Timer 1 Edge Detec t 01 1 T0CLKCFG PWC0IF 00 Div Ratio: SYS CLK / 1 Down To SYSCLK / 16384 RST 11 Out Edge Detec t 0 Out 0 1 PWC0ENDPOL PWC0ENDSRC T1CLKSR C T2CLKSR C FIGURE 14: PWC1 MODULE STRUCTURE Note that timer chaining does not affect other timer features such as: o o o Timer capture Timer auto-reload Timer output It is also possible to couple the timer chaining capability with the pulse width counter (see next section), to count long duration events. Timer 1 SYS CLK Timer 1 Div Ratio: Sys Clk / 1 Downto Sys Clk / 16384 0 15 PWC1RST RST P3.3-INT1 pin 00 P1.2-RXD1 pin 01 RXD1 pin 10 P1.6-SCK pin 11 Edge Detec t 0 RST RST PWC1RST (Status) 1 Edge Detec t PWC1STPOL PWC1STSRC RST PWC1IF 00 Edge Detec t 01 10 RST 0 1 11 Edge Detec t PWC1ENDPOL PWC1ENDSRC The PWC modules interact with timers 0 and 1. Combining the PWC module configuration with the timer configuration provides added flexibility to the operating modes. ________________________________________________________________________________________________ www.ramtron.com page 38 of 99 VRS51L2070 Two SFR registers (PWC0CFG and PWC1CFG located at addresses 9Eh and 9Fh, respectively) are dedicated to PWC configuration. TABLE 69:PULSE WIDTH COUNTER 0 CONFIG. REGISTER - PWC0CFG SFR 9EH 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic Description 7 PWC0IF 6 PWC0RST 5 PWC0ENDPOL 4 PWC0STPOL 3:2 PWC0ENDSRC Pulse Width Counter Module 0 Interrupt Flag 0 = No PWC0 interrupt occurred 1 = PWC0 interrupt occurred Read: Pulse Width Counter Operation Status 0 = PWC0 is waiting for start condition 1= PWC0 is currently counting Write: Pulse Width Counter Reset 0 = No action 1 = Reset PWC0 operation and PWC0IF PWC0 will wait for a start condition PWC0 End Event Polarity 0 = PWC0 end event is a rising edge 1 = PWC0 end event is a falling edge PWC0 Start Event Polarity 0 = PWC0 start event is a rising edge 1 = PWC0 start event is a falling edge PWC0 End Source 00 = P3.2 01 = P3.0 10 = P2.4 11 = P3.4 PWC0 Start Source 00 = P3.2 01 = P3.0 10 = P2.4 11 = P3.4 1:0 [1:0] PWC0STSRC [1:0] The configuration of the PWC module involves the following steps: o o o o o o Activate PWC module Activate timer and configure it in gating mode Configure PWC start and stop source Configure PWC start and stop event Initialize timer to 0x0002 Activate PWC interrupt if required 7.1.1 The PWC0/1 modules operate in conjunction with timers 0/1. The timer must be activated and configured in gating mode immediately after the PWC modules have been enabled. To obtain a precise measurement of the event duration, the timer registers [THx,TLx] must be initialized to 00, 02h. Once a stop event occurs, the event duration in terms of system cycles is stored in the timer registers. Once the timer has been read, the software must clear it for the next event. // PWC0 Timer initialization ptr = (char idata *) &result_dump_start_address_pwc0; PERIPHEN2 |= 0x40; PERIPHEN1 |= 0x01; T0T1CFG = 0x02; TL0 = 0x02; TH0 = 0x00; PWC0CFG |= 0x15; TABLE 70:PULSE WIDTH COUNTER 1 CONFIG. REGISTER - PWC1CFG SFR 9FH 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic Description 7 PWC1IF 6 PWC1RST Pulse Width Counter Module 0 Interrupt Flag 0 = No PWC1 interrupt occurred 1 = PWC1 interrupt occurred Read: Pulse Width Counter Operation Status 0 = PWC1 is waiting for start condition 1= PWC1 is currently counting Write: Pulse Width Counter Reset 0 = No action 1 = Reset PWC1 operation and PWC0IF PWC0 will wait for a start condition PWC1 END Event Polarity 0 = PWC1 end event is a rising edge 1 = PWC1 end event is a falling edge PWC1 Start Event Polarity 0 = PWC1 start event is a rising edge 1 = PWC1 start event is a falling edge PWC1 End Source 00 = P3.3 01 = P1.2 10 = RXD1 11 = P1.6 PWC1 Start Source 00 = P3.3 01 = P1.2 10 = RXD1 11 = P1.6 5 PWC1ENDPOL 4 PWC1STPOL 3:2 PWC1ENDSRC 1:0 [1:0] PWC1STSRC [1:0] PWC Module and Timer Initialization //Enable pwc0 (enabled first to gate timer //before timer enable !!!) //Enable Timer 0 //Set Timer 0 in gate mode /Initialize Timer //Configure PWC0 module to start on a Falling edge and //End on a Rising edge on pin P3.0 for both events The timer start source can differ from the timer stop source and the start event can differ from the end event. The PWC start and end sources are defined by the PWCxSTSRC bits of the PWCxCFG register as shown in the following tables: TABLE 71:PULSE WIDTH COUNTER 0 START / STOP SOUCE CONFIGURATION PWC0STSRC 00 01 10 11 PWC0 Start Source P3.2 - INT0 P3.0 - RXD0 default P2.4 - RXD0 alternate P3.4 - T0IN PWC0ENDSRC 00 01 10 11 PWC0 End Source P3.2 - INT0 P3.0 - RXD0 default P2.4 - RXD0 alternate P3.4 - T0IN TABLE 72:PULSE WIDTH COUNTER 1 START / STOP SOUCE CONFIGURATION PWC1STSRC 00 01 10 11 PWC1 Start Source P3.3 - INT1 P1.2 - RXD1 default RXD1 alternate P1.6 PWC1ENDSRC 00 01 10 11 PWC1 End Source P3.3 - INT1 P1.2 - RXD1 default RXD1 alternate P1.6 ________________________________________________________________________________________________ www.ramtron.com page 39 of 99 VRS51L2070 Start and stop events must be triggered by either a rising edge or a falling edge of the selected start and stop source. The PWC start source polarity is defined by the PWCxSTPOL and the stop source polarity is defined by the PWxCENDPOL. When these bits are cleared, the PWC module will be triggered by a rising edge (low to high). Setting these bits to 1 configures the PWC to be triggered by a falling edge (high to low). 7.1.2 PWC Module Reset and Interrupt Flags The PWCxRST bit, when set to 1 will force a reset of the PWC module and clear the PWCxIF flag if it is set. The PWC module will then wait for the start condition. The PWCxRST flag provides the current state of the PWC module as follows: TABLE 73: DEFINITION OF PWCXRST BIT WHEN READ PWCxRST reads as 0 1 Then... PWC module is waiting for a start condition PWC module is currently counting The PWCxIF bit will be set to 1 when a stop condition is encountered by the PWC module. The PWCxIF must be cleared by the program. One interrupt vector (Int 11) is allocated for the two PWC modules and its vector address is 005Bh. Note: o o 7.2 The PWCxIF flag remains active even if the corresponding PWC interrupt is disabled. The PWCxIF flags are not automatically cleared when exiting the interrupt service routine. They must be cleared manually by the software. //--Initialize PWC1 PERIPHEN2 |= 0x088; PERIPHEN1 |= 0x02; P0PINCFG = 0x00; T0T1CFG |= 0x40; TH1 = 0x00; TL1 = 0x02; // T1CON |= 0x04; //Enable the PWC1 module & IOport //Enable Timer 1 //P0 = Output //Set Timer 1 in Gating mode //Initialize Timer 1 to 0x02 //Run Timer 1 //Configure Timer 2 as a Timer with output toggle PERIPHEN1 |= 0x04; // Timer 2 TH2 = 0xA0; //Config Timer 2 initial value TL2 = 0x00; RCAP2H = 0xA0; //Config Timer 2 Reload value RCAP2L = 0x00; //Configure Timer Clock source & output Enable T2CLKCFG = 0x10; //T2 Clk source = System Clock //T2 Output Enable //Prescaler = Fosc / 1 //Configure Timer 2 Alternate output DEVIOMAP |= 0x04; //Config T2 output toggle and Start Timer T2CON = 0x14; //Timer 2 output toggle //Timer 2 Run //Timer mode from Sys Clk //Configure PWC1 to Start T1 on a rising edge & Stop T1 on a falling edge //(will measure T2 period) PWC1CFG = 0x65; //Bit 6 = 1: Reset PWC (bit 6 = 1) //Bit 5 = 1: Start on Rising Edge //Bit 4 = 0 Stop on rising edge //Bit 3:2 = 01 PWC1 START / STOP input = P1.2- T2out* //Infinite loop of PWC1 module monitoring by pooling //The P0 is used to monitor the activity of the PWC1 module //When the PWC1 Start condition is met, the program set P0 to 0x00 //and return it to 0xFF when the Stop condition occurs P0 = 0xFF; //Set P0 to 0xFF (PWC not running) do{ //PWC1CFG |= 0x40; //Force the PWC1 module to wait for a START condition while(!(PWC1CFG&0x40)); P0 = 0x00; while(!(PWC1CFG&0x80)); P0 = 0xFF; PWC1CFG &= 0x7F; TL1 = 0x02; TH1 = 0x00; }while(1); //wait PWC to start //clear P0 //wait PWC stop condition to occurs ie interrupt found //return P0 to FF to indicate PWC stopped //Initialize Timer 1 to 0x02 }// End of main PWC Example Program The following example program demonstrates how to configure and use the PWC1 module in Pooling Mode. //-----------------------------------------------------------------------------------------------------------------// // V2K_PWC1p1in_T2out_SDCC.c // //---------------------------------------------------// // // DESCRIPTION: For this demonstration program Timer 2 is configured to // continuously run in Output Toggle Mode on its alternate output (P1.2) and // is used to generate the stimuli required for the PWC1 module input. // The port 0 is used to monitor the activity of the PWC1 module. // // TARGET: VRS51L2xxx/VRS51L3xxx // // #include void main (void) { //Enable Timer 0 and Timer 2 ________________________________________________________________________________________________ www.ramtron.com page 40 of 99 VRS51L2070 8 UART Serial Ports TABLE 76:UART0 BAUD RATE REGISTER LOW - UART0BRL SFR A4H The serial ports on the VRS51L2070 operate in full duplex mode. However, the communication speed will be the same for transmission and reception. Communication speed is derived from an internal 16bit baud rate generator dedicated to each of the UARTs. 8.1 UART0 RX / TX Data Buffer The serial port features double buffering on the receiving side. The SFR register, UART0BUF, provides access to the transmit and receive registers of the serial port. When a read operation is performed on the UART0BUF register, it will access the receive register double buffer. When a write operation is performed on the UART0BUF, the transmit register will be loaded with the value to be transmitted. TABLE 74:UART0 DATA RX / TX REGISTER UART0BUF SFR A3H 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic Description 7:0 UART0BUF[7:0] Read: UART0 Receive Buffer Write: UART0 Transmit Buffer 8.2 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic Description 7:0 UART0BRL[7:0] UART0 LSB of Baud Rate Generator TABLE 77:UART0 BAUD RATE REGISTER HIGH - UART0BRH SFR A5H 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic Description 7:0 UART0BRH[7:0] UART0 MSB of Baud Rate Generator TABLE 78:UART0 EXTENSIONS CONFIGURATION - UART0EXT SFR A6H 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 1 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic Description 7 6 5 4 U0TIMERF U0TIMEREN U0RXSTATE MULTIPROC 3 J1708PRI[3:0] UART0 Timer Flag UART0 Timer Enable UART0 RX Line State When set, RX_available only raise if the ninth received bit is '1' When a transmit is requested, it starts after the priority bit to `1' has been probed on the RX line A standard UART has `0000' priority 8.3 UART0 Configuration Registers The configuration of the UART0 is controlled by the UART0CFG, the UART0BRH and UART0BLH registers and the UART0EXT registers. TABLE 75:UART0 CONFIGURATION REGISTER - UART0CFG SFR A2H 7 6 5 4 3 2 1 0 R/W 1 R/W 1 R/W 1 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic Description 7:4 BRADJ[3:0] 3 BRCLKSRC 2 B9RXTX 1 B9EN 0 STOP2EN UART0 Baud Rate Fine Adjustment * see formula below Baud Rate Clock Source 0 = Baud rate generator uses oscillator 1 = Baud rate generator uses external clock source Read: Last received 9th bit Write: 9th bit to transmit 9th Bit Mode Enable 0 = Data transfer are in 8-bit format 1 = Data transfer are in 9-bit format Enable Two Stop Bit Mode 0 = One stop bit 1 = Two stop bit UART0 Interrupt Configuration Register The activation of the UART0 interrupt is a two-stage process that involves enabling the interrupts at the UART0 module level and then activating the UART0 interrupt at the system level through the INTEN1 register. The upper nibble of the UART0INT register contains the UART0 interrupt activation bits and the lower nibble contains the UART0 interrupt flags in the same order. Two interrupt vectors are associated with UART0. The first interrupt vector is at address 002Bh and handles all UART0 interrupt conditions, except for the UART0 data collision interrupt (vector address 0053h), which is shared with the UART1 data collision and the IC master lost arbitration interrupts. The interrupt flags allow the interrupt service routine to define which condition triggered the interrupt, and to react accordingly. Note that the interrupt flags do not require the interrupt to be enabled in order to be operational. They can be monitored by the software at any time. ________________________________________________________________________________________________ www.ramtron.com page 41 of 99 VRS51L2070 TABLE 79: UART0 INTERRUPT REGISTER - UART0INT SFR A1H 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R, W 0 R/W 0 R/W 0 R 1 Bit Mnemonic Description 7 COLEN 6 RXOVEN 5 RXAVAILEN UART0 Collision Interrupt Enable 0 = Collision interrupt is deactivated 1 = Collision interrupt is enabled UART0 RX Overrun Interrupt Enable 0 = RX Overrun interrupt is deactivated 1 = RX Overrun interrupt is enabled UART0 RX Available Interrupt Enable 0 = RX Available interrupt is deactivated 1 = RX Available interrupt is enabled UART0 TX Empty Interrupt Enable 0 = TX Empty interrupt is deactivated 1 = TX Empty interrupt is enabled (Read) Collision Interrupt Flag When this flag is set by the UART0 module, it indicates that a collision occurred (Write) 0 = Collision detection is disabled and the collision COLENF is reset 1 = A bus collision stops the transmission and raises the COLENF flag UART0 RX Overrun Flag When set to 1 by the UART0 interface, it indicates that a data collision occurred in the UART0BUF register UART0 RX Available Flag When set to 1 by the UART0 interface, it indicates that data has been received in the UART0BUF register Writing 1 into this bit position will activate reception on UART0 UART0 TX Empty Flag When set to 1, it indicates that the transmit portion of the UART0BUF is ready to receive another byte 4 TXEMPTYEN 3 COLENF 2 RXOVF 1 RXAVENF 0 TXEMPTYF 8.4 UART1 RX/TX Data Buffer The SFR register (UART1BUF) provides access to the transmit and receive registers of the serial port. When a read operation is performed on the UART1BUF register, it will access the receive register. When a write operation is performed on the UART1SBUF, the transmit register will be loaded with the value to be transmitted. TABLE 80:UART1 DATA RX / TX REGISTER UART1BUF SFR B3H 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic Description 7:0 UART1BUF[7:0] Read: UART1 Receive Buffer Write: UART1 Transmit Buffer 8.5 UART1 Configuration registers The configuration of the UART1 is controlled by the UART1CFG, UART1BRH and UART1BLH registers and the UART1EXT registers. TABLE 81:UART1 CONFIGURATION REGISTER - UART1CFG SFR B2H 7 6 5 4 3 2 1 0 R/W 1 R/W 1 R/W 1 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic Description 7:4 BRADJ[3:0] 3 BRCLKSRC 2 B9RXTX 1 B9EN 0 STOP2EN UART1 Baud Rate Fine Adjustment * see formula below Baud Rate Clock Source 0 = Baud rate generator uses oscillator 1 = Baud rate generator uses external clock source Read: Last received 9th bit Write: 9th bit to transmit 9th Bit Mode Enable 0 = Data transfer are in 8-bit format 1 = Data Transfer are in 9-bit format Enable Two Stop Bit Mode 0 = One stop bit 1 = Two stop bit TABLE 82:UART1 BAUD RATE REGISTER LOW - UART1BRL SFR B4H 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic Description 7:0 UART1BRL[7:0] UART1 LSB of Baud Rate Generator TABLE 83:UART1 BAUD RATE REGISTER HIGH - UART1BRH SFR B5H 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic Description 7:0 UART1BRH[7:0] UART1 MSB of Baud Rate Generator ________________________________________________________________________________________________ www.ramtron.com page 42 of 99 VRS51L2070 TABLE 84:UART1 EXTENSIONS CONFIGURATION - UART1EXT SFR B6H 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 1 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic Description 7 6 5 4 U1TIMERF U1TIMEREN U1RXSTATE MULTIPROC 3:0 J1708PRI[3:0] UART1 Timer Flag UART1 Timer Enable UART1 RX Line State When set, RX_available, only raise if the ninth received bit is '1' When a transmit is requested, it starts after the priority bit to `1' has been probed on the RX line A standard UART has `0000' priority 8.6 UART1 Interrupt Configuration Register The activation of UART1's interrupt is a two stage process that involves enabling the interrupts at the UART1 module level and then activating the UART1 interrupt at the system level through the INTEN1 register. 8.7 UART0, UART1 Baud Rate Formula The UART0 baud rate is programmed using the following formula: Baud Rate = The BRADJ[3:0] bits are used for fine adjustment of the baud rate. The following steps demonstrate using the UARTxBR[15:0] and BRADJ[3:0] registers to set the appropriate baud rate. Step 1: Defining the Optimal UARTxBR[15:0] Value Use the following formula to set the UARTxBR[15:0] register to the integer component of UARTxBRideal: UARTxBRideal = 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R, W 0 R/W 0 R/W 0 R 1 Bit Mnemonic Description 7 COLEN 6 RXOVEN 5 RXAVAILEN 4 TXEMPTYEN 3 COLENF UART1 Collision Interrupt Enable 0 = Collision interrupt is deactivated 1 = Collision interrupt is enabled UART1 RX Overrun Interrupt Enable 0 = RX Overrun interrupt is deactivated 1 = RX Overrun interrupt is enabled UART1 RX Available Interrupt Enable 0 = RX Available interrupt is deactivated 1 = RX Available interrupt is enabled UART1 TX Empty Interrupt Enable 0 = TX Empty interrupt is deactivated 1 = TX Empty interrupt is enabled (Read) Collision Interrupt Flag When this flag is set by the UART1 module, it indicates that a collision has occurred (Write) 0 = Collision detection is disabled and the collision COLENF is reset 1 = A bus collision stops the transmission and raises the COLENF flag UART1 RX Overrun Flag When set to 1 by the UART1 interface, it indicates that a data collision has occurred in the UART0BUF register UART1 RX Available Flag When set to 1 by the UART1 interface, it indicates that data has been received in the UART1BUF register Writing 1 into this bit position will activate reception on UART1 UART1 TX Empty Flag When set to 1, it indicates that the transmit portion of the UART1BUF is ready to receive another byte 1 0 RXOVF RXAVENF TXEMPTYF Fclk -1 32x (Baud Rate ) TABLE 85: UART1 INTERRUPT REGISTER - UART1INT SFR B1H 2 Fclk 32x (UARTxBR[15:0] + BRADJ[3:0]/16 + 1) Note that the baud rate will likely contain a fractional component. Valid UARTxBR[15:0] values range from 0x0000 to 0xFFFF. Step 2: Defining the Optimal BRADJ[3:0] Value Use the following formula to set the BRADJ[3:0]: BRADJ[3:0] = INT[ (UARTxBRideal - UARTxBR[15:0]) * 16] The BRADJ[3:0] register can only contain an integer value between 0x00 and 0x0F. Step 3: Calculating the Error The actual baud rate vs. the ideal baud rate can be calculated using the following formula: Error % = 100x [ (Fclk /32*(UARTxBR[15:0 +BRADJ[3:0]/16 +1))-Baud Rate] Baud Rate In order to achieve reliable communication, the error should be below 2 percent. The following table provides configuration examples for typical baud rates when the internal 40MHz oscillator is used: ________________________________________________________________________________________________ www.ramtron.com page 43 of 99 VRS51L2070 8.9 TABLE 86: UARTS BAUD RATE CONFIGURATION EXAMPLES (SYS CLK =40MHZ) Com Speed 230400bps 115200bps 57600bps 38400bps 31250bps 28800bps 19200bps 9600bps 4800bps 2400bps 1200bps 300bps 8.8 UARTxBR [15:0] 0004h 0009h 0014h 001Fh 0027h 002Ah 0040h 0081h 0103h 0207h 0410h 1045h BRADJ [3:0] 07h 0Eh 0Bh 09h 00h 06h 02h 03h 07h 0Dh 0Bh 0Bh Actual Baud Rate Error (%) -0.22 -0.22 0.06 -0.03 0 0.06 -0.03 0.01 -0.01 0 0 0 UART1, Alternate Mapping Upon reset, UART1's RXD1 and TXD1 signal are mapped into pins P1.2 and P1.3, respectively. It is possible to map UART1's RXD1 and TXD1 signals into pins 41 and 40 of the VRS51L2070. Bit 4 of the DEVIOMAP register (SFR E1h) controls the mapping of the UART1 interface as shown in the following table: TABLE 88: UART1 RXD1 / TXD1 PIN MAPPING DEVIOMAP.3 Bit Value 0 (Reset) 1 RXD1 mapping P1.2 Pin 41 TXD0 mapping P1.3 Pin 40 UART0, Alternate Mapping Upon reset, UART0's RXD0 and TXD0 signals are mapped into pins P3.0 and P3.1, respectively. It is possible to re-map the RXD0 and TXD0 signals into pins P2.4 and P2.3. Bit 3 of the DEVIOMAP register (SFR E1h) controls the mapping of the UART0 interface, as shown in the following table: TABLE 87: UART0 RXD0 / TXD0 PIN MAPPING DEVIOMAP.3 Bit Value 0 (Reset) 1 RXD0 Mapping P3.0 P2.4 TXD0 mapping P3.1 P2.3 When alternate mapping for UART0 is used, the UART0 will have priority over the PWM3 and PWM4 outputs. ________________________________________________________________________________________________ www.ramtron.com page 44 of 99 VRS51L2070 8.10 UART0 and UART1 Example Programs Configuration of UART0 is essentially the same as UART1 8.10.1 UART0 String Transmit //-------------------------------------------------------------------------------------------------// // VRS2k-UART0_String_out_SDCC.c // //---------------------------------------------------// // // This program initialize the UART0 at 115200 (with SOSC = 39.2MHz) // and then send a string on UART0 TXD0 //----------------------------------------------------------------------------------------------------// #include // --- Function prototypes void txmit0( unsigned char charact); void uart0config(void); //------------------------------------// // MAIN FUNCTION // //------------------------------------// char msg[] = "VRS51L2070 by Ramtron Inc. \0"; void main (void) { int cptr = 0x00; char value = 0x00; //General purpose counter //General purpose variable PERIPHEN1 = 0x08; PERIPHEN2 = 0x08; //Enable UART0 (SFR = F5h) //Enable I/O Ports (SFR = F5h) P2PINCFG = 0xFE; //Configure Port 2.0 as Output //-- SYSTEM CLOCK PRESCALER DEVCLKCFG1 = 0x60; //SET DEVICE PRESCALER SPEED uart0config(); //Configure Uart0 //-- Send Message 1 on UART0 do{ cptr = 0x00; // Init cptr to pint to message beginning do{ txmit0(msg[cptr++]); }while(msg[cptr]!= '\0'); txmit0(13); txmit0(10); }while(1); //Send Carriage Return //Send Line Feed //--------------------------------------------------------------------------------// // TXMIT0 // // Transmit one byte on the UART0 // //--------------------------------------------------------------------------------// void txmit0( unsigned char charact){ char patof; S0BUF = charact; //Send Character do{ //wait for TX Empty Flag to be set patof = UART0INT; patof = patof & 0x01; }while (patof == 0x00); UART0INT &= 0xFE; }//end of txmit0() function 8.10.2 UART Echo and External Interrupt Configuration //----------------------------------------------------------------------------------------------------------// // VRS2k-UART0_Echo_INT0_INT1_Interrupt_SDCC.c // //----------------------------------------------------------------------------------------------------------// // // This program initialize the UART0 at 115200 (with SOSC = 40MHz) // It then transmit "Instruction message" on TXD0 // and enter in infinite loop waiting for an interrupt // As soon as a character is received it is transmitted back on TXD0 // //----------------------------------------------------------------------------------------------------------// #include //----Global variables ------// int cptr = 0x00; //general purpose counter // --- function prototypes void txmit0( unsigned char charact); void uart0config(void); //--Definton of Messages to transmit on UART0 char msg[] = "UART0 Echo + INT Test: Waiting for char on RXD0 or ext INT0 or ext INT1...\0"; char msgint0[] = "EXT INT0 received"; //-----------------------------------// //----- Interrupt INT0 ------// //----------------------------------// void INT0Interrupt(void) interrupt 0 { //-- Send "EXT INT0 Received" on UART0 cptr = 0x00; //Init cptr to pint to message beginning INTEN1 = 0x00; //Disable UART0 Interrupt do{ B = msgint0[cptr++]; txmit0(B); }while(msgint0[cptr]!= '\0'); }//end of Main //----------------- Individual Functions --------------------//--------------------------------------------------------------------------------// // UART0 CONFIG with S0REL // // Configure the UART0 to operate in RS232 mode at 115200bps // with self oscillator at 39.2MHz // //--------------------------------------------------------------------------------// void uart0config() { //--initialize UART0 at 115200bps @ 39.2MHz UART0CFG = 0x90; }//end of uart0config() function //No Fine adjustment on baud rate //Use internal clock //9 bit not used //only one stop bit UART0EXT = 0x00; //Not using UART0 Extensions UART0BRL = 0x09; UART0BRH = 0x00; //Reload for 115200 // txmit0(13); txmit0(10); INTEN1 = 0x21; //Send Carriage Return //Send Line Feed //Enable UART0 Interrupt + INT0 }//end of INT0 interrupt //---------------------------------------// //--- UART0 Interrupt --------// //--------------------------------------// void UART0Interrupt(void) interrupt 5 { char genvar; //Check if interrupt was caused by RX AVAIL genvar = UART0INT; genvar &= 0x02; // if(genvar != 0x00) { genvar = S0BUF; txmit0(genvar); //Send back the received character } ________________________________________________________________________________________________ www.ramtron.com page 45 of 99 VRS51L2070 //Check if interrupt was caused by RX OVERRUN genvar = UART0INT; genvar &= 0x04; // if(genvar != 0x00) { genvar = S0BUF; //Read S0BUF to clear RX OV condition... //his is mandatory because otherwise the RX OV condition //Stay active //interrupt activated // UART0INT = 0x32; //Enable RX AV int + TX EMPTY Int + Enable Reception txmit0(' '); //Send " OV!" on serial port txmit0('O'); // txmit0('V'); // txmit0('!'); // } }//end of uart0 interrupt //--------------------------------------------------------------------------------// // TXMIT0 // // Transmit one byte on the UART0 // //--------------------------------------------------------------------------------// void txmit0( unsigned char charact){ char variable; S0BUF = charact; //Send Character do{ //wait for TX Empty Flag to be set variable = UART0INT; variable = variable & 0x01; }while (variable == 0x00); // UART0INT &= 0xFE; }//end of txmit0() function //-----------------------------------------// // MAIN FUNCTION // //----------------------------------------// void main (void){ char value = 0x00; //general purpose variable PERIPHEN1 = 0x08; PERIPHEN2 = 0x08; //Enable UART0 //Enable IO Ports P2PINCFG = 0xFE; //Configure Port 2.0 as Output //-- SYSTEM CLOCK PRESCALER DEVCLKCFG1 = 0x60; //SET DEVICE PRESCALER SPEED uart0config(); //Configure Uart0 //-- Send "Hello" on UART0 cptr = 0x00; //Init cptr to pint to message beginning do{ txmit0(msg[cptr++]); }while(msg[cptr]!= '\0'); txmit0(13); txmit0(10); //Send Carriage Return //Send Line Feed //--Wait for Character on UART0 interrupt // Once a character is received, grab it and send it back UART0INT = 0x62; //Test: For RXOV int test Enable RX OV int + Enable //Reception INTSRC1 = 0x01; INTPINSENS1 = 0x01; INTPININV1 = 0x00; INTEN1 = 0x21; //INT0 vector source = INT0 pin //Set INT0 sensitive on edge(1) or Level(0) //Set INT0 Pin sensitivity on Low Level/Inversion //Enable INT0 (bit0) and UART0 (bit5) Interrupt INTCONFIG = 0x01; while(1); }//end of Main //Enable Global interrupt //----------------- Individual Functions --------------------//-----------------------------------------------------------------------------------------------------// // UART0 CONFIG with S0REL // // Configure the UART0 to operate in RS232 mode at 115200bps // with self oscillator at 39.2MHz // //------------------------------------------------------------------------------------------------------// void uart0config() { //--initialize UART0 at 115200bps @ 39.2MHz UART0CFG = 0x90; UART0INT = 0x62; UART0EXT = 0x00; UART0BRL = 0x09; UART0BRH = 0x00; //No Fine adjustment on baud rate //Use internal clock //9th bit not used //only one stop bit //Enable RX AV + RXO V int + Enable Reception //Not using UART0 Extensions //Reload for 115200 ??? (was 0x0a) // }//end of uart0ws0relcfg() function ________________________________________________________________________________________________ www.ramtron.com page 46 of 99 VRS51L2070 9 SPI Interface 9.1 The VRS51L2070's SPI interface peripheral is based on the Versa Mix 8051 SPI interface peripheral, but with additional features. The SPICTRL register controls the operating modes of the SPI interface in master mode. Key features include: * * * * * * * * Supports four standard SPI modes (clock phase/polarity) Operates in master and slave modes Automatic control of up to four chip select lines Configurable transaction size (1 to 32 bits) Transaction size of >32 bits is possible Double Rx and TX data buffers Configurable MSB or LSB first transaction Generation frame select/load signals SPI Control Registers TABLE 89:SPI CONTROL REGISTER - SPICTRL SFR C1H 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 1 Bit Mnemonic Description 7 SPICLK[2:0] 4 SPICS[1:0] 2 SPICLKPH 1 SPICLKPOL 0 SPIMASTER SPI Communication Speed (Master Mode) 000 = Sys Clk / 2 ( / 8 if SPISLOW = 1) 001 = Sys Clk / 4 ( / 16 if SPISLOW = 1) 010 = Sys Clk / 8 ( / 32 if SPISLOW = 1) 011 = Sys Clk / 16 ( / 64 if SPISLOW = 1) 100 = Sys Clk / 32 ( / 128 if SPISLOW = 1) 101 = Sys Clk / 64 ( / 256 if SPISLOW = 1) 110 = Sys Clk / 128 ( / 512 if SPISLOW = 1) 111 = Sys Clk / 256 ( / 1024 if SPISLOW = 1) SPI Active Chip Select Line (Master Mode) 00 = CS0 is active 01 = CS1 is active 10 = CS2 is active 11 = CS3 is active SPI Clock Phase 0 = SD0 output on rising edge and SDI sampling on falling edge 1= SD0 output on falling edge and SDI sampling on rising edge SPI Clock Polarity 0 = SCK stays at 0 when SPI is inactive 1 = SCK stays at 1 when SPI is inactive SPI Master Mode Enable 0 = SPI operates in slave mode 1 = SPI operate in master mode (default) FIGURE 15: SPI INTERFACE OVERVIEW SPI SFRs VRS51L2070 SPI INTERFACE Serial Data IN SDI Serial Data OUT SDO Serial Clock IN/OUT SCK CS0 CS1 CS2 Processor CS3 SPI IRQs SS Chip Select Output Chip Select Output Chip Select Output Chip Select Output Slave Select Input To Slave Device #1 To Slave Device #2 To Slave Device #3 To Slave Device #4 From Master Device Before the SPI can be accessed it must first be enabled by setting the SPIEN bit of the PERIPHEN1 register to 1. When the SPIMASTER bit is set to 1, the SPI interface operates in master mode. This is the default operating mode of the VRS51L2070 SPI interface after reset. 9.2 Setting Up Clock Phase and Polarity The clock phase and polarity is controlled by the SPICLKPH and SPICLKPOL bits, respectively. The following diagrams show the communication timing associated with the clock phase and polarity. SPI Mode 0: FIGURE 16: SPI MODE 0 SPI MODE 0: SPICKPOL =0,SPICKPH =1 (Normal Mode Shown) CSX SCK SDO MSB LSB SDI *Arrows indicate the edge where the data acquisition occurs ________________________________________________________________________________________________ www.ramtron.com page 47 of 99 VRS51L2070 SPI Mode 1: 9.4 Setting the SPI Communication Speed (Master Mode) FIGURE 17: SPI MODE 1 SPI MODE 1: SPICKPOL =0,SPICKPH =0 (Normal Mode Shown) CSX SCK SDO MSB LSB In master mode, the SPI interface communication speed is adjustable from "system clock /2" down to "system clock / 1024". Slower communication speeds can be useful for interfacing with slower devices or to adjust the communication speed to specific bus conditions. The SPICLK SFR register and the SPISLOW bit of the of the SPICONFIG SFR register control the SPI communication speed. SDI *Arrows indicate the edge where the data acquisition occurs SPI Mode 2: The SPI communication speed in master mode can be calculated using the following formula: FIGURE 18: SPI MODE 2 SPI MODE 2: SPICKPOL =1,SPICKPH =1 (Normal Mode Shown) SPI speed = Sys Clk [ 2(SPICLK[2:0] +1) x 4SPISLOW ] CSX SCK SDO MSB Where: LSB o o o SDI *Arrows indicate the edge where the data acquisition occurs The following tables provide example setting for SPI communication speeds with various system clock and SPICLK[2:0] and SPISLOW bit settings. SPI Mode 3: FIGURE 19: SPI MODE 3 SPI MODE 3: SPICKPOL =1,SPICKPH =0 (Normal Mode Shown) SCK MSB LSB SDI *Arrows indicate the edge where the data acquisition occurs 9.3 TABLE 90:SPI COMMUNICATION SPEED EXAMPLE (SPISLOW = 0) SPICLK CSX SDO Sys Clk = Processor operating clock SPISLOW = can be either 0 or 1 SPICLK[2:0] = from 0 to 7 Defining active chip select line As previously mentioned, only one chip select line is activated when communicating with an external SPI slave device. The SPICS bits of the SPICTRL register are used to select which CS line will be activated during the transfer . Note that with the exception of the CS0 line, the SPICSEN bit of the PERIPHEN1 register must be set to 1 in order for the SPI be able to control the SPI CS lines. 000 001 010 011 100 101 110 111 Com Speed @ 40MHz 20 MHz 10 MHz 5 MHz 2.5 MHz 1.25 MHz 625 kHz 312.5 kHz 156.3 kHz Com Speed @ 22.18MHz 11.05 MHz 5.53 MHz 2.76 MHz 1.38 MHz 691.2 kHz 345.6 kHz 172.8 kHz 86.4 kHz Com Speed @ 4MHz 2 MHz 1 MHz 500 kHz 250 kHz 125 kHz 62.5 kHz 31.3 kHz 15.6 kHz TABLE 91:SPI COMMUNICATION SPEED EXAMPLE (SPISLOW = 1) SPICLK 000 001 010 011 100 101 110 111 Com Speed @ 40MHz 5 MHz 2.50 MHz 1.25 MHz 625 kHz 312.5 kHz 156.3 kHz 78.1 kHz 39.1 kHz Com Speed @ 22.18MHz 2.76 MHz 1.38 MHz 691.2 kHz 345.6 kHz 172.8 kHz 86.4 kHz 43.2 kHz 21.6 kHz Com Speed @ 4MHz 500 kHz 250 kHz 125 kHz 62.5 kHz 31.3 kHz 15.6 kHz 7.8 kHz 3.9 kHz ________________________________________________________________________________________________ www.ramtron.com page 48 of 99 VRS51L2070 9.5 The SPISTATUS register's role is mainly for monitoring purposes. SPI Configuration and Status Registers The SPI configuration and status registers allow the activation and the monitoring of the SPI interface interrupts. They also provide access to the advanced features of the SPI interface such as: o Frame select/load generation on CS3 o Activating manual control of the chip select lines o Bit reversed mode (Bitwise Endian Control) o Interrupt activation and monitoring o Monitoring the state of the SS pin TABLE 93:SPI STATUS REGISTER - SPISTATUS SFR C9H 7 6 5 4 3 2 1 0 R/W 0 R 0 R 0 R 1 R 1 R 0 R 0 R 1 Bit Mnemonic 7 SPIREVERSE 6 5 SPIUNDERF 4 SSPINVAL 3 SPINOCS 2 SPIRXOVF 1 SPIRXAVF 0 SPITXEMPF TABLE 92:SPI CONFIGURATION REGISTER - SPICONFIG - C2H 7 6 5 4 3 2 1 0 R/W 0 W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic Description 7 SPIMANCS 6 SPIUNDERC 5 FSONCS3 SPI Manual CS Mode Enable 0 = SPI Chip select control is fully automatic 1 = SPI Chip select will be brought low by the SPI interface, and will stay low until 0 is written into SPIMANCS bit SPI Clear TX Underrun Flag (SPIUNDERF) Writing a 1 into this bit will clear the SPIUNDER bit of the SPISTATUS register This bit always reads 0 Frame Select Pulse on CS3 0 = CS3 acts in standard ways 1 = The SPI interface will send an active low frame select pulse on CS3 Frame select has priority on SPILOAD function Load Pulse on CS3 0 = CS3 acts in standard way or as frame select pulse, if FSONCS3 is set to 1 1 = The SPI interface sends an active low load pulse on the CS3 pin, if FSONCS3 is cleared SPI Slow Speed mode 0 = SPI transaction occurs at normal speed 1 = SPI transaction is 4x slower SPI RX Overrun Interrupt Enable 0 = SPI RX overrun interrupt is deactivated 1 = SPI RX overrun interrupt is enabled SPI RX Available Interrupt Enable 0 = SPI RX available interrupt is deactivated 1 = SPI RX available interrupt is enabled SPI TX Empty Interrupt Enable 0 = SPI TX empty interrupt is deactivated 1 = SPI TX empty interrupt is enabled 4 SPILOADCS3 3 SPISLOW 2 SPIRXOVEN 1 SPIRXAVEN 0 SPITXEEN 9.6 Description SPI Reverse Mode 0 = SPI operates in normal mode (MSB First) 1 = SPI operates in reverse mode (LSB First) Not used SPI TX Underrun Flag 0 = No underrun condition noticed 1 = Indicates that the SPI transmit buffer has not been fed in time. This condition is likely to occur when the Transaction size is > 32 bits This bit is cleared by setting to 1, the SPICLRTXF bit of the SPICTRL bit of the SPICONFIG register Slave Select Pin Value 0 =SS pin is low 1 = SS pin is high SPI No Chip Select 0 = At least on chip select line is active 1 = Indicates that all the chip select lines are inactive (high) SPI RX Overrun InterruptFlag 0 = No SPI RX Overrun condition detected 1 = SPI Data collision occurred SPI RX Available Interrupt Flag 0 = SPI receive buffer is empty 1 = Data is present in the SPI RX buffer SPI TX Empty Interrupt Flag 0 = SPI transmit buffer is full 1 = SPI transmit buffer is ready to receive new data SPI Transaction Directions The SPI interface can perform transactions in the standard SPI format (MSB first) as well as in the reverse format (LSB first). In applications where data must be transmitted (or received) in LSB first format, the user would normally need to perform bit reversal manually at the processor level and then send the data through the SPI interface. The SPI interface can automatically handle the bit reversal operations, unloading the processor for other tasks. When the SPIREVERSE bit of the SPISTATUS register is set to 0, the SPI transactions will take place in MSB first format. ________________________________________________________________________________________________ www.ramtron.com page 49 of 99 VRS51L2070 The following examples show the timing related to these transaction directions: FIGURE 20: SPI MSB FIRST TRANSACTION MSB First SPI Transaction (Mode 0 Shown) The SPI can trigger three interrupt sources that are handled by two interrupt vectors, as shown in the following table: Interrupt SCK SDO/SDI MSB LSB When the SPIREVERSE is set to 1, the SPI transactions are done in LSB first format, as shown in the next figure. FIGURE 21: SPI LSB FIRST TRANSACTION LSB First SPI Transaction (Mode 0 Shown) CSX SCK SDO/SDI LSB MSB Manual Chip Select Control When the SPIMANCS bit of the SPICONFIG register is set to 1, the active chip select line will stay at a logic low after the SPI master mode transaction is completed, as shown in the following figure. FIGURE 22: SPI MANUAL CHIP SELECT Manual CSx Mode (SPI Mode 0 shown) Note: CSx Stays Low CSX SC K SDO SPI Interrupts TABLE 94: SPI INTERRUPT SOURCES CSX 9.7 9.8 MS B LSB SDI *Arrows indicate the edge where the data acquisition occurs The chip select will remain at logic 0 until the SPIMANCS bit is cleared by the software. SPI TX Empty SPI RX Available SPI RX Overrun Interrupt Number Int_1 Interrupt Vector 000Bh Int_2 0013h The TX empty interrupt is set when the SPI transmit buffer is ready to receive more data. A double buffer is used in the SPI transmitter. Once transmission begins (after a write to the SPIRXTX0 register), the data is transferred to the final transmission buffer. This frees up the SPIRXTX SFR register, raises the SPITXEMPF flag of the status register and triggers an SPI TX empty interrupt if enabled. The SPI TX empty interrupt is enabled by setting the SPITXEEN bit of the SPICONFIG register to 1. The priority of the SPI TX empty interrupt is set high in order to avoid buffer overrun in 32-bit SPI transfers. The SPI RX available interrupt is activated when receive data has been transferred from the SPI RX buffer to the SPIRXTX register. The SPIRXTX register must be read by the processor before the next SPI bus data sequence is completed. The SPI RX available interrupt is enabled by setting the SPIRXAVEN bit of the SPICONFIG register to 1. The SPIRXAVF flag of the SPISTATUS register, when set to 1, indicates that data can be read. The SPIRXAVF flag is automatically reset when the SPIRXTX0 register is read. The SPI RX overrun interrupt indicates that an overrun condition has taken place. The SPI RX overrun interrupt is enabled by setting the SPIRXOVEN bit of the SPICONFIG register to 1. The SPIRXOVF flag of the SPISTATUS register, when set to 1, indicates that a data collision has occurred. All the SPI interface interrupt flags are active even if the associated interrupt is not activated and they can be monitored by the user program at any time. Please consult the Interrupt Section for more details on the SPI interface interrupts and their interaction with other peripherals ________________________________________________________________________________________________ www.ramtron.com page 50 of 99 VRS51L2070 9.9 Alternate CS3 functions 9.10 SPI Activity Monitoring For external SPI devices which require the use of a load or a frame select signal, the VRS51L2070 can be configured to either generate an active low frame select or active high load signal when operating in master mode. 9.9.1 Frame Select signal on CS3 When the FONCS3 bit of the SPICONFIG register is set to 1, the SPI interface will generate an active low frame select pulse on the CS3 pin (see the following timing diagram). FIGURE 23: SPI FRAME SELECT PULSE TIMING FRAME SELECT Pulse (SPI Mode 0 shown) CS3 SC K MS B LSB SDI *Arrows indicate the edge where the data acquisition occurs 9.9.2 Load Signal on CS3 When the SPILOADCS3 bit of the SPICONFIG register is set to 1 and the FSONCS3 bit is cleared, an active low load signal will be generated on the CS3 line of the SPI interface. FIGURE 24: SPI LOAD PULSE TIMING LOAD Pulse (SPI Mode 0 shown) CS3 Load Pulse width = 1 / Sys Clk CSX SC K SDO MS B The SPINOCS bit of the SPISTATUS register returns the logical AND of all the SPI CS lines of the VRS51L2070. If all the CS lines are inactive (logic high), the SPI interface sets the SPINOCS to 1. The SPINOCS bit is used to verify that the SPI interface is idle before reconfiguring it or starting a new transaction. The SPINOCS bit of the SPISTATUS register is valid four system clock cycles after the SPI transmission begins. This delay is independent of the SPI transaction speed. Frame Select Pulse width = 1 / Sys Clk CSX SDO The ability to monitor the state of communication of the SPI interface can be useful in highly modular applications in which the SPI interface is handled by interrupts. The SPISTATUS register contains two flags that can be used to monitor the CS and SS signals of the SPI interface. LSB SDI *Arrows indicate the edge where the data acquisition occurs Note that the frame select alternate function has priority over the load function. This means that if the FSONCS3 bit is set, the alternate function selected will be the frame select, independent of the value of the SPILOAD bit. As such, after a write operation to the SPIRXTX0 register, which will trigger a SPI transaction in master mode, a NOP instruction (1 cycle) must be added before the MOV Rn, SPISTATUS instruction (3 cycles). The SSPINVAL bit of the SPISTATUS register returns the logic level on the SS pin. 9.11 SPI TX Underrun Flag The SPI interface provides an underrun condition flag that can be used to flag whether the software has failed to update transmission buffer in time for the next transfer. This is especially useful when the SPI interface is used to transmit packets greater than 32 bits in length. If an underrun condition occurs, the SPIUNDERF bit of the SPI status register will be set to 1. This bit can be cleared by writing a 1 to the SPIUNDERC bit of the SPICONFIG register. Note that SPI underrun monitoring is not linked to any of the SPI interrupts, therefore, this flag can only be v manually by software 9.12 SPI Transaction Size The standard SPI protocol is based on 8-bit transactions. However, many devices on the market, specifically A/D and D/A converters, require transactions greater than 8 bits. To communicate with these types of devices using a standard SPI interface, the user has no choice but to send multiple 8-bit streams or to manipulate the I/Os via software to emulate the timing control signals. ________________________________________________________________________________________________ www.ramtron.com page 51 of 99 VRS51L2070 The VRS51L2070 SPI interface supports 8-bit transactions and can also be configured to support transactions that measure 1 to 32 bits in both transmit and receive directions. The value written into the SPISIZE register controls the transaction size. Upon reset, the SPI interface is configured for 8-bit transactions. The following table provides examples: TABLE 96: TRANSACTION SIZE VS. SPISIZE[7:0] SPISIZE[7:0] 0x07 0x0B 0x0D 0x10 0x17 0x1F 0x20 0x21 0x23 TABLE 95:SPI TRANSACTION SIZE - SPISIZE SFR C3H 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 1 R/W 1 R/W 1 Bit Mnemonic Description 7:0 SPISIZE[7:0] SPI transaction Size If < 32 : Transaction Size = SPISIZE + 1 If >= 32: Transaction Size = (SPISIZE *8) - 216 Default Transaction Size = 8 bits Transaction Size 8-bit 12-bit 14-bit 17-bit 24-bit 32-bit 40-bit 48-bit 64-bit The transaction size must also be configured when the operating the SPI interface in slave mode. 9.13 SPI RX/TX Data Registers Or Four SFR registers provide access to the SPI interface's receive and transmit data buffer. Performing a write operation to the SPI RX/TX buffer transfers the data to the transmit portion of the SPI interface, while a read operation reads the contents of the receive data buffer. The SPI 32-bit receive and transmit data buffers are double buffered to minimize the risk of data collision and to achieve optimal performance. SPISIZE[7:0] = Transaction Size - 1 The SPI RXTX0 register contains bits 7:0 of the SPI interface RX/TX register. Four formulas control the SPI transaction size: For Transactions Size <= 32 bits Transaction Size = SPISIZE[7:0] +1 TABLE 97: SPIRXTX0 REGISTER CONTENT FOR NORMAL AND REVERSED TRANSACTIONS For Transactions Size > 32 bits Operation Read Transaction Size = [ (SPISIZE[7:0] * 8) -216] Write Or it can be expressed by: SPISIZE[7:0] = [ Transaction Size + 216 ] 8 SPI Mode MSB First LSB First MSB First LSB First SPIRXTXx Data is... Right Justified Left Justified Left Justified Right Justified When the SPI is configured in master mode, writing to the SPIRXTX0 will trigger a data transmission. For this reason, when the transaction size is larger than 8 bits, the SPIRXTX0 register must be written last. TABLE 98:SPI RX / TX0 DATA REGISTER - SPIRXTX0 SFR C4H 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic Description 7:0 SPIRXTX0[7:0] Read: SPI RXData[7:0] Right justified in normal mode, left justified in bit reversed mode Reading this register, clears the SPIAVF and SPIRXOVF flags Write: SPI TXData[7:0] Left justified in normal mode, right justified in bit reversed mode In master mode, writing to SPIRXTX0 triggers the transmission ________________________________________________________________________________________________ www.ramtron.com page 52 of 99 VRS51L2070 TABLE 99:SPI RX / TX1 DATA REGISTER - SPIRXTX1 SFR C5H 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic Description 7:0 SPIRXTX1[7:0] Read: SPI RXData[15:8] Right justified in normal mode, left justified in bit reverse mode Write: SPI TXData[15:8] Left justified in normal mode, right justified in bit reverse mode TABLE 100:SPI RX / TX2 DATA REGISTER - SPIRXTX2 SFR C6H 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 9.14 SPI Data Input /Output The VRS51L2070 SPI interface has the ability to perform data transactions in MSB first mode or LSB first. The SPIREVERSE bit of the SPISTATUS register controls whether the data will be transmitted MBS first or LSB first. Upon device reset, the SPIREVERSE bit equals 0 and data is transmitted in MSB first format. The SPIREVERSE bit state will also affect the data transmission and the data reception buffer structure as shown in the following diagrams. FIGURE 25: SPI TRANSACTION STANDARD MODE (SPIREVERSE = 0 : MSB FIRST) Outgoing Transaction SPI Transmission (Standard Mode) Bit Mnemonic Description 7:0 SPIRXTX2[7:0] Read: SPI RXData[23:16] Right justified in normal mode, left justified in bit reverse mode Write: SPI TXData[23:16] Left justified in normal mode, right justified in bit reverse mode 7 0 7 SPIRXTX3 0 7 SPIRXTX3 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic Description 7:0 SPIRXTX3[7:0] Read: SPI RXData[31:24] Right justified in normal mode, left justified in bit reverse mode Write: SPI TXData[31:24] Left justified in normal mode, right justified in bit reverse mode 0 7 SPIRXTX2 0 SPIRXTX1 7 0 SPIRXTX0 SPI Reception (Standard Mode) TABLE 101:SPI RX / TX3 DATA REGISTER - SPIRXTX3 SFR C7H 7 MSB SDO Pin 7 R/W 0 LSB Incoming Transaction 0 7 SPIRXTX2 0 7 SPIRXTX1 0 SPIRXTX0 MSB LSB SDI Pin FIGURE 26: SPI TRANSACTION BIT REVERSE MODE (SPIREVERSE = 1: LSB FIRST) SPI Transmission (Bit Reversed Mode) 7 0 7 SPIRXTX3 0 7 SPIRXTX2 Outgoing Transaction 0 SPIRXTX1 7 0 SPIRXTX0 MSB LSB SDO Pin Incoming Transaction SPI Reception (Bit Reversed Mode) LSB MSB SDI Pin 7 0 7 SPIRXTX3 0 7 SPIRXTX2 0 SPIRXTX1 7 0 SPIRXTX0 The next tables gives examples of SPI transmission and reception in different modes if the SPI SDO pin is connected to the SDI pin. SPISIZE = 0x0F (16 bit) / SPIREVERSE= 0 (MSB First SPITX [3:0] SPIRX [3:0] xx xx D3h 42h xx xx 42h D3h xx xx 54h A6h xx xx A6h 54h SPISIZE = 0x0F (32 bit) / SPIREVERSE= 0 (MSB First SPITX [3:0] SPIRX [3:0] 45h A3h B2h DF DFh B2h A3h 45h C3h 8Ah 49h 24h 24h 49h 8Ah C3h SPISIZE = 0x0F (32 bit) / SPIREVERSE= 1 (LSB First SPITX [3:0] SPIRX [3:0] 45h A3h B2h DF DFh B2h A3h 45h C3h 8Ah 49h 24h 24h 49h 8Ah C3h ________________________________________________________________________________________________ www.ramtron.com page 53 of 99 VRS51L2070 9.14.1 Performing Variable-Bit Data Transmission For a variable-bit data transmission in master mode (when the data is not transmitted in multiples of 8 bits), the most significant bit of the data to be transmitted must first be placed at position 7 of the SPIRXTX0, with the remaining bits positioned as shown in the SPI transaction figures on the previous page. For example if SPISIZE = 0x0B and SPIREVERSE = 0, the data transaction will measure 12 bits, MSB first. For the transmission to occur in the correct order, the lower 4 data bits must first be placed into bit positions 7:4 of the SPIRXTX1 register, with bits 11:8 written into bit position 7:0 of the SPIRXTX0 register. This will trigger the transmission. The following is a sequence of steps to transmit 12 bits of data contained in an integer variable called txmitdata. 1. Clear the SPIRXTX3 and SPIRXTX2 registers (optional) 2. Put the lower quartet of the 12-bit data (bits 3:0) into the upper quartet of the SPIRXTX1 register 3. Write bit 7:0 of the 12-bit data into the SPIRXTX0 register 4. This will trigger a data transmission In C, this is expressed as follows: (...) SPIRXTX3 = 0x00; SPIRXTX2 = 0x00; SPIRXTX1 = (txmitdata << 4)&0xF0; readflag = SPIRXTX0 9.15 SPI Example Programs 9.15.1 UART to SPI Data Transmission Example //---------------------------------------------------------------------------------------// // SPI Transmit example.c // //--------------------------------------------------------------------------------------// // // This program sends characters received on the UART to the SPI Interface // //--------------------------------------------------------------------------------------// #include //----Global variables ------// int cptr = 0x00; //general purpose counter // --- function prototypes void txmit0( unsigned char charact); void uart0config(void); //-------------------------------------------------------// // Main Function // //-------------------------------------------------------// void main (void){ char value = 0x00; PERIPHEN1 = 0xC0; INTCONFIG = 0x02; event //general purpose variable //Enable SPI Interface //Erase Bypass global int, before configuring the INT0 pin //This fix inadvertent INT0 interrupt that occurs when //INT0 cause is set to Rising edge INTSRC1 = 0x01; INTPINSENS1 = 0x01; INTPININV1 = 0x00; INTEN1 = 0x01; //INT0 vector source = INT0 pin //Set INT0 sensitive on edge(1) or Level(0) //Set INT0 Pin sensitivity on Normal Level(0) / Inverted (1) //Enable INT0 (bit0) Interrupt INTCONFIG = 0x01; //Enable Global interrupt while(1); }//end of Main //Write the lower quartet of data //into the upper quartet of SPIRXTX1 register //-Dummy Read the SPI RX buffer to clear the RXAV Flag //(Facultative if SPINOCS is monitored) SPIRXTX0 = dacdata >> 4; //Writing to SPIRXTX0 will trigger the transmission For example to output 0x3A2 through the SPI interface configured in master mode and MSB first format, write 0x20 into the SPIRXTX1 SFR register and followed by 0xA2 into the SPIRXTX0 register. The reception of non multiple of 8 data when the SPI interface is configured to MSB first transaction is very straight forward as the data enters into the receiving buffer through the bit 0 of the SPIRXTX0 register and propagates towards the bit 7 of SPIRXTX3 register. //---------------------------------------------------------------------------------------// //----------------------------- Interrupt Functions -------------------------------// //---------------------------------------------------------------------------------------// //------------------------------------------------------------------------------// // Interrupt INT0 // // Send character received on the SPI Interface // //-----------------------------------------------------------------------------// void INT0Interrupt(void) interrupt 0 { //-- Send "EXT INT0 Received" on UART0 cptr = 0x00; // Init cptr to pint to message beginning INTEN1 = 0x00; /Disable Interrupts SPICTRL = 0xE1; //SPI CLK = div by 256 //SPI CS0 Active //SPI Mode 0 //SPI Master SPISIZE = 0x07; SPICONFIG = 0x10; SPIRXTX0 = S0BUF; //SPI SIZE = 8bit //LOAD on CS3 //Send Data Byte on SPI Interface INTEN1 = 0x01; }//end of INT0 interrupt //Enable Interrupt INT0 ________________________________________________________________________________________________ www.ramtron.com page 54 of 99 VRS51L2070 9.16 SPI Interface to 12-Bit ADC and DAC The following example program shows the initialisation and use of the SPI module of the VRS51L2070 as an interface to serial ADC and DAC. .//----------------------------------------------------------------------------------------------------------------------// // VRS51L2070_Generic_SPI_based_ADC_DAC_Interf1.c //----------------------------------------------------------------------------------------------------------------------// // DESCRIPTION: // This Program demonstrates the configuration and use of the SPI interface // for interface to typical serial 12 bit A/D and D/A Converters. // The program read the A/D and output the read value out on a D/A converter // To perform the conversion the ADC requires 16 clock cycles and // the DAC requires 12 clock cycles. //----------------------------------------------------------------------------------------------------------------------// #include //---Functions prototypes void ReadGEN_12BIT_ADC(void); void WriteGEN_12BIT_DAC(unsigned int ); //GEN_12BIT_ADC Read //GEN_12_BIT_DAC Write void V2KDelay1ms(unsigned int); //Standard Delay function // Global variables definitions idata unsigned char cptr = 0x00; unsigned int at 0x0060 adcdata= 0x00; //--------------------------------------------------------------------------------------------// // MAIN FUNCTION //--------------------------------------------------------------------------------------------// void main (void) { do{ ReadGEN_12BIT_ADC(); WriteGEN_12BIT_DAC(adcdata); }while(1); while(!(SPISTATUS &= 0x08)); */ //Read SPI data adcdata= (SPIRXTX1 << 8); adcdata+= SPIRXTX0; adcdata&= 0x0FFF; }//end of ReadGEN_12BIT_ADC //--------------------------------------------------------------------------------------------// // NAME: ReadGEN_12BIT_ADC //--------------------------------------------------------------------------------------------// // DESCRIPTION: // Read the GEN_12BIT_ADC A/D // ADC is connected to SPI interface using CS0 // Max clk speed is 3.2MHz, Fosc = 40MHz assumed //--------------------------------------------------------------------------------------------// void ReadGEN_12BIT_ADC() { int cptr = 0x00; char readflag = 0x00; //SPI Configuration Section //(Can be moved to Main function if only one device is connected to the SPI Interface) //Make sure the SPI Interface is activated PERIPHEN1 |= 0xC0; //--Wait activity stops on the SPI interface (Monitor SPINOCS) while(!(SPISTATUS &= 0x08)); //SPICLK = /16 (2.5MHz) //CS0 Active //SPI Mode 1 Phase = 1, POL = 0 //SPI Master Mode SPICONFIG = 0x40; //SPI Chip select is automatic //Clear SPIUNDEFC Flag //SPILOAD = 0 -> Manual CS3 behaviour //No SPI Interrupt used SPISTATUS = 0x00; //SPI transactions are in MSB First Format SPISIZE = 0x0E; //SPI Transaction Size are 15 bit //-Dummy Read the SPI RX buffer to clear the RXAV Flag readflag = SPIRXTX0; //-Perform the SPI read SPIRXTX0 = 0x00; //Writing to the SPIRXTX0 will trigger the SPI //Transaction //Wait activity stops on the SPI interface //isolate the 12 lsb of the read value //--------------------------------------------------------------------------------------------// // NAME: WriteGEN_12BIT_DAC //--------------------------------------------------------------------------------------------// // DESCRIPTION: // Write 12bit Data into the GEN_12BIT_DAC device // ADC is connected to SPI interface using CS1 // Max clk speed is 12.5MHz, Fosc = 40MHz assumed // We will set the SPI prescaler to sysclk / 8 //--------------------------------------------------------------------------------------------// void WriteGEN_12BIT_DAC(unsigned int dacdata) { char subdata = 0x00; char readflag = 0x00; PERIPHEN1 |= 0xC0; //Make sure the SPI Interface is activated //--Wait activity stops on the SPI interface (Monitor SPINOCS) while(!(SPISTATUS &= 0x08)); //SPI Configuration Section //Can be moved to Main function if only one device is connected to the SPI Interface SPICTRL = 0x4D; //SPICLK = /8 (MHz) //CS1 Active //SPI Mode 1 Phase = 1, POL = 0 //SPI Master Mode SPICONFIG = 0x40; //SPI Chip select is automatic //Clear SPIUNDEFC Flag //SPILOAD = 0 -> Manual CS3 behaviour //No SPI Interrupt used SPISTATUS = 0x00; SPISIZE = 0x0B; //SPI transactions are in MSB First Format //SPI Transaction Size are 12 bit //Read the A/D Converter //write into the D/A Converter }// End of main SPICTRL = 0x65; //least 4 System clock cycles after the Write operation to the SPIRXTX0 register //-Wait for SPINOCS Flag have time to be updated _asm NOP; _endasm; //-Format the 12 bit data so data bit 11 is positioned on bit 7 of SPIRXTX0 // and data bit 0 is positioned on bit 4 of SPIRXTX1 and Perform the SPI write operation dacdata &= 0x0FFF; //Make sure dacdata is <= 0FFFh (12 bit) SPIRXTX3 = 0x00; SPIRXTX2 = 0x00; SPIRXTX1 = (dacdata << 4)&0xF0; //-Dummy Read the SPI RX buffer to clear the RXAV Flag // (Facultative if SPINOCS is monitored) readflag = SPIRXTX0; SPIRXTX0 = dacdata >> 4; //Writing to SPIRXTX0 will trigger the transmission //--Wait the SPI transaction completes // This section can be omitted if a check of activity on the SPI Interface // is made before each access to it in master mode //Wait for the SPI RX AV Flag being set while(!(SPISTATUS &= 0x02)); // -- It is possible to monitor the SPINOCS Flag instead of the SPIRXAV Flag //The code piece below shows how to do it. However in that case, //No that the reading of the SPISTATUS register must be done at //least 4 System clock cycles after the Write operation to the SPIRXTX0 register /* //-Wait for SPINOCS Flag have time to be updated _asm NOP; _endasm; //--Wait activity stops on the SPI interface (monitor SPINOCS Flag) while(!(SPISTATUS &= 0x08)); */ }//end of WriteGEN_12BIT_DAC while(!(SPISTATUS &= 0x02)); //Wait for the SPI RX AV Flag being set /* // -- It is possible to monitor the SPINOCS Flag instead of the SPIRXAV Flag //The code piece below shows how to do it. However in that case, //No that the reading of the SPISTATUS register must be done at ________________________________________________________________________________________________ www.ramtron.com page 55 of 99 VRS51L2070 10 IC Interface 10.3 IC Control and Status Registers The VRS51L2070 includes an IC interface that can operate in master and slave mode. In master mode, the communication speed on the IC is programmable, optimizing communication between IC-based devices. Long or heavily loaded IC bus applications are likely to require slower communication speeds. Four SFR registers are dedicated to the IC interface. The IC configuration register I2CCONFIG enables: * * * * 10.1 IC Bus Pull-Up Resistors By definition, the IC requires that the user include external pull-up resistors on the SCL and SDA lines. The pull-up voltage can be either 3.3 or 5 volts. Note that the VRS51L2070 I/Os are 5V-tolerant making it possible to interface 5V, IC-based devices with the VRS51L2070. The proper value for the pull-up resistor and the proper communication speed depend on bus characteristics such as length and capacitive load. Note that the pull-up resistor value should not be below 1.25K ohms if running the IC bus at 5V; and 750 ohms if operating at 3.3V. This is required in order to limit the current to 4mA (maximum current of the I/O port connected to the IC interface). * Selection of master or slave operation Forcing a start condition after an acknowledge phase Manual control of the SCL line Activation of the master arbitration monitoring mechanism Interrupt activation TABLE 102:I2C CONFIGURATION REGISTER - I2CCONFIG SFR D1H 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 1 R/W 0 R/W 0 Bit Mnemonic Description 7 MASTRARB 6 I2CRXOVEN 5 I2CRXAVEN 4 I2CTXEEN 3 I2CMASTART 2 I2CSCLLOW 1 I2CRXSTOP 0 I2CMODE Master Lost Arbitration and Mechanism and Interrupt 0 = Deactivated 1 = Master lost arbitration monitoring and interrupt is enabled IC RX Overrun Interrupt Enable 0 = IC RX Overrun interrupt is deactivated 1 = IC RX Overrun interrupt is enabled IC RX Available Interrupt Enable 0 = IC RX Available interrupt is deactivated 1 = IC RX Available interrupt is enabled IC TX Empty Interrupt Enable 0 = IC TX empty interrupt is deactivated 1 = IC TX empty interrupt is enabled IC Master Create Start 0 = No start condition is created after data acknowledge phase 1 = Master will create a start condition after the next data acknowledge phase This bit will be cleared when the IC is idle Keep the IC SCL Low Setting this bit to 1 will force the SCL line low. This bit is read by the IC interface when it enters in the data IC. This bit must not be set during the acknowledge phase. IC Reception Stop 0 = The IC received will acknowledge after receiving a byte 1 = The IC receiver will not acknowledge after the next data byte is received I2C Mode Enable 0 = IC interface operates in slave mode 1 = IC Interface operates in master mode 10.2 IC Phases The IC protocol includes five phases: 1. 2. 3. 4. 5. IDLE (SCL = 1, SDA = 1) Device ID Device ID Acknowledge Data Data Acknowledge The VRS51L2070 IC interface has provisions to monitor activity on the IC bus, particularly the data acknowledge phase of a IC transaction. There is also a mechanism that enables the detection of communication errors. The I2CMODE bit of the I2CCONFIG register, when set to 1, will configure the IC interface as a master. In master mode, the VRS51L2070 IC interface controls the IC bus and initiates transmission and reception transactions. In master mode, the IC interface also controls the communication speed. Clearing the I2CMODE bit of the I2CCONFIG register will configure the IC interface as a slave. Slave mode can be useful for applications in which the VRS51L2070 operates as a peripheral in a hostcontrolled system. ________________________________________________________________________________________________ www.ramtron.com page 56 of 99 VRS51L2070 When in master mode, the IC interface can be forced to generate a start condition after the next data acknowledge phase. This is done by setting the I2CMASTART bit to 1. When the MASTRARB bit is set to 1, communications of the IC will be monitored and an interrupt will be generated if arbitration with slave devices on the bus is lost. The interrupt flag associated with this process is the I2CERROR bit of the I2CSTATUS register. If the I2CRXSTOP bit is set to 1, the IC interface will not acknowledge after reception of the next byte, but will generate a stop condition instead. This will, in effect, end the transaction with the master device. When the IC interface is configured as a master and the I2CSCLLOW bit of the I2CCONFIG register is set to 1, the SCL line will be driven low during the next data acknowledge phase. This feature enables the user to add the equivalent of wait states to the transfer in order to support "slow" devices connected to the IC bus. The IC interface includes support for four interrupt conditions via two interrupt vectors. * * * * RX Data Available RX Overrun TX Empty Master lost arbitration TABLE 103: IC INTERRUPT SOURCES I2CCONFIG bit (Set to 1 to activate) RX Data Available RX Overrun I2CRXAVEN TX Empty I2CTXEEN Master Lost Arbitration MASTRARB I2CRXOVEN The I2CTIMING register controls the communication speed when the IC interface is configured in master mode. When in slave mode, it defines the values of the setup and hold times. TABLE 104:IC TIMING REGISTER - I2CTIMING SFR D2H 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 1 R/W 1 R/W 0 R/W 0 Bit Mnemonic Description 7:0 I2CTIMING[7:0] IC master/slave timing configuration register See Below The following formulas demonstrate the impact of the I2CTIMING value on the communication speed and setup/hold times. In master mode: SCL period = I2CCLK 32*( I2CTIMING[7:0] + 1) The following table provides examples of the I2CTIMING values and the corresponding communication speed: TABLE 105: IC COMMUNICATION SPEED VS. I2CTIMING REGISTER VALUE (FOSC = 40MHZ) The following table summarizes the possible interrupt sources at the IC interface level. IC Interrupt 10.4 IC Timing Control Register Interrupt Vector 4Bh (Int 9) 0x4B (Int 9) 0x4B (Int 9) 0x53 (Int 10) To activate the IC interface interrupts, the corresponding enable bit of the I2CCONFIG register must be set to 1. This will allow the IC interrupt to propagate to the VRS51L2070's interrupt controller. In order for the IC interrupt to be recognized by the processor, the corresponding bit of the INTEN2 and INTSRC2 registers must be configured accordingly. See the VRS51L2070 interrupt section for more details. I2CTIMING 00h 02h 0Ch (Reset) 7Ch FFh I2C Com Speed 1.25 MHz 416.77 kHz 96.15 kHz 10kHz 4.88kHz In slave mode: Set-up/Hold Time = I2CCLKperiod * I2CTIMING[7:0] In this case, the precision is: 2 x I2CCLKperiod TABLE 106: IC SETUP AND HOLD TIME I2CTIMING 00h 0Ch FFh VS. I2CTIMING REGISTER VALUE (FOSC = 40MHZ) Setup/Hold Time 0 uS 0.3 uS 6.38 uS ________________________________________________________________________________________________ www.ramtron.com page 57 of 99 VRS51L2070 10.5 IC Slave Device ID and Advanced Configuration 10.6 IC Status Register When operating in slave mode, the device ID on the IC interface is configurable. The seven upper bits of the I2CIDCFG register contain the user-selected device ID. Bit 0 of the I2CIDCFG register has two distinct roles. The I2CAVCFG provides advanced control on IC interface operations. TABLE 107:IC DEVICE ID CONFIGURATION - I2CIDCFG SFR D3H 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic Description 7 0 I2CID[6:0] I2CADVCFG Slave IC device ID as selected by user Read: Indicates that the IC slave has received ID that is different from the I2CID. This flag is cleared when the received ID corresponds with the I2CID Writing: Slave Mode: 1= The I2CRXAV flag is raised when the IC slave receives a device ID Master Mode: 1 = Enables monitoring of the SCL line in wait state mode in case of mismatch of the SCL line vs. the expected value When the IC interface operates in master mode and the I2CADVCFG is cleared, the IC interface module will continuously monitor the SCL line. If the slave device drives the SCL line into an incorrect state, the IC interface will enter wait state mode until the slave device releases the SCL line. This mode can be useful for a IC communication debug. When the I2CADVCFG bit is set, no monitoring of the SCL line will be executed by the IC module and the transaction will proceed independently of the level of the SCL line. Monitoring of the IC interface can be done via the I2CSTATUS register located at SFR address D4h. The I2CSTATUS register is read only and values written into that location have no effect. The I2CERROR flag indicates that an error condition occurred on the IC interface. In master mode, the I2CERROR flag will be set by the VRS51L2070 IC interface, if it loses bus arbitration. In slave mode, if an unexpected stop is received, the I2CERROR flag will be set. The I2CERROR flag will be automatically reset by the IC interface the next time it exits an idle state. If the I2CNOACK flag is set to 1, it signifies that the slave device did not acknowledge the last data byte it received. The IC interface also monitors the synchronization of the SDA line. When synchronization is lost, the I2CSDASYNC bit of the I2CSTATUS register will be set by the IC interface. The I2CSDASYNC bit of the I2CSTATUS register returns the value of the SDA line the moment a read operation is performed on the I2CSTATUS register. The I2CACKPH bit when set, indicates that the IC interface is currently in the data acknowledge phase. Reading of the I2CSDASYNC and I2CCKPH bits can be used to determine whether the slave device has acknowledged. If both bits are set to 1 at a given time, the slave device did not acknowledge. When the VRS51L2070 IC interface module is configured as a slave, reading the I2CADVCFG bit as 1 indicates that the ID received does not match the current device ID. This bit will be cleared when the correct device ID is received. In slave mode, writing a 1 into the I2CADVCFG bit of the I2CIDCFG register will make the I2CRXAVF flag of the I2CSTATUS register remain at 0, after the device ID is received. If the I2CADVCFG bit is cleared, the I2CRXAVF flag will be set either when a correct device ID, or when valid data, are received. ________________________________________________________________________________________________ www.ramtron.com page 58 of 99 VRS51L2070 TABLE 108: IC STATUS REGISTER - I2CSTATUS SFR D4H 7 6 5 4 3 2 1 0 R 0 R 0 R 1 R 0 R 1 R 0 R 0 R 1 Bit Mnemonic 7 I2CERROR 6 I2CNOACK 5 I2CSDASYNC 4 I2CACKPH 3 I2CIDLEF 2 I2CRXOVF 1 I2CRXAVF 0 I2CTXEMPF Description Slave Mode Error Flag: 0 = No Error 1 = Indicates that the IC interface received an unexpected stop This flag is reset the next time the IC interface exits from an idle state (see below) Master Mode 0 = No Arbitration Error 1 = IC interface has lost arbitration This flag is reset the next time the IC interface exits from an idle state (see below) IC Acknowledge Error Flag 0 = Acknowledge was received normally 1 = No acknowledge was received during the last acknowledge phase This flag is reset the next time the IC interface exit from the idle state (see below) IC SDA Sync Status Flag 0 = SDA Pin in not in sync 1 = SDA pin is in sync When set, this flag indicates that the IC interface is in `Data Acknowledge Phase.' 5 phases of IC protocol: 1. Idle 2. Device ID 3. Device ID Acknowledge 4. Data 5. Data Acknowledge IC is idle 0 = IC interface is communicating 1 = IC interface is inactive (idle phase) and the SCL and SDA lines are high IC RX Overrun Interrupt Flag 0 = No IC RX overrun condition detected 1 = IC data collision occurred IC RX Available interrupt Flag 0 = IC receive buffer is empty 1 = Data is present in the IC RX buffer IC TX Empty interrupt Flag 0 = IC transmit buffer is full 1 = IC transmit buffer is ready to receive new data 10.7 IC Transmit/Receive register The IC interface transmit and receive buffers are accessed via the I2CRXTX SFR register, which is accessible at SFR address D5h. TABLE 109:IC DATA RX / TX REGISTER I2CRXTX - SFR D5H 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic Description 7:0 I2CRXTX[7:0] Read: IC Receive Buffer Reading the I2CRXTX register will clear the I2CRXAV and I2CRXOV flags Write: IC Transmit Buffer Writing into the I2CRXTX register will trigger the transmission 10.8 IC Interface alternate pins Upon reset, the IC interface signal SCL and SDA are mapped into pins P3.4 and P3.5, respectively. However it is also possible to map these signal into the P1.6 and P1.7 pins. Bit 5 of the DEVIOMAP register (SFR E1h) is used to configure the mapping of the IC interface at the I/O level, as shown in the following table: TABLE 110: IC MODULE MAPPING DEVIOMAP.5 Bit Value 0 (Reset) 1 SCL Mapping P3.4 P1.6 SDA Mapping P3.5 P1.7 When set, the I2CIDLEF indicates that the IC bus is idle and that a transaction can be initiated. Before initiating an IC data transfer, it is recommended to check the state of the I2CIDLEF bit. This bit indicates whether or not a data transfer is currently in progress. When new data is received in the IC receive buffer, the I2CRXAVF interrupt flag will be set. Data must be retrieved from the I2CRXTX buffer before the reception of the next data byte is complete. The I2CRXOVF flag when set, indicates an overrun condition in the IC interface receive buffer and the data is potentially corrupted. The I2CTXEMPF interrupt flag is set by the IC interface when the transmit data buffer is ready to receive another data byte. ________________________________________________________________________________________________ www.ramtron.com page 59 of 99 VRS51L2070 10.9 IC Interface Example Programs //--Wait for IC IDLE (This will generate a STOP) WaitI2CIDLE(); The following programs provide example code for IC control of EEPROM devices //--Start a Preset ADRS read (This will generate a START) I2CRXTX = eeidw+1; //Write IC device ID + R WaitTXEMP(); I2CCONFIG |= 0x02; //Force IC to Not Acknowledge after //receiving the next data byte WaitRXAV(); //Wait for RX Available bit, This will trigger IC Reception return I2CRXTX; //Return Data Byte //----------------------------------------------------------------------------// // VRS2k-IC _EEPROM.c // //----------------------------------// // // This example program demonstrate the use of the IC // interface to perform basic read and write operations on a // Standard EEPROM device. //----------------------------------------------------------------------------// #include sfr at 0xD1 CALSOSC; //Self Oscillator calibration //----Global variables ------// int cptr = 0x00; //general purpose counter }//End of EERandomRead //--------------------------------------------------------------------------------------------------// //----- Function EERandomWrite(char eeid,char data, int address) ----------// //--------------------------------------------------------------------------------------------------// char EERandomWrite(char eeidw, char eedata, int address){ I2CTIMING = 0x20; // IC Clock Speed = about 100kHz I2CCONFIG = 0x01; //IC is Master I2CRXTX = eeidw; //Write IC device ID + W WaitTXEMP(); // --- Function prototypes char EERandomRead(char,int); char EERandomWrite(char, char, int); void WaitTXEMP(void); void WaitRXAV(void); void WaitI2CIDLE(void); void wait(); I2CRXTX = address >> 8; //Write IC device ID + W WaitTXEMP(); //------------------------------------------------------------// //--------------- MAIN FUNCTION -------------------// //------------------------------------------------------------// void main (void){ return I2CRXTX; PERIPHEN1 = 0x20; INTCONFIG = 0x02; //Write IC device ID + W I2CRXTX = eedata; WaitTXEMP(); //Write IC device data //Return Data Byte }//End of EERandomWrite //Enable IC Interface //Erase Bypass global int, before configuring the INT0 pin event //This fix inadvertent INT0 interrupt that occurs when //INT0 cause is set to Rising edge INTSRC1 = 0x01; INTPINSENS1 = 0x01; INTPININV1 = 0x00; INTEN1 = 0x01; //INT0 vector source = INT0 pin //Set INT0 sensitive on edge(1) or Level(0) //Set INT0 Pin sensitivity on Normal Level(0) / Inverted (1) //Enable INT0 (bit0) Interrupt INTCONFIG = 0x01; //Enable Global interrupt while(1); }//end of Main //----------------------------------------------------------------------------// //------------------------ Interrupt Functions -------------------------// //----------------------------------------------------------------------------// //----------------------------// //---- Interrupt INT0 ----// //---------------------------// void INT0Interrupt(void) interrupt 0 { char x; //--------------------------------------------------// //-------- Function WaitTXEMP() ----------// //--------------------------------------------------// void WaitTXEMP() { wait(); do{ USERFLAGS = I2CSTATUS; USERFLAGS &= 0x01; //isolate the IC TX EMPTY flag }while( USERFLAGS == 0x00); }//end of Void WaitTXEMP() //Wait for IC TX EMPTY //--------------------------------------------------// //-------- Function WaitRXAV() ------------// //--------------------------------------------------// void WaitRXAV() { wait(); do{ USERFLAGS = I2CSTATUS; USERFLAGS &= 0x02; //isolate the I2CRXAV flag }while( USERFLAGS == 0x00); //Wait for IC RX AVAILABLE }//end of Void WaitRXAV() //-- Send IC stuff cptr = 0x00; // Init cptr to pint to message beginning INTEN1 = 0x00; //Disable Interrupts x = EERandomWrite(0xA0, 0x36, 0x0206); Delay1ms(100); x = EERandomRead( 0xA0, 0x0206); I2CRXTX = address; WaitTXEMP(); //Perform Write operation //Perform Read operation INTEN1 = 0x01; //Enable Interrupt INT0 }//end of INT0 interrupt //--------------------------------------------------------------------------// //------------------------ Individual Functions ---------------------// //--------------------------------------------------------------------------// //---------------------------------------------------------------------------------// //---- Function EERandomRead(char eeidw,int address) -----// //---------------------------------------------------------------------------------// char EERandomRead(char eeidw,int address){ I2CTIMING = 0x20; // IC Clock Speed = about 100kHz I2CCONFIG = 0x01; //IC is Master I2CRXTX = eeidw; //Write IC device ID + W WaitTXEMP(); I2CRXTX = address >> 8; //Write IC ADRSH WaitTXEMP(); I2CRXTX = address; //Write IC ADRSL //---------------------------------------------------// //-------- Function WaitI2CIDLE() ---------// //---------------------------------------------------// void WaitI2CIDLE() { wait(); do{ USERFLAGS = I2CSTATUS; USERFLAGS &= 0x08; //isolate the IC idle flag }while( USERFLAGS == 0x00); }//end of Void WaitI2CIDLE() //----------------------------------------// //-------- Function Wait() ----------// //----------------------------------------// void wait(){ char i=0; while (i<25) {i++;}; } ________________________________________________________________________________________________ www.ramtron.com page 60 of 99 VRS51L2070 11 Pulse Width Modulators (PWMs) 11.1 PWM MID and END registers The VRS51L2070 includes eight independent PWM channels, each based on a 16-bit timer. Each PWM module includes two 16-bit registers: All of the PWM modules can be configured to operate as a regular PWM with adjustable resolution, or as a general purpose 16-bit timer. The PWMEN register is used to enable the different PWM modules. TABLE 111: PWM ENABLE REGISTER - PWMEN SFR AAH 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic Description 7 PWM7EN 6 PWM6EN 5 PWM5EN 4 PWM4EN 3 PWM3EN 2 PWM2EN 1 PWM1EN 0 PWM0EN PWM7 Channel Enable 0 = PWM channel 7 is deactivated 1 = PWM channel 7 is activated PWM6 Channel Enable 0 = PWM channel 6 is deactivated 1 = PWM channel 6 is activated PWM5 Channel Enable 0 = PWM channel 5 is deactivated 1 = PWM channel 5 is activated PWM4 Channel Enable 0 = PWM channel 4 is deactivated 1 = PWM channel 4 is activated PWM3 Channel Enable 0 = PWM channel 3 is deactivated 1 = PWM channel 3 is activated PWM2 Channel Enable 0 = PWM channel 2 is deactivated 1 = PWM channel 2 is activated PWM1 Channel Enable 0 = PWM channel 1 is deactivated 1 = PWM channel 1 is activated PWM0 Channel Enable 0 = PWM channel 0 is deactivated 1 = PWM channel 0 is activated o o PWM MID value register PWM END value register The PWM MID register is a 16-bit register that configures the point at which the PWM output will change it's polarity. The PWM END register is a 16-bit register that defines the maximum PWM internal timer count value, after which it rolls over to 0000h. See the following timing diagram. FGURE 28: PWM POLARITY SETTING Cycle 1 Cycle 2 PWMLDPOL = 0 Start 0000h PWM MID Value PWM END value PWM Timer roll over here and the cycle repeats PWMLDPOL = 1 This configuration allows the user to adjust the resolution of the PWM up to 16 bits. Access to the PWM internal registers and the PWM configuration is handled by the PWMCFG register located at address A9h. The following figure provides an overview of the PWM modules. FIGURE 27: PWM MODULES OVERVIEW PWMLDPOL = 1 SYS CLK PWMTMRPR Div Ratio: Sys Clk / 1 Downto Sys Clk / 16384 PWMTMRFx PWM Timer x 0 15 PWMCLRALL CL R > PWM END PWMx MID < PWM MID 1 > PWM MID 0 PWMx Pin PWMx END PWMLDPOLx PWMxTMRENx To others PWM Modules ________________________________________________________________________________________________ www.ramtron.com page 61 of 99 VRS51L2070 TABLE 112:PWM CONFIGURATION REGISTER - PWMCFG SFR A9H TABLE 114:PWM POLARITY AND CONFIG LOAD STATUS - PWMLDPOL ABH 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic 7 6 PWMWAIT 5 PWMCLRALL 4 PWMLSBMSB 3 PWMMIDEND 2:0 PWMCH[2:0] Description PWM Waits Before Loading New Configuration 0 = New PWM configuration is loaded at the end of PWM cycle 1 = The update of the PWM configuration only occurs when the end of the PWM is reached and the bit is set to 0 PWM Clears All Channels 0 = No Action 1 = Simultaneously clears all the flags and all the PWM channel timers This bit is automatically cleared by hardware PWM LSB/MSB Select 0 = Selected PWM LSB SFR is addressed 1 = Selected PWM MSB SFR is addressed PWM MID/END Register 0 = Selected PWM MID SFR is addressed 1 = Selected PWM END SFR is addressed PWM Channel Select 000 = PWM0 on P2.0 (P5.0) 001 = PWM1 on P2.1 (P5.1) 010 = PWM2 on P2.2 (P5.2) 011 = PWM3 on P2.3 (P5.3) 100 = PWM4 on P2.4 (P5.4) 101 = PWM5 on P2.5 (P5.5) 110 = PWM6 on P2.6 (P5.6) 111 = PWM7 on P2.7 (P5.7) The PWM channels are configured one at the time. This topology has been adopted in order to minimize the number of SFR registers required to access the PWM modules. In applications where multiple PWM channels need to be configured simultaneously, the user can set the PWMWAIT bit of the PWMCFG register, configure each one of the PWM channels, and then clear the PWMWAIT bit. The PWM configurations will then be updated at the end of the next PWM cycle, after the PWMWAIT bit has been cleared. Bit Mnemonic Description 7 PWMLDPOL7 6 PWMLDPOL6 5 PWMLDPOL5 4 PWMLDPOL4 Read: 0 = Last configuration has been loaded in PWM 1 = Last configuration has not been loaded Write In PWM Mode 0 = PWM 7 cycle starts with a low level 1 = PWM 7 cycle starts with a high level In Timer Mode 0 = No action 1 = PWM timer 7 value is cleared to 0 Read: 0 = Last configuration has been loaded in PWM 1 = Last configuration has not been loaded Write In PWM Mode 0 = PWM 6 cycle starts with a low level 1 = PWM 6 cycle starts with a high level In Timer Mode 0 = No action 1 = PWM timer 6 value is cleared to 0 Read: 0 = Last configuration has been loaded in PWM 1 = Last configuration has not been loaded Write In PWM Mode 0 = PWM 5 cycle starts with a low level 1 = PWM 5 cycle starts with a high level In Timer Mode 0 = No action 1 = PWM timer 5 value is cleared to 0 Read: 0 = Last configuration has been loaded in PWM 1 = Last configuration has not been loaded Write In PWM Mode 0 = PWM 4 cycle starts with a low level 1 = PWM 4 cycle starts with a high level 3 PWMLDPOL3 2 PWMLDPOL2 TABLE 113:PWM DATA REGISTER SFR ACH 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic Description 7:0 PWMDATA[7:0] PWM Data Register The PWM data register serves to configure the selected channel MSB/LSB value of either the MID or END point, as specified in the PWMCFG register. The PWMIDx defines the actual timer value and the PWMEND defines the maximum timer count value before it rolls over. The PWMLDPOL register controls the output polarity of each one of the PWM modules or clears the timer's value when the PWM modules operate as general purpose timers. 1 PWMLDPOL1 In Timer Mode 0 = No action 1 = PWM timer 4 value is cleared to 0 Read: 0 = Last configuration has been loaded in PWM 1 = Last configuration has not been loaded Write In PWM Mode 0 = PWM 3 cycle starts with a low level 1 = PWM 3 cycle starts with a high level In Timer Mode 0 = No action 1 = PWM timer 3 value is cleared to 0 Read: 0 = Last configuration has been loaded in PWM 1 = Last configuration has not been loaded Write In PWM Mode 0 = PWM 2 cycle starts with a low level 1 = PWM 2 cycle starts with a high level In Timer Mode 0 = No action 1 = PWM timer 2 value is cleared to 0 Read: 0 = Last configuration has been loaded in PWM 1 = Last configuration has not been loaded ________________________________________________________________________________________________ www.ramtron.com page 62 of 99 VRS51L2070 0 PWMLDPOL0 Write In PWM Mode 0 = PWM 1 cycle starts with a low level 1 = PWM 1 cycle starts with a high level In Timer Mode 0 = No action 1 = PWM timer 1 value is cleared to 0 Read: 0 = Last configuration has been loaded in PWM 1 = Last configuration has not been loaded Write In PWM Mode 0 = PWM 0 cycle starts with a low level 1 = PWM 0 cycle starts with a high level 11.3 PWM Alternate Mapping Bit 6 of the DEVIOMAP register (SFR E1h) controls the mapping of the PWM module outputs, as shown in the following table: TABLE 117: PWM MODULES OUTPUT MAPPING DEVIOMAP.6 Bit Value 0 (Reset) 1 PWM 7-0 P2.7 - P2.0 P5.7 - P5.0 Note that the PWM5 and PWM6 outputs have priority over the T0EX and T1EX inputs. In Timer Mode 0 = No action 1 = PWM timer 0 value is cleared to 0 11.2 PWM Module Clock Configuration Register One system clock prescaler is associated with PWM modules 0 to 3, while another is associated with PWM modules 4 to 7. The PWM clock prescalers enables the PWM output frequency to be adjusted to match specific application needs, if required. The PWM clock prescalers are configured via the PWMCLKCFG register. The four upper bits of this register control the clock for PMM modules 4 to 7, and the four lower bits control the clock source for PWM modules 0 to 3. The PWM module clock configuration register controls the prescale value applied to the PWM modules' input clock, when the PWM modules are configured to operate as either PWMs or general purpose timers. TABLE 115: PWM CLOCK PRESCALER CONFIGURATION REGISTER - PWMCLKCFG AFH 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic Description 7:4 U4PWMCLK3[3:0] 3:0 L4PWMCLK3[3:0] PWM Timer 7, 6, 5,:4 Clock Prescaler * see table below PWM Timer 3, 2, 1,:0 Clock Prescaler * see table below The following table shows the system clock division factor applied to the PWM modules for a given PWMCLKCFG nibble. TABLE 116: PWM PRESCALER U4/L4PWMCLK Value (4 bit) 0000 0001 0010 0011 0100 0101 0110 0111 VALUES Clock Prescaler Sys Clk / 1 Sys Clk / 2 Sys Clk / 4 Sys Clk / 8 Sys Clk / 16 Sys Clk / 32 Sys Clk / 64 Sys Clk / 128 U4/L4PWMCLK Value (4 bit) 1000 1001 1010 1011 1100 1101 1110 1111 Clock Prescaler Sys Clk / 256 Sys Clk / 512 Sys Clk / 1024 Sys Clk / 2048 Sys Clk / 4096 Sys Clk / 8192 Sys Clk/ 16384 Sys Clk/ 16384 ________________________________________________________________________________________________ www.ramtron.com page 63 of 99 VRS51L2070 11.4 PWM Examples Program 11.4.1 PWM Basic Configuration The following example program shows the basic configuration of PWM modules #0, 1,2, 4 & 5 //-------------------------------------------------------------------------------------------------------------// // VRS51L2070-PWM_basic_SDCC.c // ////////////////////////////// // // DESCRIPTION: VRS51L2070 PWMs Basic initialization Demonstration Program. // Configure PWM0 as 8 bit resolution (25% duty) // Configure PWM1 as 12 bit resolution (50% duty) // Configure PWM2 as 16 bit resolution (75% duty) // Configure PWM4 as 8 bit resolution and prescaler = 4 (25% duty) // Configure PWM5 as 16 bit resolution and prescaler = 4 (75% duty) //-------------------------------------------------------------------------------------------------------------// // Rev 1.0 // Date: June 2005 //------------------------------------------------------------------------------------// #include PWMDATA = 0x00; PWMCFG = 0x4C; PWMDATA = 0xFF; //Configure PWM4 MID value (duty = 25%) PWMCFG = 0x54; //Point to PWM4 MID MSB PWMDATA = 0x00; //Set PWM MID MSB = 0x00 PWMCFG = 0x44; //Point to PWM4 MID LSB PWMDATA = 0xBF; //Set PWM MID LSB = 0xBF //---------------------------------// //Configure PWM5 END value = 0xFFFF (16bit) (Clock Prescaler = 4) PWMCFG = 0x5D; //Point to PWM5 END MSB PWMDATA = 0xFF; //Set Max Count MSB = 0xFF PWMCFG = 0x4D; //Point to PWM5 END LSB PWMDATA = 0xFF; //Set Max Count = 0xFF //Configure PWM5 MID value (duty = 75%) PWMCFG = 0x55; //Point to PWM5 MID MSB PWMDATA = 0x40; //Set PWM MID MSB = 0x04 PWMCFG = 0x45; //Point to PWM5 MID LSB PWMDATA = 0x00; //Set PWM MID LSB = 0x00 //Enable PWM0, PWM1, PWM2, PWM4 & PWM5 Modules PWMEN = 0x37; PWMCFG &= 0x1F; // --- function prototypes while(1); void delay(unsigned int); }// End of main void main (void) { PERIPHEN2 = 0x02; // Apply a clock prescaler (div / 4) on PWM 7:4 // Configure PWM Polarity PWMPOL = 0x00; //Set all PWM in normal polarity //PWM output = 0 until //PWMMID Value is reached //---------------------------------// //Configure PWM0 END value = 0x00FF (8bit) PWMCFG = 0x58; //Point to PWM0 END MSB PWMDATA = 0x00; //Set Max Count MSB = 0xFF PWMCFG = 0x48; //Point to PWM0 END LSB PWMDATA = 0xFF; //Set PWM MID MSB = 0x00 (8bit) //Configure PWM0 MID value (Duty = 25%) PWMCFG = 0x50; //Point to PWM0 MID MSB PWMDATA = 0x00; //Set PWM MID MSB = 0x00 PWMCFG = 0x40; //Point to PWM0 MID LSB PWMDATA = 0xBF; //Set PWM MID LSB = 0xBF //---------------------------------// //Configure PWM1 END value = 0x0FFF (12bit) PWMCFG = 0x59; //Point to PWM1 END MSB PWMDATA = 0x0F; //Set Max Count MSB = 0x0F PWMCFG = 0x49; //Point to PWM1 END LSB PWMDATA = 0xFF; //Set Max Count = 0xFF //Configure PWM1 MID value (Duty = 50%) PWMCFG = 0x51; //Point to PWM0 MID MSB PWMDATA = 0x08; //Set PWM MID MSB = 0x08 PWMCFG = 0x41; //Point to PWM0 MID LSB PWMDATA = 0x00; //Set PWM MID LSB = 0x00 //---------------------------------// //Configure PWM2 END value = 0xFFFF (16bit) PWMCFG = 0x5A; //Point to PWM2 END MSB PWMDATA = 0xFF; //Set Max Count MSB = 0xFF PWMCFG = 0x4A; //Point to PWM2 END LSB PWMDATA = 0xFF; //Set Max Count = 0xFF //Configure PWM2 MID value (duty = 75%) PWMCFG = 0x52; //Point to PWM2 MID MSB PWMDATA = 0x40; //Set PWM MID MSB = 0x04 PWMCFG = 0x42; //Point to PWM2 MID LSB PWMDATA = 0x00; //Set PWM MID LSB = 0x00 //---------------------------------// //Configure PWM4 END value = 0x00FF (8 bit) (Clock Prescaler = 4) PWMCFG = 0x5C; //Point to PWM4 END MSB //Clear the PWMWAIT bit to initiate //the PWMs operation 11.4.2 PWM Configuration and Control Functions //Enable PWM SFR //CLEAR All PWM Channels PWMCFG = 0x20; // Configure the PWM prescaler PWMCLKCFG = 0x20; //Set Max Count MSB = 0xFF //Point to PWM4 END LSB //Set Max Count LSB = 0xFF //---------------------------------------------------------------------------------------------------// // VRS51L2070-PWM_CFG_function_SDCC.c //--------------------------------------------------------------------------------------------------// // // DESCRIPTION: PWM configuration and control Functions // //-------------------------------------------------------------------------------------------------// // #include // --- functions prototypes void PWMConfig(char channel,int endval,int midval); void PWMdata8bit(char,char); void PWMdata16bit(char,int); void delay(unsigned int); void delay(unsigned int); void main (void) { int cptr = 0x00; // PERIPHEN2 = 0x02; //Enable PWM SFR //CLEAR All PWM Channels PWMCFG = 0x20; // Configure the PWM prescaler PWMCLKCFG = 0x00; // Configure PWM Polarity PWMLDPOL = 0x00; // Apply a clock prescaler (div / 1) on all PWM //Set all PWM in normal polarity //PWM output = 0 until //--Configure PWM5 as 8bit resolution, END = 0xFF, PWM MID = 0x000 PWMConfig(0x05, 0x0FF,0x000); //--Configure PWM0 as 8bit resolution, END = 0xFFF, PWM MID = 0x0000 PWMConfig(0x02, 0xFFF,0x000); //Continuously vary the PWM2 and PWM5 values do{ for(cptr = 0xFF0; cptr > 0x00; cptr--) { PWMdata16bit(0x02,cptr); PWMdata8bit(0x05,cptr>>4); delay(1); } }while(1); ________________________________________________________________________________________________ www.ramtron.com page 64 of 99 VRS51L2070 }// End of main //-----------------------------------------------------------------------// --------Individual Functions ------------------------//-----------------------------------------------------------------------//--------------------------------------------------------------------------------------// // -- PWMConfig // // -------------------------------------------------------------------------------------// // Description: configure PWM channel // //--------------------------------------------------------------------------------------// void PWMConfig(char channel,int endval,int midval) { char pwmch; char pwmready = 0x00; channel &= 0x07; //--------------------------------------------------------------------------------------// // -- PWMdata8bit // // -------------------------------------------------------------------------------------// // Description: Allow PWM channel data update // // ( 8bit data )l // //--------------------------------------------------------------------------------------// void PWMdata8bit(char channel,char pwmdata) { channel &= 0x07; //Make sure PWM ch number <= 7 //--check that te last configuration has been loaded PWMCFG = (channel + 0x40); //Make sure PWM ch number <= 7 PWMDATA = pwmdata; //Wait Last configuration to be loaded do{ pwmready = PWMLDPOL; }while(pwmready != 0x00); PWMCFG &= 0x3F; //Write new value in PWM Config //prevent PWM configuration to be loaded //before the configure sequence is completed //Write new Data into the PWM registers //Allows PWM update upon end of next PWM cycle }//end of PWMData8bit() //Define PWM Enable section PERIPHEN2 |= 0x02; //Enable PWM SFR //--Define the value to put into the PWMEN register switch(channel) { case 0x00 : pwmch = 0x01; break; case 0x01 : pwmch = 0x02; break; case 0x02 : pwmch = 0x04; break; case 0x03 : pwmch = 0x08; break; case 0x04 : pwmch = 0x10; break; case 0x05 : pwmch = 0x20; break; case 0x06 : pwmch = 0x40; break; case 0x07 : pwmch = 0x80; break; }//end of switch //--------------------------------------------------------------------------------------// // -- PWMdata16bit // // -------------------------------------------------------------------------------------// // Description: Allow PWM channel data update // // ( 16bit data )l // //--------------------------------------------------------------------------------------// void PWMdata16bit(char channel,int pwmdata) { channel &= 0x07; PWMCFG = (channel + 0x50); PWMDATA = pwmdata >>8; PWMCFG &= 0xEF; //Set PWM configuration register to point to //the LSB of Data value PWMDATA = pwmdata; PWMCFG &= 0x3F; PWMEN |= pwmch; //Make sure PWM ch number <= 7 //Set PWM configuration register to point to //the MSB of Data value and set the PWMWAIT bit //and set the PWMWAIT bit to prevent the //PWM configuration to be loaded //before the configure sequence is completed //Allows PWM update upon end of next PWM cycle //Enable the Selected channel }//end of PWMData16bit() //Configure PWM END point PWMCFG = (channel + 0x58); //Set PWM configuration register to point to //the MSB of End value and set the PWMWAIT bit //to prevent the PWM configuration to be loaded //before the configure sequence is completed PWMDATA = endval >> 8; PWMCFG &= 0xEF; //Set PWM configuration register to point to //the LSB of End value PWMDATA = endval; //Configure PWM MID point PWMCFG = (channel + 0x50); //Set PWM configuration register to point to //the MSB of MID value and set the PWMWAIT bit //to prevent the PWM configuration to be loaded //before the configure sequence is completed PWMDATA = midval >> 8; PWMCFG &= 0xEF; //Set PWM configuration register to point to //the LSB of End value PWMDATA = midval; PWMCFG &= 0x3F; }//end of PWMData16bit() //;--------------------------------------------------------------------------------// //;- DELAY1MSTO : 1MS DELAY USING TIMER0 // //; // //; CALIBRATED FOR 40MHZ // //;--------------------------------------------------------------------------------// void delay(unsigned int dlais){ idata unsigned char x=0; idata unsigned int dlaisloop; x = PERIPHEN1; x |= 0x01; PERIPHEN1 = x; dlaisloop = dlais; while ( dlaisloop > 0) { TH0 = 0x63; TL0 = 0xC0; T0T1CLKCFG = 0x00; T0CON = 0x04; //LOAD PERIPHEN1 REG //ENABLE TIMER 0 //TIMER0 RELOAD VALUE FOR 1MS AT 40MHZ //NO PRESCALER FOR TIMER 0 CLOCK //START TIMER 0, COUNT UP //Allows PWM update upon end of next PWM cycle do{ x=T0CON; x= x & 0x80; }while(x==0); T0CON = 0x00; dlaisloop = dlaisloop-1; }//end of while dlais... x = PERIPHEN1; x = x & 0xFE; PERIPHEN1 = x; }//End of function delais //Stop Timer 0 //LOAD PERIPHEN1 REG //DISABLEBLE TIMER 0 ________________________________________________________________________________________________ www.ramtron.com page 65 of 99 VRS51L2070 11.5 Using PWM Modules as Timers By appropriately configuring the PWMTMREN SFR, the PWM modules can also operate as general purpose 16-bit timers. The following table describes the PWMTMREN register: TABLE 118: PWM TIMER MODE ENABLE REGISTER - PWMTMREN SFR ADH 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic 7 PWM7TMREN 6 PWM6TMREN 5 PWM5TMREN 4 PWM4TMREN 3 PWM3TMREN 2 PWM2TMREN 1 PWM1TMREN 0 PWM0TMREN TABLE 120: PWM TIMER FLAGS REGISTER - PWMTMRF SFR AEH 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic 7 PWM7TMRF 6 PWM6TMRF 5 PWM5TMRF 4 PWM4TMRF 3 PWM3TMRF 2 PWM2TMRF 1 PWM1TMRF 0 PWM0TMRF Description PWM 7 Module Operating Mode 0 = PWM 7 module is configured as PWM 1 = PWM 7 module is configured as timer PWM 6 Module Operating Mode 0 = PWM 6 module is configured as PWM 1 = PWM 6 module is configured as timer PWM 5 Module Operating Mode 0 = PWM 5 module is configured as PWM 1 = PWM 5 module is configured as timer PWM 4 Module Operating Mode 0 = PWM 4 module is configured as PWM 1 = PWM 4 module is configured as timer PWM 3 Module Operating Mode 0 = PWM 3 module is configured as PWM 1 = PWM 3 module is configured as timer PWM 2 Module Operating Mode 0 = PWM 2 module is configured as PWM 1 = PWM 2 module is configured as timer PWM 1 Module Operating Mode 0 = PWM 1 module is configured as PWM 1 = PWM 1 module is configured as timer PWM 0 Module Operating Mode 0 = PWM 0 module is configured as PWM 1 = PWM 0 module is configured as timer When operating in timer mode, the PWM module timer will count from 0000h up to the maximum PWM timer value defined by the PWM MID sub registers, which are accessible through the PWMCFG register. TABLE 119: SUMMARY OF PWM MID SUB REGISTERS ACCESS PWM timer MSB max count value PWM timer MSB max count value The PWM timer flags are raised when the timer reaches the maximum value set by PWMMIDH and PWMMIDL, and then it is reset and starts again. PWMCFG bit PWMLSBMSB 0 PWMCFG bit PWMMIDEND 1 Description PWM 7 Module Timer Flag 0 = No Overflow 1 = PWM Timer 7 Overflow PWM 6 Module Timer Flag 0 = No overflow 1 = PWM Timer 6 Overflow PWM 5 Module Timer Flag 0 = No Overflow 1 = PWM Timer 5 Overflow PWM 4 Module Timer Flag 0 = No Overflow 1 = PWM Timer 4 Overflow PWM 3 Module Timer Flag 0 = No Overflow 1 = PWM Timer 3 Overflow PWM 2 Module Timer Flag 0 = No Overflow 1 = PWM Timer 2 Overflow PWM 1 Module Timer Flag 0 = No Overflow 1 = PWM Timer 1 Overflow PWM 0 Module Timer Flag 0 = No Overflow 1 = PWM Timer 0 Overflow FIGURE 29: PWM AS TIMERS OVERVIEW SYS CLK PERIPHEN2 PWMEN PWMTMRPR(7:4) Div Ratio: Sys Clk / 1 Downto Sys Clk / 16384 PWM7 Module PWM7 Pin PWM6 Module PWM6 Pin PWM5 Module PWM5 Pin PWM4 Module PWM4 Pin PWM3 Module PWM3 Pin PWM2 Module PWM2 Pin PWM1 Module PWM1 Pin PWM0 Module PWM0 Pin PWM7EN PWM6EN PWM5EN PWM4EN PWMTMRPR(3:0) Div Ratio: Sys Clk / 1 Downto Sys Clk / 16384 PWM3EN PWM2EN PWM1EN PWM0EN 1 1 Once the PWM MID value is reached, the PWM timer overflow is set and the PWM timer rolls over to 0000h. ________________________________________________________________________________________________ www.ramtron.com page 66 of 99 VRS51L2070 11.6 Configuring the PWM Timers Configuring the PWM modules to operate in PWM timer mode requires the following steps: 1. Activate the PWMSFR register 2. Configure the PWM clock prescaler (if required) 3. Set the PWMLDPOL register to 00h 4. Configure the PWM timer maximum count value by setting the PWM MID sub-registers 5. Configure the PWM timer interrupts (if required) 6. Configure the PWM modules as timers 7. Enable the PWM modules Follow the code example below to perform these seven steps : (...) PERIPHEN2 |= 0x02; //Enable PWM SFR //--Configure the PWM prescaler PWMCLKCFG = 0x03; //Apply a clock prescaler (div / 8) on PWM 3:0 //--Configure PWM Polarity PWMLDPOL = 0x00; //Set all PWM in normal polarity //PWM output = 0 until //--Configure PWM5 as timer // PWM Timer 5 counts from 0000 to F000h PWMCFG = 0x15; //Point to MSB MID PWMDATA = 0xF0; //Set PWM as Timer Max MSB PWMCFG = 0x05; PWMDATA = 0x00; //Point to LSB MID //Set PWM as Timer Max LSB //--Configure and Enable PWM as timer Interrupt to monitor PWM5 only INTSRC2 &= 0xDF; //PWM7:4 Timer module interrupt INTPINSENS1 = 0xDF; // sensitive on high level(0) INTPININV1 = 0xDF; //Set INT0 Pin sensitivity on normal level(0) INTEN2 |= 0x20; //Enable PWM7:4 Timer module interrupt #include void main (void) { int cptr = 0x00; char flagread; PERIPHEN2 |= 0x02; //Enable PWM SFR //Configure Port1 as output P1PINCFG = 0x00; //Clear All PWM Channels // PWMCFG = 0x20; // Configure the PWM prescaler PWMCLKCFG = 0x03; //--Configure PWM0 as Timer (will be monitored by pooling) // PWM Timer 0 counts from 0000 to 01F0h PWMCFG = 0x10; PWMDATA = 0x01; //Point to MSB MID PWMCFG = 0x00; PWMDATA = 0xF0; //Point to LSB MID //--Activate the PWM modules and configure the PWM modules as timers PWMEN |= 0x01; PWMTMREN |= 0x01; //Enable PWM 0 as Timer //--Configure PWM5 as Timer (will be monitored by interrupt) // PWM Timer 5 counts from 0000 to F000h PWMCFG = 0x15; //Point to MSB MID PWMDATA = 0xF0; // PWMCFG = 0x05; PWMDATA = 0x00; //Point to LSB MID //--Configure and enable PWM as timer interrupt to monitor PWM5 only INTSRC2 &= 0xDF; //PWM7:4 Timer module interrupt INTPINSENS1 = 0xDF; // sensitive on high level(0) INTPININV1 = 0xDF; //Set INT0 Pin sensitivity on normal level(0) INTEN2 |= 0x20; //Enable PWM7:4 timer module interrupt //--Activate the PWM modules and configure the PWM modules as timers PWMEN |= 0x20; //Enable PWM 5 PWMTMREN |= 0x20; //Enable PWM 5 as Timer GENINTEN = 0x03; //--Activate the PWM module and cofigure the PWM modules 5 as timer PWMEN |= 0x20; //Enable PWM 5 PWMTMREN |= 0x20; //Enable PWM 5 as Timer GENINTEN = 0x03; //Enable Global interrupt 11.7 PWMs as Timers Example Programs 11.7.1 Configuring PWM0 and PWM5 as Timers The following example program demonstrates how to initialize PWM0 and PWM5 as general purpose timers, and how to monitor the PWM timer's overflow flags by pooling or via an interrupt. //--------------------------------------------------------------------------------------------------------------// // VRS51L2070-PWM_as_Timer1_SDCC.c.c // //-------------------------------------------------------------------------------------------------------------// // // DESCRIPTION: PWM as Timer Example Program // Enable and configure PWM Timer 0 // Apply a clock prescaler on PWM Timer 0 (div/8) // Enable and configure PWM Timer 5 // Monitor PWM Timer 0 OV Flag by pooling // When PWM Timer 0 Overflow, toggle P1.0 pin // Monitor PWM Timer 5 OV Flag by interrupt // When PWM Timer 5 Overflow interrupt occurs toggle P1.5 pin ///-------------------------------------------------------------------------------------------------------------// // Apply a clock prescaler (div / 8) on PWM 3:0 // Configure PWM Polarity PWMLDPOL = 0x00; //Set all PWM in normal polarity //PWM output = 0 until //Enable global interrupt while(1){ //Wait for PWM0 as timer overflow Flag PWM0 timer flag pooled do { flagread = PWMTMRF; flagread &=0x01; }while(flagread == 0); PWMTMRF &= 0xFE; P1 = P1^0x01; }//end of while(1) //Clear the PWM0 Timer Flag //Toggle P1.0 }// End of main //------------------------------------------------------ // //----- Interrupt INT13 - PWM7:4 as Timer // //------------------------------------------------------// void INT13Interrupt(void) interrupt 13 { char flagread; INTEN2 = 0x00; //Disable PWM7:4 Timer module interrupt flagread = PWMTMRF; flagread &= 0x20; if(flagread != 0x00) P1 = P1^0x20; //Read PWM Timer OV Flags //Check if PWM Timer 5 OV Flag is active PWMTMRF &= 0xDF; //Clear the PWM Timer 5 OV Flag INTEN2 |= 0x20; //Toggle P1.5 //Enable PWM7:4 Timer module interrupt }//end of INT0 interrupt ________________________________________________________________________________________________ www.ramtron.com page 67 of 99 VRS51L2070 12 Enhanced Arithmetic Unit 12.2 Arithmetic Unit Control Registers The VRS51L2070 includes a hardware-based, enhanced arithmetic unit, which enables fast arithmetic operations. This arithmetic unit is similar to the MULT/ACCU unit on the Versa Mix 8051, with the added ability to support 16-bit division. With the exception of the barrel shifter, the arithmetic unit's operation is controlled by two SFR registers: 12.1 VRS51L2070 Arithmetic Unit Features The main features of the arithmetic unit are: o o o o o o o o o o o Hardware calculation engine Calculation result is ready as soon as the input registers are loaded Signed mathematical calculations Unsigned MATH operations are possible if the MUL engine operands are limited to 15 bits in length Auto/Manual reload of AU result register Easy implementation of complex mathematical operations 16-bit and 32-bit overflow flag 32-bit overflow can set an interrupt Arithmetic unit operand registers can be cleared individually or simultaneously Overflow flags can be configured to stay active until manually cleared Can store and use results from previous operations o o AUCONFIG1 AUCONFIG2 The following tables describe these control registers: TABLE 121: ARITHMETIC CONFIG REGISTER 1 - AUCONFIG1 SFR C2H 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit 7 Mnemonic CAPPREV 6 CAPMODE 5 OVCAPEN 4 READCAP 3:2 ADDSRC[1:0] Read: Always Read as 0 Capture Previous Result Enable 0 = Previous result capture is disabled 1 = Capture the previous result if CAPMODE bit is set to 1 0 = The capture of previous result is automatic each time a write operation is done to the AU0 1 = The capture of the previous result is manual and occurs when the CAPPREV bit is set to 1 Capture Result on 32-Bit Overflow 0 = No result capture is performed 1 = The AU result is captured and stored when a 32-bit overflow condition occurs Read Stored Result 0 = AURES contains current operation result 1 = AURES contains previous result AU Adder Input n MULCMD[1:0] 32-bit Addition Source B Input 00 = 0 (No Add) 01 = C (std 32-bit reg) 10 = AUPREV 11 = AUC (std 32-bit reg) A Input 00=Multiplication 01=Multiplication 10=Multiplication 11= Concatenation of {A, B} + C for 32-bit addition AU Multiplication Command The arithmetic unit can be configured to perform the following operations: FIGURE 30: VRS51L2070 ARITHMETIC UNIT OPERATIONS ADD32 + ADD32 (AUA, AUB) + AUC = AURES 1:0 Div16 (AUA / AUB) = AURES (AUA x AUB) + AUC = AURES = AURES = AURES (AUA x AUB) + 0 (AUA x AUB) + AUPREV MULT16 + ADD32 (AUA x AUA) + AUC (AUA x AUA) + 0 (AUA x AUA) + AUPREV (AUA x AUPREV(16lsb) + AUC (AUA x AUPREV(16lsb) + 0 (AUA x AUPREV(16lsb) + AUPREV = AURES = AURES = AURES Description 00 = AUA x AUB 01 = AUA x AUA 10 = AUA x AUPREV (16 LSB) 11 = AUA x AUB Notes In Divider Mode MULTA_IN = MULT_IN = 0x0000 In Multiplier Mode DIVA_IN = 0x0000 and DIVB_IN = 0x0001 = AURES = AURES = AURES Where AUA (multiplier), AUB (multiplicand), AUC (accumulator), AURES (result) and AUPREV (previous result) are 16, 16, 32, 32 and 32-bits wide, respectively. ________________________________________________________________________________________________ www.ramtron.com page 68 of 99 VRS51L2070 TABLE 122: ARITHMETIC CONFIG REGISTER 2 - AUCONFIG2 SFR C3H 7 6 5 4 3 2 1 0 W 0 W 0 W 0 R/W 0 R 0 R 0 R 0 R 0 Bit Mnemonic Description 7:5 AUREGCLR [2:0] Read: Always read as 0 Arithmetic Unit Operand Registers Clear 000 = No clear 001 = Clear AUA 010 = Clear AUB 011 = Clear AUC 100 = Clear AUPREV 101 = Clear all AU module registers and overflow flags 110 = Clear overflow flags only Arithmetic Unit Interrupt Enable 0 = Arithmetic unit interrupt is disabled 1 =-Arithmetic unit interrupt is enabled in divider mode Not used, Read as 0 AU division is out of range flag This flag is set if AUB = 0x0000 or (AUA = 0x8000 and AUB = 0xFFFF) Arithmetic Unit 16-Bit Overflow Flag 0 = No 16 bit overflow condition detected 1 = a 16-bit overflow occurred Will occur if there is a carry on from bit 15 to bit 1,6 but also from bit 31 to bit 32 Arithmetic Unit 32-Bit Overflow Flag 0 = No 16 bit overflow condition detected 1 = Operation result is larger than 32 bits 4 3 2 1 0 AUINTEN DIVOUTRG AUOV16 AUOV32 12.4 AUA and AUB Multiplication (Addition) Input Registers The AUA and AUB registers serve as 16-bit input operands when performing multiplication. When the arithmetic unit is configured to perform 32-bit addition, the AUA and the AUB registers are concatenated. In this case, the AUA register contains the upper 16 bits of the 32-bit operand and the AUB contains the lower 16 bits. TABLE 123: ARITHMETIC UNIT A REGISTER BIT [7:0] - AUA0 SFR A2H 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic Description 7:0 AUA[7:0] LSB of the A Operand Register TABLE 124: ARITHMETIC UNIT A REGISTER BIT [15:8]- AUA1 SFR A3H 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic Description 7:0 AUA[15:8] MSB of the A Operand Register TABLE 125:ARITHMETIC UNIT B REGISTER BIT [7:0] - AUB0 SFR B2H 12.3 Arithmetic Unit Data Registers The arithmetic unit data registers include operand and result registers that serve to store the numbers being manipulated in mathematical operations. Some of these registers are uniquely for addition (such as AUC), while others can be used for all operations. The use of the arithmetic unit operation registers is described in the following sections. 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic Description 7:0 AUB[7:0] LSB of the B Operand Register for Multiplication and Addition Operations TABLE 126:ARITHMETIC UNIT DIVISION MODE REGISTER - AUB0DIV SFR B1H 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic Description 7:0 AUB0DIV[7:0] Writing to this byte instead of AUB0 will set the arithmetic unit to divisor mode TABLE 127: ARITHMETIC UNIT B REGISTER BIT [15:8] - AUB1 SFR B3H 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic Description 7:0 AUB[15:8] MSB of the B Operand Register ________________________________________________________________________________________________ www.ramtron.com page 69 of 99 VRS51L2070 12.5 AUC Input Register TABLE 132: ARITHMETIC UNIT RESULT REGISTER BIT [7:0] - AURES0 SFR B4H The AUC register is a 32-bit register used to perform 32-bit addition. The AUPREV register can be substituted with the AUC register or by 0 in the 32-bit addition. TABLE 128:ARITHMETIC UNIT C REGISTER BIT [7:0] - AUC0 SFR A4H 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic Description 7:0 AUC[7:0] Bit [7:0]of the C Operand Register TABLE 129: ARITHMETIC UNIT C REGISTER BIT [15:8] - AUC1 SFR A5H 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic Description 7:0 AUC[15:8] Bit [15:8] of the C Operand Register TABLE 130:ARITHMETIC UNIT C REGISTER BIT [23:16] - AUC2 SFR A6H 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic Description 7:0 AUC[23:16] Bit [23:16] of the C Operand Register TABLE 131:ARITHMETIC UNIT C REGISTER BIT [31:24] - AUC3 7 6 5 4 3 2 1 0 R 0 R 0 R 0 R 0 R 0 R 0 R 0 R 0 Bit Mnemonic Description 7:0 AURES[7:0] Bit [7:0]of the RESULT Register TABLE 133: ARITHMETIC UNIT RESULT REGISTER BIT [15:8] - AURES1 SFR 5H 7 6 5 4 3 2 1 0 R 0 R 0 R 0 R 0 R 0 R 0 R 0 R 0 Bit Mnemonic Description 7:0 AURES[15:8] Bit [15:8] of the RESULT Register TABLE 134: ARITHMETIC UNIT RESULT REGISTER BIT [23:16] - AURES2 SFR B6H 7 6 5 4 3 2 1 0 R 0 R 0 R 0 R 0 R 0 R 0 R 0 R 0 Bit Mnemonic Description 7:0 AURES[23:16] Bit [23:16] of the RESULT Register TABLE 135: ARITHMETIC UNIT RESULT REGISTER BIT [31:24] - AURES3 SFR B7H 7 6 5 4 3 2 1 0 R 0 R 0 R 0 R 0 R 0 R 0 R 0 R 0 Bit Mnemonic Description 7:0 AURES[31:24] Bit [31:24] of the RESULT Register SFR A7H 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic Description 7:0 AUC[31:24] Bit [31:24] of the C Operand Register 12.6 The Arithmetic Unit AURES Register The AURES register, which is 32 bits wide, is read-only and contains the result of the last arithmetic unit operation. The AURES register is located at the output of the barrel shifter. When the arithmetic unit is configured to perform multiplication and/or addition, the AURES operates as a 32-bit register that contains the result of the previous operation(s). However when the arithmetic unit has performed a 16bit division, the upper 16 bits of the AURES register contain the quotient of the operation, while the lower 16 bits contain the remainder of the division operation. The barrel shifter is deactivated when the arithmetic unit is performing 16-bit division. Four SFR registers located in SFR Page 1 provide access to the arithmetic unit AURES register. ________________________________________________________________________________________________ www.ramtron.com page 70 of 99 VRS51L2070 12.7 AUPREV Register The AUPREV register can automatically or manually save the contents of the AURES register and re-inject it into the calculation. This feature is especially useful in applications where the result of a given operation serves as one of the operands for the next one. 12.8 Multiplication and Accumulate Operations The multiplication and accumulate operations of the arithmetic unit are defined by the MULCMD[1:0] and ADDSRC[1:0] bits of the AUCONFIG1 register. TABLE 140: MULTIPLICATION OPERATIONS VS. MULCMD BIT OF THE AUCONFIG1 As previously mentioned, there are two ways to load the AUPREV register. This is controlled by the CAPMODE bit value as follows: MULCMD[1:0] 00 01 10 11 CAPMODE = 0: Auto AUPREV load, by writing into the AUA0 register. Selected when CAPPREV = 0. CAPMODE = 1: Manual load of AUPREV when the CAPPREV bit is set to 1. TABLE 141: ADDITION OPERATIONS VS. ADDSRC BIT OF THE AUCONFIG1 ADDSRC[1:0] 00 01 10 11 Auto loading of the AUPREV register is useful in FIR filter calculations. For example, it is possible to save a total of eight MOV operations per tap calculation. TABLE 136: ARITHMETIC UNIT PREVIOUS RESULT BIT [7:0] - AUPREV0 SFR C4H 7 6 5 4 3 2 1 0 R 0 R 0 R 0 R 0 R 0 R 0 R 0 R 0 Multiplication Operation AUA x AUB AUA x AUA AUA x AUPREV (16LSB) AUA x AUA Addition operation No addition AUC AUPREV[31:0] 32-bit addition [AUA,AUB] + AUC The following figure provides a block diagram representation of the arithmetic unit operation for multiplication and addition. FIGURE 31: ARITHMETIC UNIT MULTIPLICATION AND ADDITION OVERVIEW Bit Mnemonic Description 7:0 AUPREV[7:0] Bit [7:0]of the Previous Result Register Adder1 MS B LSB AUA1 AUA0 AUB1 AUB0 Adder =11 TABLE 137:ARITHMETIC UNIT PREVIOUS RESULT BIT [15:8] - AUPREV1 SFR C5H 7 R 0 Bit 7:0 6 R 0 5 R 0 Mnemonic AUPREV[15:8] 4 R 0 3 2 R 0 R 0 1 0 R 0 R 0 Multiplicand 1 MS B LSB AUA1 AUA0 6 5 4 3 2 1 0 R 0 R 0 R 0 R 0 R 0 R 0 R 0 R 0 Bit Mnemonic Description 7:0 AUPREV[23:16] Bit [23:16] of the Previous Result Register BIT [31:24] - AUPREV3 SFR C7H 7 6 5 4 3 2 1 0 R 0 R 0 R 0 R 0 R 0 R 0 R 0 R 0 Bit Mnemonic Description 7:0 AUPREV[31:24] Bit [31:24] of the Previous Result Register = 10 01 00 ADDSRC{1:0} 0 00 AUA(1:0) 01 AUC(3:0) 01 AUPREV(3:0) 10 AUPREV(3:0) 10 AUB(1:0) 11 32 bit Add {AUA,AUB} + AUC 11 SFR C6H 7 TABLE 139:ARITHMETIC UNIT PREVIOUS RESULT x LSB LSB 00 Bit [15:8] of the Previous Result Register BIT [23:16] - AUPREV2 + Multiplicand 2 MS B MS B AUB(1:0) Description TABLE 138:ARITHMETIC UNIT PREVIOUS RESULT of MULCMD{1:0} ADDSRC{1:0} Barrel Shifter AUSHIFTCFG MS B AURES(3:0) LSB The following table provides examples of the AUCONFIG and AUSHIFTCFG register values and the corresponding math operations performed by the arithmetic unit. It also provides the value that would be present in the AURES register if the arithmetic unit input registers were initialized to the following values: * * * * AUA = 3322h AUB = 4411h AUC = 11111111h AUPREV = 12345678h ________________________________________________________________________________________________ www.ramtron.com page 71 of 99 VRS51L2070 TABLE 142:CONFIGURATION OF THE ARITHMETIC UNIT, OPERATION AND OUTPUT RESULT 12.10 Barrel Shifter AUCONFIG1 00h 00h 00h 00h 00h AURES 0A369084h 0D986D42h 0D986D42h 114563F0h 44335522h The arithmetic unit includes a 32-bit barrel shifter at the output of the 32-bit addition unit. The barrel shifter is used to perform right/left shift operations on the arithmetic unit output. The shift operation takes only one cycle. 1EA97E53h 3D52FCA6h The barrel shifter can be used to scale the output result of the arithmetic unit. F54BF29h The shifting range is adjustable from 0 to 16 in both directions. The "shifted" value can be routed to: 00h 01h AUCONFIG1 01h 00h 03h 02h 0Ch, 0Dh,0Eh,0Fh 04h 04h 3Fh 04h Operation AUA x AU! AUA x AUB AUA x AUB AUA x AUPREV15:0 (AUA,AUB) + AUC ] 32 bit addition (AUA x AUB)+ AUC ((AUA x AUB)+ AUC) x 2 (shift 2 left) ((AUA x AUB)+ AUC) / 2 (shift 2 right) o o o Multiplication and accumulate operations take place within one system clock cycle. Moreover, the shift left operation can be configured as an arithmetic or logical shift, in which the sign bit is discarded. 12.9 Division Operation (AUA / AUB1:AUB0DIV) The VRS51L2070 arithmetic unit can be configured to perform 16-bit division operations: the division of AUA by AUB1,AUB0DIV. The quotient of this operation is stored in the AURES3, AURES2 registers, with the remainder stored in the AURES1, AURES0 registers The following figure represents a 16-bit division. FIGURE 32: ARITHMETIC UNIT DIVISION OVERVIEW Division operation is triggered by writing LSB of divisor into the AUB0DIV register Divisor Dividend MSB LSB MSB LSB AUA1 AUA0 AUA1 AUB0DIV Quotient AURES AUPREV AUOV32 Remainder MSB LSB MSB LSB AURES3 AURES2 AURES1 AURES0 Writing the LSB of the divisor into the AUB0DIV register will trigger a division operation. Once the division starts, the value written in the AUB0DIV register will be automatically transferred into the AUB0 register. This operation is neither affected by the barrel shifter nor the multiplication/addition operation, defined by the AUCONFIG register. TABLE 143: ARITHMETIC UNIT SHIFT REGISTER CONFIG - AUSHIFTCFG SFR C1H 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic Description 7 SHIFTMODE 6 ARITHSHIFT 5:0 SHIFT[5:0] AU Barrel SHIFTER Shift Mode 0 = Shift value is unsigned 1 = Shift value is signed AU Arithmetic Shift Enable 0 = Left shift is considered as logical shift (sign bit is lost) 1 = Left shift is arithmetic shift where sign bit is kept The value of SHIFT[5:0] equals the amplitude of the shift performed on the arithmetic unit result register AURES Positive value represent shift to the left Negative value represent shift to the right The barrel shifter section operates independently of the multiply and accumulate sections on the arithmetic unit. As such, if the AUSHIFTCFG register bits 5:0 are set to a value other than 0, the value of AUPREV, if derived from the AURES register either automatically or manually, will be affected by the barrel shifter. When the arithmetic unit is configured to perform multiplication and addition operations, the barrel shifter is active and the shift operation performed depends on the current value of the AUSHIFTCFG register. When the arithmetic unit is configured to perform 16-bit division, the barrel shifter is deactivated. The division operation takes five system clock cycles to be complete. ________________________________________________________________________________________________ www.ramtron.com page 72 of 99 VRS51L2070 12.11 VRS51L2070 Arithmetic Unit Block Diagram The following block diagram provides a hardware description of the registers and the other components that comprise the arithmetic unit on the VRS51L2070. FIGURE 33: ARITHMETIC UNIT FUNCTIONAL DIAGRAM Multiplication / Addition addsrc Concatenation (A,B) AUOV3 2 SFR registers B AUA1 (MSB) SHIFTMODE ADD MSB ov16 a SFR registers A AUA AUOV1 6 MUL (Signed) AUB SHIFT AURES (SFR regs) AURES B AUA0 (LSB) ADD LSB A RDSTORED AUC MANLOOP AURES1 0 AUB0 (LSB) AUA0 load AURES0 (LSB) CAPPREV addsrc AUB0DIV (LSB) (16 LSB) AUPREV load Stored Result Previous AUPREV3 (MSB) AUPREV2 AUC3 (MSB) AUC2 AURES2 mulcmd AUB1 (MSB) *For Division Operations Only AURES3 (MSB) OVCAPEN AUOV3 2 AUPREV1 16 bit Division AUPREV0 (LSB) DIVOUTRG AUC1 AUA AUC0 (LSB) AUB AUA DIV by AUB (Signed) Quotient AURES(3:2) Arithmetic Unit Control SFR Remainder AURES(1:0) AUCONFIG1 AUCONFIG2 AUSHIFTCFG ________________________________________________________________________________________________ www.ramtron.com page 73 of 99 VRS51L2070 12.12 Arithmetic Unit Example Programs 12.12.1 Basic Arithmetic Operations Using the Arithmetic Unit The following example program demonstrates the required arithmetic unit configuration to perform mathematical operations //----------------------------------------------------------------------------------------------/ // VRS51L2070_MULTACCU1_SDCC.c // //----------------------------------------------------------------------------------------------/ // // DESCRIPTION: VRS51L2070 Arithmetic Unit Demonstration Program // //----------------------------------------------------------------------------------------------/ #include //-------------------------------------------------------------/ // MAIN FUNCTION //-------------------------------------------------------------/ void main (void) { PERIPHEN2 = 0x20; //Enable Arithmetic Unit DEVMEMCFG = 0x01; //SELECT SFR PAGE 1 //Configure Arithmetic Unit to perform math operations //Place Value in AUA AUA1 = 0x33; AUA0 = 0x22; //Place Value in AUB AUB1 = 0x44; AUB0 = 0x11; //Place Value in AUC AUC3 = 0x11; AUC2 = 0x11; AUC1 = 0x11; AUC0 = 0x11; //Place Value in AUPREV AUPREV3 = 0x12; AUPREV2 = 0x34; AUPREV1 = 0x56; AUPREV0 = 0x78; //--Some operation examples-// To perform: [(AUAxAUA)+0] AUCONFIG1 = 0x01; //Set operation (AUA x AUA) + 0 //AURES = 0A369084h //or... AUCONFIG1 = 0x0F; //SELECT SFR PAGE 0 }// End of main 12.12.2 FIR Filter Function The following example program shows the implementation 2070of a FIR filter computation function for one iteration; a data shifting operation; and the definition of the FIR filter coefficient table. The FIR computation algorithm is simple to implement, but requires a lot of processing power. For each new data point, multiplication with the associated coefficients and addition operations must be performed N times (N=number of filter taps). Since it is hardware-based, the VRS51L2070 arithmetic unit is very efficient in performing operations such as FIR filter computation. In the example below, the COMPUTEFIR loop is the "heart" of the FIR computation. Note that because of the arithmetic unit's features, very few instructions are needed to perform mathematical operations and the calculation results are ready at the next instruction. This provides a dramatic performance improvement when compared to having to perform all math operations manually, using general processor instructions. //Set operation (AUA,AUB)+ AUC //AURES = 44335522h //--FIR Filter Coefficient Tables //;FSAMPLE 480HZ, N=16, LOW PASS 0.1HZ -78DB @ 60HZ // To perform: [ (AUA,AUB) + AUC ] 32 bit addition AUCONFIG1 = 0x0C; //Set operation (AUA,AUB)+ AUC //AURES = 44335522h //or... AUCONFIG1 = 0x0E; DEVMEMCFG = 0x00; while(1); //Set operation (AUA,AUB)+ AUC //AURES = 44335522h //Set operation (AUA x AUB) + 0 //AURES = 0D986D42h // To perform: [(AUA x AUPREV[15:0]))+0] AUCONFIG1 = 0x02; //Set operation (AUAxAUPREV)+0 //AURES = 114563F0h //or... AUCONFIG1 = 0x0D; // To perform: [ (AUA x AUB)+ AUC ] / 2 (Shift one Right) AUCONFIG1 = 0x04; //Set operation (AUA x AUB)+ AUC AUSHIFTCFG = 0x3F; //Set barrel shifter to perform one SHIFT right //No need to preset the AUSHIFTCFG register for every //operations //AURES = F54BF29h //-----------------------------------------------------------// // VRS51L2070_AU_FIR_asm_c_-SDCC.c // //-----------------------------------------------------------------------------------------------------------------------// // // DESCRIPTION: FIR filter demonstration program - mixed ASM and C coding to optimize // the FIR loop speed. // // This program demonstrates the configuration and use of the SPI interface // for interface to serial 12-bit A/D and D/A converters. // The program reads the A/D and outputs the read value on a D/A converter // // At 40MHzm the 16-tap FIR loop + data shifting of the VRS51L2070 provide the // following performances: // // FIR computation using AU module (asm) = 10.4 uSeconds // Data shifting (asm) = 17.2 useconds // FIR Computation + Datashift = 27.6 uSeconds (1/T = 36.2 KHz) // // Rev 1.0 // Date: August 2005 //-------------------------------------------------------------------------------------------------------------------// #include // To perform: [(AUAxAUB)+0] AUCONFIG1 = 0x00; //Set operation (AUA x AUB) + 0 //AURES = 0D986D42h // or AUCONFIG1 = 0x03; // To perform: [ (AUA x AUB)+ AUC ] x 2 (Shift one LEFT) AUCONFIG1 = 0x04; //Set operation (AUA x AUB)+ AUC AUSHIFTCFG = 0x01; //Set barrel shifter to perform one SHIFT LEFT (logical) //No need to preset the AUSHIFTCFG register for every //operations //AURES = 3D52FCA6h //Set operation (AUA,AUB)+ AUC //AURES = 44335522h // To perform: [ (AUA x AUB)+ AUC ] No shift AUCONFIG1 = 0x04; //Set operation (AUA x AUB)+ AUC AUSHIFTCFG = 0x00; //No Shift //AURES = 1EA97E53h const int flashfircoef[] = {0x023D,0x049D,0x086A,0x0D2D,0x1263,0x1752,0x1B30,0x1D51, 0x1D51,0x1B30,0x1752,0x1263,0x0D2D,0x086A,0x049D,0x023D}; ________________________________________________________________________________________________ www.ramtron.com page 74 of 99 VRS51L2070 //-- Global variables definition int at 0x30 fircoef[16]; int at 0x50 datastack[16]; unsiged int at 0x75 dacdata; char *coef = &fircoef; char *ydata = &datastack; char fircptr = 0x00; //---- Functions Declaration ----// //-- FIR Filter computation function void FIRCompute(void); void CopyFIRCoef(void); //--Gen_ADC void ReadGen_ADC(void); // //- Gen_DAC void WriteGen_DAC(unsigned int ); //---Generic functions prototype void V2KDelay1ms(unsigned int); //Standard delay function // Global variables definitions idata unsigned char cptr = 0x00; unsigned int adcdata = 0x00; //-----------------------------------------------------------// //--------MAIN FUNCTION -----------------// //-----------------------------------------------------------// void main (void) { PERIPHEN2 |= 0x02; //Enable PWM SFR P2PINCFG = 0xF0; //P2[3:0] is output PWMCLKCFG = 0x10; //PWM Timer 7 Prescaler = Sys Clock / 2 //--Configure PWM7 as timer (will be monitored by interrupt) // PWM Timer 7 counts from 0000 to A2C2h PWMCFG = 0x17; //Point to MSB MID PWMDATA = 0xA2 PWMCFG = 0x07; PWMDATA = 0xC2; //Point to LSB MID //--Configure and enable PWM as timer Interrupt to monitor PWM5 only INTSRC2 &= 0xDF; //PWM7:4 Timer module Interrupt INTPINSENS1 = 0xDF; // sensitive on high level(0) INTPININV1 = 0xDF; //Set INT0 Pin sensitivity on normal level(0) INTEN2 |= 0x20; //Enable PWM7:4 Timer module interrupt //-- Copy FIR filter coefficients to IRAM CopyFIRCoef(); //--Activate the PWM modules and configure the PWM modules as timers PWMEN |= 0x80; //Enable PWM 7 PWMTMREN |= 0x80; //Enable PWM 7 as Timer GENINTEN = 0x01; //Enable global interrupt while(1); }// End of main //-----------------------------------------------------------------------------// //---------------------- Interrupt Function----- ----------------------// //-----------------------------------------------------------------------------// //------------------------------------------------------------------------------// NAME: INT13Interrupt PWMTMR7:4 as Timer //------------------------------------------------------------------------------void INT13Interrupt(void) interrupt 13 { char flagread; PERIPHEN2 |= 0x20; //Enable the Arithmetic Unit P2 = 0xFF; //Set P2 = 0xFF to monitor duration for FIR Loop *ydata = adcdata & 0x0FF; //Store the LSB of adc read data ydata += 1; *ydata = (adcdata >> 8)&0x00FF; //Store the MSB of adc read data DEVMEMCFG = 0x01; //Switch to SFR Page 1 AUCONFIG1 = 0x08; //CAPREV = 0 : Previous Res capture is automatic //CAPMODE = 1 : Capture of previous Result //occurs when AUA0 is written into //OVCAPEN = 0 : Capture on OV32 disabled //READCAP = 0 : AURES contains current result //ADDSRC = 10 : Add SCR = AUC //MULCMD = 00 : Mul cmd = AUA x AUB AUCONFIG2 = 0xA0; //Clear the Arithmetic Unit registers _asm MOV R0,#0x30; MOV R1,#0x50; _endasm; //Copy Start address of FIR Coefficient Table into R0 //Copy Start address of FIR Data Table into R1 // Yn Computation mostly in assembler -- Faster... for(fircptr = 0; fircptr < 16; fircptr++) { _asm MOV 0xA2,@R0; //copy LSB of pointed coefficient to AUA0 INC R0; MOV 0xA3,@R0; //copy MSB of pointed coefficient to AUA1 INC R0; MOV 0xB2,@R1; //copy LSB of pointed coefficient to AUB0 INC R1; MOV 0xB3,@R1; //copy MSB of pointed coefficient to AUB1 INC R1; _endasm; }//end of For cptr //-- Performing the data stack shifting allows to save 8.8uS @ 40MHz _asm MOV R0,#0x6F; MOV R1,#0x71; _endasm; for(fircptr = 16; fircptr > 0; fircptr--) { _asm mov A,@R0; mov @R1,A; dec R0; dec R1; mov A,@R0; mov @R1,A; dec R0; dec R1; _endasm; }//end of shift for loop //-Scale down the AURES output by 16 using the barrel shifter // the coefficient had been scaled up by a factor of 65536 AUSHIFTCFG = 0x30; _asm NOP; _endasm; P2 = 0x00; //Set P2 = 0x00 to signal the end of the FIR Loop dacdata = (AURES1 << 8) + AURES0; INTEN2 = 0x00; //Disable PWM7:4 Timer module interrupt flagread = PWMTMRF; //read PWM Timer OV Flags flagread &= 0x80; //check if PWM Timer 7 OV Flag is Active if(flagread != 0x00) { P2 = P2^0x01; //Toggle P2.0 (test) ReadGen_ADC(); //Read the A/D Converter FIRCompute(); //Perform the FIR filter computation and write into DAC } PWMTMRF &= 0x7F; //Clear the PWM Timer 7 OV Flag INTEN2 |= 0x20; //Enable PWM7:4 Timer module interrupt }//end of PWM as timer interrupt //-----------------------------------------------------------------------------// //---------------------- Individual Functions ---------------------------// //-----------------------------------------------------------------------------// //-----------------------------------------------------------------------// NAME: FIRCompute //----------------------------------------------------------------------void FIRCompute() { //Reset the Barrel shifter AUSHIFTCFG = 0x00; // Note: // In this case, 6 System clock cycles could be saved // by reading AURES3 and AURES2 directly DEVMEMCFG = 0x00; //Switch to SFR Page 0 WriteGen_DAC(dacdata); //Write data to SPI DAC }//End of FIRCompute //-----------------------------------------------------------------------// NAME: CopyFIRCoef //----------------------------------------------------------------------// DESCRIPTION: Copy the FIR Filter Coefficient into // SRAM variable which is faster access // than Flash //----------------------------------------------------------------------void CopyFIRCoef(void) { char cptr = 0x00; ________________________________________________________________________________________________ www.ramtron.com page 75 of 99 VRS51L2070 for(cptr = 0x00; cptr < 16; cptr++) fircoef[cptr]= flashfircoef[cptr]; }//End of CopyFIRCoef //-----------------------------------------------------------------------// NAME: ReadGen_ADC //----------------------------------------------------------------------// DESCRIPTION: Read the Gen_ADC A/D // ADC is connected to SPI interface using CS0 // Max clk speed is 3.2MHz, Fosc = 40MHz assumed //-----------------------------------------------------------------------void ReadGen_ADC() { int cptr = 0x00; char readflag = 0x00; //SPI Configuration Section /(Can be moved to Main function if only one device is connected to the SPI interface) PERIPHEN1 |= 0xC0; //Make sure the SPI interface is activated //--Wait activity stops on the SPI interface (Monitor SPINOCS) while(!(SPISTATUS &= 0x08)); SPICTRL = 0x65; SPICONFIG = 0x40; SPISTATUS = 0x00; SPISIZE = 0x0E; //SPICLK = /16 (2.5MHz) //CS0 Active //SPI Mode 1 Phase = 1, POL = 0 //SPI Master Mode //SPI Chip select is automatic //Clear SPIUNDEFC flag //SPILOAD = 0 -> Manual CS3 behaviour //No SPI interrupt used //SPI transactions are in MSB first format //SPI transaction size are 15-bit //-Dummy Read the SPI RX buffer to clear the RXAV flag readflag = SPIRXTX0; //-Perform the SPI read SPIRXTX0 = 0x00; //Writing to the SPIRXTX0 will trigger the SPI //Transaction //Wait for the SPI RX AV Flag being set while(!(SPISTATUS &= 0x02)); /* // -- It is possible to monitor the SPINOCS flag instead of the SPIRXAV flag //The code piece below shows how to do it. However in that case, //No that the reading of the SPISTATUS register must be done at //least 4 system clock cycles after the write operation to the SPIRXTX0 register //-Wait for SPINOCS Flag have time to be updated _asm NOP; _endasm; //--Wait activity stops on the SPI interface while(!(SPISTATUS &= 0x08)); */ //Read SPI data adcdata= (SPIRXTX1 << 8); adcdata+= SPIRXTX0; adcdata&= 0x0FFF; }//end of ReadGen_ADC //isolate the 12 lsb of the read value //------------------------------------------------------------------------------------------// // NAME: WriteGen_DAC //------------------------------------------------------------------------------------------// // DESCRIPTION: Write 12bit Data into the Gen_DAC device // ADC is connected to SPI interface using CS1 // Max clk speed is 12.5MHz, Fosc = 40MHz assumed // We will set the SPI prescaler to sysclk / 8 // void WriteGen_DAC(unsigned int dacdata) { SPICTRL = 0x4D; //SPICLK = /8 (MHz) //CS1 Active //SPI Mode 1 Phase = 1, POL = 0 //SPI Master Mode SPICONFIG = 0x40; //SPI Chip select is automatic //Clear SPIUNDEFC Flag //SPILOAD = 0 -> Manual CS3 behaviour //No SPI interrupt used SPISTATUS = 0x00; SPISIZE = 0x0B; //SPI transactions are in MSB first format //SPI transaction size are 12 bit //-Format the 12 bit data so data bit 11 is positioned on bit 7 of SPIRXTX0 // and data bit 0 is positioned on bit 4 of SPIRXTX1 and perform the SPI write operation dacdata &= 0x0FFF; //Make sure dacdata is <= 0FFFh (12 bit) SPIRXTX3 = 0x00; SPIRXTX2 = 0x00; SPIRXTX1 = (dacdata << 4)& 0xF0; //-Dummy read the SPI RX buffer to clear the RXAV Flag (facultative if SPINOCS is monitored) readflag = SPIRXTX0; SPIRXTX0 = (dacdata >> 4); //Writing to SPIRXTX0 will trigger the transmission //--Wait the SPI transaction completes // This section can be omitted if a check of activity on the SPI interface // is made before each access to it in master mode //Wait for the SPI RX AV flag being set while(!(SPISTATUS &= 0x02)); // -- It is possible to monitor the SPINOCS flag instead of the SPIRXAV flag //The code piece below shows how to do it. However in that case, //No that the reading of the SPISTATUS register must be done at //least 4 system clock cycles after the write operation to the SPIRXTX0 register /* //-Wait for SPINOCS flag have time to be updated _asm NOP; _endasm; //--Wait activity stops on the SPI interface (monitor SPINOCS Flag) while(!(SPISTATUS &= 0x08)); */ }//end of WriteGen_DAC //------------------------------------------------------------------------------------------// // NAME: V2KDelay1ms //------------------------------------------------------------------------------------------// // DESCRIPTION: VRS2070 specific 1 millisecond delay function // Using Timer 0 and calibrated for 40MHz oscillator //------------------------------------------------------------------------------------------// void V2KDelay1ms(unsigned int dlais){ idata unsigned char x=0; idata unsigned int dlaisloop; PERIPHEN1 |= 0x01; //LOAD PERIPHEN1 REG dlaisloop = dlais; while ( dlaisloop > 0) { TH0 = 0x63; //TIMER0 RELOAD VALUE FOR 1MS AT 40MHZ TL0 = 0xC0; T0T1CLKCFG = 0x00; //NO PRESCALER FOR TIMER 0 CLOCK T0CON = 0x04; //START TIMER 0, COUNT UP do{ x=T0CON; x= x & 0x80; }while(x==0); T0CON = 0x00; dlaisloop = dlaisloop-1; }//end of while dlais... //Stop Timer 0 PERIPHEN1 &= 0xFE; }//End of function V2KDelay1ms //Disable Timer 0 char subdata = 0x00; char readflag = 0x00; PERIPHEN1 |= 0xC0; //Make sure the SPI interface is activated //--Wait activity stops on the SPI interface (Monitor SPINOCS) while(!(SPISTATUS &= 0x08)); //SPI Configuration Section //Can be moved to main function if only one device is connected to the SPI interface ________________________________________________________________________________________________ www.ramtron.com page 76 of 99 VRS51L2070 13 Watchdog Timer The VRS51L2070 includes a watchdog timer which resets the processor in case of a program malfunction. The watchdog timer is composed of a 14-bit prescaler, which derives its source from the active system clock. An overflow of the watchdog timer resets the VRS51L2070. The WDTCFG SFR register controls the watchdog timer operations. The watchdog timer timeout period is calculated as follows: WDT Period* = 16384*(0x4000 - WDT Period) Fosc *For a given configuration, the timeout period of the watchdog timer may vary by about 200us. This delay is caused by internal timing of the watchdog timer module. TABLE 144: THE WATCHDOG TIMER REGISTER - WDTCFG 91H 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic Description 7:4 WDTPERIOD 3 WTIMEROVF 2 ASTIMER 1 WDTOVF Watchdog Timer Period Configuration *see table below WDT as Timer Overflow Flag 0 = WDT as timer as not expired 1 = WDT as timer has overflow Watchdog as Timer 0 = WDT mode 1 = WDT operate as a regular timer (no reset) Writing to this bit will clear the timer Read: 0 = Watchdog is counting 1 = Watchdog timer period has expired Write: 0 = No action 1 = Clear the watchdog timer flag Read: No Action 0 WDTRESET Watchdog Timer Reset To reset the watchdog timer, two consecutive writes to the WDTRESET bit must be made: First clear the WDTRESET bit and second, set it to 1 13.1 WDT Timeout Period The watchdog timer timeout period is controlled by adjusting bit 7:4 of the WDTCFG register. The following table provides the approximate timeout vs. the selected WDTPERIOD. 13.2 Resetting the Watchdog Timer To reset the watchdog timer, two consecutive write operations to the WDTCFG register must be performed. During the first write operation, the WDTRESET bit must be cleared. During the second write operation, the WDTRESET should be set to 1. This sequence is also required to set a new value for WDTPERIOD. For example, if the watchdog period is set to 100ms, the following sequence of operations will reset the watchdog timer: MOV MOV WDTCFG,#92h WDTCFG,#93h 13.3 Using the Watchdog as a Timer The VRS51L2070 watchdog timer can also be used as a timer. In this case, the timeout period is defined by the watchdog timer period value. Due to the presence of the 14-bit prescaler, long timeout periods can be achieved. Configuring the watchdog timer operation as a general purpose timer is achieved by: o Setting the ASTIMER bit of the WDTCFG register to 1 o Selecting the timer maximum time value of WDTPeriod o Performing a watchdog timer reset sequence to clear the timer and apply the timer configuration TABLE 145: THE WATCHDOG TIMER REGISTER TIMEOUT PERIOD WDTPERIOD Value (4 bit) Actual WDT Period** 0000 0x3FFF* 0001 0x3FFE 0010 0x3FFD 0011 0x3FFB 0100 0x3FF4 0101 0x3FE8 0110 0x3FCF 0111 0x3F86 1000 0x3F49 1001 0x3F0C 1010 0x3E9E 1011 0x3B3B 1100 0x38D9 1101 0x3677 1110 0x2364 1111 0x0000 *Not available in timer mode Approx Timeout** (40MHz) 409 - 600us 819-1000 us 1.23 - 1.36 ms 2.05 - 2.2 ms 4.92 ms 9.83 ms 20.07 ms 49.97 ms 74.96 ms 99.94 ms 249.86 ms 500.12 ms 749.98 ms 999.83 ms 2.99 s 6.71s The WTIMERFLAG bit of the WDTCFG register is used to monitor the timer overflow. When configured in timer mode, the watchdog timer does not reset the VRS51L2070 and cannot trigger an interrupt. ________________________________________________________________________________________________ www.ramtron.com page 77 of 99 VRS51L2070 13.4 Watchdog Timer Example Programs Initialization and Reset of the Watchdog Timer //---------------------------------------------------------------------------------------------------------------------// // VRS51L2070-WDT_Demo_SDCC.c // //---------------------------------------------------------------------------------------------------------------------// // DESCRIPTION: VRS51L2070 Watchdog Timer Demonstration Program // *This Program Set P1 as output // *P1 is set to 0xFF for 100ms // *Initialize the watchdog timer with a timeout period of 20ms // *Clear P1 // *Start a delay function // *If the Delay parameter of the delay function is larger than the // Timeout period of the watchdog timer, the WDT will reset the VRS51L2070 // which will bring back P1 to high level //---------------------------------------------------------------------------------------------------------------------// #include // --- function prototypes void delay(unsigned int); //-----------------------------------------------------// // MAIN FUNCTION // //-----------------------------------------------------// T0T1CLKCFG = 0x00; T0CON = 0x04; do{ x=T0CON; x= x & 0x80; }while(x==0); T0CON = 0x00; //Enable Timer 0 //Enable IOPORT P1PINCFG = 0x00; //Config port 1 as output //-- Enable the Watchdog Timer PERIPHEN2 |= 0x04; P1 = 0xFF; //Set P1 to output 0xFF delay(100); //Keep P1 high for 100ms //-- Configure the watchdog timer WDTCFG = 0x62; WDTCFG = 0x63; //Configure and Reset the Watchdog Timer //Bit 7:4 = WDTPERIOD : Define the timeout period (20ms) //Bit 3 = WTIMEROVF : WDT as timer overflow flag //Bit 2 = ASTIMER : WDT mode (0=WDT, 1=Timer) //Bit 1 = WDTOVF : WDT overflow (Timeout) Flag //Bit 0 = WDTRESET : WDT reset. To reset WDT //this bit must be cleared, then set P1 = 0x00; do{ delay(10); WDTCFG = 0x62; WDTCFG = 0x63; }while(1); //Clear P1 //If delay > 20ms then the WDT will reset the VRS51L2070 //and P1 will return to high //Reset the watchdog timer //Loop Forever }// End of main //;------------------------------------------------------------------// //;- DELAY1MSTO : 1MS DELAY USING TIMER0 //; //; CALIBRATED FOR 40MHZ //;-----------------------------------------------------------------// void delay(unsigned int dlais){ }//end of while dlais... x = PERIPHEN1; x = x & 0xFE; PERIPHEN1 = x; }//End of function delais dlaisloop = dlais; while ( dlaisloop > 0) { TH0 = 0x63; TL0 = 0xC0; //LOAD PERIPHEN1 REG //DISABLEBLE TIMER 0 14 VRS51L2070 Interrupts The VRS51L2070 has a comprehensive set of 49 interrupt sources and uses 16 interrupt vectors to handle them. The interrupts are categorized in two distinct groups: * * Module interrupt Pin change interrupts The module interrupts include interrupts that are generated by VRS51L2070 peripherals such as the UARTs, SPI, IC , PWC and port change monitoring modules. As their name implies, the pin change interrupts are interrupts that are generated by predefined conditions at the physical pin level: . The pin change interrupts can be caused by a level or an edge (rising or falling) on a given pin. Standard 8051 INT0 and INT1 interrupts are considered pin change interrupts. The VRS51L2070 includes INT0 and INT1, as well as 14 other pin interrupts distributed on ports 0 and 3. The interrupt sources share 16 interrupt vectors from 00h to 7Bh. Each interrupt vector can be configured to respond to either a pin change interrupt or a module interrupt. The two following diagrams provide an overview of the VRS51L2070 modules/pin interrupt structure, the associated SFR registers and the interaction among the interrupt management SFRs. FIGURE 34: INTERRUPT SOURCES DETAILED VIEW Module idata unsigned char x=0; idata unsigned int dlaisloop; x = PERIPHEN1; x |= 0x01; PERIPHEN1 = x; //Stop Timer 0 dlaisloop = dlaisloop-1; void main (void) { PERIPHEN1 = 0x01; PERIPHEN2 = 0x08; //NO PRESCALER FOR TIMER 0 CLOCK //START TIMER 0, COUNT UP //LOAD PERIPHEN1 REG //ENABLE TIMER 0 0 To Interrupt Controller 0 1 Pin 1 INTPININVx.y bit INTENx.y bit INTPINFx.y bit INTSRCx.y bit //TIMER0 RELOAD VALUE FOR 1MS AT 40MHZ ________________________________________________________________________________________________ www.ramtron.com page 78 of 99 VRS51L2070 FIGURE 35: INTERRUPT SOURCES OVERVIEW Interrupt Source config Not Used 0 P3.2 - INT0 pin 1 Module SPI TX Empty 0 I/O pin P3.3 - INT1 pin 1 SPI RX AV/OV 0 P3.0 pin 1 Timer 0 0 P3.1 pin 1 Port Chg 0 0 P3.4 pin 1 UART0 0 P3.5 pin 1 UART1 0 P3.6 pin Timer 1 1 0 P3.7 pin 1 Timer 2 0 P0.0 pin 1 I2C 0 P0.1 pin 1 UART Collision 0 P0.2 pin 1 PWC Modules 0 P0.3 pin 1 PWM3:0 Timer 0 P0.4 pin 1 Interrupt Vector Natural Interrupt Priority Number Int 0 0003h 1 Int 1 000Bh 2 Int 2 0013h 3 Int 3 001Bh 4 Int 4 0023h 5 Int 5 002Bh 6 Int 6 0033h 7 Int 7 003Bh 8 Int 8 0043h 9 Int 9 004Bh 10 Int 10 0053h 11 Int 11 005Bh 12 Int 12 0063h 13 Int 13 006Bh 14 Int 14 0073h 15 Int 15 007Bh 16 Details of Module / Pin controller Module 0 0 PWM7:4 Timer 0 P0.5 pin 1 WDT Timer / Arithmetic Unit 0 P0.6 pin 1 Port Chg 1 0 P0.7 pin 1 1 Pin 1 INTPININVx.y bit INTENx.y bit INTPINFx.y bit INTSRCx.y bit ________________________________________________________________________________________________ www.ramtron.com page 79 of 99 VRS51L2070 The interaction between the interrupt management configuration registers is summarized in the following table. The paragraphs below describe each one of these registers in detail. TABLE 146:VRS51L2070 INTERRUPT CONFIGURATION SUMMARY Int # Priority Interrupt Vector Interrupt Enable Interrupt Priority Interrupt Source Connected Modules Connected Pin Pin Inversion Pin Sensitivity Pin Interrupt Flag INT 0 1 0003h INTEN1.0 INTPRI1.0 INTSRC1.0 None P3.2-INT0 IPINTINV1.0 IPINSENS1.0 IPINFLAG1.0 Int 1 2 000Bh INTEN1.1 INTPRI1.1 INTSRC1.1 SPI TX Empty P3.3-INT1 IPINTINV1.1 IPINSENS1.1 IPINFLAG1.1 Int 2 3 0013h INTEN1.2 INTPRI1.2 INTSRC1.2 SPI RX Available SPI RX Overrun P3.0 IPINTINV1.2 IPINSENS1.2 IPINFLAG1.2 Int 3 4 001Bh INTEN1.3 INTPRI1.3 INTSRC1.3 Timer 0 P3.1 IPINTINV1.3 IPINSENS1.3 IPINFLAG1.3 Int 4 5 0023h INTEN1.4 INTPRI1.4 INTSRC1.4 Port Change 0 P3.4 IPINTINV1.4 IPINSENS1.4 IPINFLAG1.4 Int 5 6 002Bh INTEN1.5 INTPRI1.5 INTSRC1.5 UART0 Tx Empty UART0 RX Available UART0 RX Overrun UART0 Timer OV P3.5 IPINTINV1.5 IPINSENS1.5 IPINFLAG1.5 Int 6 7 0033h INTEN1.6 INTPRI1.6 INTSRC1.6 UART1 Tx Empty UART1 RX Available UART1 RX Overrun UART1 Timer OV P3.6 IPINTINV1.6 IPINSENS1.6 IPINFLAG1.6 Int 7 8 003Bh INTEN1.7 INTPRI1.7 INTSRC1.7 Timer 1 P3.7 IPINTINV1.7 IPINSENS1.7 IPINFLAG1.7 Int 8 9 0043h INTEN2.0 INTPRI2.0 INTSRC2.0 Timer 2 P0.0 IPINTINV2.0 IPINSENS2.0 IPINFLAG2.0 Int 9 10 004Bh INTEN2.1 INTPRI2.1 INTSRC2.1 IC Tx Empty IC RX Available IC RX Overrun P0.1 IPINTINV2.1 IPINSENS2.1 IPINFLAG2.1 Int 10 11 0053h INTEN2.2 INTPRI2.2 INTSRC2.2 UART0 Collision UART1 Collision IC Master Lost Arbitration P0.2 IPINTINV2.2 IPINSENS2.2 IPINFLAG2.2 Int 11 12 005Bh INTEN2.3 INTPRI2.3 INTSRC2.3 PWC 0 End Condition PWC 0 End Condition P0.3 IPINTINV2.3 IPINSENS2.3 IPINFLAG2.3 Int 12 13 0063h INTEN2.4 INTPRI2.4 INTSRC2.4 PWM3 as Timer OV PWM2 as Timer OV PWM1 as Timer OV PWM0 as Timer OV P0.4 IPINTINV2.4 IPINSENS2.4 IPINFLAG2.4 Int 13 14 006Bh INTEN2.5 INTPRI2.5 INTSRC2.5 PWM7as Timer OV PWM6as Timer OV PWM5as Timer OV PWM4as Timer OV P0.5 IPINTINV2.5 IPINSENS2.5 IPINFLAG2.5 Int 14 15 0073h INTEN2.6 INTPRI2.6 INTSRC2.6 Watchdog as Timer OV Arithmetic Unit OV P0.6 IPINTINV2.6 IPINSENS2.6 IPINFLAG2.6 Int 15 16 007Bh INTEN2.7 INTPRI2.7 INTSRC2.7 Port Change 1 P0.7 IPINTINV2.7 IPINSENS2.7 IPINFLAG2.7 ________________________________________________________________________________________________ www.ramtron.com page 80 of 99 VRS51L2070 14.1 Interrupt Enable Registers The interrupt enable and the general interrupt enable registers establish the link between the peripheral module/pin interrupt signals and the processor interrupt system. The GENINTEN register controls activation of the global interrupt. On the VRS51L2070, only the least significant bit of the GENINTEN is used. The GENINTEN register is similar to the standard 8051 EA bit. When the GENINTEN bit is set to 1, all the enabled interrupts emanating from the modules/pins will reach the interrupt controller. When a given interrupt bit is set to 1, the corresponding interrupt path is activated. TABLE 148: INT ENABLE 1 REGISTER - INTEN1 (MODULES /PIN/INT VECTOR) SFR 88H 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic Description 7 T1IEN P3.7 pin Int 7 U1IEN P3.6 pin Timer 1 Interrupt Enable P3.7 pin if interrupt source is set to pin Interrupt vector 7 at address 003Bh UART1 Interrupt Enable o UART1 Tx Empty o UART1 Rx Available o UART1 Rx Overrun o UART1 Baud Rate Generator as Timer Overflow P3.6 pin if interrupt source is set to pin Int 6 Interrupt vector 6 at address 0033h U0IEN P3.5 pin UART0 Interrupt Enable o UART0 Tx Empty o UART0 Rx Available o UART0 Rx Overrun o UART0 Baud Rate Generator as Timer Overflow P3.5 pin if interrupt source set to pin Int 5 Interrupt vector 5 at address 0002Bh PCHGIEN0 P3.4 pin Int 4 T0IEN P3.3 pin Int 3 SPIRXOVIEN Port Change Interrupt Module 0 Enable P3.4 pin if interrupt source is set to pin Interrupt vector 4 at address 0023h Timer 2 Interrupt Enable P3.3 pin if interrupt source is set to pin Interrupt vector 3 at address 001Bh SPI Interrupt Enable SPI Rx Available SPI Rx Overrun P3.0 pin if interrupt source is set to pin Interrupt vector 2 at address 0013h SPI Tx Empty Interrupt Enable P3.3 pin if interrupt source is set to pin Interrupt vector 0 at address 000Bh Unused P3.2 pin if interrupt source is set to pin Interrupt vector 0 at address 0003h 6 TABLE 147:GENINTEN SFR REGISTER - NAME SFR E8H 7 6 5 4 3 2 1 0 - - - - - - - R/W 0 5 Bit Mnemonic 7:2 1 Unused CLRPININT 0 GENINTEN Description It is recommended to set this bit to 1 before enabling a pin interrupt to avoid receiving an interrupt right after GENINTEN bit is set General Interrupt Enable 0 = All enabled interrupts are masked (deactivated) 1 = All enabled interrupt can raise an interrupt 4 3 2 1 0 P3.0 Int 2 SPITXEIEN P3.3 pin Int 1 No Module P3.2 pin Int 0 ________________________________________________________________________________________________ www.ramtron.com page 81 of 99 VRS51L2070 TABLE 149: INT ENABLE 2 REGISTER INTEN2 (MODULES /PIN/INT VECTOR) SFR A8H 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic Description 7 PCHGIEN1 P0.7 pin Int 15 AUWDTIEN P0.6 pin Port Change Interrupt Module 1 Enable P0.7 pin if interrupt source is set to pin Interrupt vector 8 at address 007Bh Watchdog Timer and Arithmetic Unit Interrupt Enable o Watchdog as Timer Overflow o Arithmetic Unit 32-bit Overflow P0.6 pin if interrupt source is set to pin Int14 Interrupt vector 8 at address 0073h PWMT74IEN PWM as Timer 7 to 4 Overflow Interrupt Enable o PWM as Timer Module 7 Overflow o PWM as Timer Module 6 Overflow o PWM as Timer Module 5 Overflow o PWM as Timer Module 4 Overflow P0.5 pin if interrupt source set to pin 6 5 P0.5 pin Int 13 Interrupt vector 8 at address 006Bh PWMT30IEN P0.4 pin PWM as Timer 3 to 0 Overflow Interrupt Enable o PWM as Timer Module 3 Overflow o PWM as Timer Module 2 Overflow o PWM as Timer Module 1 Overflow o PWM as Timer Module 0 Overflow P0.4 pin if interrupt source is set to pin Int 12 Interrupt vector 8 at address 0063h 3 PWCIEN 2 P0.3 pin Int 11 I2CUCOLIEN Pulse Width Counter Interrupt Enable o PWC0 END condition occurred o PWC1 END condition occurred P0.3 pin if interrupt source set to pin Interrupt vector 11 at address 005Bh IC and UARTs Interrupts Enable o IC Master Lost Arbitration o UART0 Collision Interrupt o UART1 Collision Interrupt P0.2 pin if interrupt source is set to pin 4 P0.2 pin 1 0 14.2 Interrupt Source Each one of the 16 interrupt vectors on the VRS51L2070 can be configured to function as either a peripheral module or a pin change interrupt. The selection of the interrupt source is handled by the INTSRC1 and the INTSRC2 registers. By default, the interrupt source is set to peripheral module. However, setting the INTSRC bit to 1 will "associate" the corresponding interrupt vector to the corresponding pin interrupt. When a given interrupt vector is associated with a module, the corresponding bit of the IPINSENSx must be set to 0, so it is level sensitive (reset value). TABLE 150:INTERRUPT SOURCE 1 REGISTER - INTSRC1 SFR E4H 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic Description 7 INTSRC1.7 6 INTSRC1.6 5 INTSRC1.5 4 INTSRC1.4 3 INTSRC1.3 2 INTSRC1.2 Interrupt 7 Source 0 = Timer 1 1 = P3.7 Interrupt 6 Source 0 = UART1 1 = P3.6 Interrupt 5 Source 0 = UART0 1 = P3.5 Interrupt 4 Source 0 = Port Change 0 1 = P3.4 Interrupt 3 Source 0 = Timer 0 1 = P3.1 Interrupt 2 Source 0 = SPI RXAV, SPI RXOV 1 = P3.0 Interrupt 1 Source 0 = SPI Tx EMPTY 1 = P3.3 Interrupt 0 Source 0=1 = P3.2 Int 10 Interrupt vector 10 at address 0053h 1 INTSRC1.1 I2CIEN 0 INTSRC1.0 P0.1 pin IC Interrupts Enable o TX Empty o RX Available o RX Overrun P0.1 pin if interrupt source set to pin Int 9 Interrupt vector 9 at address 004Bh T2IEN Timer 2 Interrupt Enable (INTSCR P0.0 pin Int 8 P0.0 pin if interrupt source is set to pin Interrupt vector 8 at address 0043h ________________________________________________________________________________________________ www.ramtron.com page 82 of 99 VRS51L2070 TABLE 152:INTERRUPT PRIORITY 1 REGISTER - INTPRI1 SFR E2H TABLE 151:INTERRUPT SOURCE 2 REGISTER - INTSRC2 SFR E5H 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic Description 7 INTSRC2.7 6 INTSRC2.6 5 INTSRC2.5 4 INTSRC2.4 3 INTSRC2.3 2 INTSRC2.2 1 INTSRC2.1 0 INTSRC2.0 Interrupt 15 Source 0 = Port Change 0 1 = P0.7 Interrupt 14 0 = WDT Timer OV, AU OV 1 = P0.6 Interrupt 13 Source 0 = PWM7:4 Timer 1 = P0.5 Interrupt 12 Source 0 = PWM3:0 Timer OV 1 = P0.4 Interrupt 11 Source 0 = PWC0, PWC1 1 = P0.3 Interrupt 10 Source 0 = UARTs Coll, IC Lost Arbitration 1 = P0.2 Interrupt 9 Source 0 = IC 1 = P0.1 Interrupt 8 Source 0 = Timer 2 1 = P0.0 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic Description 7 T1P37PRI 6 U1P36PRI 5 U0P35PRI 4 PC0P34PRI 3 T0P31PRI 2 SRP30PRI 1 STP33PRI 0 INT0P32PRI Interrupt 7 Priority Level (Timer 1 / P3.7) 0 = Normal Priority 1 = High Priority Interrupt 6 Priority Level (UART1 / P3.6) 0 = Normal Priority 1 = High Priority Interrupt 5 Priority Level (UART0 / P3.5) 0 = Normal Priority 1 = High Priority Interrupt 4 Priority Level (Port Chg 0 / P3.4) 0 = Normal Priority 1 = High Priority Interrupt 3 Priority Level (Timer 0 / P3.1) 0 = Normal Priority 1 = High Priority Interrupt 2 Priority Level (SPI RX / P3.0) 0 = Normal Priority 1 = High Priority Interrupt 1 Priority Level (SPI TX / P3.3) 0 = Normal Priority 1 = High Priority Interrupt 0 Priority Level (INT0 / P3.2) 0 = Normal Priority 1 = High Priority TABLE 153:INTERRUPT PRIORITY 2 REGISTER - INTPRI2 SFR E3H 14.3 Interrupt Priority The INTPRIx registers enable the user to modify the interrupt priority of either the module or the pin interrupts. When the INTPRIx is set to 0, the natural priority of module/pin interrupts prevails. Setting the INTPRIx register bit to 1 will set the corresponding module/pin priority to high. If more than two module/pin interrupts are simultaneously set to high priority, the natural priority order will apply: Priority will be give to the module/pin interrupts with high priority, over normal priority. 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic Description 7 PC1P07PRI 6 AIP06PRI 5 PWHP05PRI 4 PWLP04PRI 3 PWCP02PRI 2 INT10P01PRI 1 I2CP01PRI 0 T2P00PRI Interrupt 15 Priority Level (Port Chg 1 / P0.0) 0 = Normal Priority 1 = High Priority Interrupt 14 Priority Level (WDT, AU / P0.6) 0 = Normal Priority 1 = High Priority Interrupt 13 Priority Level (PWM7:4 timer / P0.5) 0 = Normal Priority 1 = High Priority Interrupt 12 Priority Level (PWM3:0 timer / P0.4) 0 = Normal Priority 1 = High Priority Interrupt 11 Priority Level (PWC0, PWC1 / P0.3) 0 = Normal Priority 1 = High Priority Interrupt 10 Priority Level (UARTs Coll, IC Lost Arbitration / P0.2) 0 = Normal Priority 1 = High Priority Interrupt 9 Priority Level (IC / P0.1) 0 = Normal Priority 1 = High Priority Interrupt 8 Priority Level (Timer 2 / P0.0) 0 = Normal Priority 1 = High Priority ________________________________________________________________________________________________ www.ramtron.com page 83 of 99 VRS51L2070 14.4 Pin Inversion Setting 14.5 Pin Interrupt Sensitivity Setting TABLE 154: IMPACT OF PIN INVERSION SETTING ON PIN INTERRUPT SENSITIVITY The pin interrupt can be configured as level sensitive or edge triggered. The pin interrupt sensitivity is set via the IPINSENSx and IPININVx registers. The following table summarizes the pin interrupt trigger condition settings for IPINSENx and IPININVx. Pin Inversion 0 1 Interrupt Condition Normal Interrupt Polarity Sensitivity Inverted Interrupt Polarity Sensitivity TABLE 155:INTERRUPT PIN INVERSION 1 REGISTER - IPININV1 SFR D6H 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic Description 7 P37IINV 6 P36IINV 5 P35IINV 4 P34IINV 3 P31IINV Interrupt 7 Pin Polarity 0 = P3.7 1 = P3.7 Inverted Interrupt 6 Pin Polarity 0 = P3.6 1 = P3.6 Inverted Interrupt 5 Pin Polarity 0 = P3.5 1 = P3.5 Inverted Interrupt 4 Pin Polarity 0 = P3.4 1 = P3.4 Inverted Interrupt 3 Pin Polarity 0 = P3.1 1 = P3.1 Inverted Interrupt 2 Pin Polarity 0 = P3.0 1 = P3.0 Inverted Interrupt 1 Pin Polarity 0 = P3.3 1 = P3.3 Inverted Interrupt 0 Pin Polarity 0 = P3.2 1 = P3.2 Inverted 2 P30IINV 1 P33IINV 0 P32IINV TABLE 157:IMPACT OF PIN SENSITIVITY AND PIN INVERSION SETTING ON PIN INTERRUPT Pin Sensitivity 0 0 1 1 Pin Inversion 0 1 0 1 The following tables provide the bit definitions for the IPINSENS1 and IPINSENS2 registers. It is assumed that the corresponding IPININVx bit is set to 0. If the corresponding IPININVx bit is set to 1, the corresponding interrupt event will be inverted. TABLE 158:INTERRUPT PIN SENSITIVITY 1 REGISTER - IPINSENS1 SFR E6H 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic Description 7 P37ISENS 6 P36ISENS 5 P35ISENS 4 P34ISENS 3 P31ISENS 2 P30ISENS 1 P33ISENS 0 P32ISENS Interrupt 7 Pin Sensitivity (IPININV1.7 = 0) 0 = P3.7 High Level 1 = P3.7 Rising Edge Interrupt 6 Pin Sensitivity (IPININV1.6 = 0) 0 = P3.6 High Level 1 = P3.6 Rising Edge Interrupt 5 Pin Sensitivity (IPININV1.5 = 0) 0 = P3.5 High Level 1 = P3.5 Rising Edge Interrupt 4 Pin Sensitivity (IPININV1.4 = 0) 0 = P3.4 High Level 1 = P3.4 Rising Edge Interrupt 3 Pin Sensitivity (IPININV1.3 = 0) 0 = P3.1 High Level 1 = P3.1 Rising Edge Interrupt 2 Pin Sensitivity (IPININV1.2 = 0) 0 = P3.0 High Level 1 = P3.0 Rising Edge Interrupt 1 Pin Sensitivity (IPININV1.1 = 0) 0 = P3.3 High Level 1 = P3.3 Rising Edge Interrupt 0 Pin Sensitivity (IPININV1.0 = 0) 0 = P3.2 High Level 1 = P3.2 Rising Edge TABLE 156: INTERRUPT PIN INVERSION 2 REGISTER - IPININV1 SFR D7H 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic Description 7 P07IINV 6 P06IINV Interrupt 15 Pin Polarity 0 = P0.7 1 = P0.7 Inverted Interrupt 14 Pin Polarity 0 = P0.6 1 = P0.6 Inverted Interrupt 13 Pin Polarity 0 = P0.5 1 = P0.5 Inverted Interrupt 12 Pin Polarity 0 = P0.4 1 = P0.4 Inverted Interrupt 11 Pin Polarity 0 = P0.3 1 = P0.3 Inverted Interrupt 10 Pin Polarity 0 = P0.2 1 = P0.2 Inverted Interrupt 9 Pin Polarity 0 = P0.1 1 = P0.1 Inverted Interrupt 8 Pin Polarity 0 = P0.0 1 = P0.0 Inverted 5 P05IINV 4 P04IINV 3 P03IINV 2 P02IINV 1 P01IINV 0 P00IINV Interrupt Condition High level on pin Low level on pin Rising edge on pin Falling edge on pin ________________________________________________________________________________________________ www.ramtron.com page 84 of 99 VRS51L2070 TABLE 160:INTERRUPT PIN FLAG 1 REGISTER - IPINFLAG1 SFR B8H TABLE 159:INTERRUPT PIN SENSITIVITY 2 REGISTER - IPINSENS2 SFR E7H 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic Description 7 P07ISENS Interrupt 7 Pin Sensitivity (IPININV2.7 = 0) 0 = P0.7 High Level 1 = P0.7 Rising Edge Interrupt 6 Pin Sensitivity (IPININV2.6 = 0) 0 = P0.6 High Level 1 = P0.6 Rising Edge Interrupt 5 Pin Sensitivity (IPININV2.5 = 0) 0 = P0.5 High Level 1 = P0.5 Rising Edge Interrupt 4 Pin Sensitivity (IPININV2.4 = 0) 0 = P0.4 High Level 1 = P0.4 Rising Edge Interrupt 3 Pin Sensitivity (IPININV2.3 = 0) 0 = P0.3 High Level 1 = P0.3 Rising Edge Interrupt 2 pin Sensitivity (IPININV2.2 = 0) 0 = P0.2 High Level 1 = P0.2 Rising Edge Interrupt 1 Pin Sensitivity (IPININV2.1 = 0) 0 = P0.1 High Level 1 = P0.1 Rising Edge Interrupt 0 Pin Sensitivity (IPININV2.0 = 0) 0 = P0.0 High Level 1 = P0.0 Rising Edge 6 P06ISENS 5 P05ISENS 4 P04ISENS 3 P03ISENS 2 P02ISENS 1 P01ISENS 0 P00ISENS 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic Description 7 P37IF 6 P36IF 5 P35IF 4 P34IF 3 P31IF 2 P30IF 1 P33IF 0 P32IF Interrupt 7 Pin Flag Set to 1 if P3.7 pin Interrupt occurs Interrupt 6 Pin Flag Set to 1 if P3.6 pin Interrupt occurs Interrupt 5 Pin Flag Set to 1 if P3.5 pin Interrupt occurs Interrupt 4 Pin Flag Set to 1 if P3.4 pin Interrupt occurs Interrupt 3 Pin Flag Set to 1 if P3.1 pin Interrupt occurs Interrupt 2 Pin Flag Set to 1 if P3.0 pin Interrupt occurs Interrupt 1 Pin Flag Set to 1 if P3.3 pin Interrupt occurs Interrupt 0 Pin Flag Set to 1 if P3.2 pin Interrupt occurs TABLE 161:INTERRUPT PIN FLAG 2 REGISTER - IPINFLAG2 SFR D8H 7 6 5 4 3 2 1 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic Description 7 P07IF 6 P06IF 14.6 Interrupt Pin Flags 5 P05IF For each pin interrupt there is an interrupt flag that can be monitored. When the selected interrupt event is detected on a given pin, the corresponding pin interrupt flag is set to 1 by the system. 4 P04IF 3 P03IF 2 P02IF The interrupt pin flags are automatically cleared when the RETI (return from interrupt) instruction is executed. They can also be cleared by the software at any time. 1 P01IF 0 P00IF Interrupt 15 Pin Flag Set to 1 if P0.7 pin Interrupt occurs Interrupt 14 Pin Flag Set to 1 if P0.6 pin Interrupt occurs Interrupt 13 Pin Flag Set to 1 if P0.5 pin Interrupt occurs Interrupt 12 Pin Flag Set to 1 if P0.4 pin Interrupt occurs Interrupt 11 Pin Flag Set to 1 if P0.3 pin Interrupt occurs Interrupt 10 Pin Flag Set to 1 if P0.2 pin Interrupt occurs Interrupt 9 Pin Flag Set to 1 if P0.1 pin Interrupt occurs Interrupt 8 Pin Flag Set to 1 if P0.0 pin Interrupt occurs The pin interrupt flags can be monitored via the software, even if the corresponding pin interrupt is not activated. If all the corresponding interrupts are routed to modules and all the interrupts are disabled, the IPINFLAGx registers can be used as general purpose scratchpad registers. However this is not recommended. ________________________________________________________________________________________________ www.ramtron.com page 85 of 99 VRS51L2070 15 VRS51L2070 JTAG Interface The VRS51L2070 includes a JTAG interface that enables programming of the on-board Flash as well as code debugging. In order to free up as many I/Os as possible, the JTAG interface pins are shared with regular I/O pins that can be used as general I/Os when the JTAG interface is not being used. The JTAG interface is mapped into the following pins: TABLE 162: JTAG INTERFACE PIN MAPPING JTAG Pin TDI TDO CM0 TMS TCK Function Corresponding Pin JTAG Data Input JTAG Data Output Chip Mode 0 Test Mode Select JTAG Clock P4.3 P4.2 ALE P4.1 P2.7 Activation of the JTAG interface is controlled by the CM0/ALE pin. The CM0/ALE pin includes an internal pull-up resistor. When the CM0 pin is held at a logic low and a reset is performed, the JTAG interface is activated. 15.1 Impact of JTAG interface activation When the JTAG interface is connected, it has the following impact on the VRS51L2070 operation: * * * The PWM 7 output is deactivated. The PWM7 module can still be active. The P2.7, P4.3, P4.2, P4.1 I/O pins are deactivated. The ALE pin is reserved for the JTAG interface. To efficiently debug code accessing the external SRAM memory, place a 1k Ohms resistor in the path of CM0 to the JTAG interface module. 15.2 VRS51L2070 Debugger circuit debugging. For more information on the VRS51L2070 debugger's features and use, please consult the Versa Ware JTAG user guide. 16 Flash Programming Interface (FPI) The FPI module allows the processor to perform inapplication management of the Flash memory content. The following operations are supported by the FPI module : * * * Mass Erase Page Erase Byte Write Six SFR registers are associated with the FPI module operation, as shown in the table below: TABLE 163: FLASH PROGRAMMING INTERFACE REGISTERS SFR Name E9h FPICONFIG EAh FPIADDRL EBh ECh FPIADDRH FPIDATAL EDh FPIDATAH EEh FPICLKSPD Function Configures the FPI operations Address for operation (lower byte) Address for operation (upper byte) Data to write Upper byte of data to write Clock speed during FPI operations Reset Value 34h 00h 00h 00h 00h 00h The FPI module is activated by setting bit 0 of the PERIPHEN2 register. There are two ways to perform read and write operations to the Flash using the FPI module: the standard 8-bit mode, which writes 1 byte at a time and an extended 16-bit mode, which writes 2 bytes at a time (1 word), effectively doubling the writing speed. In addition, whenever a write or read is performed, the address is incremented automatically by the FPI module, saving processor cycles. The VRS51L2070 includes advanced debugging features that enable real-time, in-circuit debugging and emulation via the JTAG interface. When the VRS51L2070 debugger is activated, the upper 1024 bytes of the Flash memory are not available for user program. The VRS51L2070 debugger is intended to be used in conjunction with the Versa Ware JTAG software, developed by Ramtron. This software provides an easy-to-use interface for device programming and in________________________________________________________________________________________________ www.ramtron.com page 86 of 99 VRS51L2070 16.1 FPI Configuration Register Flash operations are activated via the FPI configuration register. The following table describes the FPI configuration register: TABLE 164: FPI CONFIGURATION REGISTER - FPICONFIG SFR E9H 7 6 5 4 3 2 1 0 R 0 R 0 R 1 R 1 R/W 0 R/W 1 R/W 0 R/W 0 Bit Mnemonic Description 7:6 FPILOCK[1:0] These bits indicate the stage of the unlock operation: 00 : IAP protection on (no unlock steps done) 01 : IAP first unlock step done: FPI_DATA_LO received 0xAA 10 : IAP protection off: second step done FPI_DATA_LO received 0x55) 11 : Disables write/erase operations until the next system reset. This occurs if a wrong sequence is used. Always = 1 Indicates that the FPI is idle Indicates that the FPI is idle in all modes except "write byte" mode, in which the double buffer is ready for a new value Keep this bit at 0 FPI operating mode 0 = FPI operates in 16-bit mode 1 = FPI operates in 8-bit mode FPITASK Operation 00: Read Mode 01: Mass Erase 10: Page Erase 11: Write Byte (Writing to FPIDATAL start Byte Write operation ) Note that actions are only started if fpiready is high, otherwise the action is cancelled 5 4 FPIIDLE FPIRDY 3 2 RESERVED FPI8BIT 0 FPITASK[1:0] 16.2 FPI Flash Address and Data Registers The FPIADDRH and FPIADDRL registers are used to specify the address at which the IAP function will be performed. TABLE 165: FPI ADDRESS HIGH FPIADDRH SFR EBH 7 6 5 4 3 2 R/W, Reset = 0x00 FPIADDR[15:8] 1 0 The FPIADDRH register contains the MSB of the destination address. For page erase operations, it contains the page number where page erase operations are performed. TABLE 166:FPI ADDRESS LOW -FPIADDRL SFR EAH 7 0 6 0 5 0 4 0 3 0 R/W FPIADDR[7:0] 2 0 1 0 0 0 The FPIADDRL register contains the LSB of the destination address where the operation is performed. For page erase it must contain the value 0x00. The FPIDATAH and FPIDATAL SFR registers contain the data byte required to perform the FPI function. TABLE 167: FPI DATA HIGH - FPIDATAH SFR EDH 7 6 5 4 3 2 R/W, Reset = 0x00 FPIDATA[15:8] 1 0 When Read: MSB of last word read[15:8] from Flash When Write: Byte[15:8] to write in Flash TABLE 168:FPI 7 DATA LOW 6 5 - FPIDATAL SFR ECH 4 3 2 R/W, Reset = 0x00 FPIDATA[7:0] 1 0 Read: Last read byte[7:0] from Flash Writing to this byte in 'FPI write mode' triggers the FPI state machine to start the write action. 16.3 FPI Clock Speed Control Register The FPI clock speed control register sets the FPI module to an optimal speed based on the speed of the system clock. TABLE 169:FPI CLOCK SPEED CONTROL REGISTER - FPICLKSPD SFR EEH 7 6 5 4 3 2 1 0 R 0 R 0 R 0 R 0 R/W 0 R/W 0 R/W 0 R/W 0 Bit Mnemonic 7:4 3:0 Unused FPICLKSPD [3:0] Description Specifies speed of the system clock entering the FPI module Frequency range: 0000 : 20MHz to 40 MHz 0001 : 10MHz to 20 MHz 0010 : 5MHz to 10 MHz 0011 : 2.5MHz to 5 MHz 0100 : 1.25MHz to 2.5 MHz 0101 : 625kHz to 1.25 MHz 0110 : 312.5kHz to 625 kHz 0111 : 156.25kHz to 312.5 kHz 1000 : 78.12kHz to 156.25 kHz 1001 : 39.06kHz to 78.125 kHz 1010 : 19.53kHz to 39.0625 kHz Others : 9.76kHz to 19.53125 kHz Use the settings found in the following table when using the FPI at a speed other than the nominal speed of the internal oscillator. ________________________________________________________________________________________________ www.ramtron.com page 87 of 99 VRS51L2070 TABLE 170: SETTING THE FPICLKSPD REGISTER Value Range Minimum Maximum 0 (default) 20.000 MHz 40.000 MHz 1 10.000 MHz 20.000 MHz 2 5.000 MHz 10.000 MHz 3 2.500 MHz 5.000 MHz 4 1.250 MHz 2.500 MHz 5 625.000 KHz 1.250 MHz 6 312.500 KHz 625.000 KHz 7 156.250 KHz 312.500 KHz 8 78.125 KHz 156.250 KHz 9 39.063 KHz 78.125 KHz 10 19.531 KHz 39.063 KHz Other 9.766 KHz 19.531 KHz The FPICLKSPD register must be set to the corresponding system clock speed for proper operation of the FPI module. For example, a 20.0 MHz clock requires FPICLKSPD to be set to 1, while a 20.1 MHz clock requires FPICLKSPD to be set to 0. If FPICLKSPD is set incorrectly, the Flash write operation may not process correctly, causing data corruption. 16.4 Using the FPI Interface 16.4.1 Write protection The VRS51L2070 provides a safety mechanism to prevent accidental writing or erasing of the Flash. The following sequence must be written to the FPIDATAL register to unlock the VRS51L2070 each time a write is performed. FPIDATAL A AAh FPIDATAL A 55h Not performing the above sequence will lock the FPI module until a reset of the VRS51L2070 is performed. Bit 7 and 6 of the FPICONFIG provide the status of the FPI write protection circuitry. 16.4.2 FPIIDLE This bit indicates whether the previous action is complete and the FPI is idle. The FPIIDLE bit must be checked before performing any FPI operation, to ensure that the module is ready. 16.4.3 FPIRDY When writing a stream of bytes or words, this bit indicates whether the FPI is ready for the next write. Note that AAh then 55h must first be written in order to unlock the FPI module. 16.4.4 FPI8BIT The FPI8BIT bit of the FPICONFIG register defines whether the FPI module read and write operations will be performed in 8 or 16-bit format. When the FPI8BIT bit is set to 1, the FPI module will operate in 8-bit mode. The 16-bit address of the Flash memory, where the FPI operation will be performed, is defined by the value of the FPIADDRH and FPIADDRL registers. When the FPI module is used to write data into the Flash memory, the FPIDATAL register holds the value of the data to be written. When the FPI module is used to read the Flash, the read value is returned via the FPIDATAL register. When the FPI8BIT bit is cleared, the FPI module will operate in 16-bit mode. In this case, the address range is defined by a 15-bit address [0000 - 7FFF] and must be written into the FPIADDRH and FPIADDRL registers. When a 16-bit FPI write operation is performed, the 16-bit data must be stored in the FPIDATAH and FPIDATAL registers. When a Flash memory read operation is performed, the 16-bit data will be returned to the FPIDATAH and FPIDATAL registers. 16.5 Performing a Read There are three ways to read directly from the VRS51L2070 Flash memory: 1. Use the MOVC instruction 2. Use the FPI in 8-bit mode 3. Use the FPI in 16-bit mode It may be preferable to use the FPI over the MOVC instruction, because some compilers will optimize code that repeatedly checks the Flash. To perform a read, perform the following steps: o o o o o Make sure the FPI module is enabled Set FPIADDRH and FPIADDRL to the appropriate address (see section 1.1.4) Write 00000X00 to the FPICONFIG register, where X = 1 if reading 8 bits, and X = 0 if reading 16 bits Loop until FPI_IDLE is raised Get the results from FPIDATAH and FPIDATAL if in 16-bit mode, or from FPIDATAL if in 8-bit mode ________________________________________________________________________________________________ www.ramtron.com page 88 of 99 VRS51L2070 16.5.1 FPI Flash Read in 8-Bit Mode Example The following code sequence follows the above algorithm to read address ABCDh in 8-bit mode: ORL PERHIPHEN2, #1 ; Enable FPI MOV FPIADDRH, #0ABh ; Move in upper address MOV FPIADDRL, #0CDh ; Move in lower address MOV FPICONFIG, #004h ; Trigger the read in 8-bit mode Wait: MOV A, FPICONFIG ; Get the FPI status JNB ACC.7, Wait ; Jump if not ready ; The read is now done. The result in FPIDATAL 16.5.2 FPI Flash Read in 16-Bit Mode Example The following code sequence will read 16 bits from address ABCD: #include unsigned char ucupper; unsigned char uclower; void readFPI(int address) { unsigned char result; PERIPHEN2 |= 1; /* Enable FPI */ FPIADDRH = (unsigned char) (address >> 8); /* Upper address */ FPIADDRL = (unsigned char) address; /* Lower address - automatically truncates */ FPICONFIG = 0; /* Trigger the read */ do { result = FPICONFIG & 0x20; /* Check for the FPI_IDLE bit */ } while(!result) ucupper = FPIDATAH; uclower = FPIDATAL; } void main() { /*** SOME CODE***/ readFPI(0x55e6); /* This is address ABCD converted to 16 bit addressing */ /*** SOME CODE***/ while(1); } 16.6 Erasing Flash 16.6.1 Page Erase When storing nonvolatile data, it is necessary to erase the Flash before writing to it. Programming is done by byte or word boundary, while erase is done by page boundary. A page is a contiguous block of 512 addresses. Page numbers can be calculated from the following formula: Page = address / 512 Page 0 contains all the addresses from 0000h to 01FFh, page 1 contains all the addresses from 0200h to 03FFh and so on. There are 128 pages of Flash on the VRS51L2070 (64KB Flash). To erase a page, follow these steps: 1. Ensure that the FPI module is enabled 2. Write AAh to the FPIDATAL register 3. Write 55h to the FPIDATAL register 4. Write 0 to the FPIADDRL register 5. Write the page number to the FPIADDRH register 6. Write 2 to the FPICONFIG register 7. Wait for FPI_IDLE to go high 16.6.2 FPI Page Erase Example This code sequence will erase page 64: ORL PERHIPHEN2, #1 ; Enable FPI MOV FPIDATAL, #0AAh ; UNLOCK 1 MOV FPIDATAL, #055h ; UNLOCK 2 MOV FPIADDRL, #0 ; Move in 0 MOV FPIADDRH, #64 ; Move in page number MOV FPICONFIG, #2 ; Trigger the page erase Wait: MOV A, FPICONFIG ; Get the FPI status JNB ACC.7, Wait ; Jump if not ready ; The page is now erased 16.6.3 Mass Erase It is possible to completely erase the Flash memory from within a program. To do so, the following steps must be performed: 1. 2. 3. 4. 5. Make sure that the FPI module is enabled Write AAh to the FPIDATAL register Write 55h to the FPIDATAL register Write 1 to the FPICONFIG register If still possible, wait for FPI_IDLE to go to 1 The Flash is now completely erased. Warning: At this point, the Flash should be totally erased. If running from external memory, make sure it is copied back to its locations in Flash with write commands. Step 5 can only be performed if executing code from external SRAM. 16.7 Writing to the Flash There are two methods to write to the Flash: o o 8-bit double buffered 16-bit double buffered Depending on the complexity and the amount of Flash to be written, one mode may be more efficient than the other: 8-bit mode is more suited to programming a few bytes of data, while 16-bit mode is more suited to memory dumping. Writing the Flash in 8-bit mode 1. Make sure the FPI module is enabled 2. Write 7 to the FPICONFIG register 3. Set FPIADDRH and appropriate addresses FPIADDRL to the ________________________________________________________________________________________________ www.ramtron.com page 89 of 99 VRS51L2070 4. Write AAh to the FPIDATAL register 5. Write 55h to the FPIDATAL register 6. Write data to the FPIDATAL register (this triggers the operation) 7. If complete, wait for FPI_IDLE to go high. If there are more bytes to be written at a different address, return to step 3. If the next address is contiguous, go to step 4 instead. Note that the address the data is written to will be automatically incremented for the next byte. As such, the address only needs to be written once per data stream (assuming that a contiguous block is written), as shown in the following example. 16.7.1 FPI Flash Write in 8-Bit Mode Example //********************************************* //* FPI Flash Write 8bit Mode Example * //********************************************* #include /* This function uses the FPI module to write a null terminated string to flash */ void copy_to_Flash(int address, char *str) { unsigned char ready; /* Is the FPI idle? */ PERIPHEN2 |= 1; /* Enable FPI */ /* Upper address */ FPIADRH = (unsigned char) (address >> 8); /* Lower address - automatically truncates */ FPIADRL = (unsigned char) address; FPICONFIG = 7; /* Trigger the write in 8 bit mode */ while(*str) /* while not null */ { FPIDATAL = 0xaa; /* 1st step unlock */ FPIDATAL = 0x55; /* 2nd step unlock */ FPIDATAL = (unsigned char)(*str); /* Wait for the buffer to be ready */ /* The operation is not finished, check for FPI_READY */ do { ready = FPICONFIG & 0x10; }while(!ready); str++; } /* Null character encountered, write an additional 0 to memory */ FPIDATAL = 0xaa; /* 1st step unlock */ FPIDATAL = 0x55; /* 2nd step unlock */ FPIDATAL = 0; /* End in null - this avoids having to pass the string length */ /* The operation is finished, check for FPI_IDLE instead of FPI_READY */ do { ready = FPICONFIG & 0x20; }while(!ready); return; } void main(void) { /*** CODE ***/ copy_to_Flash(0x3000, "Ramtron Inc"); copy_to_Flash(0x4000, "Microsystems connecting two worlds"); /*** CODE ***/ while(1); } 16.7.2 Writing to the Flash in 16-Bit Mode Follow the steps below to write in 16-bit mode: 1. Make sure the FPI module is enabled 2. Write 3 to the FPICONFIG register 3. Set FPIADDRH and FPIADDRL to the appropriate addresses (remember to convert to 16-bit addressing) 4. Write AAh to the FPIDATAL register 5. Write 55h to the FPIDATAL register 6. Write data to the FPIDATAL register (this triggers the operation) 7. If complete, wait for FPI_IDLE to go high. If there are more bytes to be written at a different address, return to step 3. If the next address is contiguous, go to step IV instead Note that the address the data is written to will be automatically incremented for the next byte As such, the address only needs to be set once per data stream (assuming a contiguous region is written), as shown in the following example. 16.7.3 FPI Flash Write in 16-Bit Mode Example This routine copies 512 bytes (1 page) of external SRAM to the Flash memory at address E000h + XRAM. The R0 and R1 registers contain the starting address of the page to copy. //********************************************* //* FPI Flash Write 16-bit Mode Example * //********************************************* WRITE_PAGE: PUSH DPH0 PUSH DPL0 PUSH ACC PUSH B MOV ACC, R2 PUSH ACC MOV DPH0, R1 MOV DPL0, R0 MOV R2, #255 ;PUSH THE DATA POINTER ;PUSH THE VAR. TO BE USED ;LOAD THE DATA POINTER ;LOOP COUNTER (511 BYTES) ORL PERHIPHEN2, #1 MOV FPICONFIG, #3 ;ENABLE FPI MODULE ;ENABLE WRITING IN 16 BIT ;MODE ; SET THE ADDRESS MUST BE 16 BITS (ADDRESS / 2) CLR C ;CLEAR THE CARRY FLAG MOV A, R1 RRC A ;CHECK IF THERE WILL BE A CARRY CLR A ;DOES NOT AFFECT CARRY BIT RRC A ;SETS A TO 80h IF R1 WAS ODD, OR ;KEEPS IT 0 ________________________________________________________________________________________________ www.ramtron.com page 90 of 99 VRS51L2070 MOV FPIADRL, A MOV A, R1 RR A ADD A, #7 ;SET LOWER ADDRESS ;DIVIDE ADDRESS BY 2 ;ADDS E000H TO THE ADDRESS ;(E000 / 2 = 7000) MOV FPIADRH, A ; SET UPPER ADDRESS 16.8 Tips on Using the FPI Interface The following tips can be used to get the most out of the IAP features on the VRS51L2070. * WRITE_PAGE_LOOP: MOV FPIDATAL, #0AAh MOV FPIDATAL, #055h ;UNLOCK STEP 1 ;UNLOCK STEP 2 MOVX A, @DPTR MOV B, A INC DPTR ;NEXT BYTE MOVX A, @DPTR INC DPTR MOV FPIDATAH, A MOV FPIDATAL, B ;AND START THE WRITE * ;NEXT BYTE ;SET THE UPPER VALUE ;SET THE LOWER VALUE WRITE_PAGE_LOOP_WAIT: MOV A, FPICONFIG ;CHECK TO SEE IF THE ;BUFFER IS READY ;JUMP IF FPI_READY IS NOT HIGH JNB ACC.4 ,WRITE_PAGE_LOOP_WAIT DJNZ R2 ,WRITE_PAGE_LOOP * * ;NOW WRITE THE LAST WORD (BYTE 511 AND 512) MOV FPIDATAL, #0AAh MOV FPIDATAL, #055h ;UNLOCK STEP 1 ;UNLOCK STEP 2 MOVX A, @DPTR MOV B, A INC DPTR MOVX A, @DPTR INC DPTR ;(not necessary) MOV FPIDATAH, A MOV FPIDATAL, B ;AND START THE WRITE WRITE_PAGE_LAST_WAIT: MOV A, FPICONFIG ;NEXT BYTE ;NEXT BYTE * ;SET THE UPPER VALUE ;SET THE LOWER VALUE ;CHECK TO SEE IF THE ;BUFFER IS READY JUMP IF FPI_IDLE IS NOT HIGH (LAST WORD) JNB ACC.5 , WRITE_PAGE_LOOP_WAIT ;RESTORE VARIABLES USED POP B POP ACC MOV R3, ACC POP ACC POP DPL0 POP DPH0 RET * * * ;RETURN TO CALLER Shorter programming time can be achieved if the FPI Flash write routines are run from the 4KB external memory SRAM, as the circuitry that reads instructions from the Flash does not interfere with the FPI module. The Flash must be erased before reprogramming, and the same value should not be written more than once to the same Flash address, unless an erase cycle is performed in between writes. To maximize the endurance of the VRS51L2070 Flash memory, FPI Flash page erase operations should be done sparingly. The FPI mass erase function will erase the entire VRS51L2070 Flash memory, including code already programmed. IAP can be performed even if the Flash protection is enabled. It is the responsibility of the programmer not to reveal the Flash information of a secured device via the IAP. When write operations are performed at the boundaries of two contiguous blocks of memory, the address will automatically increment to the next byte/word after a write cycle. This can save processor cycles. The FPI read can be used to perform Flash memory reads, however using the MOVC instruction is more efficient. Make sure that the location being written to does not interfere with the program running in the Flash. ________________________________________________________________________________________________ www.ramtron.com page 91 of 99 VRS51L2070 17 Crystal Consideration FIGURE 36: VRS51L2070 EXTERNAL CRYSTAL OSCILLATOR CONFIGURATION By default, the VRS51L2070 derives its clock from its internal oscillator. It is also possible to use external crystal for the VRS51L2070 clock source. The crystal connected to the VRS51L2070 oscillator input should be parallel cut type, operating in fundamental mode. XTAL1 XTAL VRS51L2070 The addition of 15 to 20pF load capacitors is recommended. See the following figure for a connection diagram. Note: Oscillator circuits may differ with different crystals or ceramic resonators in higher oscillation frequency. Crystals or ceramic resonator characteristics may also vary from one manufacturer to another. XTAL2 C1 C2 The user should review the technical literature associated with specific crystal or ceramic resonator s or contact the manufacturer to select the appropriate values for the external components. ________________________________________________________________________________________________ www.ramtron.com page 92 of 99 VRS51L2070 18 Operating Conditions 18.1 Absolute Maximum Ratings Parameter Supply voltage input (VDD - VSS) I/O input voltage all except P4.6 & P4.7 I/O input voltage P4.6 & P4.7 only Maximum I/O current (sink/source) QFP64 package Min. 3.1 -0.5V VDD-0.5 Max. 3.6 5.5V VDD+0.5 Unit V V V Notes Engineering samples Preliminary Preliminary 90 100mA Preliminary 18.2 Nominal operating conditions TABLE 171: OPERATING CONDITIONS Symbol TA Description Operating temperature Min. -40 Typ. 25 Max. +85 Unit C TS VCC5 Fextosc 40 Storage temperature Supply voltage Ext. Oscillator Frequency -55 3.1 1.0 25 3.3 - 155 3.6 40 C V MHz Remarks For 3.3V application 18.3 DC Characteristics VCC = 3.3V, Temp = 25C, No load on I/Os TABLE 172: DC CHARACTERISTICS Symbol VIL1 VIL2 VIH1 VI H2 Parameter Input Low Voltage Input Low Voltage Input High Voltage Input High Voltage VOL1 Output Low Voltage VOH2 Output High Voltage ILI R RES C -10 Input Leakage Current Reset Equivalent Pull-up Resistance Valid P o r t 0 ,1,2,3,4,5,6 RESET, XTAL1 P o r t 0,1,2,3,4,5,6 RES, XTAL1 Port 0 , 1,2,3,4,5,6,ALE Port 0 , 1,2,3,4,5,6,ALE Min. -0.35 -0.35 2.0 2.0 Typ Max. 0.80 0.80 5.5 5.5 0.2 V Vcc - 0.3V V P o r t 0 , 1,2,3,4 40 RES TBD Pin Capacitance 17*mA IC C VDD 3.6* 1.1* Test Conditions VCC=3.3V VCC=3.3V VCC=3.3V VCC=3.3V IOL = Rated I/O max current Max Rated I/O Current uA Kohm 10 pF 27* mA 7.5* Power Supply Current Unit V V V V mA 5.5 mA 11* mA mA Freq=1 MHz, Ta=25C Active mode, 40MHz (Int. Oscillator) Active mode, 10MHz (Int. Oscillator) Active mode 4 MHz (Ext. Crystal) Idle mode, oscillator running 40MHz OSC stop mode *Preliminary ________________________________________________________________________________________________ www.ramtron.com page 93 of 99 VRS51L2070 18.4 VRS51L2070 Timings Parameters TABLE 173: AC CHARACTERISTICS Variable Fosc Symbol Parameter ALE Pulse Width Address Valid to ALE Low Address Hold after ALE Low ALE Low to Valid Instruction In ALE Low to #PSEN low #PSEN Pulse Width #PSEN Low to Valid Instruction In Instruction Hold after #PSEN Instruction Float after #PSEN Address to Valid Instruction In #PSEN Low to Address Float #RD Pulse Width #WR Pulse Width #RD Low to Valid Data In Data Hold after #RD Data Float after #RD ALE Low to Valid Data In Address to Valid Data In ALE low to #WR High or #RD Low Address Valid to #WR or #RD Low Data Valid to #WR High Data Valid to #WR Transition Data Hold after #WR #RD Low to Address Float #W R or #RD High to ALE High Clock Fall Time Clock Low Time Clock Rise Time Clock High Time Clock Period Min. Typ Max. Unit nS nS nS nS nS nS nS nS nS nS nS nS nS nS nS nS nS nS nS nS nS nS nS nS nS nS nS nS nS nS ________________________________________________________________________________________________ www.ramtron.com page 94 of 99 VRS51L2070 18.5 Data Memory Read Cycle Timing - Multiplexed Mode The following diagram shows the timing of a multiplexed external data memory read cycle. FIGURE 37: DATA MEMORY READ CYCLE TIMING MULTIPLEXED READ CLK P 2 A[14:8] P 0 A[7:0]/D[7:0] DATA A[7:0] ALE RD 18.6 Data Memory Write cycle Timing - Multiplexed mode The following diagram shows the timing of a multiplexed external data memory write cycle. FIGURE 38: DATA MEMORY WRITE CYCLE TIMING MULTIPLEXED WRITE CLK P 2 A[14:8] P 0 A[7:0]/D[7:0] A[7:0] D[7:0] ALE WR ________________________________________________________________________________________________ www.ramtron.com page 95 of 99 VRS51L2070 18.7 Data Memory Read cycle timing - Non-Multiplexed Mode The following diagram shows the timing of a non-multiplexed external data memory read cycle. FIGURE 39: DATA MEMORY READ CYCLE TIMING NON- MULTIPLEXED READ CLK P2:P 6 A[14:0] P 0 D[7:0] DATA RD CE- ________________________________________________________________________________________________ www.ramtron.com page 96 of 99 VRS51L2070 18.8 Timing Requirement of the External Clock The following diagram shows the timing of an external clock driving the VRS51L2070 input. FIGURE 40: TIMING REQUIREMENT OF EXTERNAL CLOCK (VSS= 0.0V IS ASSUMED) CLKPER Vdd - 0.5V 0.5V CLKLOW CLKHIGH CLKFT CLKRT TABLE 174: EXTERNAL CLOCK TIMING REQUIREMENTS Variable Fosc Symbol CLKPER CLKLOW CLKHIGH CLKFT CLKRT Parameter Ext. clock period Ext. clock low duration Ext. clock high duration Ext. clock fall time Ext. clock rise time Min. 25 Typ Max. Unit nS nS nS nS nS . ________________________________________________________________________________________________ www.ramtron.com page 97 of 99 VRS51L2070 19 VRS51L2070 Package 19.1 VRS51L2070 QFP-64 Package FIGURE 41: VRS51L2070 QFP-64 PACKAGE DRAWINGS 48 47 49 46 45 43 42 41 40 39 38 37 36 35 34 33 32 50 31 51 30 52 29 53 28 54 27 55 E1 44 26 VRS51L2070 QFP-64 56 57 58 25 24 23 59 22 60 21 61 20 62 19 63 18 64 A1 A2 c b e 17 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 D1 TABLE 175: DIMENSIONS OF QPF-64 PACKAGE Symbol Description QFP-64 D1 E1 A1 A2 L1 b c e Body size Body size Stand-off Body thickness Lead Length Lead width L/C thickness Lead pitch 14 14 0.1 1.4 1 0.35 0.127 0.8 ________________________________________________________________________________________________ www.ramtron.com page 98 of 99 VRS51L2070 20 Ordering Information 20.1 Device Number Structure VRS51 L 2070 - 40 - X X X Green Blank = No Green G = Green (lead-free) Temperature Range Blank = Industrial (-40C to +85C) Package Options R = 64-pin Quad Flat Pack (QFP-64) Operating Frequency 40: 40MHz oscillator frequency Product Number 2070 - 64-pin package Operating Voltage L= 3.1V - 3.6Volts 20.2 VRS51L2070 Ordering Options TABLE 176: VRS51L2070 PART NUMBERING Device Number VRS51L2070-40-QG Flash Size SRAM Size Package Option Voltage Temperature Frequency 64KB 4352 QFP-64 3.1V to 3.6V -40C to +85C 40MHz Errata: Engineering samples of the VRS51L2070 have an operating voltage of 3.1 to 3.6V instead of 3.0 to 3.6V Readback of the content in the THx/TLx and RCAPxH/RCAPxL timer registers will return to 0x00 unless the corresponding timer is running or, for the timers 0 and 1, the timer gating bit is set. Disclaimers Right to make change - Ramtron reserves the right to make changes to its products - including circuitry, software and services - without notice at any time. Customers should obtain the most current and relevant information before placing orders. Use in applications - Ramtron assumes no responsibility or liability for the use of any of its products, and conveys no license or title under any patent, copyright or mask work right to these products and makes no representations or warranties that these products are free from patent, copyright or mask work right infringement unless otherwise specified. Customers are responsible for product design and applications using Ramtron parts. Ramtron assumes no liability for applications assistance or customer product design. Life support - Ramtron products are not designed for use in life support systems or devices. Ramtron customers using or selling Ramtron's products for use in such applications do so at their own risk and agree to fully indemnify Ramtron for any damages resulting from such applications. IC is a trademark of Koninklijke Philips Electronics NV. ________________________________________________________________________________________________ www.ramtron.com page 99 of 99