Monday, January 27, 2014

In the yard in 2014, and to communicate with microcontrollers PC is the most popular means of an or


In the yard in 2014, and to communicate with microcontrollers PC is the most popular means of an ordinary serial port. It's easy to get started, it is up to the primitiveness easy to understand - just a stream of bytes. However, all modern standards excluded from the COM port of a PC and have to use USB-UART adapter to access your project tandoori chicken at MC. He is not always at hand. Not always such an adapter is stable because of problems with the drivers. There are other disadvantages. But every time comes to talk about how to use a USB or serial port, there are many fans of logical simplicity UART. And they have good reason. However, because the good to have an alternative? I have long been asked to tell how to organize a batch data exchange between PC and MC for example STM32F103. I'll prepare a working draft and will discuss how to adapt it to their needs. And so you decide - you need it or not. We have a board with a modern cost STM32F103C8 microcontroller with integrated hardware support for USB, I talked about it earlier I said that the serial tandoori chicken port has other drawbacks: often-COM port is not in the PC or laptop-powered device must be submitted separately, even available COM port on the PC to be agreed signal levels: PC uses RS232 interface with differential signal levels of +15 V and-15V, and microcontrollers - TTL levels (+5 V, +3.3 V, unipolar). -Often formed in the system tens of virtual COM ports, and to find the port that corresponds to your device may not be easy. In turn USB with us for many years and has its advantages:-Ability to supply power from a HOST device-Easy implementation batch exchange-Simultaneous connection to multiple programs-Ability to uniquely identify the connected device, hardware support in many modern MK, which excludes Functional USB adapters need an extremely rich, but it creates tandoori chicken a problem - not as easy to understand as a serial interface. tandoori chicken There is a separate class of devices - USB-HID, which do not require drivers, specifically designed for human interaction and various input and output devices. Ideal for data exchange with the MC. Personally I like the batch exchange. This is a convenient abstraction. Besides disassemble packet message is somewhat simpler and more convenient than working with a simple byte stream. tandoori chicken Select profile HID USB-HID - a fairly extensive class of devices, so first of all have to choose which device will be created. We can create an emulation of the keyboard, mouse, joystick, and other input devices, and can create tandoori chicken their device, not to depend on a fairly tandoori chicken rigid framework of standard and freely exchange data with a PC. I will tell you how To make the Custom HID device. This gives maximum freedom. In order not to delay the article, age tell as briefly as possible - description of the standards in the network without me a lot, but for me personally they have little help when needed to solve a specific problem. tandoori chicken The project structure I use for development under EmBlocks STM32. You can use any convenient environment, the project is not very difficult to adapt. To the basic structure of the project added: Folder USB-FS library STM32F10x, STM32L1xx and STM32F3xx USB-FS-Device Driver 4.0.0. Folders Inc and Src files: platform_config.h - collected here definition of a particular board and MCU stm32_it.h, stm32_it.c - here defined interrupt handlers tandoori chicken usb_conf.h, tandoori chicken usb_endp.c - here defined endpoints (Endpoint), dimensions addresses and their buffers, handler functions usb_desc.h, usb_desc.c - here to gather information about the device - as it will be determined when you connect to your PC and determine the size and format of data packets hw_config.c - gathered here all work with data is sent to PC hw_config.h, usb_istr.h, usb_prop.h, usb_pwr.h usb_istr.c, usb_prop.c, usb_pwr.c - need to work on USB-FS library, but not necessarily to go into them all the files we add to any project using USB. USB initialization to work correctly USB module important frequency of the MC. Not all frequencies allow to correctly set the clock USB. In our case we use a crystal oscillator to 8MHz and MC clocked at 72MHz and 48MHz USB module. In main.c enough to include a few lines of code
/ * Includes ----------------------------------------------- ------------------- * / # include "hw_config.h" # include "usb_lib.h" # include "usb_pwr.h" / * Private variables ---- -------------------------------------------------- --- * / __ IO uint8_t PrevXferComplete = 1; int main (void) {Set_System (); USB_Interrupts_Config (); Set_USBClock (); USB_Init (); while (1) {if (bDeviceState == CONFIGURED) {if (PrevXferComplete) tandoori chicken {RHIDCheckState ();}}}} The functions Set_System () configures pin lift the D + Power for

1 comment:

  1. pas cher jimmy choo chaussures, combinant style élégant et technologie de pointe, une variété de styles de pas cher jimmy choo sliders, le pointeur se place entre votre style gustatif exclusif.

    ReplyDelete