硬件使用的是官方的LAUNCHXL-CC3235SF开发板,在运行C:\ti\simplelink_cc32xx_sdk_4_20_00_07\examples\rtos\CC3235SF_LAUNCHXL\drivers\spimaster\freertos
这个例子是发现发送可以正常发送,但是接收到的数据却不对。
于是为了排除问题我把MOSI与MISO短接到了一起,按道理应该就是发送什么接收什么了吧,但是接收还是错误的。
下面是我的代码:
/* Open SPI as master (default) */ SPI_Params_init(&spiParams); spiParams.frameFormat = SPI_POL0_PHA0; spiParams.dataSize = 8; spiParams.bitRate = 1000000; masterSpi = SPI_open(CONFIG_SPI_MASTER, &spiParams); if (masterSpi == NULL) { Display_printf(display, 0, 0, "Error initializing master SPI\n"); while (1); } else { Display_printf(display, 0, 0, "Master SPI initialized\n"); } /* * Master has opened CONFIG_SPI_MASTER; set CONFIG_SPI_MASTER_READY high to * inform the slave. */ GPIO_write( CONFIG_SPI_MASTER_READY, 1 ); /* Copy message to transmit buffer */ strncpy((char *) masterTxBuffer, MASTER_MSG, SPI_MSG_LENGTH); for (i = 0; i < 1; i++) { /* * Wait until slave is ready for transfer; slave will pull * CONFIG_SPI_SLAVE_READY low. */ GPIO_write(CONFIG_SPI_MASTER_READY, 0); /* Initialize master SPI transaction structure */ masterTxBuffer[0] = 0x01; masterTxBuffer[1] =0x02; masterTxBuffer[2] =0x03; masterTxBuffer[3] =0x04; masterTxBuffer[4] =0x05; memset((void *) masterRxBuffer, 0, SPI_MSG_LENGTH); transaction.count = SPI_MSG_LENGTH; transaction.txBuf = (void *) masterTxBuffer; transaction.rxBuf = (void *) masterRxBuffer; /* Toggle user LED, indicating a SPI transfer is in progress */ // GPIO_toggle(CONFIG_GPIO_LED_1); /* Perform SPI transfer */ transferOK = SPI_transfer(masterSpi, &transaction); if (transferOK) { GPIO_write(CONFIG_SPI_MASTER_READY, 1); Display_printf(display, 0, 0, "Master received:[%02x] %02x %02x %02x %02x %02x", i, masterRxBuffer[0], masterRxBuffer[1], masterRxBuffer[2], masterRxBuffer[3], masterRxBuffer[4]); } else { Display_printf(display, 0, 0, "Unsuccessful master SPI transfer"); } /* Sleep for a bit before starting the next SPI transfer */ }
我发送的是 5 个字节 0x01 0x02 0x3 0x04 0x05,理论上也应该收到 0x01 0x02 0x3 0x04 0x05 但是在transaction.rxBuf里收到的确是 0x03 0x0c 0x0f 0x30 0x1b。
我用逻辑分析仪也看了,在逻辑分析仪上看的数据没问题:
请教下问题可能出在哪?卡在这已经一个星期了。。。多谢!