I have str736, and gnuarm toolchain.
I need to interface the micro to TI ads1240 adc through BSPI1.
Using [STR73x SOFTWARE LIBRARY I program the BSPI1 as follow:
CFG_PeripheralClockConfig(CFG_CLK_BSPI1, ENABLE);
/* BSPI1 configuration */
BSPI_InitStructure.BSPI_RxFifoSize = 1;
BSPI_InitStructure.BSPI_TxFifoSize = 1;
BSPI_InitStructure.BSPI_SSPin = BSPI_SSPin_Masked;
BSPI_InitStructure.BSPI_CLKDivider = 60;
BSPI_InitStructure.BSPI_CPOL = BSPI_CPOL_Low;
BSPI_InitStructure.BSPI_CPHA = BSPI_CPHA_2Edge;
BSPI_InitStructure.BSPI_WordLength = BSPI_WordLength_8b;
BSPI_InitStructure.BSPI_Mode = BSPI_Mode_Master;
BSPI_DeInit(BSPI1);
BSPI_Init(BSPI1, &BSPI_InitStructure);
BSPI_Cmd(BSPI1, ENABLE);
The micro run at 32MHz so using 60 as clock divider I have 1.875 us as BSPI clock period.
As explained in some library example I use the following function to read/write data from/to BPSI
static u8_t Transfer_Byte(u8_t byte)
{
/* send byte through the BSPI2 peripheral */
GPIO_BitWrite(GPIO3, GPIO_PIN_13, 1);
BSPI_WordSend(BSPI1, byte);
GPIO_BitWrite(GPIO3, GPIO_PIN_13, 0);
/* loop while Transmit FIFO is full */
GPIO_BitWrite(GPIO3, GPIO_PIN_13, 1);
while(BSPI_FlagStatus(BSPI1, BSPI_FLAG_TFF) == SET);
GPIO_BitWrite(GPIO3, GPIO_PIN_13, 0);
/* loop while Receive FIFO is empty */
GPIO_BitWrite(GPIO3, GPIO_PIN_13, 1);
while(BSPI_FlagStatus(BSPI1, BSPI_FLAG_RFNE) == RESET);
GPIO_BitWrite(GPIO3, GPIO_PIN_13, 0);
return(BSPI_WordReceive(BSPI1));
}
I toggle pin 13 of port 3 to help me in debugging.
The problem is that it seems that RFNE bit goes high before that data is effectively read. Take a look to scope trace:
As you can see the last falling edge of P3.14 is before the last Sclk pulse has been generated, therefore data read from rx fifo is wrong.
Is it a SPI programming problem?
Manuals, datasheets and example do not mention need of delay between rising of RFNE flag and the read from RXR register, but seems to be necessary.
thanks](ImageShack - Best place for all of your image hosting and image sharing needs)](http://www.st.com/stonline/products/literature/um/11662.pdf)