TI中文支持网
TI专业的中文技术问题咨询交流网站

LAUNCHXL-CC1310: 在GPIO中断函数中调用SPI函数会跑飞

Part Number:LAUNCHXL-CC1310

你好,我现在在GPIO的中断函数中,调用SPI,运行到函数SPI_transfer时,程序会跑飞。在中断函数中不能调用SPI吗?

Kevin Qiu1:

在SPI_MODE_BLOCKING中,SPI_transfer()将阻止任务执行,直到完成或发生超时

中断中不能有任何形式的阻塞,尝试使用SPI_MODE_CALLBACK模式

,

yuan jiadong:

把模式改为CALLBACK,还是会在SPI_transfer跑飞。

主函数:

UART_init();SPI_init();// Initialize the SPI driverGPIO_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 parametersspiParams.transferMode = SPI_MODE_CALLBACK;//spiParams.dataSize = 8;// 8-bit data sizespiParams.mode = SPI_MASTER;//SPI MASTERspiParams.frameFormat = SPI_POL0_PHA1;//SPI POL0 PHA0spiParams.bitRate = 4000000;//4MHZ// Fill in transmitBufferspiTransaction.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() failedwhile (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);}

,

Kevin Qiu1:

UART_write依然是阻塞的,先将UART_write去掉试试

赞(0)
未经允许不得转载:TI中文支持网 » LAUNCHXL-CC1310: 在GPIO中断函数中调用SPI函数会跑飞
分享到: 更多 (0)