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

No, I mean datasheet of the controller (the chip) on the display board.

Search further.

JW

PierreBoss
Associate II

I don't have it... I will ask at my tutor monday. I will keep you informed !

Ask google, it works on weekends, too.

JW

Paul1
Lead

Check for SPI:

  • Wiring/cabling correct? Broken wires, etc.
  • Clock active edge(CPOL,CPHA...), configure in MCU to match display (configure: data out on rise/fall, data in on rise/fall)
  • Ensure both ends using same Endian: Is the device expecting MSB or LSB first? How about the MCU? (Don't assume)
  • Bits per word/words per transfer: 8/16/32bits? One word or more?
  • See Wikipedia for details on SPI settings (CPOL,CPHA...): https://en.wikipedia.org/wiki/Serial_Peripheral_Interface

All of above have to be configured compatible between MCU and Device/Display.

As others said:

  • Take your display part number and search the web for its datasheet
  • On that find the connection pinout and verify your wiring
  • On that also find the display controller IC
  • Search the web for the display controller datasheet
  • Use that to determine the SPI configuration (items I listed above)
  • Configure the SPI settings using STM32CubeMX
  • Generate code with new SPI settings.

Paul

> Configure the SPI settings using STM32CubeMX

Hardly so, for ATSAM... :)

JW

PierreBoss
Associate II

For the chip, I find a datasheet that explain how the Chip Select works (in attachment of this message). When I read it, it looks like I use it correctly...

PierreBoss
Associate II
  • Wiring/cabling correct? Broken wires, etc. ==> the cabling is correct because whith an other program (Arduino program), the screen is on.
  • Clock active edge(CPOL,CPHA...), configure in MCU to match display (configure: data out on rise/fall, data in on rise/fall) ==> the clock is well configure
  • Ensure both ends using same Endian: Is the device expecting MSB or LSB first? How about the MCU? (Don't assume) ==> don't know yet but i think it's good because when I compare my MOSI of my program and the MOSI of Arduino program (which put on the screen) it is exactly the same
  • Bits per word/words per transfer: 8/16/32bits? One word or more? ==> 8 per transfer and this is the correct amount

PierreBoss
Associate II

I try to change my SPI settings, SPI PIN settings (MISO in input, ...) but nothing make my MISO works....

PierreBoss
Associate II

Hi, I have some news!

I thought the problem was with my SPI or PIN setup but after many changes it didn't do anything.

I reworked my functions and there I have a result (which does not work yet but encouraging).

Here is my MISO signal:

0693W00000BaFqwQAF.png 

We can see that there is a response from the screen. However, the 8-bit multi transfers are maybe a little too stuck (no cut between 5 transfers) and my CS resets to 1 before the end of my multi transfer.

Here is my spi_trasnmit (data) function:

static inline void spi_transmit(uint8_t data)
{	
	while ((SPI0->SPI_SR & SPI_SR_TXEMPTY) == 1);
	
	spi_write(SPI0, data, SPI_CHIP_SEL, 0);
	
	while ((SPI0->SPI_SR & SPI_SR_TDRE) == 1);
}

Here is my spi_receive (data) function:

{	
	uint8_t data_read, Chip_Sel_read;
	
	spi_transmit(data);
	
	while((SPI0->SPI_SR & SPI_SR_RDRF) == 0);
	
	spi_read(SPI0, &data_read, &Chip_Sel_read);
	
	return data_read;
}

and here is the function I call to do my 5 byte transfer:

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 */

This is probably the point where you can't get any more help here, simply because this is STM32 forum, so users here typically don't use ATSAM. You might need to go to MCHP's ATSAM-related forum for specific help.

JW