cancel
Showing results for 
Search instead for 
Did you mean: 

My MISO signals (SPI) always return 0 during a multy transfer bytes

PierreBoss
Associate II

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 :0693W00000Ba11uQAB.pngMOSI :

0693W00000Ba12YQAR.pngMISO :

0693W00000Ba11lQAB.png 

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 :

0693W00000Ba15hQAB.png

21 REPLIES 21
PierreBoss
Associate II

Ok thank you guys for your help ! I will write the answer of my problem here when I will find it.

PierreBoss
Associate II

I found the solution of my problem. Everithing work thanks to this function :

static inline uint8_t transmission(uint8_t data, uint8_t reception)
{
	spi_write(SPI0, data, SPI_CHIP_SEL, 0);
	
	while ((SPI0->SPI_SR & SPI_SR_TDRE) == SPI_SR_TDRE);
	
	if(reception)
	{
		uint8_t data_read, Chip_Sel_read;
		
		spi_read(SPI0, &data_read, &Chip_Sel_read);
		
		//return 0;
		return data_read;
	}
	else
	{
		uint8_t poubelle_data, poubelle_CS;
		spi_read(SPI0, &poubelle_data, &poubelle_CS);
		return 1;
	}
}