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 of 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 of the Bluetooth printer is shown in Figure 1:
Figure 1 The overall idea of the design of the Bluetooth printer
is to use a single-chip microcomputer 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 the 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 the master device to query and initiate the connection, and the Bluetooth on the printer side acts as the slave device to wait for the connection to be established. 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:
Figure 2 Ericsson ROK 101 008 hardware block diagram
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
Figure 3 Schematic diagram of Bluetooth HCI transmission layer
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 visible to 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
There are three main types of transport layers: HCI USB; HCI PCM; HCI UART. We use a microcontroller to control the Bluetooth module through the HCI-UART transport sublayer. The schematic diagram of the connection is shown in Figure 4:
Figure 4 Schematic diagram of the connection between the microcontroller and Bluetooth
Generally speaking, directly connecting the microcontroller and the Bluetooth chip within a short distance can ensure reliable data transmission, and there is no need to connect the 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 the 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 an instruction, it will return a command completion event (Command_Complete_Event) with status parameter information to inform the host (microcontroller) of the execution of the command.
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 the master device, the above parameter settings need to be done before querying 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 connection to be established. 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 single-chip
microcomputer, the host and the printer The interface circuit between the single-chip microcomputer, the host and the printer is very simple. Take the connection with the printer as an example. The circuit is shown in Figure 5:
Figure 5 Schematic diagram of the connection between the single-chip microcomputer and the printer
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 generally matching resistors on the printer side. Therefore, P3.3, which is the output of the STROBE signal, cannot be directly connected to the printer. Here we use a NAND gate to increase the driving ability to achieve control. When the single-chip microcomputer receives the data sent by the host through 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. Listen to the BUSY signal on P3.7. 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 solution does not involve the specific model of the printer, nor does it need to change the user's printer driver, so it is applicable to most general printers. This method of using a single-chip microcomputer to control the Bluetooth module through the UART transmission layer is not only applicable to the development of Bluetooth printers, but also to 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.