cancel
Showing results for 
Search instead for 
Did you mean: 

SPI to communicate with an external flash memory

fabioaymoto9
Associate II
Posted on May 17, 2011 at 15:15

Hello;

I'm trying to communicate to an external flash memory (M25PE80) using SPI. I´m using the STM8SPI librarie but I´m not having success to write/read from memory. My doubt is about the configuration of pins. Are there any Option Byte that I must set to use the SPI alternate function? Does I need to use the GPIO_Init to configure the ports used for SPI (MISO, MOSI, CLK)? For the Chip Select pin, I´m using the PortG0 as GPIO_MODE_OUT_PP_LOW_FAST.

These are the code I´m using to init the SPI (Funtions from stm8s_spi.c):

SPI_DeInit();

SPI_Init(SPI_FIRSTBIT_MSB, SPI_BAUDRATEPRESCALER_64,SPI_MODE_MASTER,SPI_CLOCKPOLARITY_HIGH, SPI_CLOCKPHASE_2EDGE, SPI_DATADIRECTION_2LINES_FULLDUPLEX,SPI_NSS_SOFT, 0x07);

SPI_Cmd(ENABLE);

Regards

3 REPLIES 3
fabioaymoto9
Associate II
Posted on May 23, 2011 at 04:15

Problem Solved! There is no need to configure the SPI pins. The Init Function configure all the correct parameters.

nholzem
Associate II
Posted on May 23, 2011 at 09:13

Haven't tried yet SPI, but isn't the SPI_NSS pin supposed to act as a chip select? (instead of using GPIOG0 in your example)

fabioaymoto9
Associate II
Posted on May 23, 2011 at 14:11

Hello Nico;

Yes, as an output pin you could use the GPIOE5 pin, but considering that in SPI communication you can select as many devices as many chip select pins you have, you could config any I/O pin for this function (chip select). For write into the external flash memory you will need to control the exactly moment to set or reset this pin. The other pins are really alternate function pins. You just write on a register and the ucontroller transmits/receive data for you.

Regards.

Fabio