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.

TM4C1290 SPI通信使用官方例程实现自收发的问题,谁能帮帮我呀!!!!!!

Other Parts Discussed in Thread: TM4C1290NCPDT

最近在学习使用TM4C1290NCPDT中的spi通信,使用官方的例程spi_master.c无法实现自收功能,使用串口打印出接收FIFO中的数据为空,以下是我的代码,希望各位前辈帮忙解答,谢谢!

int main(void)
{

uint32_t pui32DataTx[NUM_SSI_DATA];
uint32_t pui32DataRx[NUM_SSI_DATA];
uint32_t ui32Index = 0;

//设置系统时钟 120 MHZ
ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_16MHZ |
SYSCTL_OSC_MAIN |
SYSCTL_USE_PLL |
SYSCTL_CFG_VCO_480), 120000000 );

//初始化Uart1
InitConsole();

// 打印欢迎信息
UARTprintf("\nSPI Example App\n");
UARTprintf("Type something to see it show up on the other terminal: \n\n");

UARTprintf("SSI ->\n");
UARTprintf(" Mode: SPI\n");
UARTprintf(" Data: 8-bit\n\n");


// 使能SSI0外设
SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI0);

// 使能GPIO端口A,才能使用这些引脚。
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

// 将端口A2,A3,A4和A5配置为SSI0功能的引脚复用。
GPIOPinConfigure(GPIO_PA2_SSI0CLK);
GPIOPinConfigure(GPIO_PA3_SSI0FSS);
GPIOPinConfigure(GPIO_PA4_SSI0XDAT0); // SPI_DO
GPIOPinConfigure(GPIO_PA5_SSI0XDAT1); // SPI_DI

// 配置SSI引脚的GPIO设置。
// The pins are assigned as follows:
// PA5 - SSI0Tx
// PA4 - SSI0Rx
// PA3 - SSI0Fss
// PA2 - SSI0CLK
GPIOPinTypeSSI(GPIO_PORTA_BASE, GPIO_PIN_5 | GPIO_PIN_4 | GPIO_PIN_3 |
GPIO_PIN_2);


// 配置和使能SPI主模式的SSI端口。
// 在SPI模式,主模式,1MHz SSI频率和8位数据中使用SSI0,系统时钟供应,空闲时钟电平低电平和有效低电平时钟。

SSIConfigSetExpClk(SSI0_BASE, ui32SysClock, SSI_FRF_MOTO_MODE_0,
SSI_MODE_MASTER, 1000000, 8);

// 使能 SSI0 模块.
SSIEnable(SSI0_BASE);

// Read any residual data from the SSI port. This makes sure the receive
// FIFOs are empty, so we don't read any unwanted junk. This is done here
// because the SPI SSI mode is full-duplex, which allows you to send and
// receive at the same time. The SSIDataGetNonBlocking function returns
// "true" when data was returned, and "false" when no data was returned.
// The "non-blocking" function checks if there is any data in the receive
// FIFO and does not "hang" if there isn't.
while(SSIDataGetNonBlocking(SSI0_BASE, &pui32DataRx[0]))
{
}

// Initialize the data to send.
pui32DataTx[0] = 'S';
pui32DataTx[1] = 'P';
pui32DataTx[2] = 'I';

// Display indication that the SSI is transmitting data.
UARTprintf("Sent:\n ");

// Send 3 bytes of data.
for(ui32Index = 0; ui32Index < NUM_SSI_DATA; ui32Index++)
{
// Display the data that SSI is transferring.
UARTprintf("'%c' ", pui32DataTx[ui32Index]);

// Send the data using the "blocking" put function. This function
// will wait until there is room in the send FIFO before returning.
// This allows you to assure that all the data you send makes it into
// the send FIFO.
SSIDataPut(SSI0_BASE, pui32DataTx[ui32Index]);
}

// Wait until SSI0 is done transferring all the data in the transmit FIFO.
while(SSIBusy(SSI0_BASE))
{
}

// Display indication that the SSI is receiving data.
UARTprintf("\nReceived:\n ");

// Receive 3 bytes of data.
for(ui32Index = 0; ui32Index < NUM_SSI_DATA; ui32Index++)
{
// Receive the data using the "blocking" Get function. This function
// will wait until there is data in the receive FIFO before returning.
SSIDataGet(SSI0_BASE, &(pui32DataRx[ui32Index]));

// Since we are using 8-bit data, mask off the MSB.
pui32DataRx[ui32Index] &= 0x00FF;

// Display the data that SSI0 received.
UARTprintf("'%c' ", pui32DataRx[ui32Index]);
}


return(0);
}