请问HAL库如何设置SPI2一直使能接收中断?

2019-07-14 18:26发布


利用STM32的SPI2作为从设备,想中断接收数据,一直没调通。
现在使这样的,再主函数while(1)循环前,调用一次
HAL_SPI_Receive_IT(&hspi2, (uint8_t *)&spi2RecvBuff[0],2);
主循环里,现在基本清空了。SPI的接收回调函数里,通过串口发送一组数据,然后再调用
HAL_SPI_Receive_IT(&hspi2, (uint8_t *)&spi2RecvBuff[0],2);
想通过这种方法,使SPI2一直处于中断接收使能状态。

结果串口一直没有数据发送过来。用示波器测量SCK和MOSI,是有波形的,和主设备发过来的数据一致。

然后将以上的接收中断函数改成,发送中断函数,使设备不停的发送。
结果测量SCK和MISO,有对应波形,串口也有数据发过来。

是不是调用中断接收函数,还需要做些其他操作?

主函数部分:
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
18条回答
谦谦三君子
2019-07-15 17:14
本帖最后由 any012 于 2016-11-24 14:48 编辑

HAL_SPI_Receive_IT(&hspi2, (uint8_t *)&spi2RecvBuff[0],1)放在回调函数里:

SPI_Receive_IT function is called.
SPI interrupt enable.
SPI enable.
1ms时间到

SPI_RxCloseIRQHandler function is called.
SPI RX interrupt disable.
SPI ERR interrupt disable.
SPI rx callback.
spi2 recive over.
SPI_Receive_IT function is called.
SPI interrupt enable.
1ms时间到

1ms时间到

1ms时间到

----------------------------------------

HAL_SPI_Receive_IT(&hspi2, (uint8_t *)&spi2RecvBuff[0],1)放在中断函数里:

SPI_RxCloseIRQHandler function is called.
SPI RX interrupt disable.
SPI ERR interrupt disable.
SPI rx callback.
spi2 recive over.
SPI_Receive_IT function is called.
SPI interrupt enable.
SPI_Receive_IT function is called.
SPI interrupt enable.
1ms时间到

SPI_RxCloseIRQHandler function is called.
SPI RX interrupt disable.
SPI ERR interrupt disable.
SPI rx callback.
spi2 recive over.
SPI_Receive_IT function is called.
SPI interrupt enable.
SPI_Receive_IT function is called.
SPI interrupt enable.
1ms时间到

SPI_RxCloseIRQHandler function is called.
SPI RX interrupt disable.
SPI ERR interrupt disable.
SPI rx callback.
spi2 recive over.
SPI_Receive_IT function is called.
SPI interrupt enable.
SPI_Receive_IT function is called.
SPI interrupt enable.
1ms时间到

一周热门 更多>