完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
最近在学习使用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 Appn"); UARTprintf("Type something to see it show up on the other terminal: nn"); UARTprintf("SSI ->n"); UARTprintf(" Mode: SPIn"); UARTprintf(" Data: 8-bitnn"); // 使能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); ] |
|
相关推荐
3 个讨论
|
|
SPI没有回环模式,无法实现自收发的,需要外部给他发,他才能收到。
关于这段代码的介绍,其实开头就有的。 //! This example shows how to configure the SSI0 as SPI Master. The code will //! send three characters on the master Tx then polls the receive FIFO until //! 3 characters are received on the master Rx. 需要Rx有3个字符的接收才输出的。 |
|
|
|
|
|
只有小组成员才能发言,加入小组>>
336 浏览 1 评论
529 浏览 2 评论
NA555DR VCC最低电压需要在5V供电,为什么用3.3V供电搭了个单稳态触发器也使用正常?
774 浏览 3 评论
MSP430F249TPMR出现高温存储后失效了的情况,怎么解决?
651 浏览 1 评论
对于多级放大电路板,在PCB布局中,电源摆放的位置应该注意什么?
1130 浏览 1 评论
AT32F407在USART2 DMA发送数据时,接包接到了要发送的数据,程序还是处于等待传输完成的标识判断中,为什么?
58浏览 29评论
147浏览 23评论
请问下tpa3220实际测试引脚功能和官方资料不符,哪位大佬可以帮忙解答下
252浏览 20评论
请教下关于TAS5825PEVM评估模块原理图中不太明白的地方,寻求答疑
202浏览 14评论
两个TMP117传感器一个可以正常读取温度值,一个读取的值一直是0,为什么?
59浏览 13评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-23 13:12 , Processed in 1.171748 second(s), Total 56, Slave 46 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号