上回讲到怎么采集一路的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. ubantu下git的连接和使用

    目录 操作命令 创建仓库,并提交一个readme文件. 文件改动怎么办 版本回退 版本库(Repository) 撤销修改 删除文件 远程仓库 添加远程库 本地有一个仓库,想要在GitHub上同步这个 ...

  2. SWUST OJ(961)

    进制转换问题 #include<stdio.h> #include<stdlib.h> #define STACK_SIZE 100 #define STCK_INCREMEN ...

  3. Ubuntu环境下,项目出现:Call to undefined function curl_init() 提示

    原因: 没有开启curl扩展 安装或者开启扩展 ubuntu 执行安装Curl的扩展 sudo apt-get install -y php-curl 同: mysql,redis,curl,等. 摘 ...

  4. prometheus热重启

    prometheus启动命令添加参数 --web.enable-lifecycle 然后热重启:curl -XPOST http://localhost:9090/-/reload

  5. DFS例题

    特殊的质数肋骨(递归)] -题目描述-农民约翰的母牛总是生产出最好的肋骨.你能通过农民约翰和美国农业部标记在每根肋骨上的数字认出它们. 农民约翰确定他卖给买方的是真正的质数肋骨,是因为从右边开始切下肋 ...

  6. webstorm激活教程

    虽然webStorm,phpStorm以及jetbrains系列的很好用,但是每隔一段时间就需要激活一下,这样太费劲了,今天军哥给大家推荐一个永久激活的办法 此教程适用于jetbrains 的所有系列 ...

  7. Mad Libs游戏 & 华氏温度与摄氏温度转换

    Mad Libs游戏 animal1 = input("请输入一种动物") animal2 = input("请输入一种动物") movement1 = inp ...

  8. pip 安装 nexmo

    pip install nexmo报错 是因为缺少 libffi-devel 需要    yum install libffi-devel 然后再执行  pip install nexmo 即可成功

  9. Problem D: 平面上的点——Point类 (IV)

    Description 在数学上,平面直角坐标系上的点用X轴和Y轴上的两个坐标值唯一确定.现在我们封装一个“Point类”来实现平面上的点的操作. 根据“append.cc”,完成Point类的构造方 ...

  10. 路由器桥接尝试WDS

    第一步:设置主路由器192.168.1.1. 第二步:设置副路由器. 进入副路由器的设置界面 点击「网络参数」->「LAN口设置」 把副路由器的LAN地址设置为192.168.1.2防止与主路由 ...