Use this forum to chat about hardware specific topics for the ESP8266 (peripherals, memory, clocks, JTAG, programming)

User avatar
By NetFalcon
#83847 Hi,
i want to send a specific 32bit command via SPI (using the IDF).
The code below works (oscilloscope shows it) but I need to have cpha = 1.

So the working code is:
spi_config.interface.cpha = 0; // <- infinite loop in spi_trans if I switch to 1 here, 0 works
and not working, but I need:
spi_config.interface.cpha = 1;

This does not work and spi_trans never finishes. On the oscilloscope the stream of transmission is endless. I am a bit confused why this is the case ? How can I send a simple 8Bit command with cpha = 1? What am I missing ?

Thanks for your help.
Kind regards
Frank

Code: Select allstatic void spi_master_write_slave_task(void *arg)
{
   while(true){
      
   ESP_LOGI(TAG, "start write");   
   spi_trans_t trans = {0};
    uint32_t data = 0xAAFFAA55;

    trans.mosi = &data;
    trans.bits.val = 0;
    trans.bits.cmd = 0;
    trans.bits.mosi = 32;
   spi_trans(HSPI_HOST, trans);
   ESP_LOGI(TAG, "end write");
   vTaskDelay(1000 / portTICK_RATE_MS);
   }
}


Code: Select all
void app_main(void)
{
   
   
    ESP_LOGI(TAG, "init spi");
    spi_config_t spi_config;

   spi_config.interface.val = SPI_DEFAULT_INTERFACE;
   spi_config.intr_enable.val = SPI_MASTER_DEFAULT_INTR_ENABLE;

   spi_config.interface.bit_tx_order = 0;
   spi_config.interface.bit_rx_order = 0;
      spi_config.interface.cpol = 0;
    spi_config.interface.cpha = 1; // <- infinite loop in spi_trans if I switch to 1 here, 0 works
   

    spi_config.intr_enable.val = SPI_MASTER_DEFAULT_INTR_ENABLE;
    spi_config.mode = SPI_MASTER_MODE;

    spi_config.clk_div = SPI_2MHz_DIV;

   
    spi_config.event_cb = NULL;
    spi_init(HSPI_HOST, &spi_config);
   


    xTaskCreate(spi_master_write_slave_task, "spi_master_write_slave_task", 4096, NULL, 10, NULL);

}