Page 1 of 1

Problem with SPI

Posted: Thu Mar 26, 2020 4:22 pm
by breedj
Hi,

I've got some problems with SPI (mode 1) using an ESP32-WROVER-IB (16MB). I have made a pcb with two MAX11163 ADC's in daisychain mode. See page 21 of https://datasheets.maximintegrated.com/ ... X11163.pdf. Thay are SPI compatible.

Up to an SPI frequency of 20MHz all goes well, but at 40 MHz frequencies I get problems. I receive the wrong data and I do not know why. The ADC's are 250ksps and should be capable of doing at least 60MHz clock speed. The signals at 40MHz look good on the scope. I've added some screenshots at 40MHz probed directly at the ESP32 pins. The scope has no problem decoding de data at all. Every frame is decoded correctly by the scope. But the data printed by the ESP32 is not correct at 40MHz

At the bottom I've added some data examples below. It looks like the data at 40MHZ is shifting and a '1' is added to the left or a bit is missing. This also occures when reading only 16 bit instead of 32.

I've tried all other SPI modes. Also tried other values of miso_delay_mode. All no succes. Can anyone give me a clue? I'm clearly missing something here.

Here is the example code for the Arduino framework. It also does not work with Platform IO (Arduino).
  1. #include <SPI.h>
  2. #include "driver/spi_master.h"
  3.  
  4. static const uint32_t spiClk = 40000000;
  5. static const int ADC_CNVST = 5;
  6.  
  7. SPIClass * hspi = NULL;
  8.  
  9. void setup() {
  10.   Serial.begin(115200);
  11.  
  12.   hspi = new SPIClass(HSPI);
  13.   hspi->begin(14, 12, -1, -1);  
  14.   pinMode(ADC_CNVST, OUTPUT);
  15.   //hspi->beginTransaction(SPISettings(spiClk, MSBFIRST, SPI_MODE1));
  16.   hspi->setBitOrder(MSBFIRST);
  17.   hspi->setDataMode(SPI_MODE1);
  18.   hspi->setFrequency(spiClk);
  19.   hspi->setHwCs(false);
  20. }
  21.  
  22. uint16_t values_a[1000];
  23. uint16_t values_b[1000];
  24.  
  25. // the loop function runs over and over again until power down or reset
  26. void loop() {
  27.   hspiCommand();  
  28.    
  29.   for (int i=0; i < 1000; i=i+10) {
  30.     Serial.print(values_a[i], HEX);
  31.     Serial.print(" ");
  32.     Serial.println(values_b[i], HEX);
  33.   }
  34. }
  35.  
  36. void hspiCommand() {      
  37.   uint32_t adc_data;
  38.    
  39.   for (int i=0; i < 1000; i++)
  40.   {        
  41.     digitalWrite(ADC_CNVST, HIGH);  // Start conversion
  42.     delayMicroseconds(3);           // Wait 3us, conversion time
  43.     adc_data = hspi->transfer32(0);        
  44.     digitalWrite(ADC_CNVST, LOW);   // End      
  45.     values_a[i] = (uint16_t)(adc_data & 0xFFFF);
  46.     values_b[i] = (uint16_t)(adc_data >> 16);        
  47.   }  
  48. }

Data received at:
f=40MHz (BAD)
D72D 1101011100101101 DFF8 1101111111111000
572C 101011100101100 DFF9 1101111111111001
5727 101011100100111 DFF3 1101111111110011
D726 1101011100100110 DFED 1101111111101101
D72A 1101011100101010 DFF5 1101111111110101
D72F 1101011100101111 DFF8 1101111111111000
5732 101011100110010 DFEA 1101111111101010
571F 101011100011111 DFF6 1101111111110110
5732 101011100110010 DFEB 1101111111101011
D722 1101011100100010 DFF5 1101111111110101
D728 1101011100101000 DFF5 1101111111110101
D72A 1101011100101010 DFEA 1101111111101010
D72F 1101011100101111 DFF9 1101111111111001
5722 101011100100010 DFED 1101111111101101
D729 1101011100101001 DFEA 1101111111101010
D729 1101011100101001 DFF3 1101111111110011
5727 101011100100111 DFEF 1101111111101111
572A 101011100101010 DFEA 1101111111101010
5726 101011100100110 DFF5 1101111111110101
572B 101011100101011 DFEB 1101111111101011
5733 101011100110011 DFEC 1101111111101100
5729 101011100101001 DFED 1101111111101101
5730 101011100110000 DFEF 1101111111101111
5728 101011100101000 DFEF 1101111111101111
D724 1101011100100100 DFEB 1101111111101011
5726 101011100100110 DFEA 1101111111101010
D727 1101011100100111 DFEC 1101111111101100
572D 101011100101101 DFF8 1101111111111000


f=20MHz (GOOD)
AE55 1010111001010101 BFD6 1011111111010110
AE48 1010111001001000 BFDC 1011111111011100
AE54 1010111001010100 BFEE 1011111111101110
AE5D 1010111001011101 BFD5 1011111111010101
AE5A 1010111001011010 BFD8 1011111111011000
AE4D 1010111001001101 BFED 1011111111101101
AE4D 1010111001001101 BFD5 1011111111010101
AE51 1010111001010001 BFDF 1011111111011111
AE4C 1010111001001100 BFDB 1011111111011011
AE54 1010111001010100 BFE3 1011111111100011
AE4B 1010111001001011 BFF4 1011111111110100
AE3D 1010111000111101 BFDE 1011111111011110
AE6B 1010111001101011 BFE7 1011111111100111
AE50 1010111001010000 BFDC 1011111111011100
AE55 1010111001010101 BFEC 1011111111101100
AE49 1010111001001001 BFE6 1011111111100110
AE58 1010111001011000 BFD6 1011111111010110
AE69 1010111001101001 BFD4 1011111111010100
AE53 1010111001010011 BFE8 1011111111101000
AE53 1010111001010011 BFF0 1011111111110000
AE5F 1010111001011111 BFE8 1011111111101000
AE4C 1010111001001100 BFEE 1011111111101110
AE5D 1010111001011101 BFE6 1011111111100110
AE57 1010111001010111 BFDA 1011111111011010
AE5B 1010111001011011 BFEC 1011111111101100
AE53 1010111001010011 BFE6 1011111111100110
AE54 1010111001010100 BFDB 1011111111011011
AE64 1010111001100100 BFEB 1011111111101011
AE4F 1010111001001111 BFD1 1011111111010001
AE44 1010111001000100 BFF2 1011111111110010

Re: Problem with SPI

Posted: Fri Jun 17, 2022 7:50 am
by gjgsmithvr
I don't have an answer for you but have been looking into ESP32 SPI and in particular HSPI and came across this in the documentation which you may already be aware of, but may be of interest..."Transfer Speed Considerations"
https://docs.espressif.com/projects/esp ... iderations