我正在尝试在 OpenMV(主)和 TI CC3220(从)之间进行串行通信。引脚分配是
德州仪器 | 开放MV | |
---|---|---|
莫西 | P7 | P0 |
味噌 | P6 | P1 |
SLCK | P5 | P2 |
党卫军 | P8 | P3 |
两个设备之间的电线如上连接。OpenMV microPython 代码很简单。代码片段是:
cs = Pin("P3", Pin.OUT_OD)
#The code below gets executed in a loop. I have removed other parts of logic
spi = SPI(2, SPI.MASTER, baudrate=115200, polarity=0, phase=1)
cs.low()
spi.send(b'5') #Hardcoded to 5 for the testing
cs.high()
SPI的配置设置为:
Name: CONFIG_SPI_SLAVE
Mode: Four Pin Active Low
SS Control: HW
SCLK Pin: P05/7
MISO Pin: P06/14
MISO Pin: P07/15
SS Pin: P08/18
我遇到的挑战是没有调用 TI 的回调函数。
void transferCompleteFxn(SPI_Handle handle, SPI_Transaction *transaction)
{
LOG_INFO("In transfer complete \r\n");
sem_post(&slaveSem);
}
代码如下:
status = sem_init(&slaveSem, 0, 0);
if (status != 0) {
while(1);
}
LOG_INFO("Sem init done\r\n");
SPI_Params_init(&spiParams);
spiParams.bitRate = 115200;
spiParams.frameFormat = SPI_POL0_PHA1;
spiParams.mode = SPI_SLAVE;
spiParams.transferCallbackFxn = transferCompleteFxn;
spiParams.transferMode = SPI_MODE_CALLBACK;
slaveSpi = SPI_open(CONFIG_SPI_SLAVE, &spiParams);
if (slaveSpi == NULL) {
LOG_INFO("Error initializing slave SPI\r\n");
while (1);
}
else {
LOG_INFO("Slave SPI initialized\r\n");
}
/* Copy message to transmit buffer */
strncpy((char *) slaveTxBuffer, SLAVE_MSG, SPI_MSG_LENGTH);
for (i = 0; i < MAX_LOOP; i++) {
/* Initialize slave SPI transaction structure */
transaction.count = SPI_MSG_LENGTH;
transaction.txBuf = NULL;
transaction.rxBuf = (void *) slaveRxBuffer;
/* Toggle on user LED, indicating a SPI transfer is in progress */
GPIO_toggle(CONFIG_GPIO_LED_1);
transferOK = SPI_transfer(slaveSpi, &transaction);
if (transferOK) {
GPIO_write(CONFIG_SPI_SLAVE_READY, 0);
LOG_INFO("GPIo write done\r\n");
/* Wait until transfer has completed */
sem_wait(&slaveSem);
以下声明不会被执行
LOG_INFO("SEM wait done\r\n");
/*
* Drive CONFIG_SPI_SLAVE_READY high to indicate slave is not ready
* for another transfer yet.
*/
LOG_INFO("Slave received\r\n");
}
else {
LOG_INFO("Unsuccessful slave SPI transfer\r\n");
}
}
SPI_close(slaveSpi);