上回讲到怎么采集一路的adc的数据,这次我们来采集两路的数据。

现在直接修改原先的代码

/* Private variables ---------------------------------------------------------*/
uint16_t AD_Value_Buf[];
uint16_t AD_X_Value = ;
uint16_t AD_Y_Value = ;
/* USER CODE END PV */
/* USER CODE BEGIN 3 */
for(uint8_t i=;i<;i++)
{
/*##-1- Start the conversion process #######################################*/
HAL_ADC_Start(&hadc1);//<为启动ADC装换
/*##-2- Wait for the end of conversion #####################################*/
/**
* Before starting a new conversion, you need to check the current state of
* the peripheral; if it’s busy you need to wait for the end of current
* conversion before starting a new one.
* For simplicity reasons, this example is just waiting till the end of the
* conversion, but application may perform other tasks while conversion
* operation is ongoing.
*/
HAL_ADC_PollForConversion(&hadc1, );//<表示等待转换完成,第二个参数表示超时时间,单位ms.
/* Check if the continous conversion of regular channel is finished */
if(HAL_IS_BIT_SET(HAL_ADC_GetState(&hadc1), HAL_ADC_STATE_REG_EOC))
{ /*##-3- Get the converted value of regular channel ######################*/
AD_Value_Buf[i] = HAL_ADC_GetValue(&hadc1);
#ifdef RTT_LOG_ENABLED
loge("AD_Value_Buf[%d] %d",i,AD_Value_Buf[i]);
#endif//RTT_LOG_ENABLED
}
} HAL_ADC_Stop(&hadc1);

现在测测一下

现在和我们的HID的报告相结合

  mouseHID.buttons = ;
mouseHID.x = ;
mouseHID.y = ;
mouseHID.wheel = ;
    AD_X_Value = AD_Value_Buf[];
AD_Y_Value = AD_Value_Buf[];
  #ifdef RTT_LOG_ENABLED
loge("AD_X_Value %d",AD_X_Value);
loge("AD_Y_Value %d",AD_Y_Value);
   #endif//RTT_LOG_ENABLED
// Send HID report
mouseHID.x = AD_Value_map(AD_X_Value,,,-,);//从0-4095映射到-20~20
mouseHID.y = AD_Value_map(AD_Y_Value,,,,-);//从0-4095映射到20~-20
USBD_HID_SendReport(&hUsbDeviceFS, (uint8_t*)&mouseHID, sizeof(struct mouseHID_t));
/* USER CODE BEGIN 0 */
int16_t AD_Value_map(int16_t x, int16_t in_min, int16_t in_max, int16_t out_min, int16_t out_max)
{
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
/* USER CODE END 0 */

利用STM32CubeMX来生成USB_HID_Mouse工程【添加ADC】(2)【非dma和中断方式】的更多相关文章

  1. 利用STM32CubeMX来生成USB_HID_Mouse工程【添加ADC】(1)

    现在原来的基础上添加ADC的功能. 现在(利用STM32CubeMX来生成USB_HID_Mouse工程)基础上新增硬件 JoyStick Shield 游戏摇杆扩展板 与STM32F103C8的连接 ...

  2. 利用STM32CubeMX来生成USB_HID_Mouse工程

    硬件开发板:STM32F103C8 软件平台 好了现在开始利用STM32CubeMX来生成我们的工程 1.新建工程 选择MCU的型号 选择选择时钟 开启usb的模块 选择USB的类 配置时钟树(主要是 ...

  3. 利用STM32CubeMX来生成USB_HID_host工程

    修改时钟(备注这边使用25mhz的主晶振) 选择debug_level等级为3

  4. 试用bus hound来分析STM32CubeMX来生成USB_HID_Mouse工程

    Bus Hound (x64). Complements of www.perisoft.net STM32_HID_mouse Device - Device ID (followed by the ...

  5. 使用STM32CubeMX生成USB_HOST_HID工程[添加对CAPS_LOCK指示灯的控制][SetReport]

    在之前(使用STM32CubeMX生成USB_HOST_HID工程)的基础上进行修改 在结合之前在pc上的测试 USB之HID类Set_Report Request[调试手记1] 测试代码如下: /* ...

  6. 利用STM32CubeMX之SPI

    现在我们继续使用STM32CubeMX来生成SPI工程.我们的硬件平台还是我们熟悉的STM32F103C8开发板. 设置时钟树中的配置 现在打开SPI的设置 如果想修改管脚的名字可以红色框中进行修改, ...

  7. STM32 ADC多通道转换DMA模式与非DMA模式两种方法(HAL库)

    一.非DMA模式(转) 说明:这个是自己刚做的时候百度出来的,不是我自己做出来的,因为感觉有用就保存下来做学习用,原文链接:https://blog.csdn.net/qq_24815615/arti ...

  8. 利用STM32CubeMX生成HID双向通讯工程

    使用开发板为正点原子ministm32 现在我们先使用HID descriptor Tool来生成我们需要的hid的 保存使用选择.H // D:\usb资料\HID\MSDEV\Projects\t ...

  9. 使用STM32CubeMX生成RTC工程[闹钟中断2]

    在上次使用STM32CubeMX生成RTC工程[闹钟中断]基础上实现周期间隔的闹钟 一些场合需要周期性的闹钟 现在为了方便设置每十秒来一次. 备注: 当然可以直接修改HAL库static HAL_St ...

随机推荐

  1. windows 多用户登陆设置

    在 “运行”中输入gpedit.msc打开“本地组策略编辑器” | 计算机配置 | 管理模板 | windows 组件 | 远程桌面服务 | 远程桌面会话主机 | 连接 | 限制连接的数量 | 编辑 ...

  2. 《HTTP 权威指南》笔记:第十六章&第十七章 国际化、内容协商与转码

    <HTTP 权威指南>笔记:第十六章 国际化 客户端通过在请求报文中的 Accept-Language 首部和 Accept-Charset 首部来告知服务器:“我理解这些语言.”服务器通 ...

  3. C# Log4Net 日志

    C#使用Log4Net记录日志 第一步:下载Log4Net            下载地址:http://logging.apache.org/log4net/download_log4net.cgi ...

  4. Linux - 7种运行级别

    目录:etc/rc.d/init.d 1. linux开机过程 2. 运行级别(0-6) 存储位置 etc/inittab,开机加载,也可以用命令init [数字]切换. # 0 - 停机(默认时为0 ...

  5. TCP建立连接为什么是三次握手,为什么不是两次或四次?

    什么是三次握手 学过网络编程的人,应该都知道TCP建立连接的三次握手,下面简单描述一下这个过程. 如图所示 第一次握手:客户端发送TCP包,置SYN标志位为1,将初始序号X,保存在包头的序列号(Seq ...

  6. Delegate, NSNotification, KVO, Block

    delegate: 当我们第一次编写iOS应用时,我们注意到不断的在使用“delegate”,并且贯穿于整个SDK.delegation模式不是iOS特有的模式,而是依赖与你过去拥有的编程背景.针对它 ...

  7. 2015-10-06 认识jQuery1

                                                                                                    jQue ...

  8. kali-rolling安装使用sonarqube教程(docker方式)

    一.说明 最近要找一款代码审计工具,Fortify SCA太贵,VisualCodeGrepper不太好用.在freebuf上看到可用sonarqube来建代码自动化扫描系统所以也来试一试. 直接安装 ...

  9. VLC的一些接口

    其他参考链接: 1.https://www.cnblogs.com/smartsensor/p/4343769.html ======================================= ...

  10. jquery promise (Deferred)

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...