最近用到了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中断是什么意思呢?
提前感谢各位回复的大佬!谢谢!
|