Question
STM32F4XX SPI3 Data register is always 0xff and TXE is 1
Posted on January 22, 2018 at 19:55
I am trying to interface SPI3 of STM32F4with external SPI F-RAm memory chip. But after writing dummy data(0x00) in data register, data register is set to 0xff and it doest not change and my TXE bit is always set. Have i not initialize my GPIO port and SPI properly?
Her is my initialization
int main(void)
{ uint8_t flagstatus=255; uint8_t last_position[4]; // tseting last saved position uint8_t du_current_location=0; init_USART(9600, PARITY_NONE); USART_puts(USART1, '\n\r USART Initialize complete\n\r'); // GPIO initialization for SPI3 RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE); GPIO_InitTypeDef GPIO_InitStruct; GPIO_InitStruct.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11; GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStruct.GPIO_OType = GPIO_OType_PP; GPIO_InitStruct.GPIO_Speed = GPIO_Speed_25MHz; GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(GPIOC,&GPIO_InitStruct); GPIO_InitStruct.GPIO_Pin = GPIO_Pin_12; GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStruct.GPIO_OType = GPIO_OType_PP; GPIO_InitStruct.GPIO_Speed = GPIO_Speed_25MHz; GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_DOWN; GPIO_Init(GPIOC,&GPIO_InitStruct); GPIO_PinAFConfig(GPIOC, GPIO_PinSource10,GPIO_AF_SPI3); GPIO_PinAFConfig(GPIOC, GPIO_PinSource11,GPIO_AF_SPI3); GPIO_PinAFConfig(GPIOC, GPIO_PinSource12,GPIO_AF_SPI3); GPIO_InitStruct.GPIO_Pin = GPIO_Pin_15; GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStruct.GPIO_OType = GPIO_OType_PP; GPIO_InitStruct.GPIO_Speed = GPIO_Speed_25MHz; GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_DOWN; GPIO_Init(GPIOA, &GPIO_InitStruct); // SPI 3 initialization RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI3,ENABLE); SPI_InitTypeDef SPI_InitStruct; SPI_InitStruct.SPI_DataSize=SPI_DataSize_8b; SPI_InitStruct.SPI_CPOL=SPI_CPOL_High; SPI_InitStruct.SPI_CPHA=SPI_CPHA_2Edge; SPI_InitStruct.SPI_Mode=SPI_Mode_Master; SPI_InitStruct.SPI_NSS=SPI_NSS_Soft; SPI_InitStruct.SPI_BaudRatePrescaler=SPI_BaudRatePrescaler_64; SPI_InitStruct.SPI_FirstBit=SPI_FirstBit_MSB; SPI_InitStruct.SPI_Direction=SPI_Direction_2Lines_FullDuplex; SPI_InitStruct.SPI_CRCPolynomial=7; // This need to check I dont need it SPI_Init(SPI3, &SPI_InitStruct); GPIO_SetBits(GPIOA, GPIO_Pin_15); SPI_Cmd(SPI3,ENABLE);GPIO_ResetBits(GPIOA, GPIO_Pin_15);
SPI3->DR=0x00; // this is dummy variable to initiate SPI communication while(SPI_I2S_GetFlagStatus(SPI3, SPI_I2S_FLAG_RXNE)==1); while(SPI_I2S_GetFlagStatus(SPI3, SPI_I2S_FLAG_RXNE)==0); flagstatus=SPI3->DR; SPI3->DR=0x05; while(SPI_I2S_GetFlagStatus(SPI3, SPI_I2S_FLAG_RXNE)==1); while(SPI_I2S_GetFlagStatus(SPI3, SPI_I2S_FLAG_RXNE)==0); flagstatus=SPI3->DR; GPIO_SetBits(GPIOA, GPIO_Pin_15); SPI_Cmd(SPI3,DISABLE); }