Getting garbage data or missing data in SPI communication with NRF52840 board with two SPI slaves. Using SDK 17.1

Hi, I am trying to do the SPI communication between  a SPI master and two SPI slaves. I am using NRF52840 Dev Kit as SPI master and 2 ESP32-S3 as SPI slaves. I am using SDK version 17.1 for NRF. I am  sending and receiving a 32 bytes of data. My work flow is to send a 32 Bytes of data from Master to Slave then Slave will respond on that . So as per the SPI I need to send two commands from Master to read the data from Slave. In first command '0x11', Slave will prepare the data on its side, then Master will send a dummy command  '0x13' to read that data. Currently for debugging I have added a  dummy data to transmit and receive. Total data which I may need to transmit or receive could be 2 Kbytes.

For template I have used the SPI example from the SDK peripheral example

I have used the following pins for SPI master on NRF side

#define ESP1_IO_PIN               36
#define ESP_32_S3_1_PWR      6              // MUX Select PIN
#define ESP_ESP_32_S3_1_TRIG 15

#define ESP_32_S3_1_SS         12       // P0.12
#define ESP1_SPI_MISO_PIN   11      // P0.11
#define ESP1_SPI_MOSI_PIN   41     // P1.09
#define ESP1_SPI_SCK_PIN     40    // P1.08
#define ESP1_EN_PIN               33   // P1.08


#define ESP2_IO_PIN                    43
#define ESP_32_S3_2_PWR          46


#define ESP_32_S3_2_SS          45
#define ESP2_SPI_MISO_PIN    13
#define ESP2_SPI_MOSI_PIN    17
#define ESP2_SPI_SCK_PIN      16
#define ESP2_EN_PIN                44 // P1.08


#define ESP_32_S3_1_SPI_INSTANCE 1
#define ESP_32_S3_2_SPI_INSTANCE 2

I have added the main.c code here

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/**
* Copyright (c) 2015 - 2021, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

I have uploaded the SPI master code for NRF

spi_master_code_nrf_side_tested221222.zip

Here, I have uploaded the code for ESP32-S3 

3806.spi_slave_esp32s3.zip

Issues

  1. While communicating with NRF with ESP32-S3 I have to put delay in NRF side code.
  2. Otherwise it will receive some garbage for some bytes or zero
  3. I have tested with providing different delays like 30 ms, 40 ms , 50 ms, but I am able to get exact data without any loss or garbage on 50 ms delay or more than any value of 50 ms only.
  4. I have calculated the checksum for whole 32 Bytes of data to check if data get corrupted
  5. I want to remove that delay to get max speed for transmission.

    In case of setting the delay to 10 ms

In case of setting delay to 30 ms

In case of setting the delay to 50 ms

Please give me suggestion for how to resolve this issue for removing the delay from the code.

Parents
  • Hello,

    Have you made sure there is proper ground wire between the two (three) boards and that supply voltage is about the same? Do you have a logic analyzer trace of the SPI pins (ss, clk, miso and mosi), I think that could give some valuable information here.

    Best regards,
    Kenneth

Reply
  • Hello,

    Have you made sure there is proper ground wire between the two (three) boards and that supply voltage is about the same? Do you have a logic analyzer trace of the SPI pins (ss, clk, miso and mosi), I think that could give some valuable information here.

    Best regards,
    Kenneth

Children