2014-09-04 01:07 AM
Hi,
the my problem is comunication with SPI. The configuration SPI is following: /* Private define ------------------------------------------------------------*/ /* Uncomment the size of data to be transmetted (only one data size must be selected) */ #define SPI_DATASIZE SPI_DataSize_8b #define SPIx SPI1 #define SPIx_CLK RCC_APB2Periph_SPI1 #define SPIx_IRQn SPI1_IRQn #define SPIx_IRQHandler SPI1_IRQHandler #define SPIx_SCK_PIN GPIO_Pin_13 #define SPIx_SCK_GPIO_PORT GPIOB #define SPIx_SCK_GPIO_CLK RCC_AHBPeriph_GPIOB #define SPIx_SCK_SOURCE GPIO_PinSource13 #define SPIx_SCK_AF GPIO_AF_0 #define SPIx_MISO_PIN GPIO_Pin_14 #define SPIx_MISO_GPIO_PORT GPIOB #define SPIx_MISO_GPIO_CLK RCC_AHBPeriph_GPIOB #define SPIx_MISO_SOURCE GPIO_PinSource14 #define SPIx_MISO_AF GPIO_AF_0 #define SPIx_MOSI_PIN GPIO_Pin_15 #define SPIx_MOSI_GPIO_PORT GPIOB #define SPIx_MOSI_GPIO_CLK RCC_AHBPeriph_GPIOB #define SPIx_MOSI_SOURCE GPIO_PinSource15 #define SPIx_MOSI_AF GPIO_AF_0 #define SPIx_NSS_PIN GPIO_Pin_12 #define SPIx_NSS_GPIO_PORT GPIOB #define SPIx_NSS_GPIO_CLK RCC_AHBPeriph_GPIOB #define SPIx_NSS_SOURCE GPIO_PinSource12 #define SPIx_NSS_AF GPIO_AF_0 void spiInit() { GPIO_InitTypeDef GPIO_InitStructure; SPI_InitTypeDef SPI_InitStructure; /* Enable the SPI peripheral */ RCC_APB2PeriphClockCmd(SPIx_CLK, ENABLE); /* Enable SCK, MOSI, MISO and NSS GPIO clocks */ RCC_AHBPeriphClockCmd(SPIx_SCK_GPIO_CLK | SPIx_MISO_GPIO_CLK | SPIx_MOSI_GPIO_CLK | SPIx_NSS_GPIO_CLK , ENABLE); /* SPI pin mappings */ GPIO_PinAFConfig(SPIx_SCK_GPIO_PORT, SPIx_SCK_SOURCE, SPIx_SCK_AF); GPIO_PinAFConfig(SPIx_MOSI_GPIO_PORT, SPIx_MOSI_SOURCE, SPIx_MOSI_AF); GPIO_PinAFConfig(SPIx_MISO_GPIO_PORT, SPIx_MISO_SOURCE, SPIx_MISO_AF); GPIO_PinAFConfig(SPIx_NSS_GPIO_PORT, SPIx_NSS_SOURCE, SPIx_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 = SPIx_SCK_PIN; GPIO_Init(SPIx_SCK_GPIO_PORT, &GPIO_InitStructure); /* SPI MOSI pin configuration */ GPIO_InitStructure.GPIO_Pin = SPIx_MOSI_PIN; GPIO_Init(SPIx_MOSI_GPIO_PORT, &GPIO_InitStructure); /* SPI MISO pin configuration */ GPIO_InitStructure.GPIO_Pin = SPIx_MISO_PIN; GPIO_Init(SPIx_MISO_GPIO_PORT, &GPIO_InitStructure); /* SPI NSS pin configuration */ GPIO_InitStructure.GPIO_Pin = SPIx_NSS_PIN; GPIO_Init(SPIx_NSS_GPIO_PORT, &GPIO_InitStructure); /* SPI configuration -------------------------------------------------------*/ SPI_I2S_DeInit(SPIx); SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; SPI_InitStructure.SPI_Mode = SPI_Mode_Master; SPI_InitStructure.SPI_DataSize = SPI_DATASIZE; SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low; SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge; SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4; SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; SPI_InitStructure.SPI_CRCPolynomial = 7; /* Initializes the SPI communication */ SPI_Init(SPIx, &SPI_InitStructure); /* Enable the SPI peripheral */ SPI_Cmd(SPIx, ENABLE); } I ask you if this configuration is correct! The use the SPI for comunication EEPROM with the following schematic: Thanks2014-09-04 02:16 AM
The Input/Output sense seems backward. Wouldn't MOSI need to go to SI?
2014-09-04 05:09 AM
Exact!
I invert the pins and verify the source code! Thanks2014-09-04 07:23 AM
I eliminated the EEPROM device in schematic.
I send the char with SPI and monitoring the signal in output from microcontroller. SSI_CLK --> is low; CS_EEPROM --> is low for 100 ms (duration
of
transmission of the
given
)then
back high for 500 ms;
SSI_DIN --> is low. The executed code is
the following:
int main(void) { uint8_t Dato = 0xAA; /* Initialize the SPI EEPROM driver ----------------------------------------*/ spiInit(); /* Infinite loop */ while (1) { SPI_SSOutputCmd(SPIx,ENABLE); /*!< Send WriteAddr address byte to write to */ SPI_SendData8(SPI1, Dato); Delay(100);SPI_SSOutputCmd(SPIx,DISABLE);
Delay(500); } } Why the CLK signal is absent? Help me!2014-09-09 01:12 AM