cancel
Showing results for 
Search instead for 
Did you mean: 

SPI Flash Issue

peter_lanius
Associate II
Posted on January 10, 2010 at 12:27

SPI Flash Issue

5 REPLIES 5
jj
Associate II
Posted on May 17, 2011 at 13:37

Really like the care & detail (especially scope captures) of your post.

a) Note that the sole output from your serial flash module is MISO.

b) There is a known issue with ''normal/customary'' SPI ''automatic'' CS generation via STM32. Haven't time now to fully review your code.

So:

1) Temporarily ''break'' connection between STM-NSS to CS-flash. Wire in a debounced switch along with pull-up R to CS-flash - so that CS-flash can be @ either 3V3 or ground. After power-up - switch from 3V3 to ground.

2) Repeat your SPI sequence - again capturing MISO. Should the MISO signal now make normal/expected transitions - your STM-NSS coding and/or connection is suspect.

3) Should (2) above still fail - test/confirm that you can drive MISO to near ground - with a sub 10mA current sink. If you cannot - STM32 or misconnection is too stiff. If you can drive MISO to near ground - STM and related connections have ''passed.''

4) Always advise - confirm ''strange'' operation across multiple accessories (your flash module) and multiple STM pcbs.

This should get you going...

peter_lanius
Associate II
Posted on May 17, 2011 at 13:37

Hi,

I have progressed past my issues with I2C and Timers to interface with my SPI serial flash module. The module is based on the Atmel AT45DB161B 2MB flash and produced by ETT (see schematic below). I've set all jumpers to enabled, meaning all pull-up resistors are enabled.

When I look at the SPI signals on my DSO, CS, Clock and MOSI look fine, but MISO looks weird, see images below. It seems like the flash is unable to pull MISO low properly, but I have no ideas why.

I am running SPI1 @ 2.25MHz. The board is rated to 20MHz. SPI is initialised as follows:

/* Defines for the SPI and GPIO pins used to drive the SPI Flash */

#define SPI_FLASH SPI1

#define SPI_FLASH_CLK RCC_APB2Periph_SPI1

#define SPI_FLASH_GPIO GPIOA

#define SPI_FLASH_GPIO_CLK RCC_APB2Periph_GPIOA

#define SPI_FLASH_PIN_SCK GPIO_Pin_5

#define SPI_FLASH_PIN_MISO GPIO_Pin_6

#define SPI_FLASH_PIN_MOSI GPIO_Pin_7

#define SPI_FLASH_CS GPIO_Pin_4

#define SPI_FLASH_CS_GPIO GPIOA

#define SPI_FLASH_CS_GPIO_CLK RCC_APB2Periph_GPIOA

/* Enable SPI and GPIO clocks */

RCC_APB2PeriphClockCmd(SPI_FLASH_CLK | SPI_FLASH_GPIO_CLK | SPI_FLASH_CS_GPIO_CLK, ENABLE);

/* Configure SPI pins: SCK, MISO and MOSI */

GPIO_InitStructure.GPIO_Pin = SPI_FLASH_PIN_SCK | SPI_FLASH_PIN_MISO | SPI_FLASH_PIN_MOSI;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_Init(SPI_FLASH_GPIO, &GPIO_InitStructure);

/* Configure I/O for Flash Chip select */

GPIO_InitStructure.GPIO_Pin = SPI_FLASH_CS;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;

GPIO_Init(SPI_FLASH_CS_GPIO, &GPIO_InitStructure);

/* Deselect the FLASH: Chip Select high */

SPI_FLASH_CS_HIGH();

/* SPI configuration */

SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;

SPI_InitStructure.SPI_Mode = SPI_Mode_Master;

SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;

SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;

SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;

SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;

SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_32;

SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;

SPI_InitStructure.SPI_CRCPolynomial = 7;

SPI_Init(SPI_FLASH, &SPI_InitStructure);

/* Enable the SPI */

SPI_Cmd(SPI_FLASH, ENABLE);

Thanks, Peter

peter_lanius
Associate II
Posted on May 17, 2011 at 13:37

Thanks Guys,

it turns out it was a problem in the Chip Select code. As per your suggestion I triggered CS externally and it worked and than it was easy to find the problem... Should have bought a 4 channel DSO, then I could see all 4 signals at once :-[

[ This message was edited by: peter_lanius on 10-01-2010 08:24 ]

kjepsen9
Associate II
Posted on May 17, 2011 at 13:37

Hello,

you sure you have good connections?

It seems you have problems driving the signal high as well, due to the long charge time in the begining to get the level high.

Kasper

jj
Associate II
Posted on May 17, 2011 at 13:37

Good for you - proud/pleased to have assisted.

Yours is our 60th ''successful'' STM32 ''remote'' diagnosis/fix...

Happy to ''repay'' the assistance lanchon/others provided me/my small firm...