2014-05-07 06:53 AM
Using STM3220G-EVAL with my serial FLASH added to board.
I am writing to a serial flash via the SPI port. My clock speed is 30Mhz. All is working fine, but I was expecting less delay between the SPI clock transfers. My code is shown below. The scope image shows a 700ns delay between clock tranfers. This is mostly cuaed by waiting for the RXNE bit to set. Since the received byte is clocked in as the transmit byte is clocked out I would expect minimal delay between byte transfers. In other word I would expect to see a continuous clock sequence during this transfer. Is this the delay I should expect or is there something in my setup that I can change to make the delay shorter? (I tried to attach image of scope trace but your websight gave me Errors)
// SPI configuration
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;// set to full duplex mode, separate MOSI and MISO lines
SPI_InitStructure.SPI_Mode = SPI_Mode_Master; // transmit in master mode, NSS pin has to be always high
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; // one packet of data is 8 bits wide
SPI_InitStructure.SPI_CPOL = SPI_CPOL_High; // the clock pin is set normally high
SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge; // data is clocked on the rising edge (2nd edge from normally high aka serial mode 3)
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; // set the NSS management to internal software controlled
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2;// run the SPI clock as fast as possible
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; // data is transmitted MSB first
SPI_InitStructure.SPI_CRCPolynomial = 7;
SPI_Init(MX25L6406_SPI, &SPI_InitStructure);
/// Enable SPI Peripheral
SPI_Cmd(MX25L6406_SPI, ENABLE);
************************************************************************
//Read flash ID function
//Enable Flash Chip Select
MX25L6406_CS_Low();
while (SPI_I2S_GetFlagStatus(MX25L6406_SPI, SPI_I2S_FLAG_TXE) == RESET);
SPI_I2S_SendData(MX25L6406_SPI, 0x009F);
while(SPI_I2S_GetFlagStatus(MX25L6406_SPI, SPI_I2S_FLAG_RXNE) == RESET) {}
SPI_I2S_ReceiveData(MX25L6406_SPI
while (SPI_I2S_GetFlagStatus(MX25L6406_SPI, SPI_I2S_FLAG_TXE) == RESET
SPI_I2S_SendData(MX25L6406_SPI, 0x0000);
while(SPI_I2S_GetFlagStatus(MX25L6406_SPI, SPI_I2S_FLAG_RXNE) == RESET) {}
MX25L6406_ID_struct.manufacturer_ID = SPI_I2S_ReceiveData(MX25L6406_SPI);
while (SPI_I2S_GetFlagStatus(MX25L6406_SPI, SPI_I2S_FLAG_TXE) == RESET);
SPI_I2S_SendData(MX25L6406_SPI, 0x0000);
while(SPI_I2S_GetFlagStatus(MX25L6406_SPI, SPI_I2S_FLAG_RXNE) == RESET) {}
MX25L6406_ID_struct.memory_type_ID = SPI_I2S_ReceiveData(MX25L6406_SPI);
while (SPI_I2S_GetFlagStatus(MX25L6406_SPI, SPI_I2S_FLAG_TXE) == RESET);
SPI_I2S_SendData(MX25L6406_SPI, 0x0000);
while(SPI_I2S_GetFlagStatus(MX25L6406_SPI, SPI_I2S_FLAG_RXNE) == RESET) {}
MX25L6406_ID_struct.memory_density_ID = SPI_I2S_ReceiveData(MX25L6406_SPI);
// Disable Flash Chip
MX25L6406_CS_High();
2014-05-07 07:08 AM
Attached scope trace bitmap image
________________ Attachments : NewFile0.bmp : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I1I3&d=%2Fa%2F0X0000000bkp%2F.KA2G9MMtTw.QbMj8II2CUExOx2NQ27MFB9A4t6l0WE&asPdf=false2014-05-07 07:27 AM
is there something in my setup that I can change to make the delay shorter?
Yes, stop tying TXE and RXNE together, you are forcing rigid serialization when in fact the holding buffer asserting TXE will be available as soon as the first bit starts shifting