Design of USB interface for embedded ECG and blood pressure monitor

Publisher:水手谷水手Latest update time:2016-10-11 Source: ofweekKeywords:S3C44B0X Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
  USB interface circuit design for monitor

  The main control chip of the system adopts 32-bit high-performance embedded ARM microprocessor S3C44B0X, and the USB dedicated control chip is USBN9603. USBN9603 has 7 built-in FIFO ports, including 1 bidirectional control port, 3 sending ports and 3 receiving ports, each with 64 bytes.

  The interface circuit between USB controller and S3C44B0X is shown in Figure 1. The USB controller is designed as Bank2, that is, the nGCS2 bank selection line is used as the chip select line of USBN9603, and the chip select address of the chip is 0x4000000. This article adopts a parallel data interface, and the lower 8-bit data lines D0~D7 of the two chips are connected to transmit communication data in parallel. Both MODE0 and MODE1 pins are grounded, and USBN9603 is configured as non-multiplexed mode. Since this working mode requires address line A0 as the selection line for accessing the USBN9603 on-chip registers DATA_IN, DATA_OUT and ADDR registers, it is necessary to connect A18 in the 32-bit address bus to A0 of the USB controller. When reading and writing USBN9603, it is divided into two bus cycles: first, set the address line A0 high, that is, set the bus address to 0x4040000, and write the address of the register to be accessed from the data line D[0:7], so that the address is sent to the chip in the first bus cycle; then, in the second cycle, set A0 low, that is, set the bus address to 0x4000000, and read and write D[0:7] to realize the read and write operation of the register. The entire USB communication process mainly handles various interrupt events including receiving and sending data. Connect the INT pin of USBN9603 to the external interrupt EINT0 pin of S3C44B0X, and set the USB interrupt to the vector interrupt request mode. Since the DMA mode is not used, DACK needs to be set high, and the DMA request line DRQ is suspended. The USB cable has 4 wires, D+ and D- are USB differential signal lines, and the other two are 5V power line and ground line. USBN9603 supports low-speed and full-speed USB communication. Connect a 1.5KΩ pull-up resistor to the D+ signal line to make it work in full-speed mode.

  USB interface firmware implementation of monitor

  The operation of the USB communication process starts from the host. According to the agreed timing, a token packet is first sent out, which contains information such as the operation type, direction, peripheral address and endpoint number. Then the data sender is specified in the token to send a data packet or indicate that there is no data transmission. The USB peripheral responds with a confirmation packet to indicate that the transmission is successful.

  This paper adopts the master-slave USB communication structure. The host computer realizes the collection of ECG and blood pressure data and the initialization of system equipment by sending various pre-agreed protocol commands. The main data include the following: ECG data is in segments, each segment includes 32KB ECG data and 6B acquisition time information, and several segments are transmitted each time. The data volume is large and the transmission reliability requirement is also high; blood pressure data includes diastolic and systolic pressure and their acquisition time, a total of 10B. Since blood pressure monitoring is relatively frequent, blood pressure monitoring data within a period of time will be transmitted each time, and the data volume is also relatively large; download the upgraded version of the firmware and other file information. The data flow of these three types of data is relatively large, and the reliability requirements are relatively high. All three types of data use the block transmission channel type. In addition, each USB transmission must have a control transmission channel. Therefore, three channels are required, namely the control channel, BulkIN channel and BulkOUT channel.

  USB firmware data structure 

  This article deals with the four types of descriptors that the host computer requires the device to transmit in the control transmission during the USB device configuration enumeration phase. They are hierarchically: device descriptor, configuration descriptor, interface descriptor and endpoint descriptor. Among them, higher-level descriptors will notify the host of any other lower-level descriptor information.

  The device descriptor is the first descriptor that the host reads when the device is connected. Each device can only have one device descriptor, which contains the information of the entire device and the configuration number supported by the device, with a total of 18 fields. Each USB device has one or more configuration descriptors, which contain the power management of the device and the interface number supported by the device configuration. When the device receives the request to obtain the configuration descriptor, it transmits the configuration descriptor and all its interfaces, endpoints and other subsidiary descriptors to the host. This article sets a configuration, and its descriptor has a total of 8 fields. The interface contains a group of endpoints. This article sets an interface, and its descriptor has 9 fields, which provides the host computer with information such as the number and type of endpoints used by the device. Each interface descriptor has zero or more endpoint descriptors, which contain the information required for the host to communicate with the endpoint. Endpoint 0 is used as a control endpoint for communication, and endpoint 1 and endpoint 2 are block transfer modes respectively. Its descriptor contains information such as endpoint number, transfer direction, endpoint transfer type, and maximum transfer bytes of data packets.

  USB firmware communication flow

  After entering the communication module, the USB firmware framework process first calls the initialization routine to configure the USB interface device and put it into operation, and then enables the interrupt. The main function of USB communication is implemented in the interrupt service. The main program just waits in a loop for an exit button. When an interrupt signal is detected, it enters the interrupt service subroutine, determines the interrupt type based on the value of register MAEV, and enters the corresponding processing process.

  The USB communication of the device mainly realizes the Bulk transmission function of ECG and blood pressure data. Based on the communication protocol of USB bus receiving and sending data, the monitor also has a specific application layer communication protocol. After receiving the user communication command, the firmware parses the control command and executes the corresponding routine. For example, when transmitting ECG and blood pressure data, the command 0x10, after receiving the command code 0x10, the firmware obtains the length of the data to be transmitted, the transmission flag of ECG or blood pressure selection and its record number from the command parameters, calls GetRecordData() according to the record number, searches for data from the Flash storage area and stores it in the sending buffer of BulkState. If ECG data is transmitted, the acquisition time of the ECG data segment must be obtained through GetTIme(). After all the data to be transmitted are ready, the transmission begins. Since the maximum buffer of Bulk transmission is 64B, 64B data is sent first, and then the host computer is judged in the TX_EV routine whether it is received successfully. If successful, the next batch of block input transactions is transmitted, otherwise it needs to be retransmitted. The above process is repeated until the data is sent.

  USB firmware module routines

  initialization

  The initialization routine of the USB interface includes the initialization operation of the USBN9603 chip and the initialization of user variables, and then the device enumeration operation begins. During the initialization phase, the firmware needs to operate the registers of the USBN9603 in strict order.

  USB device enumeration process

  Connect the system's USB cable to a USB port (hub or host root hub), and the device is powered on; there are two 15KΩ pull-up resistors between the USB D+ and D- data lines and the connected hub port or host root hub. At this time, the pull-up resistor will cause the level on the data signal line to rise, notifying the hub that a new device has been connected; then, the hub uses the interrupt channel to report the event to the host. When a new device is indeed connected, the host sends a Set_Port_Feature request to the hub connected to the device, causing the hub to send a USB hardware reset command to the port for 10ms, and then identify the speed of the device. At this point, the device has completed the initialization operation. When the host proves that the device has left the reset state, it starts USB control transmission on the default channel of endpoint 0 and enters the enumeration phase.
 

  USB interface circuit design for monitor

  The main control chip of the system adopts 32-bit high-performance embedded ARM microprocessor S3C44B0X, and the USB dedicated control chip is USBN9603. USBN9603 has 7 built-in FIFO ports, including 1 bidirectional control port, 3 sending ports and 3 receiving ports, each with 64 bytes.

  The interface circuit between USB controller and S3C44B0X is shown in Figure 1. The USB controller is designed as Bank2, that is, the nGCS2 bank selection line is used as the chip select line of USBN9603, and the chip select address of the chip is 0x4000000. This article adopts a parallel data interface, and the lower 8-bit data lines D0~D7 of the two chips are connected to transmit communication data in parallel. Both MODE0 and MODE1 pins are grounded, and USBN9603 is configured as non-multiplexed mode. Since this working mode requires address line A0 as the selection line for accessing the USBN9603 on-chip registers DATA_IN, DATA_OUT and ADDR registers, it is necessary to connect A18 in the 32-bit address bus to A0 of the USB controller. When reading and writing USBN9603, it is divided into two bus cycles: first, set the address line A0 high, that is, set the bus address to 0x4040000, and write the address of the register to be accessed from the data line D[0:7], so that the address is sent to the chip in the first bus cycle; then, in the second cycle, set A0 low, that is, set the bus address to 0x4000000, and read and write D[0:7] to realize the read and write operation of the register. The entire USB communication process mainly handles various interrupt events including receiving and sending data. Connect the INT pin of USBN9603 to the external interrupt EINT0 pin of S3C44B0X, and set the USB interrupt to the vector interrupt request mode. Since the DMA mode is not used, DACK needs to be set high, and the DMA request line DRQ is suspended. The USB cable has 4 wires, D+ and D- are USB differential signal lines, and the other two are 5V power line and ground line. USBN9603 supports low-speed and full-speed USB communication. Connect a 1.5KΩ pull-up resistor to the D+ signal line to make it work in full-speed mode.

  USB interface firmware implementation of monitor

  The operation of the USB communication process starts from the host. According to the agreed timing, a token packet is first sent out, which contains information such as the operation type, direction, peripheral address and endpoint number. Then the data sender is specified in the token to send a data packet or indicate that there is no data transmission. The USB peripheral responds with a confirmation packet to indicate that the transmission is successful.

  This paper adopts the master-slave USB communication structure. The host computer realizes the collection of ECG and blood pressure data and the initialization of system equipment by sending various pre-agreed protocol commands. The main data include the following: ECG data is in segments, each segment includes 32KB ECG data and 6B acquisition time information, and several segments are transmitted each time. The data volume is large and the transmission reliability requirement is also high; blood pressure data includes diastolic and systolic pressure and their acquisition time, a total of 10B. Since blood pressure monitoring is relatively frequent, blood pressure monitoring data within a period of time will be transmitted each time, and the data volume is also relatively large; download the upgraded version of the firmware and other file information. The data flow of these three types of data is relatively large, and the reliability requirements are relatively high. All three types of data use the block transmission channel type. In addition, each USB transmission must have a control transmission channel. Therefore, three channels are required, namely the control channel, BulkIN channel and BulkOUT channel.

  USB firmware data structure 

  This article deals with the four types of descriptors that the host computer requires the device to transmit in the control transmission during the USB device configuration enumeration phase. They are hierarchically: device descriptor, configuration descriptor, interface descriptor and endpoint descriptor. Among them, higher-level descriptors will notify the host of any other lower-level descriptor information.

  The device descriptor is the first descriptor that the host reads when the device is connected. Each device can only have one device descriptor, which contains the information of the entire device and the configuration number supported by the device, with a total of 18 fields. Each USB device has one or more configuration descriptors, which contain the power management of the device and the interface number supported by the device configuration. When the device receives the request to obtain the configuration descriptor, it transmits the configuration descriptor and all its interfaces, endpoints and other subsidiary descriptors to the host. This article sets a configuration, and its descriptor has a total of 8 fields. The interface contains a group of endpoints. This article sets an interface, and its descriptor has 9 fields, which provides the host computer with information such as the number and type of endpoints used by the device. Each interface descriptor has zero or more endpoint descriptors, which contain the information required for the host to communicate with the endpoint. Endpoint 0 is used as a control endpoint for communication, and endpoint 1 and endpoint 2 are block transfer modes respectively. Its descriptor contains information such as endpoint number, transfer direction, endpoint transfer type, and maximum transfer bytes of data packets.

  USB firmware communication flow

  After entering the communication module, the USB firmware framework process first calls the initialization routine to configure the USB interface device and put it into operation, and then enables the interrupt. The main function of USB communication is implemented in the interrupt service. The main program just waits in a loop for an exit button. When an interrupt signal is detected, it enters the interrupt service subroutine, determines the interrupt type based on the value of register MAEV, and enters the corresponding processing process.

  The USB communication of the device mainly realizes the Bulk transmission function of ECG and blood pressure data. Based on the communication protocol of USB bus receiving and sending data, the monitor also has a specific application layer communication protocol. After receiving the user communication command, the firmware parses the control command and executes the corresponding routine. For example, when transmitting ECG and blood pressure data, the command 0x10, after receiving the command code 0x10, the firmware obtains the length of the data to be transmitted, the transmission flag of ECG or blood pressure selection and its record number from the command parameters, calls GetRecordData() according to the record number, searches for data from the Flash storage area and stores it in the sending buffer of BulkState. If ECG data is transmitted, the acquisition time of the ECG data segment must be obtained through GetTIme(). After all the data to be transmitted are ready, the transmission begins. Since the maximum buffer of Bulk transmission is 64B, 64B data is sent first, and then the host computer is judged in the TX_EV routine whether it is received successfully. If successful, the next batch of block input transactions is transmitted, otherwise it needs to be retransmitted. The above process is repeated until the data is sent.

  USB firmware module routines

  initialization

  The initialization routine of the USB interface includes the initialization operation of the USBN9603 chip and the initialization of user variables, and then the device enumeration operation begins. During the initialization phase, the firmware needs to operate the registers of the USBN9603 in strict order.

  USB device enumeration process

  Connect the system's USB cable to a USB port (hub or host root hub), and the device is powered on; there are two 15KΩ pull-up resistors between the USB D+ and D- data lines and the connected hub port or host root hub. At this time, the pull-up resistor will cause the level on the data signal line to rise, notifying the hub that a new device has been connected; then, the hub uses the interrupt channel to report the event to the host. When a new device is indeed connected, the host sends a Set_Port_Feature request to the hub connected to the device, causing the hub to send a USB hardware reset command to the port for 10ms, and then identify the speed of the device. At this point, the device has completed the initialization operation. When the host proves that the device has left the reset state, it starts USB control transmission on the default channel of endpoint 0 and enters the enumeration phase.

Keywords:S3C44B0X Reference address:Design of USB interface for embedded ECG and blood pressure monitor

Previous article:Development of a bioimpedance analyzer based on USB2.0 interface
Next article:Learning STM32 general timer

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号