I'm honestly not sure if this is a hardware or software problem at this point, but I was able to bit bang the SPI interface before and it worked 95% well. Applicable code snippets and logic analyzer screenshots are below.
Code: Select all
void spi_task() {
uint8_t send_byte = 0x00;
uint8_t recv_byte = 0x00;
spi_slave_transaction_t t;
memset(&t, 0, sizeof(t));
t.length=8; // 8 Bits of Data
t.tx_buffer=&send_byte;
t.rx_buffer=&recv_byte;
while(1) {
recv_byte = 0x00;
spi_slave_transmit(SPI2_HOST, &t, portMAX_DELAY);
// Code here that picks new send_byte based on recv_byte
// Removed due to hard coding send_byte for testing
send_byte = 0b01010101;
}
}
//Main application
void app_main(void)
{
//Configuration for the SPI bus
spi_bus_config_t buscfg={
.mosi_io_num=GPIO_MOSI,
.miso_io_num=GPIO_MISO,
.sclk_io_num=GPIO_SCLK,
};
//Configuration for the SPI slave interface
spi_slave_interface_config_t slvcfg={
.mode=0,
.spics_io_num=GPIO_CS,
.queue_size=1,
.flags=0,
.post_setup_cb=my_post_setup_cb,
.post_trans_cb=my_post_trans_cb
};
// Set Up GPIO
gpio_setup(); // (Custom Function Removed for Brevity)
//Initialize SPI slave interface
spi_slave_initialize(SPI2_HOST, &buscfg, &slvcfg, SPI_DMA_DISABLED);
// Initialize the SPI Task
xTaskCreate(&spi_task, "SPI_TASK", 4096, NULL, 1, NULL);
}