cancel
Showing results for 
Search instead for 
Did you mean: 

How to configure SPI on STM32F103?

quentin239955_stm1
Associate II
Posted on May 23, 2012 at 11:52

Hi,

I am trying to use the OLIMEX STM32-P103 (ARM cortex M3) as SPI master to get some information from an accelerometer but, I dont know how to use SPI. Even after many hours of searching on the internet i did not found any examples or tutorial. Can someone help me by giving me links or explaining me?

Thanks

PS: I am using IAR workbench for ARM.

      Please excuse me for my bad english.

#spi-stm32f103
11 REPLIES 11
Posted on May 23, 2012 at 13:55

How about the examples in the various firmware libraries?

STM32F10x_StdPeriph_Lib_V3.5.0\Project\STM32F10x_StdPeriph_Examples\SPI\*

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
quentin239955_stm1
Associate II
Posted on May 23, 2012 at 14:54

Thank for your responce,

I found one in the IAR example but with the STM3210E name (in STM32F10x\stm32f10x_stdperiph_lib\Project\STM32F10x_StdPeriph_Examples\SPI\FullDuplex_SoftNSS) and when I program it on the chip it does not work.

Which firmware library are you speaking about? Where can I find it?

frankmeyer9
Associate II
Posted on May 23, 2012 at 15:10

Sure it can't work.

You need to take it as an example, and use it as a template for your project. The I2C interface might not be the same, i.e. might use other pins. There might be other differences between this two boards.

quentin239955_stm1
Associate II
Posted on May 23, 2012 at 15:34

Yes, the

example

helped me

understand how

to

declare the

SPI

but

not

how to use

it

or assign

pins

.
frankmeyer9
Associate II
Posted on May 23, 2012 at 16:54

I guess you can't circumvent comparing the schematics of both boards.

If they use the same SPI interface, i.e. the same pins, you don't need to change the initialization. Otherwise you will need to change your project to match your layout.

Locate where the initializations are done, and change accordingly.

> Yes, the

example

helped me

understand how

to

declare the

SPI

but

not

how to use

it

or assign

pins

.

I don't know the code you speak of.

A peripheral initialization requires several consecutive steps, which are not necessarily done in one place (one function.). It shouldn't be too difficult to find out.

quentin239955_stm1
Associate II
Posted on May 23, 2012 at 17:26

I have compared

the two

boards

and

find

that

the pins are,

in fact,

different

.

And I

still do not understand

,

even

after

searching

in the code

,

how to change

the pins used

.

The main.c program in attached.

________________

Attachments :

main.c : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I008&d=%2Fa%2F0X0000000bRy%2FwueX7qNoj9ng0bSvOrGX0bmz6xv5YU0Bk4mJTsIxGQw&asPdf=false
frankmeyer9
Associate II
Posted on May 23, 2012 at 21:43

void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
#ifdef USE_STM3210C_EVAL
/* Enable SPI3 Pins Software Remapping */
GPIO_PinRemapConfig(GPIO_Remap_SPI3, ENABLE);
#endif
/* Configure SPIy pins: SCK, MISO and MOSI */
GPIO_InitStructure.GPIO_Pin = SPIy_PIN_SCK | SPIy_PIN_MISO | SPIy_PIN_MOSI;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(SPIy_GPIO, &GPIO_InitStructure);
/* Configure SPIz pins: SCK, MISO and MOSI */
GPIO_InitStructure.GPIO_Pin = SPIz_PIN_SCK | SPIz_PIN_MISO | SPIz_PIN_MOSI;
GPIO_Init(SPIz_GPIO, &GPIO_InitStructure);
}

This

SPIy

and

SPIz

definitions are somewhere else, and the pin definitions too :

SPIy_PIN_SCK, SPIy_PIN_MISO, SPIy_PIN_MOSI

#ifdef USE_STM3210C_EVAL
/* Enable SPI3 Pins Software Remapping */
GPIO_PinRemapConfig(GPIO_Remap_SPI3, ENABLE);
#endif

Seems all a little bit hidden, but follow this mentioned #defines

.

SPIy

and

SPIz

are somewhere mapped to

SPI1

,

SPI3

or

SPI3.

quentin239955_stm1
Associate II
Posted on May 24, 2012 at 09:57

Ok,

I will look for

that and I

'll inform you

of my

progress

.

An other question : Do you know where I can found the peripheral libraries for STM32F103 (in PDF), I did not found it yet.

Thank you.
frankmeyer9
Associate II
Posted on May 24, 2012 at 13:14

On the STM32F1 page fund there

http://

click on any STM32F10x device in the list (scroll down...).

This opens another Tab in your browser (usually), displaying available resurces for the selected part.

Select the ''Design support'' tab on this page, and scroll down. The standard peripheral lib is there in the list, and is the same for all F10x parts.

Don't ask me why it's missing in the STM32F1 overview page, and you need to select a part first...