Problem with SPI function

Go To Last Post
9 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello,

 

For an intership, I need to program the Arduino function SPI.transfer(data) (https://www.arduino.cc/en/Refere...) in Atmel Stuido.

I use the microprocessor SAM3X8E (https://ww1.microchip.com/downlo..., page 676-707 for the SPI part).

 

I did this function :

 

static inline uint8_t spi_transmit(uint8_t data)
{
    /* Transmission of the data/
    SPI0->SPI_TDR = data;
    
    /* wait the end of the transmission*/
    while(SPI0->SPI_SR & SPI_SR_RDRF == 0); 
    
    /* return the data receive */
    return (SPI0->SPI_RDR & SPI_RDR_RD_Msk);
}

 

(Note : SPI_RDR_RD_Msk is a mask to select the 16 bits which interess me of the register RDR)

 

But this function doesn't do the transmission I think...
Can you see anything bad in this function ?

 

Thank you !

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Have you correctly configure the SPI (including clocks, pins, etc) before calling this function?

 

PierreBoss wrote:
this function doesn't do the transmission I think

What do you mean, "I think" ?

 

Use an oscilloscope or logic analyser to know for sure

 

Please see Tip #1 in my signature, below, for how to properly post source code:

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:

Have you correctly configure the SPI (including clocks, pins, etc) before calling this function?

 

Yeah the SPI is correctly configurate

 

awneil wrote:

PierreBoss wrote:
this function doesn't do the transmission I think

What do you mean, "I think" ?

 

Use an oscilloscope or logic analyser to know for sure

 

I use I think because I need this function to pilot a screen and this is the only function to change to make work this screen and it steel doesn't work frown. i don't know what to measure with an oscilloscope to see if the transmission is make or not...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

PierreBoss wrote:
For an intership,

PierreBoss wrote:
i don't know what to measure with an oscilloscope to see if the transmission is make or not...

Then get your supervisor/mentor to show you

 

This is not purely a software exercise - so being able to use hardware debug tools is an essential part of the process.

It is unreasonable to ask you to do this task if you don't know how to use these tools.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:

This is not purely a software exercise - so being able to use hardware debug tools is an essential part of the process.

It is unreasonable to ask you to do this task if you don't know how to use these too

 

He is not here tooday and tomorrow i will be not here... But ok I will see with him to see what I need to mesure ! 

 

If someone see a software error in my function don't be shy !

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


Have you looked at the Application Notes on the Product Page?

 

https://www.avrfreaks.net/commen...

 

https://www.avrfreaks.net/commen...

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yeah it's include in the datasheet.

I mesure with my oscilloscope the difference between a code with the screen on and mine and there is 2 differences :

The pin SPI0_MOSI is at 1 in working code (and in mine is 0) and an another PIN which I don't really understan his utility (Screen_GPIO3) is at 0 on working code (and in mine is 1).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There will be more information in the Application Note.

 

You should test your code without the screen attached first ...

 

Can you post traces from your scope?

(screen capture is far better than photos)

 

Tip #1 also covers posting pictures.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Whitout the screen my code works perfectely. This is why I try to plug a screen now. No I can't post traces...

Last Edited: Thu. May 27, 2021 - 11:49 AM