This post was last edited by flyword on 2019-2-12 22:42
Continue the evaluation and use of the xmc4800 kit development board. In the DAVE software, there are two USB APP applications: USB_VCOM and WINUSB. Infineon has implemented the USB virtual serial port module in the USB_VCOM APP and the winusb application in the WINUSB APP. This post will mainly introduce the application process of winusb.
Winusb is a USB middleware provided by Microsoft, similar to libusb, so that users no longer have to worry about USB drivers, and can directly use winusb to quickly complete communication and data exchange with USB devices.
This post will simply apply WINUSB APP and use the ADC module to realize the simplest USB interface oscilloscope. , sans-serif] The specific steps are as follows:
1. Add related APP. Here we add 1 WINUSB and 1 ADC_MEASUREMENT.
sans-serif]
2. Configure ADC_MEASUREMENT. Here, select ADC pin 14.0 and ADC working mode non-interrupt mode. , sans-serif]3. About the application of WINUSB APP, the specific contents are as follows:
The usage process is USB initialization, USB connection, USB enumeration, and start USB data transmission.
4. After this configuration, generate the code, and then simply add a program in main.c to read the ADC and send it through the USB port. The specific code is as follows:
- #include<dave.h> //Declarations from DAVE Code Generation (includes SFR declaration)
- int main(void)
- {
- DAVE_STATUS_t status;
- status = DAVE_Init(); /* Initialization of DAVE APPs */
- if(status != DAVE_STATUS_SUCCESS)
- {
- /* Placeholder for error handler code. The while loop below can be replaced with an user error handler. */
- XMC_DEBUG("DAVE APPs initialization failed\n");
- while(1U)
- {
- }
- }
- if(USBD_WINUSB_Connect() != USBD_WINUSB_STATUS_SUCCESS)
- {
- return -1;
- }
- while(!USBD_WINUSB_IsEnumDone());
- uint8_t adc_string[4];
- /* Placeholder for user application code. The while loop below can be replaced with user application code. */
- while(1U)
- {
- uint16_t adc_value=ADC_MEASUREMENT_GetResult(&ADC_MEASUREMENT_Channel_A);
- sprintf(adc_string,"%d",adc_value);
- USBD_WINUSB_WriteData(winusb_info.config.in_endpoint.Address,&adc_string,4);
- }
- }
复制代码
5. 之后切换xmc4800 kit usb连线,并插入到电脑,此时第一次使用winusb,需要安装驱动程序,具体的程序英飞凌已经在inf文件夹里提供了,添加安装即可,之后检查设备管理器,会出现winusb设备。至此,我们对于xmc4800 kit的操作就OK了。
6. 如何读取winusb的数据呢?我这里采用了.NET的winusb库,在VS2017中添加winusb库以后,在程序中根据winusb的设备GUID建立设备实例,对USB 输入端点 进行操作即可读取xmc4800 kit usb口传输过来的ADC数据data_get。
7. 进一步对data_get的数据处理后,得到最终的ADC电压值。利用曲线显示插件,最终显示xmc4800 kit ADC数据曲线截图如下,这里ADC由于没有外加电压,因此测出来的数值基本是一条线(红线)。
8. 今天分享到此。可以看到APP的引入,我们在使用相关部件时,这里包括USB、ADC,都无需深入掌握相关的底层代码,从而能全力关注到自己的顶层应用上,极大的缩短了产品的开发时间,而APP应用也降低了这款MCU的应用难度和门槛。
此内容由EEWORLD论坛网友flyword原创,如需转载或用于商业用途需征得作者同意并注明出处