2013-07-25 11:00 PM
hello
i have configure the SPI1 in the stm32F0 for a data acquisition from a sensor. I marked that the processor always enter in the RXNE interrupt despite there is no data in the MISO pin. /* SPI1 Periph clock enable */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1,ENABLE); RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB| RCC_AHBPeriph_GPIOC| RCC_AHBPeriph_GPIOF, ENABLE); /* SPI1 Config -------------------------------------------------------------*/ SPI_InitStructure_Position.SPI_Direction = SPI_Direction_1Line_Rx; SPI_InitStructure_Position.SPI_Mode = SPI_Mode_Master; SPI_InitStructure_Position.SPI_DataSize = SPI_DataSize_8b; SPI_InitStructure_Position.SPI_CPOL = SPI_CPOL_High; SPI_InitStructure_Position.SPI_CPHA = SPI_CPHA_2Edge; SPI_InitStructure_Position.SPI_NSS = SPI_NSS_Soft; SPI_InitStructure_Position.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_256; SPI_InitStructure_Position.SPI_FirstBit = SPI_FirstBit_MSB; SPI_InitStructure_Position.SPI_CRCPolynomial = 7; SPI_Init(SPI1, &SPI_InitStructure_Position); /* Configure SPI1 pins: SCK & MISO */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6 ; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_Init(GPIOA, &GPIO_InitStructure); /* Configure PC5 pin: CS pin */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType =GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(GPIOC, &GPIO_InitStructure); /* Connect SPI_SCK */ GPIO_PinAFConfig(GPIOA, GPIO_PinSource5, GPIO_AF_0); /* Connect SPI_MISO */ GPIO_PinAFConfig(GPIOA, GPIO_PinSource6, GPIO_AF_0); /*SPI1 enable */ SPI_Cmd(SPI1, ENABLE); SPI_I2S_ITConfig(SPI1,SPI_I2S_IT_RXNE,ENABLE); NVIC_InitStructure.NVIC_IRQChannel=SPI1_IRQn; NVIC_InitStructure.NVIC_IRQChannelPriority=2; NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE; NVIC_Init(&NVIC_InitStructure);}2013-07-26 04:06 AM
Sorry, I don't understand what the question is.
RXNE will set based on clock cycles on the SPI bus, what the data pin is doing is pretty irrelevant. If you don't clear the RXNE state in the interrupt it will keep re-entering. I'd advise you to configure the NVIC prior to enabling the interrupt source.2013-08-01 02:39 AM
Hi Clive1,
My project is to get 18 bits from a sensor ,but in the stm32 we have just 16 bits maximum of data size ,so do you have any idea to resolve my problem.Thanks.2013-08-01 04:15 AM
If it can stream multiple words you could read 8x 18 as 9x 16 (144 bits) or 4x 18 as 9x 8 (72 bits)? Then separate your 18-bit words in memory.
Alternatively you could bit-bang the interface. The STM32F0, as I recall, has move flexible SPI settings.2013-08-05 01:58 AM
Thank you Clive for your reply.