Hello,
I'm trying to port my code for driving spi memory (S25FL256S) from nRF51822 to nRF52840.
I'm using nRF52840 Preview DK, S140 and SDK 15.0.0.
On nRF51 I used custom PCB (spi memory works fine) and SDK V810.
I have connected SPI memory to nRF52840:
SS - P1.01
CLK - P1.02
MOSI - P1.03
MISO - P1.04
And memory is powering separatelly from 3.3V supply (GND is common with nRF52840 DK).
Problem:
When SPI transfers bytes, MISO line is driving low.
I.e. I send request for ID (REMS) and I got responce 0x00, 0x00, 0x01, 0x18 instead 0xFF, 0xFF, 0x01, 0x18.
Whatever, I thought, correct data still incoming.
But when I tried go futher on code to make test read-write-read data on flash, code is not working anymore. I suppose, this is because different behaviour of MISO line in comparation with nRF51.
nRF51 code:
/* SPI Init Function - Initializes SPI to required mode*/
U8 S25FL_SPI_Init(void)
{
spi_master_config_t SPIC = SPI_MASTER_INIT_DEFAULT;
// Initializing a SPI master driver.
SPIC.SPI_Freq = SPI_FREQUENCY_FREQUENCY_M1;
SPIC.SPI_CONFIG_ORDER = SPI_CONFIG_ORDER_MsbFirst;
#if defined(SPI_MASTER_0_ENABLE)
SPIC.SPI_Pin_SCK = SPIM0_SCK_PIN;
SPIC.SPI_Pin_MISO = SPIM0_MISO_PIN;
SPIC.SPI_Pin_MOSI = SPIM0_MOSI_PIN;
SPIC.SPI_Pin_SS = SPIM0_SS_PIN;
#elif defined(SPI_MASTER_1_ENABLE)
SPIC.SPI_Pin_SCK = SPIM1_SCK_PIN;
SPIC.SPI_Pin_MISO = SPIM1_MISO_PIN;
SPIC.SPI_Pin_MOSI = SPIM1_MOSI_PIN;
SPIC.SPI_Pin_SS = SPIM1_SS_PIN;
#endif /* SPI_MASTER_ENABLE */
if(spi_master_open(SPI_MASTER_HW, &SPIC) != NRF_SUCCESS) return 0;
S25FL.TxBuf[0] = 0;
S25FL.RxBuf[0] = 0;
spi_master_send_recv(SPI_MASTER_HW, S25FL.TxBuf, 1, S25FL.RxBuf, 1);
return 1;
}
/* Read ID Function - Reads Flash ID and fills Flash Parameters Structure*/
U32 S25FL_ReadID(void)
{
U32 ID;
S25FL_IDCFI_p idcfi;
S25FL.TxBuf[0] = FLASH_CMD_READ_ID; //0x90XXXXXXXXXX - Command
S25FL.TxBuf[1] = 0; //0xXX000000XXXX - Address
S25FL.TxBuf[2] = 0;
S25FL.TxBuf[3] = 0;
S25FL.TxBuf[4] = 0; //0xXXXXXXXX01XX - Manufacture ID
S25FL.TxBuf[5] = 0; //0xXXXXXXXXXXYY - Device ID
S25FL.ID = 0;
if(spi_master_send_recv(SPI_MASTER_HW, S25FL.TxBuf, 6, S25FL.RxBuf, 6) != NRF_SUCCESS)
return 0;
ID = (S25FL.RxBuf[4] << 8) | S25FL.RxBuf[5];
...
}
nRF52 code:
/* SPI Init Function - Initializes SPI to required mode*/
U8 S25FL_SPI_Init(void)
{
nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG;
spi_config.ss_pin = S25FL_SS;
spi_config.miso_pin = S25FL_MISO;
spi_config.mosi_pin = S25FL_MOSI;
spi_config.sck_pin = S25FL_SCK;
spi_config.frequency = NRF_DRV_SPI_FREQ_1M;
spi_config.bit_order = NRF_DRV_SPI_BIT_ORDER_MSB_FIRST;
APP_ERROR_CHECK(nrf_drv_spi_init(&spi, &spi_config, NULL, NULL));
S25FL.TxBuf[0] = 0;
S25FL.RxBuf[0] = 0;
return 1;
}
/* Read ID Function - Reads Flash ID and fills Flash Parameters Structure*/
U32 S25FL_ReadID(void)
{
U32 ID;
S25FL_IDCFI_p idcfi;
ret_code_t ret;
S25FL.TxBuf[0] = FLASH_CMD_READ_ID; //0x90XXXXXXXXXX - Command
S25FL.TxBuf[1] = 0; //0xXX000000XXXX - Address
S25FL.TxBuf[2] = 0;
S25FL.TxBuf[3] = 0;
S25FL.TxBuf[4] = 0; //0xXXXXXXXX01XX - Manufacture ID
S25FL.TxBuf[5] = 0; //0xXXXXXXXXXXYY - Device ID
S25FL.ID = 0;
ret = nrf_drv_spi_transfer(&spi, S25FL.TxBuf, 6, S25FL.RxBuf, 6);
if(ret) return 0;
ID = (S25FL.RxBuf[4] << 8) | S25FL.RxBuf[5];
...
}
In general, I replaced all spi_master_send_recv to nrf_drv_spi_transfer.
Here is full datasheet on memory, REMS section described at page 80:
S25FL256S_SPANSION.pdf
Regards!