以前也做过SPI,都还可以,现在搞这个SPI怎么也进不了发送中断!
代码:
初始化
void SpiBInit(void)
{
SpibRegs.SPIFFTX.all = 0xC0C3; // Enable FIFOs, set TX FIFO level to 3
SpibRegs.SPIFFRX.all = 0x0023; // Set RX FIFO level to 3
SpibRegs.SPIFFCT.all = 0x00;
SpibRegs.SPIFFTX.bit.TXFIFO=1; // exit reset status
SpibRegs.SPIFFRX.bit.RXFIFORESET=1;
SpibRegs.***.bit.SPISWRESET = 0;
SpibRegs.***.bit.CLKPOLARITY = 0;
SpibRegs.***.bit.*** = (16-1);
SpibRegs.***.bit.SPILBK = 0;
// Enable master (0 == slave, 1 == master)
// Enable transmission (Talk)
// Clock phase (0 == normal, 1 == delayed)
// SPI interrupts are disabled
SpibRegs.***.bit.MASTER_SLAVE = 1;
SpibRegs.***.bit.TALK = 1;
SpibRegs.***.bit.CLK_PHASE = 0;
SpibRegs.***.bit.SPIINTENA = 0;
// Set the baud rate
SpibRegs.SPIBRR.bit.SPI_BIT_RATE = 499;
// Set FREE bit
// Halting on a breakpoint will not halt the SPI
SpibRegs.SPIPRI.bit.FREE = 1;
// Release the SPI from reset
SpibRegs.***.bit.SPISWRESET = 1;
SpibRegs.SPIFFTX.bit.TXFFINTCLR=1;
SpibRegs.SPIFFRX.bit.RXFFINTCLR=1;
SpibRegs.SPIFFRX.bit.RXFFOVFCLR=1;
SpibRegs.SPISTS.bit.OVERRUN_FLAG = 1;
}
开中断:
IER |= M_INT6;
PieCtrlRegs.PIEIER6.bit.INTx4 = 1; // SPI-B TX
……(略)
中断处理:
__interrupt void Spib_TxInt_isr(void)
{
SpibRegs.SPISTS.bit.OVERRUN_FLAG = 1;
//
GpioDataRegs.GPASET.bit.GPIO23 = 1;
SpibRegs.SPIFFRX.bit.RXFFINTCLR=1;
SpibRegs.SPIFFRX.bit.RXFFOVFCLR=1;
SpibRegs.SPIFFTX.bit.TXFFINTCLR=1; // Clear Interrupt flag
PieCtrlRegs.PIEACK.all = PIEACK_GROUP6;
}
发送:
void Spi_B_Send(Uint16 dat )
{
……
for ( i = 0; i < 3; i++ )
{
SpibRegs.SPITXBUF = 0x5555;
}
}
程序中,由于发现SPISTS状态显示中断发生,所以额外加入了清除状态的语句。
现在的目的,需要三个字发送完后处理某些工作,
(当打开接收中断时,倒是可以正常进入,也参考了手册中 表18-3的说明)
注:CPU:TMS320f28377D
谢谢大家
Seven Han:建议对照下controlsuite中关于F28377d的spi例程。
以前也做过SPI,都还可以,现在搞这个SPI怎么也进不了发送中断!
代码:
初始化
void SpiBInit(void)
{
SpibRegs.SPIFFTX.all = 0xC0C3; // Enable FIFOs, set TX FIFO level to 3
SpibRegs.SPIFFRX.all = 0x0023; // Set RX FIFO level to 3
SpibRegs.SPIFFCT.all = 0x00;
SpibRegs.SPIFFTX.bit.TXFIFO=1; // exit reset status
SpibRegs.SPIFFRX.bit.RXFIFORESET=1;
SpibRegs.***.bit.SPISWRESET = 0;
SpibRegs.***.bit.CLKPOLARITY = 0;
SpibRegs.***.bit.*** = (16-1);
SpibRegs.***.bit.SPILBK = 0;
// Enable master (0 == slave, 1 == master)
// Enable transmission (Talk)
// Clock phase (0 == normal, 1 == delayed)
// SPI interrupts are disabled
SpibRegs.***.bit.MASTER_SLAVE = 1;
SpibRegs.***.bit.TALK = 1;
SpibRegs.***.bit.CLK_PHASE = 0;
SpibRegs.***.bit.SPIINTENA = 0;
// Set the baud rate
SpibRegs.SPIBRR.bit.SPI_BIT_RATE = 499;
// Set FREE bit
// Halting on a breakpoint will not halt the SPI
SpibRegs.SPIPRI.bit.FREE = 1;
// Release the SPI from reset
SpibRegs.***.bit.SPISWRESET = 1;
SpibRegs.SPIFFTX.bit.TXFFINTCLR=1;
SpibRegs.SPIFFRX.bit.RXFFINTCLR=1;
SpibRegs.SPIFFRX.bit.RXFFOVFCLR=1;
SpibRegs.SPISTS.bit.OVERRUN_FLAG = 1;
}
开中断:
IER |= M_INT6;
PieCtrlRegs.PIEIER6.bit.INTx4 = 1; // SPI-B TX
……(略)
中断处理:
__interrupt void Spib_TxInt_isr(void)
{
SpibRegs.SPISTS.bit.OVERRUN_FLAG = 1;
//
GpioDataRegs.GPASET.bit.GPIO23 = 1;
SpibRegs.SPIFFRX.bit.RXFFINTCLR=1;
SpibRegs.SPIFFRX.bit.RXFFOVFCLR=1;
SpibRegs.SPIFFTX.bit.TXFFINTCLR=1; // Clear Interrupt flag
PieCtrlRegs.PIEACK.all = PIEACK_GROUP6;
}
发送:
void Spi_B_Send(Uint16 dat )
{
……
for ( i = 0; i < 3; i++ )
{
SpibRegs.SPITXBUF = 0x5555;
}
}
程序中,由于发现SPISTS状态显示中断发生,所以额外加入了清除状态的语句。
现在的目的,需要三个字发送完后处理某些工作,
(当打开接收中断时,倒是可以正常进入,也参考了手册中 表18-3的说明)
注:CPU:TMS320f28377D
谢谢大家
mangui zhang:最好检测一下发送中断标志是否置位然后确定是中断未打开等其他问题
还有相关外设的时钟配置和使能也需要考虑