2021-06-03 07:03 AM
I work with SAM3X8E microcontroller (datasheet : https://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-11057-32-bit-Cortex-M3-Microcontroller-SAM3X-SAM3A_Datasheet.pdf, page 676 to 707 for SPI)
I want to make a multi transfer bytes thanks to SPI Bus. I initialize my CS as a GPIO to control it manually. My CS, MOSI and CLK works well but my MISO always return me 0...
This is some screen of the signals :
CS :MOSI :
MISO :
This is my initialization of the SPI Bus :
/* Configure an SPI peripheral. */
spi_enable_clock(SPI0);
spi_disable(SPI0);
spi_reset(SPI0);
spi_set_master_mode(SPI0);
spi_disable_mode_fault_detect(SPI0);
spi_set_peripheral_chip_select_value(SPI0, SPI_CHIP_SEL);
/* data samples on rising edge because Polarity = Phase = 0 */
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));
SPI0->SPI_CSR[0] |= SPI_CSR_CSAAT;
spi_enable(SPI0);
This is the code of my multi tranfer bytes :
uint8_t ftData8;
EVE_cs_set(); //CS at 0
spi_transmit_32(...); //Make 4 spi_transmit(...)
ftData8 = spi_receive(0x00); /* read data byte by sending another dummy byte */
EVE_cs_clear(); //CS at 1
return ftData8; /* return byte read */
And this is the code of my function spi_transmit(...) :
static inline uint8_t spi_transmit(uint8_t data)
{
while ((SPI0->SPI_SR & SPI_SR_TDRE) == 0);
spi_write(SPI0, data, SPI_CHIP_SEL, 0);
while ((SPI0->SPI_SR & SPI_SR_RDRF) == 0);
uint8_t data_read, Chip_Sel_read;
spi_read(SPI0, &data_read, &Chip_Sel_read);
return data_read;
}
Can you see where is the problem ?
PS :
I have a screen of a workwell MISO (in the same case) if you want to see how it's should looks like :
2021-06-03 07:09 AM
So a STM32 is the master and the SAM3X8E is a slave? In that case, the MISO line is being driven by the slave and the STM32 has no control over it.
2021-06-03 07:11 AM
No the slave is a screen : (https://fr.rs-online.com/web/p/ecrans-tftlcd/1931154/) and the SAM3X8E is the master
2021-06-03 07:16 AM
Well, this is an STM32-related forum, so you shouldn't really expect Atmel/Microchip-related questions being answered; nonetheless, as you miss signal from the *slave*, the problem here is in the display, or, probably, in the way how you access it.
Start with reading thoroughly the datasheet to the display's controller.
JW
2021-06-03 07:17 AM
This is an STM32 forum. Why ask the question here? Surely Atmel has a similar forum somewhere.
Regardless, the screen is the slave, so you'd need to verify you're taking with it correctly. Maybe returning all 0s is what it's supposed to do here.
2021-06-03 07:23 AM
Sorry... I ask here because some STM32 use the same microcontroller ! And I ask aswell at Atmel forum too.
No look at correct MISO screenshot the screen need to return me some datas ! If he returns me 0 he can't continues his initialization.
2021-06-03 08:22 AM
OK so where's the datasheet to the display's controller, describing the SPI communication with it?
JW
2021-06-03 08:27 AM
Thank you man. https://docs.rs-online.com/c436/A700000006982756.pdf here the datasheet of the display (page 8 to 10 of the datasheet for SPI)
2021-06-03 12:46 PM
That's useless. You need datasheet to the controller. Expect tens to hundreds of pages of description of protocol layers and registers.
JW
2021-06-04 04:16 AM
This is the datasheet of my microcontroller (https://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-11057-32-bit-Cortex-M3-Microcontroller-SAM3X-SAM3A_Datasheet.pdf, page 676 to 707)
The other datasheet which I have is the one of the screen...