SPI Callback Functions
Posted: Wed Feb 19, 2020 2:12 pm
Hello everyone,
I have a question regarding SPI callback functions as I need to use handshaking to synchronise SPI transactions between a master and two slaves. As demonstrated in the spi_slave example on github, I am using the functions post_setup_cb() to drive a handshaking GPIO high and post_trans_cb() to subsequently drive it low. This action is performed both SPI slaves as an indication to the master to initiate a transaction. The master receives the handshake and initiates a transaction with the corresponding slave. For the sake of brevity, I can say that the transactions are simply used to implement some voting logic and upon inconsistencies, the three devices will change their functionality (slave/master) in a "round-robin" fashion.
This works as intended for a few cycles (i.e. functionality changes) before SPI transactions "freeze" and voting stops working. After many days of debugging, I have identified the problem as being the handshake GPIO(s) as it is constantly high and not producing a rising edge signal for the SPI master. I suspect that post_trans_cb() is not being called therefore not clearing the handshake. I am fairly confident that this is the case as I have used a push button to simulate this signal and it is working correctly. Also, referring to the lines of code below, I am not receiving the binary semaphore testSem2 in the slave's app_main().
void IRAM_ATTR post_trans_cb(spi_slave_transaction_t *trans)
{
WRITE_PERI_REG(GPIO_OUT_W1TC_REG, (1<<GPIO_HANDSHAKE));
xSemaphoreGiveFromISR(testSem2, NULL);
portYIELD_FROM_ISR();
}
Sorry for the long-winded spiel, essentially I want to know when these functions (post_setup_cb and post_trans_cb) are called and if clearing SPI data registers can be used to call (or force) post_trans_cb? I've tried WRITE_PERI_REG(SPI_W0_REG(HSPI_HOST), 0) to "clear" SPI registers, but does not seem to do much.
This is a very big bottleneck to my project and I can't progress without this resolved. I would appreciate any help or advice anybody on this forum can offer.
Thanks in advanced,
I have a question regarding SPI callback functions as I need to use handshaking to synchronise SPI transactions between a master and two slaves. As demonstrated in the spi_slave example on github, I am using the functions post_setup_cb() to drive a handshaking GPIO high and post_trans_cb() to subsequently drive it low. This action is performed both SPI slaves as an indication to the master to initiate a transaction. The master receives the handshake and initiates a transaction with the corresponding slave. For the sake of brevity, I can say that the transactions are simply used to implement some voting logic and upon inconsistencies, the three devices will change their functionality (slave/master) in a "round-robin" fashion.
This works as intended for a few cycles (i.e. functionality changes) before SPI transactions "freeze" and voting stops working. After many days of debugging, I have identified the problem as being the handshake GPIO(s) as it is constantly high and not producing a rising edge signal for the SPI master. I suspect that post_trans_cb() is not being called therefore not clearing the handshake. I am fairly confident that this is the case as I have used a push button to simulate this signal and it is working correctly. Also, referring to the lines of code below, I am not receiving the binary semaphore testSem2 in the slave's app_main().
void IRAM_ATTR post_trans_cb(spi_slave_transaction_t *trans)
{
WRITE_PERI_REG(GPIO_OUT_W1TC_REG, (1<<GPIO_HANDSHAKE));
xSemaphoreGiveFromISR(testSem2, NULL);
portYIELD_FROM_ISR();
}
Sorry for the long-winded spiel, essentially I want to know when these functions (post_setup_cb and post_trans_cb) are called and if clearing SPI data registers can be used to call (or force) post_trans_cb? I've tried WRITE_PERI_REG(SPI_W0_REG(HSPI_HOST), 0) to "clear" SPI registers, but does not seem to do much.
This is a very big bottleneck to my project and I can't progress without this resolved. I would appreciate any help or advice anybody on this forum can offer.
Thanks in advanced,