Problem using SPI in Olimex STM32 E407 Board (CS is not working properly)

104 views
Skip to first unread message

Juan FM

unread,
Mar 1, 2018, 5:29:35 AM3/1/18
to NuttX
Hi!
I continue my adventure in NuttX a after make it run I2C in the Olimex, I'm playing with SPI but I have some problems.
So this is the situation, I want to use the RFID-RC522 tag reader, which have fully working driver and a APP that works too. But the problem is the port of NuttX for my board it hasn't integrate the SPI yet(I mean when the pin mapping and configuration is not set yet), so I've done the next changes to make it available:
  • In the file board.h I added:
  • I added the files : stm32_mfrc522.c and stm32_spi.c. Also added to the makefile.
  • In the stm32_bringup file, I added theses lines:

  • Finally in the stm32_boot file I added this inside the board_initialize function:



After theses changes, I connect the logic analyzer and I try to run it, and I receive this good looking image:

(Channel 3 is the enable signal)
As you can see MISO is returning the same command that I send to it, like a echo and the enable is not active.

The only moment that the enable is active, is at the startup of the system, and then come back to high level(Next imagen).

Then a 2 ms later, it come back to high level.

Finally in the menuconfig, I follow the steps given in the Alan's video.

So I think that the problem might be related to the CS SPI pin, that maybe I'm not doing a properly set-up.
On other hand I'm not fully understanding how it works SPI in NuttX, because you initiliaze the SPI Bus and in a different part you initialize the GPIO pin that control the CS, but at anytime it's called the gpiowrite function to modify the state of the pin

Thank you for your time!!

Juan
Auto Generated Inline Image 1
Auto Generated Inline Image 2
Auto Generated Inline Image 3
Auto Generated Inline Image 4
Auto Generated Inline Image 5

Alan Carvalho de Assis

unread,
Mar 1, 2018, 8:40:02 AM3/1/18
to Juan FM, NuttX
Hi Juan,

Yes, you need to double check if CS is working fine.

I faced similar issues in the past because CS was not working correctly.

BR,

Alan

On 3/1/18, Juan FM <jflor...@gmail.com> wrote:
> Hi!
> I continue my adventure in NuttX a after make it run I2C in the Olimex, I'm
>
> playing with SPI but I have some problems.
> So this is the situation, I want to use the RFID-RC522 tag reader, which
> have fully working driver and a APP that works too. But the problem is the
> port of NuttX for my board it hasn't integrate the SPI yet(I mean when the
> pin mapping and configuration is not set yet), so I've done the next
> changes to make it available:
>
> - In the file board.h I added:
>
>
> - I added the files : stm32_mfrc522.c and stm32_spi.c. Also added to the
>
> makefile.
> - In the stm32_bringup file, I added theses lines:
>
>
>
> - Finally in the stm32_boot file I added this inside the
> board_initialize function:
>
>
>
>
> After theses changes, I connect the logic analyzer and I try to run it, and
>
> I receive this good looking image:
>
> (Channel 3 is the enable signal)
> As you can see MISO is returning the same command that I send to it, like a
>
> echo and the enable is not active.
>
> The only moment that the enable is active, is at the startup of the system,
>
> and then come back to high level(Next imagen).
>
> Then a 2 ms later, it come back to high level.
>
> Finally in the menuconfig, I follow the steps given in the Alan's video.
>
> So I think that the problem might be related to the CS SPI pin, that maybe
> I'm not doing a properly set-up.
> On other hand I'm not fully understanding how it works SPI in NuttX,
> because you initiliaze the SPI Bus and in a different part you initialize
> the GPIO pin that control the CS, but at anytime it's called the gpiowrite
> function to modify the state of the pin
>
> Thank you for your time!!
>
> Juan
>
> --
> You received this message because you are subscribed to the Google Groups
> "NuttX" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to nuttx+un...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
Message has been deleted

Juan FM

unread,
Mar 1, 2018, 9:55:48 AM3/1/18
to NuttX
Hi Alan,

I just solve it!
The problem was that when I declared the CS pin the arguments wasn't correct. This argument is in the arch file.
(GPIO_ALT|GPIO_AF5|GPIO_SPEED_
50MHz|GPIO_PORTA|GPIO_PIN4)

So to make it works properly I change to a regular output pint and now it works:
(GPIO_OUTPUT|GPIO_SPEED_50MHz| GPIO_OUTPUT_SET|GPIO_PORTA|GPIO_PIN4)

Sebastien Lorquet

unread,
Mar 1, 2018, 10:56:12 AM3/1/18
to nu...@googlegroups.com
yes!

the spi block in the stm32 offers a CS pin, but it has so many restrictions in master mode that its no use.

so you can just use any gpio in output mode as a cs line. this allows you to have multiple cs pins and multiple peripherals on a single spi bus.

sebastien
--
Envoyé de mon appareil Android avec Courriel K-9 Mail. Veuillez excuser ma brièveté.

Juan FM

unread,
Mar 2, 2018, 5:35:48 AM3/2/18
to NuttX
Thank you!
It's good to know the reason, because I make it work but I didn't fully understand why it was working.
Reply all
Reply to author
Forward
0 new messages