硬汉嵌入式论坛

 找回密码
 立即注册
查看: 665|回复: 1
收起左侧

[STM32CubeF4] 请教关于STM32最新HAL库的DMA的问题

[复制链接]

10

主题

32

回帖

62

积分

初级会员

积分
62
发表于 2023-3-10 17:48:08 | 显示全部楼层 |阅读模式
最近用到了STM32,在最新的HAL库下,用到了串口和IIC的DMA,目前有一些问题不是很懂,想请教一下大佬们。
1.串口空闲中断+DMA
最新的库里面有一个函数HAL_UARTEx_ReceiveToIdle_DMA()可以自动DMA传输,当产生空闲中断时,即使未接收到指定数量的数据也终止传输。函数说明如下:

    以DMA模式接收一定量的数据,直到接收到预期的数据数量或发生IDLE事件。

    * @note Reception is initiated by this function call. Further progress of reception is achieved thanks
    *         to DMA services, transferring automatically received data elements in user reception buffer and
    *         calling registered callbacks at half/end of reception. UART IDLE events are also used to consider
    *         reception phase as ended. In all cases, callback execution will indicate number of received data elements.

    * @note  When the UART parity is enabled (PCE = 1), the received data contain the parity bit (MSB position).

    * @note  When UART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M = 01),
    *         the received data is handled as a set of uint16_t. In this case, Size must indicate the number
    *         of uint16_t available through pData.

参考的别人的用法,在空闲中断中处理数据然后再次调用这个函数,接受从头开始了,但是DMA配置的是回环模式,这个模式不应该是接受到数组末尾才从头开始吗?

对于GPS信息,是否有必要使用双重缓冲,在空闲中断中拷贝数据到第二个缓冲区,对第二个缓冲区解析数据?


2.I2C DMA+GPIO中断

通过I2C读取MPU6050,INT引脚配置为GPIO中断。实现思路是I2C DMA配置为普通模式,然后再GPIO中断中调用I2C DMA读取函数吗?

另外I2C可配置  EVENT 和 ERR 中断,但是开启中断的函数__HAL_I2C_ENABLE_IT()传参有下面3种:

EVENT 中断事件有

    I2C_IT_BUF: Buffer interrupt enable

    I2C_IT_EVT: Event interrupt enable

    I2C_IT_ERR: Error interrupt enable

其中BUF中断是什么意思呢?


提前感谢各位回复的大佬!谢谢!



回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106749
QQ
发表于 2023-3-10 18:32:45 | 显示全部楼层
1、GPS你是一秒处理一次吧,这样的话,DMA循环或者或者正常模式都可以。那个方便用那个
2、这个需要你看下STM32的参考手册了,我一直用的IO模拟方式
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2024-5-4 07:01 , Processed in 0.155305 second(s), 25 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表