cancel
Showing results for 
Search instead for 
Did you mean: 

SPI1 Remap Problem

davidhauser
Associate II
Posted on February 24, 2009 at 02:53

SPI1 Remap Problem

4 REPLIES 4
davidhauser
Associate II
Posted on May 17, 2011 at 12:35

Hey I'd like to remap the SPI1 interface (especially I want to operate the LCD display of the motor controller kit via a remaped SPI1 -> original it's SPI2). This is my code:

Quote:

SPI_InitTypeDef SPI_InitStructure;

GPIO_InitTypeDef GPIO_InitStructure;

/* Enable GPIOA, GPIOB, SPI1 and AFIO clock */

RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_SPI1, ENABLE);

/* Configure NCS (PB.02) in Output Push-Pull mode */

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;

GPIO_Init(GPIOB, &GPIO_InitStructure);

/* Configure NWR(RNW) (PA.12), RS (PA.11) in Output Push-Pull mode */

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;

GPIO_Init(GPIOA, &GPIO_InitStructure);

/* Set NWR and RS to high */

LCD_CtrlLinesWrite(GPIOA, CtrlPin_NWR, Bit_SET);

LCD_CtrlLinesWrite(GPIOA, CtrlPin_RS, Bit_SET);

GPIO_Init(GPIOA, &GPIO_InitStructure);

/* Configure SPI1 pins: SCK (PB.03), MISO(DO) (PB.04) and MOSI(DI) (PB.05) */

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

GPIO_Init(GPIOB, &GPIO_InitStructure);

/* Remaping of SPI1 */

GPIO_PinRemapConfig(GPIO_Remap_SPI1, ENABLE);

/* SPI1 Config */

SPI_DeInit(SPI1);

SPI_StructInit(&SPI_InitStructure);

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_2;

SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;

SPI_Init(SPI1, &SPI_InitStructure);

/* SPI1 enable */

SPI_Cmd(SPI1, ENABLE);

Is there any mistake in it? Thanks for your help.

davidhauser
Associate II
Posted on May 17, 2011 at 12:35

Solution:

I had to remap the JTAG (for using PB.03).

Quote:

...

/* Remaping of SPI1 (JTAG disable for PB.03)*/

GPIO_PinRemapConfig(GPIO_Remap_SPI1, ENABLE);

GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);

...

regulus
Associate II
Posted on May 17, 2011 at 12:35

I have the same problem with STM32F103RBT6. I have added this row:

GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);

I tried also this:

GPIO_PinRemapConfig(GPIO_Remap_SWJ_Disable, ENABLE);

But in result i have ONLY SCLK on PB3.

I still have no MOSI & MISO. Why ?

I work on Keil MCB-STM32 Board.

On port PA (without remap) everything works OK.

johnmcgavin9
Associate II
Posted on May 17, 2011 at 12:35

Probably a bit late but for anyone else who also gets driven crazy by this.

Section 2.4.7 of the errata sheet - I2C1 with SPI1 remapped and used in master mode:

Description

Conflict between the SPI1 MOSI signal and the I2C1 SMBALERT signal (even if

SMBALERT is not used).

Workaround

Do not use SPI1 remapped in master mode and I2C1 together.

When using SPI1 remapped, the I2C1 clock must be disabled.