cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F0 spi clock problem

zlajoan
Associate II
Posted on September 04, 2014 at 12:29

Hi!

I'm trying to communicate with Atmel AT45DB081D dataflash over SPI. For testing I've send command to read Manufacturer and Device ID (0x9F on MOSI). After I've sent data, SPI clock stops to pulse and, I assume, slave is not able to send any data because clock is not present. This is my first time using SPI on STM32F0. Screenshot is attached below. (SCK-green, MOSI-yellow, CS-blue, MISO-red). Any suggestions how to force SPI clock to continue?

/public/STe2ecommunities/mcu/Lists/STM32Discovery/Attachments/11972/scope_0.bmp

Here is the SPI initialization:

void SPI1_Config(void)
{
SPI_InitTypeDef SPI_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
/* Enable the SPI periph */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);
/* Enable SCK, MOSI, MISO and NSS GPIO clocks */
RCC_AHBPeriphClockCmd(SPI1_SCK_GPIO_CLK | SPI1_MISO_GPIO_CLK | SPI1_MOSI_GPIO_CLK | SPI1_NSS_GPIO_CLK, ENABLE);
GPIO_PinAFConfig(SPI1_SCK_GPIO_PORT, SPI1_SCK_SOURCE, SPI1_SCK_AF);
GPIO_PinAFConfig(SPI1_MOSI_GPIO_PORT, SPI1_MOSI_SOURCE, SPI1_MOSI_AF);
GPIO_PinAFConfig(SPI1_MISO_GPIO_PORT, SPI1_MISO_SOURCE, SPI1_MISO_AF);
GPIO_PinAFConfig(SPI1_NSS_GPIO_PORT, SPI1_NSS_SOURCE, SPI1_NSS_AF);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_3;
/* SPI SCK pin configuration */
GPIO_InitStructure.GPIO_Pin = SPI1_SCK_PIN;
GPIO_Init(SPI1_SCK_GPIO_PORT, &GPIO_InitStructure);
/* SPI MOSI pin configuration */
GPIO_InitStructure.GPIO_Pin = SPI1_MOSI_PIN;
GPIO_Init(SPI1_MOSI_GPIO_PORT, &GPIO_InitStructure);
/* SPI MISO pin configuration */
GPIO_InitStructure.GPIO_Pin = SPI1_MISO_PIN;
GPIO_Init(SPI1_MISO_GPIO_PORT, &GPIO_InitStructure);
/* SPI NSS pin configuration */
GPIO_InitStructure.GPIO_Pin = SPI1_NSS_PIN;
GPIO_Init(SPI1_NSS_GPIO_PORT, &GPIO_InitStructure);
/* SPI configuration -------------------------------------------------------*/
SPI_I2S_DeInit(SPI1);
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
SPI_InitStructure.SPI_NSS = SPI_NSS_Hard;
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_32;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_InitStructure.SPI_CRCPolynomial = 7;
/* Configure the SPI interrupt priority */
NVIC_InitStructure.NVIC_IRQChannel = SPI1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* Initializes the SPI communication */
SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
SPI_Init(SPI1, &SPI_InitStructure);
/* Initialize the FIFO threshold */
SPI_RxFIFOThresholdConfig(SPI1, SPI_RxFIFOThreshold_QF);
/* Enable the Rx buffer not empty interrupt */
SPI_I2S_ITConfig(SPI1, SPI_I2S_IT_RXNE, ENABLE);
/* Enable the SPI Error interrupt */
SPI_I2S_ITConfig(SPI1, SPI_I2S_IT_ERR, ENABLE);
/* Enable NSS output for master mode */
SPI_SSOutputCmd(SPI1, ENABLE);
SPI_NSSPulseModeCmd(SPI1, ENABLE);
/* Enable the SPI peripheral */
SPI_Cmd(SPI1, ENABLE);
}

Thanks, Zlatko
6 REPLIES 6
Posted on September 04, 2014 at 14:11

Send any data.

Btw., this is not a STM32-specific question (not even STM32 Evaluation Tools'). You should read the FLASH's datasheet more carefully.

JW
zlajoan
Associate II
Posted on September 04, 2014 at 14:25

Sorry for misunderstanding, but this is STM32 problem. I'm using STM32F0 discovery board as master and flash as slave. I did sent data to slave but I can not receive any because SCK clock is not provided by master anymore after first data was sent.

Posted on September 04, 2014 at 18:55

Any suggestions how to force SPI clock to continue?

You send more data, it's a symmetrical interface. This data is considered pad or filler.
Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Posted on September 04, 2014 at 18:58

From a different SPI Flash ROM implementation I prototyped.

void ReadJEDEC(void)
{
static const uint8_t tx[4] = { 0x9F, 0x00, 0x00, 0x00 }; // Request JEDEC ID
uint8_t rx[4];
int i;
GPIOC->BSRRH = GPIO_Pin_13; // set PC13 (CS) low
for(i=0; i<
sizeof
(tx); i++)
rx[i] = SPI2_send(tx[i]);
GPIOC->BSRRL = GPIO_Pin_13; // set PC13 (CS) high
printf(''JEDEC'');
for(i=0; i<sizeof(rx); i++)
printf('' %02X'', rx[i]);
putchar('
');
}

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
zlajoan
Associate II
Posted on September 05, 2014 at 10:28

Thanks Clive!

It seems like hardcoding but it is working, clock continue to pulse.

Zlatko

Posted on September 05, 2014 at 14:58

It seems like hardcoding but it is working, clock continue to pulse.

In as much as your left shoulder goes everywhere your right shoulder goes.
Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..