Hello,
I have already done a topic for my SPI problem but I do an other one because I have much more informations !
I work with a microcontroleur SAM3X8E (https://ww1.microchip.com/downlo...) and I need to make a SPI connection with a screen (as slave).
The problem is that my spi_transmit(data) function always return me 0 and I don't know why...
This is my function :
static inline uint8_t spi_transmit(uint8_t data) { printf("Donnee a envoyer : %i \n", data); uint8_t data_send = SPI_TDR_TD(data); //Transmission while ((SPI0->SPI_SR & SPI_SR_TDRE) == 0); SPI0->SPI_TDR = data_send; printf("Transmis : %i \n", data_send); //Read while ((SPI0->SPI_SR & SPI_SR_RDRF) == 0); uint8_t data_read = SPI0->SPI_RDR; printf("Lu : %i \r\n", data_read); return data & SPI_RDR_RD_Msk; }
It's inspire from the Arduino SPI transfer one.
When I run my code, this is what I have :
[look at the file attachement name : Capture d’écran 2021-06-01 120152]
The data seems to be send but when I try to read I always have 0...
I used an oscilloscope to understan this problem and this is what I have (SPI MISO in purple and SPI SCLK in yellow) :
[look at the file attachement name : SDS00005]
Do you have any idea about this problem ?
/* Configure SPI0 pins */ gpio_configure_pin(SPI0_MISO_GPIO, (PIO_PERIPH_A | PIO_DEFAULT)); gpio_configure_pin(SPI0_MOSI_GPIO, (PIO_PERIPH_A | PIO_DEFAULT)); gpio_configure_pin(SPI0_SPCK_GPIO, (PIO_PERIPH_A | PIO_DEFAULT)); /* Initilization of SPI */ spi_enable_clock(SPI0); spi_disable(SPI0); spi_reset(SPI0); spi_set_lastxfer(SPI0); spi_set_master_mode(SPI0); spi_disable_mode_fault_detect(SPI0); spi_set_peripheral_chip_select_value(SPI0, SPI_CHIP_PCS); spi_set_clock_polarity(SPI0, SPI_CHIP_SEL, SPI_CLK_POLARITY); spi_set_clock_phase(SPI0, SPI_CHIP_SEL, SPI_CLK_PHASE); spi_set_bits_per_transfer(SPI0, SPI_CHIP_SEL, SPI_CSR_BITS_8_BIT); spi_set_baudrate_div(SPI0, SPI_CHIP_SEL, (sysclk_get_peripheral_hz() / gs_ul_spi_clock)); spi_enable(SPI0);