Hi, I'm using a MCBSTM32E board, with a ST32E103ZE Arm Cortex M3 processor. I am trying to get the SPI interface to work, but so far I've had no luck.
I've tried simulating, and capturing the pin outputs with an oscilloscope, but I get no output.
Relevant code:
void M_SPIInit(void) { SPI_InitTypeDef SPI_InitStructure; // SPI1 configuration SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; SPI_InitStructure.SPI_Mode = SPI_Mode_Master; SPI_InitStructure.SPI_DataSize = SPI_DataSize_16b; SPI_InitStructure.SPI_CPOL = SPI_CPOL_High; SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge; SPI_InitStructure.SPI_NSS = SPI_NSS_Hard; SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4; SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; SPI_InitStructure.SPI_CRCPolynomial = 7; SPI_Init(SPI1, &SPI_InitStructure); } int main (void) { stm32_Init(); M_SPIInit(); SPI_Cmd(SPI1, ENABLE); SPI_I2S_SendData(SPI1,word); }
Try to put SPI_NSS low level.
Have you configured the GPIOs used for the SPI?
And enabled all the appropriate clocks?
I have tried setting NSS to Software, but no change.
I have configured the GPIOs like this:
NSS - Floating input SCK - Alternate Function Push-pull (Max 50 MHz) MISO - Floating input MOSI - Alternate Function Push-pull (Max 50 MHz)
I have no idea which clocks to set, I'm using their configuration wizard. They are set (as far as I can tell) like this:
External Clock Enabled (8 MHz) PLL Enabled, 8 times multiplier and does not exceed maximum of 72 MHz. PLL source : HSE clock PLLXTPRE : HSE System Clock switch : PLL clock
I don't use any ST chips but is this really correct?
SCK - Alternate Function Push-pull (Max 50 MHz)
Having a pin as a high-impedive input or a push-pull output sounds just like GPIO settings. Don't you have somewhere to set that these pins should not be GPIO but should be owned by the SPI controller?
I couldn't find anywhere to change it, but I think it is correct.
One of the other possible settings is General Purpose Output (Max 50 MHz), so I'm assuming that is how you select between GPIO and Alternate functions.
There is also an Alternate remapping Setting, to map the outputs to other pins.
I got it working!
This was missing:
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);
There wasn't a setting for it in their config wizard, that's why I missed it.
Whose config wizard?
Keil's
File name is STM32_Init.c , but it's not a c file. When opened in uVision it is used as a configuration wizard.
Yes, it is.
But it contains special character sequences (in comments) that are spotted by the Wizard.
where did you obtain the stm32_init.c file?
In the Install folder, under examples\boards\Keil\MCBSTM32E
Some the examples have it.
Keil\ARM\Boards\Keil\MCBSTM32E\Blinky
See: http://www.keil.com/support/docs/2735.htm - which includes a link to the appropriate section of the uVision Manual...