cancel
Showing results for 
Search instead for 
Did you mean: 

Configuring SPI1

simon13
Associate II
Posted on May 04, 2009 at 20:13

Configuring SPI1

3 REPLIES 3
simon13
Associate II
Posted on May 17, 2011 at 13:11

Hi Everyone,

I have been trying to configure the STM32F103RB SPI1 interface and my hardware is not showing the same as my Keil software simulator.

The main parts of my code are...

/* Set SPI to master and CPOL=1, CPHA=1 */

SPI1->CR1 = 0x0000;

SPI1->CR1 |= SPI_CR1_MSTR | SPI_CR1_CPOL | SPI_CR1_CPHA;

/* Set SSOE to enable */

SPI1->CR2 |= SPI_CR2_SSOE;

/* Enable SPI */

SPI1->CR1 |= SPI_CR1_SPE;

/* Read SPI status register */

sts = SPI1->SR;

In the Keil software simulator I see my 'sts' variable = 0x0002 which shows the TX_buffer is empty as I would expect.

When I run on hardware the 'sts' variable = 0x0000 and I cannot transmit any data by using a line such as (I see no activity with an oscilloscope):

SPI1->DR = 0xAA55;

Am I missing something really obvious? The software simulator shows I am configuring the correct register addresses so I assume it maybe a setup issue elsewhere.

Any ideas and suggestion would be appreciated.

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

Usual suspects in such cases are:

a) failure or incorrect enabling of specific peripheral

b) failure to enable the clock for that peripheral

ST's FW library provides several ''known good'' SPI as master examples - review these with emphasis to a & b above...

simon13
Associate II
Posted on May 17, 2011 at 13:11

In my case it was b) failure to enable the clock for that peripheral.

All working now.

Thanks