We have already seen the power and possibility of running a Single chip computer using CH552. The main limitation with CH552 is the speed of the computer and the useful internal RAM available to the user.
The maximum clock speed of CH552 is 24 MHz. The internal xRAM available to the user is 1kB. Within this 1kB xRAM, the BASIC-52 will allocate around 512 bytes of xRAM for STACK and to keep many other status bits at RAM. We can refer to BASIC-52 manual for for more details.
Enhanced core E8051 based CH558T microcontroller:The CH55x family consists of CH551, CH552, CH554, CH558 and CH559.
The CH558 and CH559 comes in T & L package which consists of more pins(20 & 48), capable of running at 48 MHz and having more internal xRAM of 4kb and 6kB respectively.
Wireless Bluetooth Connectivity:For serial communication and keyboard, we need to connect the single chip computer to a PC or Phone. But once we connect it to a phone or PC, we can not change the connection easily.
Instead if we connect the PC or Phone to the Single Chip Computer through a wireless connection using Bluetooth, we can seamlessly transfer the connection. There is no physical connection so we can keep the Single Chip Computer anywhere we want. Even we can keep the computer next room. Only requirement is the range of the bluetooth. We can also keep the computer of a robot or any enclosure without any visibility.
CH558T:If we notice carefully on the above pinout, we can notice PORT3, PORT4 and PORT5 pins are used. We can not directly access any of the PORTs except PORT1 using BASIC-52. So it is easy to go with 20 pin SSOP20 package than 48 pin QFP48 package.
If we have either CH558 or CH559 in any of the package should work.
FIRMWARE:The source code assembles without any error with Microchip's C51ASM assembler in windows10/11 .It is available from the microchip website.
There are two changes made to the original file. Since we are going to use the IC at 48 MHz, the default frequency of BASIC-52 source code changed to support 48 MHz. This will help when we execute any time or timer dependent code.
Original code for 11.059200 MHz is
;CONSTANTS
;
XTALV: DB 128+8 ; DEFAULT CRYSTAL VALUE
DB 00H
DB 00H
DB 92H
DB 05H
DB 11H
;Current code for 48.000000 MHz is
;CONSTANTS
;
XTALV: DB 128+8 ; DEFAULT CRYSTAL VALUE
DB 00H
DB 00H
DB 00H
DB 00H
DB 48H
;The other change is CH558 uses 4kB internal xRAM compared to CH559 which uses 6kB of xRAM. The range of the internal xRAM is different for CH558 from CH559. The xRAM range for CH558 ranges from 0000H to 0FFFH. So the ERAMEND EQU 0FFFH. This is also corrected to report the proper available memory.
;=== CH558 Added =====
ERAMEND EQU 0FFFH ; EX-RAM last addr (4KB)
;=====================
;=== CH559 Added =====
;ERAMEND EQU 017FFH ; EX-RAM last addr (6KB)
;=====================
;CONNECTION:We need just two wires to the Single Chip Computer namely VCC(+5V) and GND. For this purpose small micro USB breakout board is used for easy connection. We can use any of the available connector or directly connect two wires with correct polarity.
CH558 requires just 4 connections. VCC, GND, Tx and Rx
Bluetooth module requires 4 connections. VCC, GND, Tx and Rx
Some of the Bluetooth modules may support only 3.3V logic level signals. In that case we need to reduce the Tx signal from CH558 to 3.3V for safe and reliable operation.
I2C, SPI and other legacy functions may share the same pin. Please check the pin for any conflict with other functions. We can re-assign the pins and assemble the source code to avoid any conflict.
I2C interface:;----- Definitions ----------------------------------------------------------
; === CH558T ===
SDA bit P1.6 ;I2C serial data line.
SCL bit P1.7 ;I2C serial clock line.I2CSTART Sends a start condition to I2C bus.
I2CSTOP Sends a stop condition to I2C bus.
I2CPUT [byte] Sends a byte to the I2C bus.
After calling, acknowledgment (0/1) received from the receiving side is entered in status (18H)
I2CGET ([acknowledge]) [variable]
Reads a byte from I2C to a BASIC variable and
acknowledge (0/1) returned to the sender, ACK = 0, NACK = 1
I2C EEPROM Write program using BASIC-52
I2C-EEPROM WRITEテストプログラム
100 FOR J=0 TO 63
200 I2CSTART
300 I2CPUT 0A0H
400 SADR=J*16
410 SADRH=INT(SADR/256)
420 SADRL=SADR.AND.0FFH
500 I2CPUT SADRH
600 I2CPUT SADRL
700 FOR I=0 TO 15
800 WD=SADR+I
810 WD=WD.AND.0FFH
900 I2CPUT WD
1000 NEXT I
1100 I2CSTOP
1200 FOR I=0 TO 200 : NEXT I
1300 NEXT JI2C EEPROM read program using BASIC-52
I2C-EEPROM READテストプログラム
100 FOR J=0 TO 63
200 I2CSTART
300 I2CPUT 0A0H
400 SADR=J*16
410 SADRH=INT(SADR/256)
420 SADRL=SADR.AND.0FFH
500 I2CPUT SADRH
600 I2CPUT SADRL
700 I2CSTART
710 I2CPUT 0A1H
800 FOR I=0 TO 15
810 IF I=15 THEN ACK=1 ELSE ACK=0
900 I2CGET (ACK)RD
910 PRINT RD,
920 NEXT I
930 PRINT
1100 I2CSTOP
1300 NEXT JSPI interface:SCS BIT P1.4 ; CH552/CH558 CS(SS)
MOSI BIT P1.5 ; CH552/CH558
MISO BIT P1.6 ; CH552/CH558
SCK BIT P1.7 ; CH552/CH558SPISTART [speed] setup SPI interface - "speed" is system-clock division facter, must be 32 or above
SPIPUT [byte] put "byte" to SPI
** byte received from SPI are stored at address 18h of i-ram, same features as SPIROT
SPIGET [variable] get "valiable" from SPI
SPIROT ([byte]) [variable] data rotate, put "byte" and get "valiable" to/from SPI
SPICS [0/1] CS(SS) port Low/High control
MCP3002 – 10 Bit Analog to Digital Converter program using BASIC-52
100 REM MCP3002 – 10 Bit Analog to Digital Converter Test Program
200 REM
300 HIGH = 1
400 LOW = 0
500 SPICS HIGH
600
700 DIM CMD(2), RESP(2)
800 CMD(0) = 68h
900 CMD(1) = 00h
1000
1100 SPISTART 96 : REM Clock 500KHz
1200
1300 For I = 0 To 100
1400 SPICS LOW
1500 SPIROT (CMD(0)) RESP(0)
1600 SPIROT (CMD(1)) RESP(1)
1700 SPICS HIGH
1800 AD = RESP(0) * 256 + RESP(1)
1900 AD = AD .and. 03FFh
2000 V = AD * 5.0 / 1023
2100 PRINT AD, V
2200 FOR K=1 TO 10000 : NEXT K
2300 NEXT I
2400
2500 EndSPI-EEPROM 25LC040A test program
100 REM SPI-EEPROM 25LC040A Test Program
200 REM
300 HIGH = 1
400 LOW = 0
500 SPICS HIGH
700 Rcmd = 03h
800 Wcmd = 02h
900 Wecmd = 06h
1100 SPISTART 32
1300 J = 10
1500 REM EEPROM WRITE
1600 REM
1700 For Iw = 0 To 511 Step 16
1900 SPICS LOW
2000 SPIPUT Wecmd
2100 SPICS HIGH
2300 Iwh = int(Iw/256)
2400 Iwh = Iwh * 8
2500 Iwh = Wcmd .or. Iwh
2600 Iwl = Iw .and. 00FFh
2800 SPICS LOW
2900 SPIPUT Iwh
3000 SPIPUT Iwl
3200 For I = 0 To 15
3300 J = J .and. 00FFh
3400 SPIPUT J
3500 J = J + 1
3600 Next I
3800 SPICS HIGH
3910 REM WAIT FOR WRITE PROCESS END
3920 REM
3930 FOR I=1 to 100 : NEXT I
4000 Next Iw
4200 REM EEPROM READ
4300 REM
4400 For Iw = 0 To 511 Step 16
4600 Iwh = int(Iw/256)
4700 Iwh = Iwh * 8
4800 Iwh = Rcmd .or. Iwh
4900 Iwl = Iw .and. 00FFh
5100 Ph1. Iw,
5200 PRINT ":",
5400 SPICS LOW
5500 SPIPUT Iwh
5600 SPIPUT Iwl
5800 FOR I = 0 TO 15
5900 SPIGET J
6000 Ph0. J,
6100 NEXT I
6300 SPICS HIGH
6500 PRINT
6700 next Iw
6900 EndADC:;ADCSTART [channel] setup ADC function - "channel" is aanalog input port number [0-7]
ADCGET [variable] get "valiable" from ADC [0-2047]
ADCSTOP close ADC function and analog port
ADC test program
10 REM analog port 4
20 ADCSTART 4
30 FOR I=1 TO 10
40 FOR J=1 TO 5
50 ADCGET ADV
60 V=ADV*3.3/2048
70 PRINT V,
80 FOR K=1 TO 4000 : NEXT K
90 NEXT J
100 PRINT
110 NEXT I
120 ADCSTOPBLUETOOTH MODULE:We can change the Module default name to any other valid names mentioned in the AT command manual of the Bluetooth manufacturer. In this case the name is changed to BASIC-52. Most of the Bluetooth module comes with default baud rate of 9600. In this case the baud rate is changed to 19200.
CAUTION:There is no capacitor used in SSOP20 adapter board or external decoupling or bulk capacitor for testing. It is recommended to add decoupling or bulk capacitor as per requirement.
To program the internal FLASH memory of CH558T, the IC needs to enter into bootloader mode. In this situation we need VDD33 pin #20 should have some minimal capacitor. Similary VIN5 pin#19 also should have few microfarad capacitor for reliable operation during flashing the internal FLASH. After that since we are not using the USB and only using Tx and Rx, those capacitors are not necessary.
The following video shows the connection, connectivity with PC and running ASCIIART program which is standard benchmark for speed comparision. With CH558T at 48 MHz it took 11.92 seconds.


Comments