SPI loopback not working with SDK



  • Hello,

    I'm testing the SPI loopback with SDK but the received data is always read as FF. I'm connecting DO and DI pins manually. Can someone shed some light on this?

    Below is the code snippet:

    static void spi_lowlevel_init(uint8_t spi_index)
    {
    	gpiohs_set_drive_mode(7, GPIO_DM_OUTPUT);
    	spi_set_clk_rate(SPI_DEVICE_1, 100000);     /*set clk rate*/
    }
    
    static void spi_write_data(uint8_t *data_buff, uint32_t length)
    {
    	spi_init(SPI_DEVICE_1, SPI_WORK_MODE_0, SPI_FF_STANDARD, 8, 0);
    	spi_send_data_standard(SPI_DEVICE_1, SPI_CHIP_SELECT_3, NULL, 0, data_buff, length);
    }
    
    static void spi_read_data(uint8_t *data_buff, uint32_t length)
    {
    	spi_init(SPI_DEVICE_1, SPI_WORK_MODE_0, SPI_FF_STANDARD, 8, 0);
    	spi_receive_data_standard(SPI_DEVICE_1, SPI_CHIP_SELECT_3, NULL, 0, data_buff, length);
    }
    
    int main(void)
    {
    	uint8_t result[5] = {0}, frame[5];
    	int i;
    
    	uarths_init();
    	io_mux_init();
    	dmac_init();
    	plic_init();
    	sysctl_enable_irq();
    	sd_lowlevel_init(0);
    
    	for (i = 0; i < 5; i++)
    		frame[0] = 0x11;
    
    	/*!< Send the CMD bytes */
    	spi_write_data(frame, 5);
    	spi_read_data(result, 5);
    
    	for (i = 0; i < 5; i++)
    		printf("Received data: %x\n", result[i]);
    
    	return 0;
    }
    


  • @vowstar Do you have any info?