2015-09-13 03:38 AM
Guys,
I want to use SPI1 for communicating with VS1... Is my configuration right ?#if !defined (USE_STM3210B_EVAL) && !defined (USE_STM3210E_EVAL) && !defined (USE_STM3210C_EVAL)&& !defined (USE_STM32100E_EVAL)
//#define USE_STM3210B_EVAL
#define USE_STM3210E_EVAL
//#define USE_STM32100E_EVAL
//#define USE_STM3210C_EVAL
#endif
/* Define the STM32F10x hardware depending on the used evaluation board */
#if defined (USE_STM3210B_EVAL) || defined (USE_STM3210E_EVAL) || defined (USE_STM32100E_EVAL)
#define SPI_MASTER SPI1
#define SPI_MASTER_CLK RCC_APB2Periph_SPI1
#define SPI_MASTER_GPIO GPIOA
#define SPI_MASTER_GPIO_CLK RCC_APB2Periph_GPIOA
#define SPI_MASTER_PIN_NSS GPIO_Pin_4
#define SPI_MASTER_PIN_SCK GPIO_Pin_5
#define SPI_MASTER_PIN_MISO GPIO_Pin_6
#define SPI_MASTER_PIN_MOSI GPIO_Pin_7
#define SPI_SLAVE SPI2
#define SPI_SLAVE_CLK RCC_APB1Periph_SPI2
#define SPI_SLAVE_GPIO GPIOB
#define SPI_SLAVE_GPIO_CLK RCC_APB2Periph_GPIOB
#define SPI_SLAVE_PIN_NSS GPIO_Pin_12
#define SPI_SLAVE_PIN_SCK GPIO_Pin_13
#define SPI_SLAVE_PIN_MISO GPIO_Pin_14
#define SPI_SLAVE_PIN_MOSI GPIO_Pin_15
#define SPI_SLAVE_DMA DMA1
#define SPI_SLAVE_DMA_CLK RCC_AHBPeriph_DMA1
#define SPI_SLAVE_Rx_DMA_Channel DMA1_Channel4
#define SPI_SLAVE_Rx_DMA_FLAG DMA1_FLAG_TC4
#define SPI_SLAVE_Tx_DMA_Channel DMA1_Channel5
#define SPI_SLAVE_Tx_DMA_FLAG DMA1_FLAG_TC5
#define SPI_SLAVE_DR_Base 0x4000380C
#elif defined (USE_STM3210C_EVAL)
#define SPI_MASTER SPI3 /* SPI pins are remapped by software */
#define SPI_MASTER_CLK RCC_APB1Periph_SPI3
#define SPI_MASTER_GPIO GPIOC
#define SPI_MASTER_GPIO_NSS GPIOA
#define SPI_MASTER_GPIO_CLK (RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOA)
#define SPI_MASTER_PIN_NSS GPIO_Pin_4
#define SPI_MASTER_PIN_SCK GPIO_Pin_10
#define SPI_MASTER_PIN_MISO GPIO_Pin_11
#define SPI_MASTER_PIN_MOSI GPIO_Pin_12
#define SPI_SLAVE SPI2
#define SPI_SLAVE_CLK RCC_APB1Periph_SPI2
#define SPI_SLAVE_GPIO GPIOB
#define SPI_SLAVE_GPIO_CLK RCC_APB2Periph_GPIOB
#define SPI_SLAVE_PIN_NSS GPIO_Pin_12
#define SPI_SLAVE_PIN_SCK GPIO_Pin_13
#define SPI_SLAVE_PIN_MISO GPIO_Pin_14
#define SPI_SLAVE_PIN_MOSI GPIO_Pin_15
#define SPI_SLAVE_DMA DMA1
#define SPI_SLAVE_DMA_CLK RCC_AHBPeriph_DMA1
#define SPI_SLAVE_Rx_DMA_Channel DMA1_Channel4
#define SPI_SLAVE_Rx_DMA_FLAG DMA1_FLAG_TC4
#define SPI_SLAVE_DR_Base 0x4000380C
#endif
I want to use
XCS = NSS = PA4
SCK = PA5
MOSI = PA6
MISO = PA7
Here's the GPIO config :
/**
* @brief Configures the different GPIO ports.
* @param None
* @retval None
*/
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
//define DREQ,XDCS,XRST PORT
/*!< GPIOC and GPIOD Periph clock enable */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE,ENABLE);
/*!< Configure PE.08, PE.09 XDCS, XRST */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 ;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
//GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOE, &GPIO_InitStructure);
/*Configure GPIO pin : PE7 as input, DREQ */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 ;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
//GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOE, &GPIO_InitStructure);
#ifdef USE_STM3210C_EVAL
/* Enable SPI3 Pins Software Remapping */
GPIO_PinRemapConfig(GPIO_Remap_SPI3, ENABLE);
/* Configure SPI_MASTER pins: SCK and MOSI */
GPIO_InitStructure.GPIO_Pin = SPI_MASTER_PIN_SCK | SPI_MASTER_PIN_MOSI;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(SPI_MASTER_GPIO, &GPIO_InitStructure);
/* Configure SPI_MASTER NSS pin */
GPIO_InitStructure.GPIO_Pin = SPI_MASTER_PIN_NSS;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(SPI_MASTER_GPIO_NSS, &GPIO_InitStructure);
#else
/* Configure SPI_MASTER pins: NSS, SCK and MOSI */
GPIO_InitStructure.GPIO_Pin = SPI_MASTER_PIN_NSS | SPI_MASTER_PIN_SCK | SPI_MASTER_PIN_MOSI;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(SPI_MASTER_GPIO, &GPIO_InitStructure);
#endif
/* Configure SPI_SLAVE pins: NSS, SCK and MISO*/
GPIO_InitStructure.GPIO_Pin = SPI_SLAVE_PIN_NSS | SPI_SLAVE_PIN_SCK;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(SPI_SLAVE_GPIO, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = SPI_SLAVE_PIN_MISO;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(SPI_SLAVE_GPIO, &GPIO_InitStructure);
}
Thanks for the info
2015-09-15 02:53 PM
I see that from datasheet reference as well, thanks,
can I use SPI1 for 2 function ? one for SDcard and one for VS1053 ? I will use NSS for VS1053 and another port for example PE10 for SDcard CS ? Thanks