A bluetooth printer implementation solution
[Copy link]
Introduction As a short-range wireless communication protocol, Bluetooth technology stands out among many wireless solutions for its low cost, low power consumption, high speed, convenience and flexibility. The working distance of Bluetooth 10m can well meet the application occasions of most digital devices, such as office or home. Printer is a commonly used device. Getting rid of the inconvenience brought by printer connection and realizing wireless printing can reduce the unpleasant cables on the desktop, and the printer can be moved away from the host and placed in a suitable position in the room. This article introduces a method of using Bluetooth technology to realize wireless connection between the host and the printer and realize remote control printing. The overall idea of the design scheme of Bluetooth printer is shown in Figure 1: A single-chip microcomputer is used on the host side to simulate the printer to work, intercept the data and control signals transmitted from the host parallel port, and transmit them to the printer side through Bluetooth wireless connection. The single-chip microcomputer on the printer side simulates the host to control the printer according to the received Bluetooth data, thereby realizing the Bluetooth wireless connection between the printer and the host. The Bluetooth on the host side acts as a master device to query and initiate the connection, and the Bluetooth on the printer side acts as a slave device to wait for the establishment of the connection. The single-chip microcomputer uses 89C2051, and the Bluetooth chip uses the ROK101-008 produced by Ericsson that supports point-to-point connection. The module includes five main parts: wireless part, baseband controller, flash memory, power control module and internal clock. It provides UART, PCM, I2C standard interfaces and built-in crystal oscillator. Its hardware block diagram is shown in Figure 2: This solution is suitable for general printers with Centronic parallel interface. Users do not need to change the printer driver. They only need to connect the two boards containing the single-chip microcomputer and Bluetooth to the host and the printer respectively to perform wireless printing. The whole process is transparent to the original printer driver, which provides great convenience for printer users. Single-chip microcomputer control of Bluetooth module The Bluetooth specification defines the host control interface (HCI), which provides a standard command interface for baseband controllers, hardware controllers, hardware status and control registers. The host sends control commands and data to the Bluetooth module through the HCI transport layer, and the Bluetooth module sends its status information and data back to the host through the HCI transport layer. The main purpose of the HCI transport layer is to achieve transparency. The transport layer does not need to be aware of the data sent by the host controller driver to the host controller, which allows the interface (HCI) or the host controller to be upgraded without affecting the transport layer. As shown in Figure 3, at least four different types of packets are transmitted in the HCI transport layer - HCI commands, HCI events, ACL data and SCL data. Each HCI packet starts with an HCI indicator header, and different indicator headers represent different types of HCI packets: 0x01 HCI command packet 0x02 HCI ACL data packet 0x03 HCI SCO data packet 0x04 HCI event packet The transport layer mainly has the following three types: HCI USB; HCI PCM; HCI UART. We use a single-chip microcomputer to control the Bluetooth module through the HCI-UART transport sublayer. The schematic diagram of the connection is shown in Figure 4: Generally speaking, directly connecting the single-chip microcomputer to the Bluetooth chip within a short distance can ensure reliable data transmission, and there is no need to connect CTS and RTS signals for flow control. The UART communication between the microcontroller and Bluetooth uses 8 data bits, 1 stop bit, no parity check, and uses a typeless little endian format, that is, the lowest bit is sent first. The UART communication format and baud rate can be adjusted by sending HCI instructions from the microcontroller to Bluetooth. The ROK-101-008 chip can support a UART rate of up to 460.8Kbps. The first HCI instruction sent to the Bluetooth module should be a software reset (Soft Reset) command. When Bluetooth executes a command, it will return a command completion event (Command_Complete_Event) with status parameter information to inform the host (microcontroller) of the command execution. After the software reset is completed, in order to make the Bluetooth module wait for inquiries and connection initiations from other Bluetooth devices as a slave device, we also need to set some timer values and perform a series of parameter settings. Even if it is the host-side Bluetooth as a master device, the above parameter settings need to be done before inquiring and establishing a connection. The parameters that need to be set are mainly the following: * Set Event Filter (set event filter) * Write Scan Enable (set scan parameters, such as whether query and paging can be performed) * Write Authentication Enable (set whether authentication is required) * Write Page Timeout (set paging timeout, generally this value can be set to 7s) After setting the above parameters, the Bluetooth module on the printer side is ready to be a slave device and wait for the establishment of a connection. The Bluetooth module on the host side also needs to perform an inquiry process to obtain the Bluetooth address of the remote device and initiate a connection based on the Bluetooth address obtained by the inquiry. Once the Bluetooth connection is established, data can be sent and received to achieve Bluetooth wireless printing. Connection between the microcontroller, the host and the printer The interface circuit between the microcontroller, the host and the printer is very simple. Take the connection with the printer as an example. The circuit is shown in Figure 5: Connect the P1 port of the 89C2051 directly to the data port of the printer, and use P3.7 to sample the BUSY signal of the printer. Since the connection between the host and the printer is generally long, there are usually matching resistors on the printer side. Therefore, P3.3, which is the STROBE signal output, cannot be directly connected to the printer. Here we use a NAND gate to increase the driving capability to achieve control. When the microcontroller receives the data sent by the host via Bluetooth, it simulates the host on the printer side to control the printer. First, the data to be sent to the printer is output from the P1 port, and then a negative pulse is generated from P3.3 through the gate circuit in reverse, which is sent to the printer as a selection signal. The BUSY signal on P3.7 is listened. When the signal level is low, it means that the data has been received by the printer and the next data can be sent. Conclusion The above scheme does not involve the specific model of the printer, and there is no need to change the driver of the user's printer, so it is suitable for most general printers. This method of using a microcontroller to control the Bluetooth module through the UART transmission layer is not only suitable for the development of Bluetooth printers, but also suitable for various embedded Bluetooth systems. ■References: 1. Specifications of the Bluetooth System Version 1.1, http://www.bluetooth.com. 2. Ericsson ROK 101 008 Data Sheet, http://www.ericsson.com. 3. Jin Chun et al., Bluetooth Technology, Electronic Industry Press, 2001. 4. Li Hua et al., Practical Interface Technology of MCS-51 Series Microcontrollers, Beijing University of Aeronautics and Astronautics Press, 1993.
Fig.1 The overall idea of Bluetooth printer designFig.2
Ericsson ROK 101 008 hardware block diagramFig.3
Schematic diagram of Bluetooth HCI transport layerFig.4
Schematic diagram of MCU and Bluetooth connectionFig.5
Schematic diagram of MCU and printer connection
|