2012-08-22 09:30 AM
Hi, I want change polarity on the fly example
When I setting the SPI master, I setting ''SPI_CPOL_Low'' trasmit the 16 bit data, and work! But I need recive another 16bit data with polarity inverse ''SPI_CPOL_Hight'' The protocolo is this: (ADF7021 ''Serial Interface Readback Timing Diagram'') Send screen of datasheet: Send 32bit + 1bit clock + 16 bit clock with inverse polarity Send 32bit = Ok but How to send in the fly 1 bit clock and inverse polarity on the fly? /* SPI configuration -------------------------------------------------------*/ SPI_I2S_DeInit(SPI1); SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; SPI_InitStructure.SPI_DataSize = SPI_DataSize_16b; 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_32; SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; SPI_InitStructure.SPI_CRCPolynomial = 7; SPI_InitStructure.SPI_Mode = SPI_Mode_Master; SPI_Init(SPI1, &SPI_InitStructure); /* Enable the SPI peripheral */ SPI_Cmd(SPI1, ENABLE);2012-08-22 10:51 AM
I try in this mode but I have a problem:
This code: //send 32bit SPI_I2S_SendData16(SPI1, 0xAAAA); while(!(SPI1->SR & SPI_I2S_FLAG_TXE)); //wait is busy SPI_I2S_SendData16(SPI1, 0xAAAA); while(!(SPI1->SR & SPI_I2S_FLAG_TXE)); //wait is busy //change polarity SPI1->CR1 = SPI1->CR1 & ~(1<<6); //SPE = 0 SPI1->CR1 = SPI1->CR1 | (1<<1); //CPOL = 1 SPI1->CR1 = SPI1->CR1 | (1<<6); //SPE = 1 //send 16nit SPI_I2S_SendData16(SPI1, 0xAAAA); while(!(SPI1_TX_busy)); //restore polarity SPI1->CR1 = SPI1->CR1 & ~(1<<6); //SPE = 0 SPI1->CR1 = SPI1->CR1 & ~(1<<1); //CPOL = 0 SPI1->CR1 = SPI1->CR1 | (1<<6); //SPE = 1 The result are: The 32bit send perfect, but when the change polarity not change! change only the first bit and the rest of bit the phase is equal of first trasmission: First Send 32 bit: change phase, and this result: (one bit change fase the resdt of bis no change)2012-08-22 03:22 PM
TXE is no good for telling when TX is complete, it indicates the holding register is empty, and will assert just before the first bit leaves, not when the last one does. RXNE would be a better flag.