Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By Gagan
#81371 Hi, i am interfacing nRF52832(M) and ESP8266 12E(S) via SPI for sending image data. Both are on 4M mode, normal communication is working but when transfer 10kb, its not getting proper data.

I am using Arduino IDE for programming. Using SPI.Slave function for receiving data on ESP side
problem is that when transferring data with delay(5000 ms) than the data is received fine, but using less delay like 100 ms its only receive about 1800 bytes instead of 10kb


nrf side sending


Code: Select alluint32_t wifiSpiWrite(uint8_t *txBuf, uint32_t len)
{
   uint32_t ret = SPI_SUCCESS;
   ret = nrf_drv_spi_transfer(&spi_2, txBuf, len, NULL, 0);
   return ret;
}

wifiSpiWrite(NotifyData,34);

if(imageByteCount >= 10230 )  // when sent 10kb then send this
   {     
         imageByteCount = 0;
         wifiMod.firstData[0] = 0x02;
         wifiMod.firstData[1] = 0x00;
         for(int i =2; i<34;i++)
         {
            wifiMod.firstData[i] = 0x06; // when data is complete then send this
         }
         wifiSpiWrite(wifiMod.firstData, 34);
         for (int i = 0; i < 34; i++)
         {
            wifiMod.rxBuff[i] = 0;
         }
         nrf_delay_ms(100); // so that spi can write and send
         
}
}




ESP side receiving

initialize of SPI
hspi_slave_begin(0, this); // for 4M mode


Code: Select allSPISlave.onData([](uint8_t * data, size_t len)
{
      if (data[0] ==  0x02 )
      { 
        Serial.printf("- - Value of index1 %d \n",index1);
        memcpy(&Event_Data[index1],&data[1],31);
        index1 += 31;
      }
}




Output of above

Code: Select all- - Value of index1 32
- - Value of index1 63
- - Value of index1 94
- - Value of index1 125
- - Value of index1 156
- - Value of index1 187
- - Value of index1 218
- - Value of index1 249
- - Value of index1 280
- - Value of index1 311
- - Value of index1 342
- - Value of index1 373
- - Value of index1 404
- - Value of index1 435
- - Value of index1 466
- - Value of index1 497
- - Value of index1 528
- - Value of index1 559
- - Value of index1 590
- - Value of index1 621
- - Value of index1 652
- - Value of index1 683
- - Value of index1 714
- - Value of index1 745
- - Value of index1 776
- - Value of index1 807
- - Value of index1 838
- - Value of index1 869
- - Value of index1 900
- - Value of index1 931
- - Value of index1 962
- - Value of index1 993
- - Value of index1 1024
- - Value of index1 1055
- - Value of index1 1086
- - Value of index1 1117
- - Value of index1 1148
- - Value of index1 1179
- - Value of index1 1210
- - Value of index1 1241
- - Value of index1 1272
- - Value of index1 1303
- - Value of index1 1334
- - Value of index1 1365
- - Value of index1 1396
- - Value of index1 1427
- - Value of index1 1458
- - Value of index1 1489
- - Value of index1 1520
- - Value of index1 1551
- - Value of index1 1582
- - Value of index1 1613
- - Value of index1 1644
- - Value of index1 1675
- - Value of index1 1706
- - Value of index1 1737
- - Value of index1 1768
- - Value of index1 1799
- - Value of index1 1830
- - Value of index1 1861
- - Value of index1 1892




thanks in Advance
User avatar
By DIRR70
#81403 Hello Gagan,

Your code is a bit too fragmentary to fully understand it. Out of what I can see I would say your problem can be that you are ignoring the "size_t len" parameter for the "SPISlave.onData" event. You are just assuming that the data has 0x02 as the first character and always is 32 characters long. Even though you might send data this way it does not has to arrive in the same manner.

For a first test I would suggest, just to log the incoming buffer length "Serial.println (len);". I'm pretty sure that you will see that counting all the dumped "len"s together you will get the number of bytes you've expected. Then you can log each received data byte (considering the len parameter) and see in what packages the data arrives.

If that won't help please post the entire ESP code to get a better overview... :)