hi Petr,
Thanks for your suggestion, I make some progress in my task of writing EEPROM with spi.
my present work statue as the following:
figure 1
but the datasheet requirement as follows:
figure 2
in order to meet the requirement I have to setting as the chapter 40.5.6.6 Fast Continuous Selection Format discription, that means masking Tasc and Tcsc is needed in my SPI configuration .
but it is likely that I could not understand the masking rules right, I try many cases but cann't reach the figure 2 shows in past 3 days.
I only can setting as the figure 3 shows:
figure 3
That mean write enable byte 6 and data 5 could not be send out via MOSI.
Do you mind help me to correct my fast continues setting?
the follow is my setting:
I think the question should happend on the function Write_Byte(), but I really puzzled the description in chapter 40.5.6.6 Fast Continuous Selection Format.
Besides, I am not sure if the Tasc and Tcsc in register CTAR0 setting would affect the final output?
The controller present fp should be 40MHz.
******************************************************************************
static uint8_t Write_Byte(uint8_t cmd)
{
uint16_t response = 0x0000;
SPI_3.PUSHR.PUSHR.R = (uint32_t)((((uint32_t)cmd) & 0x000000FF) + 0x0B000000);
while (SPI_3.SR.B.RFDF != 1){} /* Wait for Receive FIFO Drain Flag = 1 */
response = (uint8_t)SPI_3.POPR.R; /* Read data received by master SPI */
SPI_3.SR.R = 0x90020000;
return((uint8_t)((0x02 & response) >> 1));
}
/**************************************************************************
**************************************************************************/
static uint8_t Write_FirstByte(uint8_t cmd)
{
uint16_t response = 0x0000;
SPI_3.PUSHR.PUSHR.R = (uint32_t)((((uint32_t)cmd) & 0x000000FF) + 0x08010000); /**/
while (SPI_3.SR.B.RFDF != 1){} /* Wait for Receive FIFO Drain Flag = 1 */
response = (uint8_t)SPI_3.POPR.R; /* Read data received by master SPI */
SPI_3.SR.R = 0x90020000;
return((uint8_t)((0x02 & response) >> 1));
}
/**************************************************************************
**************************************************************************/
void EEPROMWriteByte(uint8_t* Data, uint32_t DataSize, uint32_t Address)
{
SPI_Status_t spi3_status = 0;
uint8_t* spi3_rx_byte = 0;
uint8_t write_response,i;
uint8_t* data;
data = Data;
SPI_3.MCR.B.HALT = 0x1;
SPI_3.MCR.R = 0x80010001;
SPI_3.MODE.CTAR[0].R = 0x38020002; /1.25 MHz/
SPI_3.MCR.B.HALT = 0x0;
write_response = Write_FirstByte(EEPROM_CMD_WREN);
/fast continues send setting, MCR bit29 is set/
SPI_3.MCR.B.HALT = 0x1;
SPI_3.MCR.R = 0x80000005;
SPI_3.MODE.CTAR[0].R = 0x38020002; /1.25 MHz SUCCESS/
SPI_3.MCR.B.HALT = 0x0;
write_response = Write_Byte(EEPROM_CMD_WRITE); /*command write */
write_response = Write_Byte(Hi(Address)); /high address byte/
write_response = Write_Byte(Mid(Address)); /Middle address byte/
write_response = Write_Byte(Lo(Address)); /low address byte/
for (i = 0; i < (DataSize); i++) /* Datasize equal 5, plan to send 1, 2, 3, 4, 5 to EEPROM via MOSI*/
{
write_response = Write_Byte(i+1);
}
/*wait for completion of previous continues frame and begin to read status register */
SPI_3.MCR.B.HALT = 0x1;
SPI_3.MCR.R = 0x80010001;
SPI_3.MODE.CTAR[0].R = 0x38020002; /1.25 MHz/
SPI_3.MCR.B.HALT = 0x0;
/read register status EEPROM_CMD_RDSR equal 5/
write_response = Write_FirstByte(EEPROM_CMD_RDSR);
/write disable command EEPROM_CMD_WRDI equal 4/
write_response = Write_FirstByte(EEPROM_CMD_WRDI);
SPI_3.MCR.B.HALT = 0x1;
}
EEPROMWriteByte() function is call in 10ms task.
Great thanks for your help!
Wang Haibin