CH559DS1
CH559DS1
CH559DS1
cn
1. Overview
The CH559 is an enhanced E8051 MCU compatible with MCS51 instruction set. 79% of its instructions
are single-byte single-cycle instructions, and the average instruction speed is 8 to 15 times faster than that
of the standard MCS51.
CH559 supports up to 56MHz system clock, built-in 64KB Flash-ROM, 256B on-chip iRAM, 6KB
on-chip xRAM, and some of xRAM support DMA mode.
CH559 has a built-in ADC converter, 4 timers/PWM, 2 UARTs, 2SPIs, and dual port Root-HUB, which
support USB-Host and USB-Device modes.
Flash-ROM 64KB iRAM 256B T0 T2 Timer3 PWM1 UART0 UART1 SPI0 SPI1 LED
(Code or Data) xRAM 6KB T1 PWM PWM2 Modem M/S M Ctrl
Power-on
Reset
1T
Internal Address & Data & DMA Bus
Watch-dog E8051 Core
Reset
XT USB
Internal
8-bit 8-bit 8-bit 8-bit 8-bit XT 8-bit USB 5-bit
Oscillator PLL
xBUS Port0 AD Port1 Port2 Port3 OSC Port4 H/D Port5
LDO VolReg 5V->3.3V
Pins: GND VIN5 VDD33 P00~P07 P10~P17 P20~P27 P30~P37 P40~P47 P50/1/4/5/7
2. Features
l Core: Enhanced E8051 core, compatible with MCS51 instruction set, 79% of its instructions are
single-byte single-cycle instructions, and the average instruction speed is 8 to 15 times faster than that
of the standard MCS51, with special XRAM data fast copy instruction, and dual DPTR pointer.
l ROM: Non-volatile 64KB Flash-ROM, which supports 100K writing cycles, it can be all used for
program memory. Or it can be divided into three pieces, 60KB for program memory, 1KB for
data-flash and 3KB for BootLoader or ISP code.
l RAM: 256-byte on-chip iRAM, for fast data cache or stack pointer; 6KB on-chip xRAM, for mass
data or DMA operation; support off-chip SRAM extending up to 32KB.
l USB: Built-in USB controller and dual USB transceiver, supports USB-Host and USB-Device modes,
supports USB 2.0 full speed (12Mbps) and low speed (1.5Mbps). In USB-Host mode, CH559 may
CH559 Datasheet 2 http://wch.cn
manage 2 USB devices at the same time. Maximum support 64-byte packet, built-in FIFO and support
DMA mode.
l Timer: 4 timers. T0, T1 and T2 are standard MCS51 timers, T2 is extended to support 2 captures.
TMR3 is built in 8-level FIFO, support DMA and signal capturing and 16-bit PWM output.
l PWM: 3 PWM outputs. PWM1 and PWM2 are 2 8-bit PWM outputs, TMR3 supports 16-bit PWM
output.
l UART: 2 UARTs. UART0 is a standard MCS51 UART. UART1 is compatible with 16C550, built-in
8-level FIFO, supports Modem signals, supports RS485 half-duplex mode, and supports local address
presetting for auto-matching or multi-device communication.
l SPI: 2 SPIs, high speed rate up to Fsys/2, support simplex multiplexing of serial data input and output.
SPI0 has built-in FIFO, supports Master/Slave mode. SPI1 only supports Master mode.
l ADC: 8-channel 10-bit or 11-bit A/D converter, built-in 2-level FIFO, supports DMA, sampling rate
up to 1Mbps, and support 2 channels auto-switching detection.
l LED-CTRL: LED control card interface, built-in 4-level FIFO, supports DMA mode, and
1/2/4-channel data interface, high speed rate up to Fsys/2.
l XBUS: 8-bit parallel external bus, compatible with standard MCS51 bus, used to connect off-chip
SRAM memory or other peripherals, supports direct 15-bit address or ALE multiplexed low 8-bit
address, and supports 4 bus speeds.
l GPIO: Supports up to 45 GPIO pins (including XI/XO, RST and USB signal pins), 3.3V voltage
output, and all support 5V-tolerant input except P1.0-P1.7, XI, XO or RST.
l Interrupt: Supports 14 interrupt sources, including 6 interrupts compatible with the standard MCS51
(INT0, T0, INT1, T1, UART0, T2), and 8 extended interrupts (SPI0, TMR3, USB, ADC, UART1,
PWM1, GPIO, WDOG). GPIO interrupt can be selected from 7 pins.
l Watch-Dog: 8-bit configure presetting watchdog timer WDOG, support timer interrupt.
l Reset: Supports 4 reset sources, built-in power on reset, supports software reset and watchdog
overflow reset, configurable external input reset.
l Clock: Built-in 12MHz clock, support external crystal oscillator through alternate GPIO pins, built-in
PLL for USB clock and Fsys.
l Power: Built-in 5V to 3.3V LDO, 3.3V working voltage internal, support 3.3V and 5V voltage input.
Support low power sleep mode, support USB, UART0, UART1, SPI0 and some GPIOs wake-up.
l Unique ID for identification.
3. Package
CH559 Datasheet 3 http://wch.cn
48
47
46
45
44
43
42
41
40
39
38
37
P1.5/AIN5/MOSI
P1.4/AIN4/SCS
P1.3/AIN3
P1.2/AIN2/PWM3/CAP3
P1.1/AIN1/T2EX/CAP2
P1.0/AIN0/T2/CAP1
VDD33
VIN5
P0.0/AD0/UDTR
P0.1/AD1/URTS
P0.2/AD2/RXD_
P0.3/AD3/TXD_
1 P1.6/AIN6/MISO P0.4/AD4/UCTS 36
2 P1.7/AIN7/SCK P0.5/AD5/UDSR 35 1 P1.2/AIN2/PWM3/CAP3 VDD33 20
3 P5.7/RST P0.6/AD6/URI 34 2 P1.4/AIN4/SCS VIN5 19
4 P3.0/RXD P0.7/AD7/UDCD 33 3 P1.5/AIN5/MOSI GND/VSS 18
5 P4.5/PWM2_/A5 P5.0/DM 32 4 P1.6/AIN6/MISO P0.2/RXD_ 17
6 P4.4/LED3/TNOW_/TXD1_/A4 P5.1/DP 31 5 P1.7/AIN7/SCK P0.3/TXD_ 16
7 CH559L 30 6 CH559T 15
8 P3.1/TXD P5.4/HM/ALE/XB 29 7 P5.7/RST P5.0/DM 14
9 P3.2/LED0/INT0 P5.5/HP/!A15/XA 28 8 P3.2/LED0/INT0 P5.1/DP 13
10 P3.3/LED1/!A15/INT1 P2.7/TXD1/DA7/A15 27 9 P3.4/LEDC/T0 P2.7/TXD1 12
11 P3.4/LEDC/XCS0/T0 P2.6/RXD1/A14 26 10 P4.6/XI/SCS_ P2.6/RXD1 11
P3.5/DA6/T1 P2.5/TNOW/PWM2/A13/T2EX_/CAP2_ P4.7/XO/SCK_ P2.5/TNOW/PWM2/T2EX_/CAP2_
P4.2/PWM3_/CAP3_/A2
12 25
P4.0/LED2/A0/RXD1_
P3.6/WR P2.4/PWM1/A12
P2.2/MISO1/A10
P4.3/PWM1_/A3
P2.1/MOSI1/A9
P2.3/SCK1/A11
P4.6/XI/SCS_
P4.7/XO/SCK_
P3.7/RD
GND/VSS
P4.1/A1
P2.0/A8
13
14
15
16
17
18
19
20
21
22
23
24
4. Pin definitions
Pin No.
Pin Alternate
Description
SSOP20 LQFP48 Name (Left preferential)
5V external power input of internal 5V->3.3V LDO,
19 41 VIN5 V5
requires an external 0.1uF decoupling capacitor.
Internal voltage regulator output and internal 3.3V
working power input,
When supply voltage is less than 3.6V, connect VIN5
20 42 VDD33 VDD/VCC
to input the external power supply.
When supply voltage is greater than 3.6V, an external
3.3uF decoupling capacitor is required.
18 18 GND VSS Ground.
- 40 P0.0 AD0/UDTR P0 port: 8-bit open-drain bidirectional port by default,
- 39 P0.1 AD1/URTS can be configured to quasi-bidirectional port by
17 38 P0.2 AD2/RXD_ configuring the P0_PU register to enable the intermal
16 37 P0.3 AD3/TXD_ pull-up resistor.
- 36 P0.4 AD4/UCTS P0 will automatically switch to push-pull output
- 35 P0.5 AD5/UDSR modes temporarily when accessing xbus, as
- 34 P0.6 AD6/URI bidirectional data buses AD0-AD7; or output the
lower 8 bits of address as needed when accessing
- 33 P0.7 AD7/UDCD xbus in address multiplexing mode.
CH559 Datasheet 4 http://wch.cn
SFRs use address from 80h to FFh of internal data memory, and can only be accessed by direct-address
instructions. Some addresses support bit addressing such as x0h and x8h, to avoid modifying the values of
other bits when accessing a specific bit. Other registers with the addresses that are not the multiple of 8 can
only be accessed by bytes.
Some SFRs can be written only in safe mode, and are read-only in unsafe mode, such as: GLOBAL_CFG,
PLL_CFG, CLOCK_CFG, SLEEP_CTRL, WAKE_CTRL.
Some SFRs have one or more names, such as: SPI0_CK_SE/SPI0_S_PRE, UDEV_CTRL/UHUB0_CTRL,
UEP1_CTRL/UH_SETUP, UEP2_CTRL/UH_RX_CTRL, UEP2_T_LEN/UH_EP_PID,
UEP3_CTRL/UH_TX_CTRL, UEP3_T_LEN/UH_TX_LEN, P5_PIN/P4_CFG.
Some addresses may correspond to multiple seperate SFRs, such as: TL2/T2CAP1L, TH2/T2CAP1H,
SAFE_MOD/CHIP_ID, T3_COUNT_L/T3_CK_SE_L, T3_COUNT_H/T3_CK_SE_H,
SER1_FIFO/SER1_RBR/SER1_THR/SER1_DLL, SER1_IER/SER1_DLM, SER1_IIR/SER1_FCR,
SER1_ADDR/SER1_DIV, ROM_CTRL/ROM_STATUS.
CH559 Datasheet 6 http://wch.cn
xSFRs occupy address from 2440h to 298Fh of the external data memory xdata, or 40H-8Fh of pdata.
xSFRs can only be accessed by bytes by indirect addressing through the MOVX instruction, it is based on
the DPTR pointer by default, but you can also use faster R0 or R1 as the pdata type pointer to access xSFR
named pU* and pLED_* after bXIR_XSFR is set to 1.
Some xSFRs may have one or more names, such as: UEP2_3_MOD/UH_EP_MOD,
UEP2_DMA_H/UH_RX_DMA_H, UEP2_DMA_L/UH_RX_DMA_L, UEP2_DMA/UH_RX_DMA,
UEP3_DMA_H/UH_TX_DMA_H, UEP3_DMA_L/UH_TX_DMA_L, UEP3_DMA/UH_TX_DMA.
CH559 contains all the standard registers of 8051, and adds some other device control registers. See the
table below for the specific SFRs.
Table 5.1 Table of special function registers
SFR 0, 8 1, 9 2, A 3, B 4, C 5, D 6, E 7, F
SPI0_CK_SE
0xF8 SPI0_STAT SPI0_DATA SPI0_CTRL SPI0_SETUP XBUS_SPEED RESET_KEEP WDOG_COUNT
SPI0_S_PRE
UDEV_CTRL
0xE0 ACC USB_INT_EN USB_CTRL USB_DEV_AD UHUB1_CTRL USB_DMA_AL USB_DMA_AH
UHUB0_CTRL
TL2 TH2
0xC8 T2CON T2MOD RCAP2L RCAP2H PIN_FUNC GPIO_IE
T2CAP1L T2CAP1H
P5_PIN
0xC0 P4_OUT P4_IN P4_DIR P4_PU P0_DIR P0_PU PORT_CFG
P4_CFG
SER1_FIFO
0x98 SCON SBUF PWM_DATA2 PWM_DATA PWM_CTRL PWM_CK_SE PWM_CYCLE
SER1_DLL
ROM_CTRL
0x80 P0 SP DPL DPH ROM_ADDR_L ROM_ADDR_H PCON
ROM_STATUS
Timer/counter2 register
Port setting register
SPI1 register
PWM1 and PWM2 register
UART1 register
Timer/counter 0 and 1 register
Flash-ROM register
ROM_ADDR_H
XBUS_SPEED FDh XBUS speed configuration register 1111 1111b
XBUS_AUX A2h XBUS auxiliary configuration register 0000 0000b
PIN_FUNC CEh Pin function selection register 0000 0000b
P4_CFG C7h Port4 configuration register 0000 0000b
P5_IN C7h Port5 input register (read-only): 0000 0000b
PORT_CFG C6h Port configuration register 0000 1111b
Port0 pull-up enable register
0000 0000b
(En_P0_Pullup=0)
P0_PU C5h
Port0 pull-up enable register
1111 1111b
(En_P0_Pullup=1)
P0_DIR C4h Port0 direction control register 0000 0000b
P4_PU C3h Port4 pull-up enable register 1111 1111b
Port setting P4_DIR C2h Port4 direction control register 0000 0000b
registers P4_IN C1h Port4 input register (read-only): 1111 1111b
P4_OUT C0h Port4 output register 0000 0000b
P3_PU BFh Port3 pull-up enable register 1111 1111b
P3_DIR BEh Port3 direction control register 0000 0000
P2_PU BDh Port2 pull-up enable register 1111 1111b
P2_DIR BCh Port2 direction control register 0000 0000b
P1_PU BBh Port1 pull-up enable register 1111 1111b
P1_DIR BAh Port1 direction control register 0000 0000b
P1_IE B9h Port1 input enable register 1111 1111b
P3 B0h Port3 input & output register 1111 1111b
P2 A0h Port2 input & output register 1111 1111b
P1 90h Port1 input & output register 1111 1111b
P0 80h Port0 input & output register 1111 1111b
TH1 8Dh Timer1 count register high xxxx xxxxb
TH0 8Ch Timer0 count register high xxxx xxxxb
Timer/counter
TL1 8Bh Timer1 count register low xxxx xxxxb
0 and 1
TL0 8Ah Timer0 count register low xxxx xxxxb
registers
TMOD 89h Timer0/1 mode register 0000 0000b
TCON 88h Timer0/1 control register 0000 0000b
UART0 SBUF 99h UART0 data register xxxx xxxxb
registers SCON 98h UART0 control register 0000 0000b
TH2 CDh Timer2 count register high 0000 0000b
TL2 CCh Timer2 count register low 0000 0000b
T2COUNT CCh 16-bit SFR consists of TL2 and TH2 0000h
Timer/counter 2 T2CAP1H CDh Timer2 capture 1 data high byte (read only) xxxx xxxxb
registers T2CAP1L CCh Timer2 capture 1 data low byte (read only) xxxx xxxxb
16-bit SFR consists of T2CAP1L and
T2CAP1 CCh xxxxh
T2CAP1H
RCAP2H CBh Count reload/capature 2 data register high 0000 0000b
CH559 Datasheet 9 http://wch.cn
SER1_DLL 9Ah UART1 baud rate divisor latch LSB xxxx xxxxb
SER1_FIFO 9Ah UART1 FIFO data register xxxx xxxxb
SER1_DIV 97h UART1 predivisor latch register 0xxx xxxxb
SER1_ADDR 97h UART1 bus address preset register 1111 1111b
SER1_MSR 96h UART1 MODEM status register (read-only) 1111 0000b
SER1_LSR 95h UART1 line status register (read-only) 0110 0000b
UART1
SER1_MCR 94h UART1 MODEM control register 0000 0000b
registers
SER1_LCR 93h UART1 line control register 0000 0000b
UART1 interrupt identification register
SER1_IIR 92h 0000 0001b
(read-only)
SER1_FCR 92h FIFO control register (write-only) 0000 0000b
SER1_DLM 91h UART1 baud rate divisor latch MSB 1000 0000b
SER1_IER 91h UART1 interrupt enable register 0000 0000b
ADC_EX_SW F7h ADC extend switch control register 0000 0000b
ADC_SETUP F6h ADC setup register 0000 1000b
ADC_FIFO_H F5h ADC FIFO high byte (read-only) 0000 0xxxb
ADC_FIFO_L F4h ADC FIFO low byte (read-only) xxxx xxxxb
16-bit SFR consists of ADC_FIFO_L and
ADC_FIFO F4h 0xxxh
ADC_FIFO_H
ADC_CHANN F3h ADC channel selection register 0000 0000b
ADC
ADC_CTRL F2h ADC control register 0000 0000b
registers
ADC_STAT F1h ADC status register 0000 0100b
ADC_CK_SE EFh ADC clock divisor setting register 0001 0000b
ADC_DMA_CN EEh DMA remainder word count register 0000 0000b
ADC_DMA_AH EDh DMA address high byte 0000 xxxxb
ADC_DMA_AL ECh DMA address low byte xxxx xxx0b
16-bit SFR consists of ADC_DMA_AL and
ADC_DMA ECh 0xxxh
ADC_DMA_AH
USB_DMA_AH E7h Current DMA address high byte (read-only) 000x xxxxb
USB_DMA_AL E6h Current DMA address low byte (read-only) xxxx xxx0b
16-bit SFR consists of USB_DMA_AL and
USB_DMA E6h xxxxh
USB_DMA_AH
UHUB1_CTRL E5h USB HUB1 control register 1100 x000b
UHUB0_CTRL E4h USB HUB0 control register 0100 x000b
UDEV_CTRL E4h USB device port control register 0100 x000b
USB
USB_DEV_AD E3h USB device address register 0000 0000b
registers
USB_CTRL E2h USB control register 0000 0110b
USB_INT_EN E1h USB interrupt enable register 0000 0000b
UEP4_T_LEN DFh Endpoint4 transmittal length register 0xxx xxxxb
UEP4_CTRL DEh Endpoint4 control register 0000 0000b
UEP0_T_LEN DDh Endpoint0 transmittal length register 0xxx xxxxb
UEP0_CTRL DCh Endpoint0 control register 0000 0000b
USB_HUB_ST DBh USB host HUB port status register (read only) 0000 0000b
CH559 Datasheet 11 http://wch.cn
USB_MIS_ST DAh USB miscellaneous status register (read only) xx10 1000b
USB_INT_ST D9h USB interrupt status register (read only) 00xx xxxxb
USB_INT_FG D8h USB interrupt flag register 0010 0000b
UEP3_T_LEN D7h Endpoint3 transmittal length register 0xxx xxxxb
UH_TX_LEN D7h USB host transmittal length register 0xxx xxxxb
UEP3_CTRL D6h Endpoint3 control register 0000 0000b
UH_TX_CTRL D6h USB host transmittal endpoint control register 0000 0000b
UEP2_T_LEN D5h Endpoint2 transmittal length register 0000 0000b
UH_EP_PID D5h USB host endpoint and token PID register 0000 0000b
UEP2_CTRL D4h Endpoint2 control register 0000 0000b
UH_RX_CTRL D4h USB host receiver endpoint control register 0000 0000b
UEP1_T_LEN D3h Endpoint1 transmittal length register 0xxx xxxxb
UEP1_CTRL D2h Endpoint1 control register 0000 0000b
UH_SETUP D2h USB host auxiliary setup register 0000 0000b
USB_RX_LEN D1h USB receiving length register (read only) 0xxx xxxxb
UEP4_1_MOD 2446h Endpoint1&4 mode control register 0000 0000b
UEP2_3_MOD 2447h Endpoint2&3 mode control register 0000 0000b
UH_EP_MOD 2447h USB host endpoint mode control register 0000 0000b
UEP0_DMA_H 2448h Endpoint0&4 buffer start address high byte 000x xxxxb
UEP0_DMA_L 2449h Endpoint0&4 buffer start address low byte xxxx xxx0b
16-bit SFR consists of UEP0_DMA_L and
UEP0_DMA 2448h xxxxh
UEP0_DMA_H
UEP1_DMA_H 244Ah Endpoint1 buffer start address high byte 000x xxxxb
UEP1_DMA_L 244Bh Endpoint1 buffer start address low byte xxxx xxx0b
16-bit SFR consists of UEP1_DMA_L and
UEP1_DMA 244Ah xxxxh
UEP1_DMA_H
UEP2_DMA_H 244Ch Endpoint 2 buffer start address high byte 000x xxxxb
UEP2_DMA_L 244Dh Endpoint 2 buffer start address low byte xxxx xxx0b
USB 16-bit SFR consists of UEP2_DMA_L and
UEP2_DMA 244Ch xxxxh
registers UEP2_DMA_H
on xSFR USB host rx endpoint buffer start address high
UH_RX_DMA_H 244Ch 000x xxxxb
byte
USB host rx endpoint buffer start address low
UH_RX_DMA_L 244Dh xxxx xxx0b
byte
16-bit SFR consists of UH_RX_DMA_L and
UH_RX_DMA 244Ch xxxxh
UH_RX_DMA_H
UEP3_DMA_H 244Eh Endpoint3 buffer start address high byte 000x xxxxb
UEP3_DMA_L 244Fh Endpoint3 buffer start address low byte xxxx xxx0b
16-bit SFR consists of UEP3_DMA_L and
UEP3_DMA 244Eh xxxxh
UEP3_DMA_H
USB host tx endpoint buffer start address high
UH_TX_DMA_H 244Eh 000x xxxxb
byte
USB host tx endpoint buffer start address low
UH_TX_DMA_L 244Fh xxxx xxx0b
byte
CH559 Datasheet 12 http://wch.cn
B register (B):
Reset
Bit Name Access Description
value
Arithmetic register, mainly used for multiplication and division
[7:0] B RW 00h
operations; it supports bit addressing
CH559 Datasheet 13 http://wch.cn
The program status word (PSW) contains status that reflects the current state of the CPU and it supports bit
addressing. It contains the carry bit, the auxiliary carry (for BCD operation), parity bit, overflow bit and
the 2 register bank select bits RS0 and RS1. The space of register bank may be accessed by direct or
indirect way.
Table 5.3.3 Operations affecting flag bits (X means that flag bit is related to the operation result)
Operation CY OV AC Operation CY OV AC
ADD X X X SETB C 1
ADDC X X X CLR C 0
SUBB X X X CPL C X
CH559 Datasheet 14 http://wch.cn
0 = Write protection.
1 = DataFlash can be written and erased.
MOVX_@R0/R1 command field control:
1 bXIR_XSFR RW 0 = MOVX_@R0/R1 for standard xdata area xRAM/xBUS/xSFR. 0
1 = MOVX_@R0/R1 for xSFR only, not for xRAM/xBUS
Watchdog reset enable:
0 bWDOG_EN RW 0 = as timer only. 0
1 = enable reset if timer overflow.
Chip ID (CHIP_ID):
Reset
Bit Name Access Description
value
[7:0] CHIP_ID RO Always 59h, used for chip identification 59h
Some SFRs can only be written in safe mode, while they are always read-only in non-safe mode. Steps to
enter safe mode:
(1). Write 55h to register.
(2). Write AAh to register.
(3). 13-23 system frequency periods are in safe mode, one or more safe SFRs or general SFRs can be
changed during this time.
(4). After the period expires, safe mode ends automatically.
(5). Write anything to this register can get out of safe mode in advance.
6. Memory structure
6.1 Memory space
CH559 addressing memory is divided into program memory, internal code memory and external data
memory.
CH559 Datasheet 16 http://wch.cn
DataFlash addressing from F000h to F3FFH, supports byte (8 bit) read, dual-byte(16 bit) write and block
(1K byte) erase, keeping the data after chip power-down, and also may be used for CodeFlash.
CodeFlash includes application code of low address and Bootloader code of high address, they can also be
combined with DataFlash for storing single application code.
Configuration information is total 16 bit, and may be configured by programmer, refer to Table 6.1.
CH559 Datasheet 17 http://wch.cn
External data memory is total 64KB, as shown in figure 6.1, 6KB of it are used for on-chip xRAM and
xSFR, except the reserved area, others (4000h to FFFFh) are all used for external parallel bus.
2. Flash-ROM write, changing some data bits in the target dual byte from 1 to 0:
(1). Get into safe mode, SAFE_MOD = 55h; SAFE_MOD = 0AAh;
(2). Enable writing by setting GLOBAL_CFG, bCODE_WE corresponds to code, and bDATA_WE to
data;
(3). Set ROM_ADDR, write in 16-bit destination address, high 15-bit valid only;
(4). Set ROM_DATA, write in 16-bit data, step (3) and step (4) may be exchanged;
(5). Set ROM_CTRL to 09Ah, execute writing, and the program will suspend during the operation;
(6). After the operation ,the program goes on, read ROM_STATUS to check the operation result. If
multiple data need to be written , repeat steps from (3) to (6);
(7). Get into safe mode again, SAFE_MOD = 55h; SAFE_MOD = 0AAh;
(8). Set GLOBAL_CFG to disable writing, bCODE_WE = 0, bDATA_WE = 0.
3. Flash-ROM read:
Read data or code from the destination address through instruction MOVC or pointer of program area.
When CH559 presets Bootloader, CH559 supports downloading application code through USB or UART.
Without Bootloader, application code and Bootloader may only download through specialized programmer.
Reserve 5 wires between CH559 and programmer for on-board programming in the circuit.
The ID number can be used with the downloading tools to encrypt the target program. For the general
application, only the first 32 bits of the ID number are used.
After power-on or system reset, CH559 is in running status by default. When some function modules are
unused, close their clocks to reduce power dissipation. When CH559 is no need to run, set PD in PCON to
get into sleep modes, and may be waked up by USB, UART0, UART1, SPI0 or some GPIOs.
Only power on reset can enable CH559 to reload the configuration information and reset RESET_KEEP,
other hot resets do not affect.
Bootloader runs first after power-on reset if ISP Bootloader is downloaded, it switches to the application
code through software reset based on requirement. This software reset will clear bBOOT_LOAD, but not
affect bRST_FLAG1/0 (as bBOOT_LOAD=1 before reset), so bRST_FLAG1/0 still indicates power on
reset status after switching to application state.
Watchdog timer overflow signal will trigger bWDOG_IF_TO to 1, which is automatically reset when
WDOG_COUNT is reloaded or when it goes into corresponding interrupt service.
Write different initial values to WDOG_COUNT to realize different timing period Twdc. When the system
clock is 12MHz, Twdc is about 5.9s when 00h is written, and about 2.8s when 80h is written.
When watchdog timer overflows and bWDOG_EN=1, watchdog reset occurs. Auto delay Trdl to keep
reset status. CH559 runs from address 0 after delay.
8. System clock
8.1 Diagram of clock
CH559 Datasheet 24 http://wch.cn
bOSC_EN_XT bSLP_OFF_USB
USB
Divider
bSLP_OFF_LED
LED_CK_SE
LED-CTRL
Divider
bSLP_OFF_ADC
ADC_CK_SE
ADC
Divider
bSLP_OFF_UART1 SER1_D*
UART1
Divider
bSLP_OFF_SPI0
SPI0_CK_SE
SPI0
Divider
SPI1_CK_SE
SPI1
Divider
bSLP_OFF_PIS1
PWM_CK_SE
PWM1/2
Divider
bSLP_OFF_TMR3
T3_CK_SE
Timer3
bSLP_OFF_XRAM
xRAM
Divider
Watch-DOG
Divide 262144
E8051_core
T0/T1/T2/UART0/GPIO
Fsys FlashROM/iRAM/SFR
Select one of internal clock or external clock as source clock, then generate high frequency Fpll after
frequency multiplier PLL. Generate system clock Fsys and USB module clock Fusb4x after 2 frequency
dividers. The system clock Fsys is provided to different modules of CH559 directly or after clock gate, to
CH559 Datasheet 25 http://wch.cn
reduce power dissipation, set sleep control register to close unused modules clocks.
System clock configuration register (CLOCK_CFG), only can be written in safe mode:
Reset
Bit Name Access Description
value
On-chip crystal oscillator enable
1 = Enable.
7 bOSC_EN_INT RW 1
0 = On-chip crystal oscillator disabled and external
crystal oscillator enabled
External crystal oscillator enable
1 = Enable, a crystal or ceramic oscillator to XI (P4.6)
6 bOSC_EN_XT RW and XO (P4.7). An external quartz crystal or ceramic 0
oscillator needs to be connected between XI and XO.
0 = Disable external oscillator.
Watchdog interrupt flag:
1 = Interrupt from timer overflow.
5 bWDOG_IF_TO RO 0 = No interrupt. This bit will be automatically reset 0
after WDOG_COUNT reloads or gets into
corresponding interrupt service.
System clock frequency division factor
[4:0] MASK_SYS_CK_DIV RW 11000b
00000b means 100000b.
PLL clock configuration register (PLL_CFG), only can be written in safe mode:
Reset
Bit Name Access Description
value
[7:5] MASK_USB_4X_DIV RW USB clock divisor factor, 000b means 1000b. 110b
[4:0] MASK_PLL_MULT RW PLL reference clock multiplier factor 11000b
Notes:
(1). PLL frequency is recommended not to beyond 24MHz~350MHz;
(2). Priority-use-of lower Fsys to reduce dynamic power dissipation and get wider Working temperature;;
(3). Set Fusb4x 48MHz when USB module enabled;
(4). Changing external crystal and modifying system frequency are two separate operations, suggestion in
two conditions:
(A). If external crystal oscillator frequency is less than 13MHz, switch to external crystal first and then
modify system frequency.
(B). If external crystal oscillator frequency is more than 13MHz, reduce PLL reference clock multiplier
factor to avoid Fpll overflow first, then switch to external crystal, and modify system frequency at
last, or modify system frequency when modify PLL_CFG.
9. Interrupt
CH559 supports maximum 14 interrupt sources, including 6 sources compatible with standard MCS51
interrupt: INT0, T0, INT1, T1, UART0, T2, and 8 extend interrupt sources: SPI0, TMR3, USB, ADC,
UART1, PWM1, WDOG, and GPIO which can be selected from 7 I/O pins.
IP and IP_EX registers are used for interrupt priority setting. The corresponding interrupt source will be
high (low) priority if this bit is 1 (0). There is default priority order (refer to Table 9.1.1) for interrupt
sources in the same level, the current interrupt priority is shown by PH_FALG combined with PL_FLAG.
The pins are general I/O port state if not set reused. All I/O ports have real “read-change-write” function
and support SETB or CLR command to change the direction and level of pins while they are used as
general digital I/O pins.
P0 pull-up enable register (P0_PU) and Pn pull-up enable register (Pn_PU), n=1/2/3:
Reset
Bit Name Access Description
value
P0.x pin pull-up resistor enable (when En_P0_Pullup=0) 00h
[7:0] P0_PU RW
P0.x pin pull-up resistor enable (when En_P0_Pullup=1) FFh
[7:0] Pn_PU RW Pn.x pin pull-up resistor enable: FFh
0 = Pull-up resistor disabled.
1 = Pull-up resistor enabled.
Port Pn configuration is realized by bPn_OC (in PORT_CFG), Pn_DIR and Pn_PU, details as follows.
Ports P0-P3 support pure input, push-pull output and standard bi-direction modes, P4 supports pure input
and push-pull output modes. There are controllable internal pull-up resistors attached to VDD33 and
protection diodes attached to GND for all pins.
Figure 10.2.1 shows pins p1.x of P1, also suitable for ports P0, P2 and P3 without P1_IE, AIN or
ADC_CHANN.
CH559 Datasheet 33 http://wch.cn
10.3 P4 port
P4 output register (P4_OUT):
Reset
Bit Name Access Description
value
[7:0] P4_OUT.0~P4_OUT.7 RW Pin P4.x data output bit, support addressing by bit 00h
The left-to-right priority shown in table above is the priority of some modules competing for using GPIO.
For example, P2 has been set output bus address high 8 bits but only A8-A10 addresses are used actually,
then P2.4/P2.5 can be used as PWM1/PWM2 in higher priority, P2.6 can be used as RXD1, P2.7can be
used as TXD1 or DA7 in higher priority, so the waste of P2.4 and P2.7 can be avoided when A12-A15
addresses are unused.
Reset
Bit Name Access Description
value
UART0 Tx state instruction:
7 bUART0_TX R0 0
1 = it is transmitting.
UART0 Rx state instruction:
6 bUART0_RX R0 0
1 = it is receiving.
Safe mode state instruction:
5 bSAFE_MOD_ACT R0 0
1 = it is in safe mode.
Pin ALE clock output enable:
1 = ALE outputs system frequency divided by 12
without XBUS operation, that is Fsys/12.
4 bALE_CLK_EN RW 0
0 = Clock signal is disabled, it only outputs address
low 8 bits latch signal while access to external bus to
reduce EMI.
General flag bit2:
3 GF2 RW 0
User-defined. Can be reset or set by software.
Enable DPTR add by 1 automatically after
2 bDPTR_AUTO_INC RW 0
MOVX_@DPTR command
1 Reserved RO Reserved 0
Dual DPTR data pointer select bit:
0 DPS RW 0 = DPTR0. 0
1 = DPTR1.
bXBUSn_WIDTH1 and bXBUSn_WIDTH0 (n=0, 1), used to select valid pulse width of bus CS n writing
and reading:
CH559 Datasheet 38 http://wch.cn
00 = 2 clock period.
01 = 4 clock period.
10 = 8 clock period.
11 = 16 clock period.
Some of the pins above that are not used in external bus mode can be used for other modules according to
GPIO alternate priority, and pins not used from P4.0 to P4.5 can also be set P4_DIR hold input mode.
When bXBUS_CS_OE=1, bus address A15 invert signal will select output pin according to ALE output
mode. !A15 will select P5.5 to output when ALE output is enabled, and select P3.3 to output when ALE
output is disabled. ALE output state is decided by bUH1_DISABLE, bXBUS_EN, bXBUS_AL_OE
combined with bALE_CLK_EN. Please refer to Table 11.2.2.
12. Timer
12.1 Timer0/1
Timer0 and Timer1 are 2 16-bit timers and counters, which are configured by registers TCON and TMOD.
TCON is used for start-up control, overflow interrupt and external interrupt control of T0 and T1. Each
timer is 16-bit consist of two 8-bit units, high byte of timer0 is THO, and low byte is TL0. High byte of
timer1 is TH1, and low byte is TL1. Timer1 may also be used for UART0 baud rate generator.
interrupt routine.
INT0 interrupt type:
0 IT0 RW 0 = Low level action. 0
1 = Falling edge action.
12.2 Timer2
Timer2 is a 16-bit auto-reload timer and counter, configured by registers T2CON and T2MOD, high byte
of Timer2 is TH2, and low is TL2. Timer2 may be used for baud rate generator for UART0, and provide 2
level capture which capture value stored in registers RCAP2 and T2CAP1.
12.3 Timer3
Table 12.3.1 List of Timer3 registers
Reset
Name Address Description
value
T3_FIFO_H AFh Timer3 FIFO high byte xxh
T3_FIFO_L AEh Timer3 FIFO low byte xxh
T3_FIFO AEh 16-bit SFR consists of T3_FIFO_L and T3_FIFO_H xxxxh
T3_DMA_AH ADh DMA address high byte 0xh
T3_DMA_AL ACh DMA address low byte xxh
T3_DMA ACh 16-bit SFR consists of T3_DMA_AL and T3_DMA_AH 0xxxh
T3_DMA_CN ABh DMA remainder word count register 00h
T3_CTRL AAh Timer3 control register 02h
T3_STAT A9h Timer3 status register 00h
T3_END_H A7h Timer3 count end value high byte xxh
T3_END_L A6h Timer3 count end value low byte xxh
T3_END A6h 16-bit SFR consists of T3_END_L and T3_END_H xxxxh
T3_COUNT_H A5h Timer3 current count high byte (read only) 00h
T3_COUNT_L A4h Timer3 current count low byte (read only) 00h
CH559 Datasheet 44 http://wch.cn
Timer3 clock divisor setting register (T3_CK_SE), valid only when bT3_EN_CK_SE=1:
Reset
Bit Name Access Description
value
Timer3 clock divisor setting high byte, lower 4 bits valid
[7:0] T3_CK_SE_H RW 00h
only, higher 4 bits are fixed to 0.
[7:0] T3_CK_SE_L RW Timer3 clock divisor low byte 20h
CH559 Datasheet 45 http://wch.cn
1 = 1 divided clock.
DMA enable and DMA interrupt enable for timer3:
4 bT3_DMA_EN RW 1 = Enable. 0
0 = Disable.
Timer3 output enable:
3 bT3_OUT_EN RW 1 = Enable. 0
0 = Disable.
Timer3 count enable:
2 bT3_CNT_EN RW 1 = Enable. 0
0 = Disable.
1 = Force clear FIFO and count of timer3.
1 bT3_CLR_ALL RW 1
Reset by software.
Timer3 mode:
0 bT3_MOD_CAP RW 0 = Timer or PWM. 0
1 = Capture.
Note: Timer3 capture point selection in capture mode: bT3_CAP_M1 & bT3_CAP_M0:
00 = Disable capture;
01 = Trigger by any edge, capture from any edge to any edge (level change);
10 = Trigger by falling edge, capture from falling edge to falling edge;
11 = Trigger by rising edge, capture from rising edge to rising edge.
Data repeater times in PWM mode: bT3_CAP_M1 & bT3_CAP_M0:
00 = 1 times;
01 = 4 times;
10 = 8 times;
11 = 16 times.
12.4 PWM
CH559 Timer3 supports 16-bit PWM and two 8-bit PWM. Support default output setting low-level or
high-level, modify duty cycle dynamically, and get the wanted after a simple RC circuit just like a low
speed DAC.
PWM3 duty cycle = T3_FIFO / T3_END, from 0% to 100%. If T3_FIFO >T3_END, PWM3 duty cycle =
100%.
12.5 Timer
12.5.1 Timer0/1
(1). Set timer internal clock frequency by T2MOD. Timer0/1 frequency is Fsys/12 when bTn_CLK (n=0/1)
CH559 Datasheet 49 http://wch.cn
Mode3: Timer0 is divided into 2 separate 8-bit timer/counter, and borrowed TR1 of Timer1. Timer1
substitutes the borrowed TR1 control bit by whether starting mode3. Timer1 stops when it gets into mode3.
CH559 Datasheet 50 http://wch.cn
12.5.2 Timer2
Timer2 16-bit reload timer/counter mode:
(1). Clear RCLK and TCLK in T2CON, select non-baud rate generator mode.
(2). Clear C_T2 in T2CON to use internal clock, jump to step(3); or set it to 1 to use pin T2 falling-edge as
count clock, skip step (3).
(3). Set T2MOD to select Timer internal clock. Timer2 frequency is Fsys/12 when bT2_CLK = 0, Fsys/4
when bTMR_CLK = 0 and Fsys when bTMR_CLK = 1 if bT2_CLK = 1.
(4). Clear CP_RL2 in T2CON, to select Timer2 16-bit reload timer /counter function.
(5). Set RCAP2L and RCAP2H as reload value when timer overflow, and TL2 and TH2 initial value
(generally the same as RCAP2L and RCAP2H), set TR2 to 1 to enable Timer2.
(6). Query TF2 or Timer2 interrupt to get current timer/counter status.
bTMR_CLK
÷4 0
bT2_CLK
Fsys 1 1 C_T2
0
TL2 TH2
÷12 0 (8bit) (8bit) TF2
1
T2=P1.0
TR2 Timer2
RCAP2L RCAP2H Interrupt
(8bit) (8bit)
EXEN2
Transition Detector
T2EX=P1.1 EXF2
12.5.3 Timer3
(1). Set bT3_EN_CK_SE in T3_SETUP to 1, enable T3_CK_SE, set frequency divisor, timer3 clock is
Fsys/T3_CK_SE, clear bT3_EN_CK_SE after setting.
(2). Set T3_END value or PWM cycles.
(3). Enable T3_SETUP as required.
(4). Set control bit of T3_CTRL, select working mode, clear bT3_CLR_ALL, and set bT3_CNT_EN 1 to
enable Timer3.
(5). Configure T3_DMA_AL, T3_DMA_AH, T3_DMA_CN as required, and set bT3_DMA_EN to enable
DMA.
SET
1 R Q 1
PWM3=P1.2
GPIO 0 Comparator 0
S CLR Q
bT3_OUT_EN bT3_PWM_POLAR
16bit Buffer
1 bT3_IF_FIFO_REQ
PWM3_=P4.2
GPIO 0 reading & bT3_IE_FIFO_REQ
bTMR3_PIN_X writing
T3_FIFO_L T3_FIFO_H bT3_IF_FIFO_OV
& bT3_IE_FIFO_OV
(8bit) (8bit)
bT3_CNT_EN Timer3
T3_COUNT_L T3_COUNT_H T3_END_L T3_END_H
Interrupt
÷T3_CK_SE (8bit) (8bit) (8bit) (8bit)
bT3_IF_DMA_END
Fsys & bT3_DMA_EN
bT3_CAP_CLK Comparator
0
Value: 0000 bT3_IF_END
1
bT3_IE_END 0
Transition Detector 0
bT3_IF_ACT 1
CAP3=P1.2 1
bT3_IE_ACT
bT3_MOD_CAP
bT3_CAP_M1 | bT3_CAP_M0=1
For example, set T3_END to 4000h, the original capture data is below:
1234h, 2345h, 0456h, C000h, C000h, 1035h, 3579h, C000h, 2468h, 0987h
After combination: 1234h, 2345h, 0456h, 9035h, 3579h, 6468h, 0987h
UART0 is a standard MCS51 UART, which receives and transmits data with SBUF. Reading for receiving,
writing for transmitting.
communication.
In mode1 and mode3, UART0 baud rate is generated by T1 when RCLK=0 and TCLK=0. Set T1 in mode2
auto reload 8-bit timer, clear bT1_CT and bT1_GATE, as follow:
In mode1 and3, UART0 baud rate is generated by T2 when RCLK=1 and TCLK=1. Set T2 in mode2 auto
reload 16-bit timer, clear C_T2 and CP_RL2, as follow:
The last 3 configurations in the above table are iRS485 half-duplex communication modes. In this case,
RS485EN=1, RXD1/TXD1 connect iRS485 pins XA/XB, and directly support simple long-distance
multi-device communication like RS485 bus through built-in half-duplex differential transceiver. In
iRS485 half-duplex mode, set as follow:
(1). Set bMCR_HALF in SER1_MCR to 1 to enable half-duplex mode;
(2). Set bUH1_DISABLE in UHUB1_CTRL to 1 to disable HP/HM.
SER_ADDR preset local address for multi-device communication in slave mode, interrupt when address
match or receive broadcast address and allow receiving the following data. Not allow to receive any data
before it receives matching address, and stop receiving when start to send or rewrite SER1_ADDR until
address match or receive broadcast address.
Bus address auto-compare function is enabled when SER1_ADDR != 0FFH and bLCR_PAR_EN = 1, and
configure as follow: set bLCR_WORD_SZ1, bLCR_WORD_SZ0 and bLCR_PAR_MOD1 to 1, set
bLCR_PAR_MOD0 to 1 when address bit is 0, and clear bLCR_PAR_MOD0 when address bit is 1.
CH559 Datasheet 61 http://wch.cn
UART1 baud rate divisor latch LSB (SER1_DLM, SER1_DLL), valid when bLCR_DLAB=1:
Reset
Bit Name Access Description
value
[7:0] SER1_DLL RW Baud rate divisor consists of SER1_DLL (low byte) and xxh
DLM (high byte), and valid when bLCR_DLAB = 1.
[7:0] SER1_DLM RW Baud rate divisor = Fsys * 2 / SER1_DIV / 16 / baud rate 80h
UART1 application:
(1). Set bLCR_DLAB in SER1_LCR to 1, set SER1_DIV, count the baud rate divisor and write into
SER1_DLM and SER1_DLL.
(2). Set SER_LCR to select data length and parity bit.
(3). Set SER_IER to select interrupt (optional).
(4). Set bMCR_OUT2 in SER1_MCR to enable interrupt output when interrupt enabled, otherwise query
the interrupt status
(5). Read or write SER_FIFO to receive or transmit data, and the allowed receive baud rate error should be
less than 2%.
SPI0 features:
(1). Supports master mode and slave mode;
(2). Supports mode0 and mode3 clock mode;
(3). 3-line full duplex mode or 2-line half-duplex mode is optional;
(4). MSB or LSB is optional to send first;
(5). Clock frequency is variable and can be maximum half of system frequency;
(6). 3-byte receiver FIFO and 1-byte transmitter FIFO inside;
CH559 Datasheet 62 http://wch.cn
SPI1 features:
(1). Supports master mode only, MSB send in first;
(2). Supports clock mode0 and mode3;
(3). 3-line full duplex mode or 2-line half-duplex modes is optional;
(4). Clock frequency is variable and can be maximum half of system frequency.
Reset
Bit Name Access Description
value
[7:5] Reserved RO Reserved 000b
Data byte transfer completion interrupt flag:
1 = One byte has been transferred,.
4 bS1_IF_BYTE RW Directly write 0 to reset, or write 1 to the corresponding 0
bit in the register to reset. Valid FIFO operation while
bS0_AUTO_IF = 1 can also reset it.
SPI1 empty flag:
3 bS1_FREE R0 1 = No SPI shifting at present, usually in idle period 1
between data bytes
[2:0] Reserved RO Reserved 000b
Reset by software.
Clear byte receiving completion interrupt flag
automatically by SPI1_DATA valid operation enable
bit:
0 bS1_AUTO_IF RW 0
1 = I will clear byte receiving completion interrupt flag
bS1_AUTO_IF automatically when there is valid
SPI1_DATA read/write operation
Mode0: bSn_MST_CLK = 0
Mode3: bSn_MST_CLK = 1
to the demand
(4). Set bS0_SCK_OE and bS0_MOSI_OE in SPI control register SPI0_CTRL as 1 , bS0_MISO_OE as 0,
set P1 direction bSCK and bMOSI as output, bMISO as input ,and CS pin as output.
Data transmission:
(1). Write SPI0_DATA register, write data ready for sending to FIFO and start SPI transmission once
automatically.
(2). Wait for S0_FREE until it is 1, indicating that data transmission is over, and can continue to send next
byte.
Data reception:
(1). Write SPI0_DATA register, start SPI transmission once by writing any data such as 0FFh to FIFO.
(2). Wait for S0_FREE until it is 1, indicating that data reception is over, and can get data by reading
SPI0_DATA
(3). The operation above can also start SPI transmission once while bS0_DATA_DIR has been 1, otherwise
no SPI transmission starts.
Data transmission:
(1) Wait for S0_IF_BYTE bit setting or interrupt for a byte data exchanged event.
(2) Write the SPI0_DATA register for sending data to the FIFO.
(3) Or wait the S0_FREE bit changed from 0 to 1, continue to send next byte.
Data reception:
(1) Wait for S0_IF_BYTE bit setting or interrupt for a byte data exchanged event.
(2) Read the SPI0_DATA register for receiving data from the FIFO.
(3) Query MASK_S0_RFIFO_CNT register (that consists of S0_R_FIFO1 bit and S0_R_FIFO0 bit) to
obtain the number of bytes remaining in FIFO.
CH559 Datasheet 68 http://wch.cn
The size of MASK_ADC_FIFO_CNT is 2 bits, indicating the current count of ADC FIFO.
MASK_ADC_FIFO_CNT Description
00b Epty FIFO, return current ADC result if reading FIFO
01b 1 result in FIFO
10b 2 results in FIFO, and FIFO full
11b Unknown error
MASK_ADC_CHANN Description
00b Cannel manual selection mode by SFR ADC_CHANN
01b Atomatic switch mode between AIN0 and AIN1
10b Atomatic switch mode between AIN6 and AIN4
11b Atomatic switch mode between AIN6 and AIN7
There are 3 parts for USB registers, and some registers are multiplexed in host and device mode.
(1). USB global registers.
(2). USB device control registers.
(3). USB host control registers.
UIF_TRANSFER valid.
0 = No pause.
1 = Force reset USB SIE.
2 bUC_RESET_SIE RW 1
Reset by software.
Force clear FIFO and count of USB.
1 bUC_CLR_ALL RW 1
Reset by software.
1 = DMA enable and DMA interrupt enable for USB
0 bUC_DMA_EN RW 0
0 = Disable DMA.
CH559 can configure number of bidirectional endpoints from 0 to 4 and the maximum data packet size for
all endpoints is 64 bytes.
Endpoint0 is for default control pipe as a message pipe and control transfers are carried only through
message pipe. There is a group of 64 bytes buffer shared by endpoint0 sending and receiving.
Endpoint1 and endpoint2 and endpoint3 each have a sending pipe (IN) and a receiving pipe (OUT), and the
transmitter and receiver each have a single 64-byte buffer or a double 64-byte buffer for USB transfers.
Endpoint4 has a sending pipe (IN) and a receiving pipe (OUT), and the transmitter and receiver each have
a single 64-byte buffer for USB transfers.
Each endpoint has a control register (UEPn_CTRL) and a transmittal length register (UEPn_T_LEN) (n =
0/1/2/3/4) to configure the data toggle flag, handshake response, transmittal length, etc.
The pull-up resistor of the USB device port is enabled or disabled by the software settings. If you set the
bUC_DEV_PU_EN bit in the USB_CTRL register, the USB device function start. At this time, the CH559
internal DP or DM pin connected to the pull-up resistor according to the bUD_LOW_SPEED bit. When
the event of bus reset, suspend or resume is detected or USB transfer completion, the USB SIE will
generate the corresponding interrupt flag and interrupt request. The use program can directly query USB
interrupt flag register (USB_INT_FG) or query in the interrupt service routine (ISR). If UIF_TRANSFER
bit is valid, you should also do the corresponding processing according to the value of interrupt status
register (USB_INT_ST) and MASK_UIS_ENDP and MASK_UIS_TOKEN. If you configure the
bUEP_R_TOG bit for each endpoint OUT transaction, you can query the U_TOG_OK bit or
bUIS_TOG_OK bit to determine whether the current received data toggle match with the expected, and if
the toggle is OK, the data is valid otherwise the data should be discarded. After processing the send or
receive data, you need to correct the toggle of the endpoint for the next data packet to send or receive data
packet match-detect. Setting the bUEP_AUTO_TOG bit may enable toggle turn automatically after
transfer completion.
The prepared data to send by each endpoint are placed in the buffer of each endpoint, and the length of data
should be written to the transmittal length register of each endpoint (UEPn_T_LEN). The receive data by
each endpoint are placed in the buffer of each endpoint, and the length of receive data of each endpoint is
all placed in the USB receiving data length register (USB_RX_LEN).
MASK_UEP_R_RES consists of bUEP_R_RES1 bit and bUEP_R_RES0 bit, used to indicate handshake
response type for USB endpoint n receiving (SETUP/OUT):
00 = ACK
01 = timeout/ no response (for isochronous transfers)
10 = NAK
11 = STALL
MASK_UEP_T_RES consist of bUEP_T_RES1 bit and bUEP_T_RES0 bit, used to indicate handshake
response type for USB endpoint n transmittal (IN):
00 = DATA0/DATA1 and expected host ACK
01 = DATA0/DATA1 and expected host no response (for Isochronous transfers)
10 = NAK
11 = STALL
Configuration of buffer mode of endpoint 0 and 4 by bUEP4_RX_EN bit and bUEP4_TX_EN bit. Refer to
the following table.
0 = Disable.
Enable USB endpoint3 transmittal (IN):
6 bUEP3_TX_EN RW 1 = Enable. 0
0 = Disable.
5 Reserved RO Reserved 0
4 bUEP3_BUF_MOD RW Buffer mode control of USB endpoint3. 0
Enable USB endpoint2 receiving (OUT):
3 bUEP2_RX_EN R0 1 = Enable. 0
0 = Disable.
Enable USB endpoint2 transmittal (IN):
2 bUEP2_TX_EN RW 1 = Enable. 0
0 = Disable.
1 Reserved RO Reserved 0
0 bUEP2_BUF_MOD RW Buffer mode control of USB endpoint 2. 0
Configuration buffer mode of endpoint 1 or 2 or 3 by bUEPn_RX_EN bit and bUEPn_TX_EN bit and
bUEPn_BUF_MOD bit, (n = 1/2/3). Refer to the following table.
After processing the USB things initiated by the host, CH559 will automatically set the interrupt flag
UIF_TRANSFER bit. The user program can read the interrupt flag register (USB_INT_FG) by the way of
query or interrupt, and deal with according to the interrupt flags. If the UIF_TRANSFER bit is valid, it
also needs to analyze the interrupt status register (USB_INT_ST) and deal with based on the current
handshake response PID (MASK_UIS_H_RES) for USB host transmittal.
If you configure the bUEP_R_TOG bit for host receiver endpoint (IN), you can query the U_TOG_OK bit
or bUIS_TOG_OK bit to determine whether the current received data toggle match the expected, and if the
toggle is OK, the data is valid otherwise the data should be discarded. After processing the send or receive
data, you need to correct the toggle of the endpoint for the next data packet to send or receive data packet
to match-detect. Setting the bUEP_AUTO_TOG bit can be achieved toggle turn automatically after
transfer completion.
The UH_EP_PID register for host mode is alternate-function of the UEP2_T_LEN register for device
mode, which is used to configure the endpoint number of the target device and the PID of USB packet. The
data buffer start address for USB data packet following SETUP/OUT packet is filled in UH_TX_DMA
register and the length of data should be written to the transmit length register of host endpoint
(UH_TX_LEN). The receiving data packet start address by host endpoint is placed in the UH_RX_DMA
register, and the length of receive data of host endpoint is placed in the USB receiving data length register
(USB_RX_LEN).
1 = High level.
0 = Low level.
Current HM pin level:
4 bUHS_HM_PIN RO 1 = High level. 0
0 = Low level.
Device attached status on USB hub0 DP/DM, (equal
to bUMS_H0_ATTACH):
3 bUHS_H0_ATTACH RO 0
1 = Connect.
0 = Disconnect.
DM level saved at device attached to USB hub0:
2 bUHS_DM_LEVEL RO 1 = High level. 0
0 = Low level.
Current DP pin level:
1 bUHS_DP_PIN RO 1 = High level. 0
0 = Low level.
Current DM pin level:
0 bUHS_DM_PIN RO 1 = High level. 0
0 = Low level.
Configuration buffer mode of USB host transmittal endpoint by bUH_EP_TX_EN bit and
bUH_EP_TBUF_MOD bit. Refer to the following table.
Configuration buffer mode of USB host receiving endpoint by bUH_EP_TX_EN bit and
bUH_EP_TBUF_MOD bit. Refer to the following table.
18. Parameters
18.1 Absolute maximum ratings
Stresses at or above the absolute maximum ratings listed in the table below may cause permanent damage
to the device.
Symbol Parameter description Min. Max. Unit
TA Operating temperature -40 85 ℃
TS Storage temperature -55 125 ℃
Internal operating supply voltage (VCC33 is connected to
VDD33 -0.4 3.6 V
power, GND is connected to ground)
External input supply voltage (VIN5 is connected to power,
VIN5 -0.4 5.6 V
GND is connected to ground)
VIO5 Voltage on the input or output pins support 5V -0.4 5.5 V
CH559 Datasheet 92 http://wch.cn
VIO3 Voltage on the input or output pins not support 5V -0.4 VDD33+0.4 V