你好,我现在在GPIO的中断函数中,调用SPI,运行到函数SPI_transfer时,程序会跑飞。在中断函数中不能调用SPI吗?
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
把模式改为CALLBACK,还是会在SPI_transfer跑飞。
主函数:
UART_init(); SPI_init(); // Initialize the SPI driver GPIO_init(); GPIO_setConfig(Board_SPI_SLAVE_READY, GPIO_CFG_IN_PD | GPIO_CFG_IN_INT_RISING); /* install Button callback */ GPIO_setCallback(Board_SPI_SLAVE_READY, gpioButtonFxn0); /* Enable interrupts */ GPIO_enableInt(Board_SPI_SLAVE_READY); SPI_Params_init(&spiParams); // Initialize SPI parameters spiParams.transferMode = SPI_MODE_CALLBACK; // spiParams.dataSize = 8; // 8-bit data size spiParams.mode = SPI_MASTER; //SPI MASTER spiParams.frameFormat = SPI_POL0_PHA1; //SPI POL0 PHA0 spiParams.bitRate = 4000000; //4MHZ // Fill in transmitBuffer spiTransaction.count = MASSAGE; spiTransaction.txBuf = (void *)transmitBuffer; spiTransaction.rxBuf = (void *)receiveBuffer; UART_Params_init(&uartParams); uartParams.writeDataMode = UART_DATA_BINARY; uartParams.readDataMode = UART_DATA_BINARY; uartParams.readReturnMode = UART_RETURN_FULL; uartParams.readEcho = UART_ECHO_OFF; uartParams.baudRate = 115200; uart = UART_open(Board_UART0, &uartParams); if (uart == NULL) { // UART_open() failed while (1); } spi = SPI_open(Board_SPI0, &spiParams); if (spi == NULL) { while (1); // SPI_open() failed } while(1) { }
中断函数:
void gpioButtonFxn0(uint_least8_t index) { spiTransaction.txBuf = (void *)transmitBuffer1; spiTransaction.rxBuf = (void *)receiveBuffer; SPI_transfer(spi,&spiTransaction); UART_write(uart,receiveBuffer,MASSAGE); }
UART_write依然是阻塞的,先将UART_write去掉试试