Page 1 of 1

SPI receive in SPI master, byte shifting in the buffer

Posted: Thu Apr 25, 2019 7:18 pm
by GG23800
Hi all,

I am trying to read data from a device on SPI bus using DMA. This device work in half_duplex only. I want to read successively large amount of data considering the ESP is the master. So I initialise the spi with:

Code: Select all

#define SPI_MOSI      23
#define SPI_MISO      19
#define SPI_CLK       18
#define SPI_COM_SPEED    5000000
#define SPI_ENABLE1         5                                                  
#define SPI_ENABLE2         4     

spi_device_handle_t spi;
uint8_t *lines;

static void USC_spi_init()
{
    gpio_set_pull_mode(SPI_MOSI, GPIO_PULLUP_ONLY);
    gpio_set_pull_mode(SPI_CLK, GPIO_PULLUP_ONLY);
    gpio_set_pull_mode(SPI_MISO, GPIO_PULLUP_ONLY);

    spi_bus_config_t buscfg={ 
        .miso_io_num = SPI_MISO,
        .mosi_io_num = SPI_MOSI,
        .sclk_io_num = SPI_CLK,
        .quadwp_io_num = -1,
        .quadhd_io_num = -1,
        .max_transfer_sz = SPI_MAX_DMA_LEN
    };

    spi_device_interface_config_t devcfg={
        .clock_speed_hz = SPI_COM_SPEED,      //Bus frequency
        .mode = 1,                            //SPI mode 1: polarity 0, phase 1
        .spics_io_num = -1,                   //CS pin
        .queue_size = 1,                      /
        .flags = SPI_DEVICE_HALFDUPLEX
    };
    
    spi_bus_initialize(VSPI_HOST, &buscfg, 2); //last flag, 0 no DMA, 1 or 2 DMA
    /* On attache la carte US au bus SPI */
    spi_bus_add_device(VSPI_HOST, &devcfg, &spi);
}
I initialise the DMA buffer with:

Code: Select all

uint8_t *lines;

void init_line_buffer(uint8_t **line_buff)
{
    uint8_t *temp=NULL;
    bool toto=false;
    temp=(uint8_t *)heap_caps_malloc(4096, MALLOC_CAP_DMA); //size is in byte and need to be %4
    if (temp==NULL) {printf("error with pvPortMallocCaps line\n");}
    toto=esp_ptr_dma_capable(temp);
    if (toto==0) {printf("\n\n\nWARNING, can't initiate line DMA buffer!!!\n\n\n");}
    (*line_buff)=temp;
}

void delete_line_buffer(uint8_t **line_buff)
{
    heap_caps_free(*line_buff);
}
To read data from the device, i have:

Code: Select all

epf_error_t USC_read_8bline_auto(int nbpoint)
{
    int ret=0;
    epf_error_t err = EPF_ERR_NOERROR;
    printf("number of points: %i\n", nbpoint);

    spi_transaction_t t;
    memset(&t, 0, sizeof(t));
    t.length=0; //8*nbpoint; to try in full duplex mode
    t.tx_buffer=NULL;
    t.rx_buffer=lines;
    t.rxlength=8*nbpoint;//to be %4;
    gpio_set_level(SPI_ENABLE2, 0);
    ret=spi_device_transmit(spi, &t);
    //ret=spi_device_polling_transmit(spi, &t);
    if (ret)
    {
        err = EPF_ERR_SPI;
        return err;
        printf("error while reading spi in read validation function\n");
    }
    gpio_set_level(SPI_ENABLE2, 1);

    return err;
}
where SPI_ENABLE2 act as CS line.

And then in my main code I have:

Code: Select all

    init_line_buffer(&lines);
    int np=256;

    for (int i=0 ; i<10 ; i++)
    {
        for (int k=0 ; k<np ; k++) {lines[k]=0;}
        USC_ask_8bline_auto();
        usleep(300);
        err=USC_read_8bline_auto(np);
        printf("loop %i\n", i);
        for (int j=np-100 ; j<np ; j++)
        {
            printf("data[%i]=%i, ",j, lines[j]);
        }
        printf("\n\n");
        
        delete_line_buffer(&lines)
    }
where USC_ask_8bline_auto() is function that send a command to the device in SPI to ask for data, this command is 6 bytes long. So in this example I ask and read 10 times via SPI. My logs are then:
data[28]=127, data[29]=127, data[30]=127, data[31]=127, data[32]=127, data[33]=126, data[34]=127, data[35]=127, data[36]=127, data[37]=126, data[38]=126, data[39]=127, data[40]=127, data[41]=127, data[42]=127, data[43]=127, data[44]=127, data[45]=127, data[46]=127, data[47]=126, data[48]=126, data[49]=126, data[50]=126, data[51]=127, data[52]=126, data[53]=126, data[54]=126, data[55]=126, data[56]=126, data[57]=127, data[58]=126, data[59]=127, data[60]=126, data[61]=126, data[62]=127, data[63]=127, data[64]=127, data[65]=126, data[66]=127, data[67]=127, data[68]=126, data[69]=127, data[70]=127, data[71]=127, data[72]=127, data[73]=127, data[74]=127, data[75]=127, data[76]=127, data[77]=127, data[78]=127, data[79]=127, data[80]=127, data[81]=127, data[82]=127, data[83]=127, data[84]=127, data[85]=127, data[86]=127, data[87]=127, data[88]=126, data[89]=126, data[90]=127, data[91]=127, data[92]=127, data[93]=127, data[94]=127, data[95]=127, data[96]=127, data[97]=127, data[98]=127, data[99]=126, data[100]=127, data[101]=127, data[102]=127, data[103]=127, data[104]=127, data[105]=127, data[106]=127, data[107]=127, data[108]=126, data[109]=127, data[110]=126, data[111]=127, data[112]=126, data[113]=127, data[114]=126, data[115]=127, data[116]=127, data[117]=127, data[118]=127, data[119]=126, data[120]=126, data[121]=127, data[122]=0, data[123]=0, data[124]=0, data[125]=0, data[126]=0, data[127]=0,

loop 1
data[28]=126, data[29]=127, data[30]=127, data[31]=126, data[32]=127, data[33]=126, data[34]=127, data[35]=126, data[36]=127, data[37]=127, data[38]=127, data[39]=127, data[40]=126, data[41]=127, data[42]=126, data[43]=126, data[44]=127, data[45]=127, data[46]=127, data[47]=127, data[48]=126, data[49]=127, data[50]=126, data[51]=126, data[52]=127, data[53]=126, data[54]=126, data[55]=127, data[56]=127, data[57]=126, data[58]=126, data[59]=127, data[60]=127, data[61]=127, data[62]=127, data[63]=127, data[64]=127, data[65]=126, data[66]=127, data[67]=127, data[68]=127, data[69]=126, data[70]=127, data[71]=127, data[72]=127, data[73]=127, data[74]=127, data[75]=127, data[76]=127, data[77]=127, data[78]=127, data[79]=127, data[80]=127, data[81]=127, data[82]=127, data[83]=127, data[84]=127, data[85]=127, data[86]=127, data[87]=127, data[88]=127, data[89]=127, data[90]=127, data[91]=127, data[92]=127, data[93]=127, data[94]=127, data[95]=127, data[96]=127, data[97]=127, data[98]=127, data[99]=127, data[100]=127, data[101]=127, data[102]=127, data[103]=127, data[104]=127, data[105]=127, data[106]=127, data[107]=127, data[108]=127, data[109]=127, data[110]=127, data[111]=126, data[112]=127, data[113]=127, data[114]=127, data[115]=127, data[116]=0, data[117]=0, data[118]=0, data[119]=0, data[120]=0, data[121]=0, data[122]=0, data[123]=0, data[124]=0, data[125]=0, data[126]=0, data[127]=0,

loop 2
data[28]=127, data[29]=127, data[30]=127, data[31]=126, data[32]=126, data[33]=127, data[34]=127, data[35]=127, data[36]=127, data[37]=127, data[38]=126, data[39]=127, data[40]=127, data[41]=126, data[42]=126, data[43]=127, data[44]=127, data[45]=127, data[46]=127, data[47]=126, data[48]=127, data[49]=127, data[50]=127, data[51]=126, data[52]=126, data[53]=127, data[54]=127, data[55]=127, data[56]=127, data[57]=127, data[58]=127, data[59]=126, data[60]=127, data[61]=126, data[62]=127, data[63]=127, data[64]=127, data[65]=127, data[66]=127, data[67]=127, data[68]=127, data[69]=127, data[70]=127, data[71]=127, data[72]=127, data[73]=127, data[74]=127, data[75]=127, data[76]=127, data[77]=127, data[78]=127, data[79]=127, data[80]=127, data[81]=127, data[82]=127, data[83]=126, data[84]=127, data[85]=127, data[86]=127, data[87]=127, data[88]=127, data[89]=127, data[90]=127, data[91]=127, data[92]=127, data[93]=127, data[94]=127, data[95]=127, data[96]=127, data[97]=127, data[98]=127, data[99]=127, data[100]=126, data[101]=127, data[102]=127, data[103]=127, data[104]=127, data[105]=127, data[106]=127, data[107]=126, data[108]=127, data[109]=126, data[110]=0, data[111]=0, data[112]=0, data[113]=0, data[114]=0, data[115]=0, data[116]=0, data[117]=0, data[118]=0, data[119]=0, data[120]=0, data[121]=0, data[122]=0, data[123]=0, data[124]=0, data[125]=0, data[126]=0, data[127]=0,

loop 3
data[28]=127, data[29]=126, data[30]=127, data[31]=126, data[32]=127, data[33]=127, data[34]=127, data[35]=126, data[36]=127, data[37]=126, data[38]=126, data[39]=127, data[40]=127, data[41]=127, data[42]=127, data[43]=127, data[44]=127, data[45]=127, data[46]=127, data[47]=127, data[48]=126, data[49]=127, data[50]=126, data[51]=126, data[52]=126, data[53]=127, data[54]=127, data[55]=127, data[56]=126, data[57]=126, data[58]=126, data[59]=127, data[60]=127, data[61]=127, data[62]=127, data[63]=126, data[64]=127, data[65]=127, data[66]=127, data[67]=127, data[68]=126, data[69]=127, data[70]=127, data[71]=127, data[72]=127, data[73]=127, data[74]=127, data[75]=127, data[76]=127, data[77]=127, data[78]=127, data[79]=127, data[80]=127, data[81]=127, data[82]=127, data[83]=127, data[84]=127, data[85]=127, data[86]=127, data[87]=127, data[88]=127, data[89]=127, data[90]=127, data[91]=127, data[92]=127, data[93]=127, data[94]=127, data[95]=127, data[96]=127, data[97]=127, data[98]=127, data[99]=127, data[100]=127, data[101]=126, data[102]=127, data[103]=127, data[104]=0, data[105]=0, data[106]=0, data[107]=0, data[108]=0, data[109]=0, data[110]=0, data[111]=0, data[112]=0, data[113]=0, data[114]=0, data[115]=0, data[116]=0, data[117]=0, data[118]=0, data[119]=0, data[120]=0, data[121]=0, data[122]=0, data[123]=0, data[124]=0, data[125]=0, data[126]=0, data[127]=0,

loop 4
data[28]=127, data[29]=127, data[30]=127, data[31]=127, data[32]=127, data[33]=127, data[34]=127, data[35]=127, data[36]=127, data[37]=127, data[38]=127, data[39]=127, data[40]=127, data[41]=127, data[42]=126, data[43]=126, data[44]=126, data[45]=127, data[46]=127, data[47]=126, data[48]=126, data[49]=127, data[50]=126, data[51]=126, data[52]=127, data[53]=126, data[54]=126, data[55]=126, data[56]=126, data[57]=127, data[58]=127, data[59]=127, data[60]=127, data[61]=127, data[62]=127, data[63]=127, data[64]=127, data[65]=127, data[66]=127, data[67]=127, data[68]=127, data[69]=127, data[70]=127, data[71]=127, data[72]=127, data[73]=127, data[74]=127, data[75]=126, data[76]=127, data[77]=127, data[78]=127, data[79]=127, data[80]=127, data[81]=127, data[82]=127, data[83]=126, data[84]=127, data[85]=127, data[86]=127, data[87]=127, data[88]=127, data[89]=127, data[90]=127, data[91]=127, data[92]=127, data[93]=127, data[94]=127, data[95]=127, data[96]=127, data[97]=127, data[98]=0, data[99]=0, data[100]=0, data[101]=0, data[102]=0, data[103]=0, data[104]=0, data[105]=0, data[106]=0, data[107]=0, data[108]=0, data[109]=0, data[110]=0, data[111]=0, data[112]=0, data[113]=0, data[114]=0, data[115]=0, data[116]=0, data[117]=0, data[118]=0, data[119]=0, data[120]=0, data[121]=0, data[122]=0, data[123]=0, data[124]=0, data[125]=0, data[126]=0, data[127]=0,

loop 5
data[28]=127, data[29]=127, data[30]=127, data[31]=126, data[32]=127, data[33]=127, data[34]=127, data[35]=127, data[36]=127, data[37]=127, data[38]=127, data[39]=126, data[40]=127, data[41]=126, data[42]=126, data[43]=127, data[44]=127, data[45]=127, data[46]=126, data[47]=126, data[48]=127, data[49]=127, data[50]=126, data[51]=126, data[52]=126, data[53]=127, data[54]=127, data[55]=127, data[56]=126, data[57]=127, data[58]=127, data[59]=126, data[60]=127, data[61]=127, data[62]=127, data[63]=127, data[64]=127, data[65]=127, data[66]=127, data[67]=127, data[68]=127, data[69]=127, data[70]=127, data[71]=127, data[72]=127, data[73]=127, data[74]=127, data[75]=127, data[76]=127, data[77]=127, data[78]=127, data[79]=127, data[80]=127, data[81]=127, data[82]=127, data[83]=127, data[84]=127, data[85]=127, data[86]=127, data[87]=127, data[88]=127, data[89]=127, data[90]=127, data[91]=127, data[92]=0, data[93]=0, data[94]=0, data[95]=0, data[96]=0, data[97]=0, data[98]=0, data[99]=0, data[100]=0, data[101]=0, data[102]=0, data[103]=0, data[104]=0, data[105]=0, data[106]=0, data[107]=0, data[108]=0, data[109]=0, data[110]=0, data[111]=0, data[112]=0, data[113]=0, data[114]=0, data[115]=0, data[116]=0, data[117]=0, data[118]=0, data[119]=0, data[120]=0, data[121]=0, data[122]=0, data[123]=0, data[124]=0, data[125]=0, data[126]=0, data[127]=0,

loop 6
data[28]=127, data[29]=127, data[30]=127, data[31]=127, data[32]=126, data[33]=126, data[34]=126, data[35]=127, data[36]=127, data[37]=127, data[38]=127, data[39]=127, data[40]=127, data[41]=126, data[42]=127, data[43]=126, data[44]=126, data[45]=127, data[46]=127, data[47]=127, data[48]=126, data[49]=126, data[50]=127, data[51]=126, data[52]=127, data[53]=127, data[54]=126, data[55]=127, data[56]=127, data[57]=126, data[58]=127, data[59]=126, data[60]=127, data[61]=127, data[62]=127, data[63]=127, data[64]=127, data[65]=126, data[66]=127, data[67]=126, data[68]=127, data[69]=127, data[70]=127, data[71]=127, data[72]=127, data[73]=127, data[74]=127, data[75]=127, data[76]=127, data[77]=127, data[78]=127, data[79]=127, data[80]=127, data[81]=127, data[82]=127, data[83]=127, data[84]=127, data[85]=127, data[86]=0, data[87]=0, data[88]=0, data[89]=0, data[90]=0, data[91]=0, data[92]=0, data[93]=0, data[94]=0, data[95]=0, data[96]=0, data[97]=0, data[98]=0, data[99]=0, data[100]=0, data[101]=0, data[102]=0, data[103]=0, data[104]=0, data[105]=0, data[106]=0, data[107]=0, data[108]=0, data[109]=0, data[110]=0, data[111]=0, data[112]=0, data[113]=0, data[114]=0, data[115]=0, data[116]=0, data[117]=0, data[118]=0, data[119]=0, data[120]=0, data[121]=0, data[122]=0, data[123]=0, data[124]=0, data[125]=0, data[126]=0, data[127]=0,

loop 7
data[28]=127, data[29]=127, data[30]=127, data[31]=127, data[32]=127, data[33]=127, data[34]=127, data[35]=126, data[36]=127, data[37]=127, data[38]=127, data[39]=127, data[40]=127, data[41]=126, data[42]=127, data[43]=126, data[44]=127, data[45]=126, data[46]=126, data[47]=126, data[48]=126, data[49]=127, data[50]=127, data[51]=127, data[52]=126, data[53]=127, data[54]=127, data[55]=127, data[56]=127, data[57]=127, data[58]=127, data[59]=127, data[60]=126, data[61]=127, data[62]=127, data[63]=127, data[64]=127, data[65]=127, data[66]=127, data[67]=127, data[68]=127, data[69]=127, data[70]=127, data[71]=127, data[72]=127, data[73]=127, data[74]=127, data[75]=126, data[76]=127, data[77]=127, data[78]=127, data[79]=127, data[80]=0, data[81]=0, data[82]=0, data[83]=0, data[84]=0, data[85]=0, data[86]=0, data[87]=0, data[88]=0, data[89]=0, data[90]=0, data[91]=0, data[92]=0, data[93]=0, data[94]=0, data[95]=0, data[96]=0, data[97]=0, data[98]=0, data[99]=0, data[100]=0, data[101]=0, data[102]=0, data[103]=0, data[104]=0, data[105]=0, data[106]=0, data[107]=0, data[108]=0, data[109]=0, data[110]=0, data[111]=0, data[112]=0, data[113]=0, data[114]=0, data[115]=0, data[116]=0, data[117]=0, data[118]=0, data[119]=0, data[120]=0, data[121]=0, data[122]=0, data[123]=0, data[124]=0, data[125]=0, data[126]=0, data[127]=0,

loop 8
data[28]=127, data[29]=127, data[30]=127, data[31]=127, data[32]=126, data[33]=127, data[34]=127, data[35]=127, data[36]=126, data[37]=126, data[38]=127, data[39]=127, data[40]=126, data[41]=126, data[42]=126, data[43]=126, data[44]=126, data[45]=126, data[46]=127, data[47]=126, data[48]=126, data[49]=127, data[50]=126, data[51]=127, data[52]=127, data[53]=127, data[54]=127, data[55]=126, data[56]=127, data[57]=126, data[58]=127, data[59]=127, data[60]=127, data[61]=127, data[62]=127, data[63]=127, data[64]=127, data[65]=127, data[66]=127, data[67]=127, data[68]=127, data[69]=126, data[70]=127, data[71]=127, data[72]=127, data[73]=127, data[74]=0, data[75]=0, data[76]=0, data[77]=0, data[78]=0, data[79]=0, data[80]=0, data[81]=0, data[82]=0, data[83]=0, data[84]=0, data[85]=0, data[86]=0, data[87]=0, data[88]=0, data[89]=0, data[90]=0, data[91]=0, data[92]=0, data[93]=0, data[94]=0, data[95]=0, data[96]=0, data[97]=0, data[98]=0, data[99]=0, data[100]=0, data[101]=0, data[102]=0, data[103]=0, data[104]=0, data[105]=0, data[106]=0, data[107]=0, data[108]=0, data[109]=0, data[110]=0, data[111]=0, data[112]=0, data[113]=0, data[114]=0, data[115]=0, data[116]=0, data[117]=0, data[118]=0, data[119]=0, data[120]=0, data[121]=0, data[122]=0, data[123]=0, data[124]=0, data[125]=0, data[126]=0, data[127]=0,

loop 9
data[28]=126, data[29]=127, data[30]=127, data[31]=127, data[32]=127, data[33]=127, data[34]=127, data[35]=126, data[36]=127, data[37]=126, data[38]=127, data[39]=127, data[40]=127, data[41]=127, data[42]=127, data[43]=127, data[44]=126, data[45]=126, data[46]=127, data[47]=126, data[48]=127, data[49]=127, data[50]=126, data[51]=126, data[52]=127, data[53]=126, data[54]=127, data[55]=127, data[56]=127, data[57]=127, data[58]=126, data[59]=127, data[60]=127, data[61]=127, data[62]=126, data[63]=127, data[64]=127, data[65]=127, data[66]=127, data[67]=127, data[68]=0, data[69]=0, data[70]=0, data[71]=0, data[72]=0, data[73]=0, data[74]=0, data[75]=0, data[76]=0, data[77]=0, data[78]=0, data[79]=0, data[80]=0, data[81]=0, data[82]=0, data[83]=0, data[84]=0, data[85]=0, data[86]=0, data[87]=0, data[88]=0, data[89]=0, data[90]=0, data[91]=0, data[92]=0, data[93]=0, data[94]=0, data[95]=0, data[96]=0, data[97]=0, data[98]=0, data[99]=0, data[100]=0, data[101]=0, data[102]=0, data[103]=0, data[104]=0, data[105]=0, data[106]=0, data[107]=0, data[108]=0, data[109]=0, data[110]=0, data[111]=0, data[112]=0, data[113]=0, data[114]=0, data[115]=0, data[116]=0, data[117]=0, data[118]=0, data[119]=0, data[120]=0, data[121]=0, data[122]=0, data[123]=0, data[124]=0, data[125]=0, data[126]=0, data[127]=0,
Basically, the device send random 126/127.
We see that each time we read data from SPI, the buffer filling shit 6 bytes on the left. I have check on the oscilloscope that the data are sent correctly by the device, no 0 are sent.

How can I fix this problem?

Note that if I read only one byte (at the end of the while loop) using the native rx_buffer of the spi_transaction_t structure, the shift is 6 bytes at each time, there is a kind of reset of the shifting.

Re: SPI receive in SPI master, byte shifting in the buffer

Posted: Fri Apr 26, 2019 2:58 am
by ESP_Sprite
Can I ask why you do your CS in software, instead of using the hardware CS?

Re: SPI receive in SPI master, byte shifting in the buffer

Posted: Fri Apr 26, 2019 6:51 am
by GG23800
Hi ESP_Sprite,

I do my CS in soft because in need two CS line with this device, one to telling it that it will have to read from the SPI, the second to tell him that it will write on the SPI. To improve efficiency, I will include the reading CS line in the spi_bus_config_t structure latter.

Re: SPI receive in SPI master, byte shifting in the buffer

Posted: Fri Apr 26, 2019 7:10 am
by GG23800
I have also try to shift my receive buffer to see if I receive the whole data with:

Code: Select all

epf_error_t USC_read_8bline_auto(int nbpoint, int offset)
{
    int ret=0;
    epf_error_t err = EPF_ERR_NOERROR;
    printf("number of points: %i\n", nbpoint);

    spi_transaction_t t;
    memset(&t, 0, sizeof(t));
    t.length=0;
    t.tx_buffer=NULL;
    t.rx_buffer=&lines[offset];
    t.rxlength=8*nbpoint;//to be %4;
    gpio_set_level(SPI_ENABLE2, 0);
    ret=spi_device_transmit(spi, &t);
    //ret=spi_device_polling_transmit(spi, &t);
    if (ret)
    {
        err = EPF_ERR_SPI;
        return err;
        printf("error while reading spi in read validation function\n");
    }
    gpio_set_level(SPI_ENABLE2, 1);

    return err;
}
And in my main I have now:

Code: Select all

 for (int i=0 ; i<10 ; i++)
    {
        for (int k=0 ; k<np ; k++) {lines[k]=0;}
        USC_ask_8bline_auto();
        usleep(300);
        err=USC_read_8bline_auto(np,6*(i+1));
        printf("loop %i\n", i);
        for (int j=np-100 ; j<np ; j++)
        {
            printf("data[%i]=%i, ",j, lines[j]);
        }
        printf("\n\n");
    }
Which work more or less, I have now:
I (23701) spi_master: Allocate RX buffer for DMA
loop 0
data[28]=126, data[29]=126, data[30]=126, data[31]=126, data[32]=126, data[33]=127, data[34]=126, data[35]=127, data[36]=126, data[37]=126, data[38]=126, data[39]=126, data[40]=127, data[41]=127, data[42]=127, data[43]=127, data[44]=127, data[45]=127, data[46]=127, data[47]=127, data[48]=127, data[49]=127, data[50]=127, data[51]=127, data[52]=127, data[53]=127, data[54]=127, data[55]=127, data[56]=127, data[57]=127, data[58]=127, data[59]=127, data[60]=127, data[61]=126, data[62]=127, data[63]=127, data[64]=127, data[65]=127, data[66]=127, data[67]=127, data[68]=127, data[69]=127, data[70]=127, data[71]=127, data[72]=127, data[73]=127, data[74]=127, data[75]=127, data[76]=127, data[77]=127, data[78]=127, data[79]=127, data[80]=127, data[81]=127, data[82]=127, data[83]=127, data[84]=127, data[85]=127, data[86]=127, data[87]=127, data[88]=127, data[89]=127, data[90]=127, data[91]=126, data[92]=126, data[93]=126, data[94]=126, data[95]=126, data[96]=127, data[97]=127, data[98]=127, data[99]=127, data[100]=127, data[101]=126, data[102]=127, data[103]=126, data[104]=126, data[105]=127, data[106]=126, data[107]=126, data[108]=126, data[109]=127, data[110]=127, data[111]=127, data[112]=127, data[113]=127, data[114]=127, data[115]=127, data[116]=126, data[117]=127, data[118]=127, data[119]=127, data[120]=127, data[121]=127, data[122]=127, data[123]=127, data[124]=126, data[125]=127, data[126]=127, data[127]=127,

loop 1
data[28]=126, data[29]=127, data[30]=126, data[31]=126, data[32]=126, data[33]=126, data[34]=126, data[35]=127, data[36]=127, data[37]=126, data[38]=126, data[39]=127, data[40]=126, data[41]=126, data[42]=126, data[43]=126, data[44]=126, data[45]=126, data[46]=126, data[47]=126, data[48]=126, data[49]=127, data[50]=127, data[51]=127, data[52]=127, data[53]=127, data[54]=127, data[55]=127, data[56]=127, data[57]=127, data[58]=127, data[59]=127, data[60]=127, data[61]=127, data[62]=127, data[63]=127, data[64]=126, data[65]=127, data[66]=127, data[67]=127, data[68]=127, data[69]=127, data[70]=127, data[71]=127, data[72]=127, data[73]=127, data[74]=127, data[75]=127, data[76]=127, data[77]=127, data[78]=127, data[79]=127, data[80]=127, data[81]=127, data[82]=127, data[83]=127, data[84]=127, data[85]=127, data[86]=127, data[87]=127, data[88]=127, data[89]=127, data[90]=127, data[91]=127, data[92]=127, data[93]=127, data[94]=127, data[95]=127, data[96]=127, data[97]=127, data[98]=127, data[99]=127, data[100]=127, data[101]=126, data[102]=127, data[103]=127, data[104]=127, data[105]=126, data[106]=126, data[107]=127, data[108]=127, data[109]=126, data[110]=127, data[111]=127, data[112]=126, data[113]=127, data[114]=127, data[115]=126, data[116]=126, data[117]=126, data[118]=126, data[119]=127, data[120]=127, data[121]=127, data[122]=127, data[123]=127, data[124]=127, data[125]=126, data[126]=127, data[127]=127,

I (23965) spi_master: Allocate RX buffer for DMA
loop 2
data[28]=127, data[29]=127, data[30]=127, data[31]=127, data[32]=126, data[33]=127, data[34]=127, data[35]=127, data[36]=127, data[37]=126, data[38]=127, data[39]=126, data[40]=126, data[41]=126, data[42]=126, data[43]=127, data[44]=126, data[45]=126, data[46]=126, data[47]=127, data[48]=127, data[49]=126, data[50]=126, data[51]=126, data[52]=126, data[53]=126, data[54]=127, data[55]=126, data[56]=126, data[57]=126, data[58]=127, data[59]=127, data[60]=127, data[61]=127, data[62]=127, data[63]=126, data[64]=127, data[65]=127, data[66]=126, data[67]=127, data[68]=127, data[69]=127, data[70]=127, data[71]=127, data[72]=127, data[73]=127, data[74]=127, data[75]=127, data[76]=127, data[77]=127, data[78]=127, data[79]=127, data[80]=127, data[81]=127, data[82]=127, data[83]=127, data[84]=127, data[85]=127, data[86]=127, data[87]=127, data[88]=127, data[89]=127, data[90]=127, data[91]=127, data[92]=127, data[93]=127, data[94]=127, data[95]=127, data[96]=127, data[97]=127, data[98]=127, data[99]=127, data[100]=127, data[101]=127, data[102]=127, data[103]=127, data[104]=127, data[105]=127, data[106]=127, data[107]=127, data[108]=127, data[109]=126, data[110]=127, data[111]=126, data[112]=126, data[113]=126, data[114]=127, data[115]=127, data[116]=127, data[117]=127, data[118]=126, data[119]=127, data[120]=127, data[121]=127, data[122]=127, data[123]=127, data[124]=127, data[125]=127, data[126]=127, data[127]=127,

loop 3
data[28]=127, data[29]=127, data[30]=127, data[31]=127, data[32]=127, data[33]=127, data[34]=127, data[35]=127, data[36]=127, data[37]=127, data[38]=127, data[39]=126, data[40]=127, data[41]=126, data[42]=126, data[43]=126, data[44]=126, data[45]=126, data[46]=126, data[47]=126, data[48]=126, data[49]=126, data[50]=126, data[51]=126, data[52]=126, data[53]=126, data[54]=126, data[55]=126, data[56]=126, data[57]=126, data[58]=127, data[59]=127, data[60]=127, data[61]=127, data[62]=127, data[63]=127, data[64]=127, data[65]=127, data[66]=127, data[67]=127, data[68]=127, data[69]=127, data[70]=127, data[71]=127, data[72]=127, data[73]=127, data[74]=127, data[75]=127, data[76]=127, data[77]=127, data[78]=127, data[79]=127, data[80]=127, data[81]=127, data[82]=127, data[83]=127, data[84]=127, data[85]=127, data[86]=127, data[87]=127, data[88]=127, data[89]=127, data[90]=127, data[91]=127, data[92]=127, data[93]=127, data[94]=127, data[95]=127, data[96]=127, data[97]=127, data[98]=127, data[99]=127, data[100]=127, data[101]=126, data[102]=127, data[103]=127, data[104]=127, data[105]=127, data[106]=127, data[107]=127, data[108]=127, data[109]=127, data[110]=127, data[111]=127, data[112]=127, data[113]=127, data[114]=127, data[115]=126, data[116]=126, data[117]=126, data[118]=126, data[119]=126, data[120]=127, data[121]=127, data[122]=127, data[123]=127, data[124]=127, data[125]=127, data[126]=127, data[127]=126,

I (24229) spi_master: Allocate RX buffer for DMA
loop 4
data[28]=0, data[29]=0, data[30]=126, data[31]=127, data[32]=127, data[33]=127, data[34]=127, data[35]=127, data[36]=127, data[37]=127, data[38]=127, data[39]=127, data[40]=127, data[41]=127, data[42]=127, data[43]=127, data[44]=127, data[45]=126, data[46]=127, data[47]=126, data[48]=126, data[49]=126, data[50]=127, data[51]=126, data[52]=126, data[53]=126, data[54]=126, data[55]=126, data[56]=126, data[57]=127, data[58]=126, data[59]=127, data[60]=127, data[61]=126, data[62]=127, data[63]=126, data[64]=126, data[65]=126, data[66]=127, data[67]=127, data[68]=127, data[69]=127, data[70]=127, data[71]=127, data[72]=127, data[73]=127, data[74]=127, data[75]=127, data[76]=127, data[77]=127, data[78]=127, data[79]=127, data[80]=127, data[81]=127, data[82]=127, data[83]=127, data[84]=127, data[85]=127, data[86]=127, data[87]=127, data[88]=127, data[89]=127, data[90]=127, data[91]=127, data[92]=127, data[93]=127, data[94]=127, data[95]=127, data[96]=127, data[97]=127, data[98]=127, data[99]=127, data[100]=127, data[101]=127, data[102]=127, data[103]=127, data[104]=127, data[105]=127, data[106]=127, data[107]=127, data[108]=127, data[109]=127, data[110]=127, data[111]=127, data[112]=127, data[113]=127, data[114]=127, data[115]=127, data[116]=127, data[117]=127, data[118]=127, data[119]=127, data[120]=126, data[121]=127, data[122]=127, data[123]=126, data[124]=126, data[125]=126, data[126]=127, data[127]=126,

loop 5
data[28]=0, data[29]=0, data[30]=0, data[31]=0, data[32]=0, data[33]=0, data[34]=0, data[35]=0, data[36]=126, data[37]=127, data[38]=127, data[39]=127, data[40]=127, data[41]=127, data[42]=127, data[43]=127, data[44]=127, data[45]=127, data[46]=127, data[47]=127, data[48]=126, data[49]=127, data[50]=127, data[51]=127, data[52]=127, data[53]=126, data[54]=126, data[55]=127, data[56]=127, data[57]=126, data[58]=126, data[59]=127, data[60]=127, data[61]=126, data[62]=126, data[63]=126, data[64]=126, data[65]=126, data[66]=126, data[67]=126, data[68]=126, data[69]=126, data[70]=126, data[71]=127, data[72]=127, data[73]=127, data[74]=127, data[75]=127, data[76]=127, data[77]=127, data[78]=127, data[79]=127, data[80]=127, data[81]=127, data[82]=127, data[83]=127, data[84]=127, data[85]=127, data[86]=126, data[87]=127, data[88]=127, data[89]=127, data[90]=127, data[91]=127, data[92]=127, data[93]=127, data[94]=127, data[95]=127, data[96]=127, data[97]=127, data[98]=127, data[99]=127, data[100]=127, data[101]=127, data[102]=127, data[103]=127, data[104]=127, data[105]=127, data[106]=127, data[107]=127, data[108]=127, data[109]=127, data[110]=127, data[111]=127, data[112]=127, data[113]=126, data[114]=127, data[115]=127, data[116]=127, data[117]=127, data[118]=127, data[119]=127, data[120]=127, data[121]=127, data[122]=127, data[123]=127, data[124]=127, data[125]=127, data[126]=127, data[127]=127,

I (24492) spi_master: Allocate RX buffer for DMA
loop 6
data[28]=0, data[29]=0, data[30]=0, data[31]=0, data[32]=0, data[33]=0, data[34]=0, data[35]=0, data[36]=0, data[37]=0, data[38]=0, data[39]=0, data[40]=0, data[41]=0, data[42]=126, data[43]=126, data[44]=127, data[45]=127, data[46]=127, data[47]=127, data[48]=127, data[49]=127, data[50]=127, data[51]=127, data[52]=127, data[53]=127, data[54]=127, data[55]=127, data[56]=126, data[57]=126, data[58]=127, data[59]=127, data[60]=127, data[61]=127, data[62]=127, data[63]=126, data[64]=126, data[65]=126, data[66]=126, data[67]=126, data[68]=126, data[69]=126, data[70]=126, data[71]=126, data[72]=126, data[73]=126, data[74]=126, data[75]=126, data[76]=127, data[77]=127, data[78]=127, data[79]=127, data[80]=127, data[81]=127, data[82]=127, data[83]=127, data[84]=127, data[85]=127, data[86]=127, data[87]=127, data[88]=127, data[89]=127, data[90]=127, data[91]=127, data[92]=127, data[93]=127, data[94]=127, data[95]=127, data[96]=127, data[97]=127, data[98]=127, data[99]=127, data[100]=127, data[101]=127, data[102]=127, data[103]=127, data[104]=127, data[105]=127, data[106]=127, data[107]=127, data[108]=127, data[109]=127, data[110]=127, data[111]=127, data[112]=127, data[113]=127, data[114]=127, data[115]=127, data[116]=127, data[117]=127, data[118]=127, data[119]=127, data[120]=127, data[121]=127, data[122]=127, data[123]=127, data[124]=127, data[125]=127, data[126]=127, data[127]=126,

loop 7
data[28]=0, data[29]=0, data[30]=0, data[31]=0, data[32]=0, data[33]=0, data[34]=0, data[35]=0, data[36]=0, data[37]=0, data[38]=0, data[39]=0, data[40]=0, data[41]=0, data[42]=0, data[43]=0, data[44]=0, data[45]=0, data[46]=0, data[47]=0, data[48]=126, data[49]=127, data[50]=127, data[51]=127, data[52]=127, data[53]=127, data[54]=127, data[55]=127, data[56]=126, data[57]=127, data[58]=127, data[59]=127, data[60]=127, data[61]=127, data[62]=127, data[63]=127, data[64]=127, data[65]=127, data[66]=126, data[67]=126, data[68]=126, data[69]=126, data[70]=126, data[71]=126, data[72]=126, data[73]=126, data[74]=126, data[75]=126, data[76]=126, data[77]=126, data[78]=126, data[79]=126, data[80]=126, data[81]=126, data[82]=127, data[83]=127, data[84]=127, data[85]=127, data[86]=127, data[87]=127, data[88]=127, data[89]=127, data[90]=127, data[91]=127, data[92]=127, data[93]=126, data[94]=127, data[95]=127, data[96]=127, data[97]=127, data[98]=126, data[99]=127, data[100]=127, data[101]=127, data[102]=127, data[103]=127, data[104]=127, data[105]=127, data[106]=127, data[107]=127, data[108]=127, data[109]=127, data[110]=127, data[111]=127, data[112]=127, data[113]=127, data[114]=127, data[115]=127, data[116]=127, data[117]=127, data[118]=127, data[119]=127, data[120]=127, data[121]=127, data[122]=127, data[123]=127, data[124]=127, data[125]=127, data[126]=127, data[127]=127,

I (24750) spi_master: Allocate RX buffer for DMA
loop 8
data[28]=0, data[29]=0, data[30]=0, data[31]=0, data[32]=0, data[33]=0, data[34]=0, data[35]=0, data[36]=0, data[37]=0, data[38]=0, data[39]=0, data[40]=0, data[41]=0, data[42]=0, data[43]=0, data[44]=0, data[45]=0, data[46]=0, data[47]=0, data[48]=0, data[49]=0, data[50]=0, data[51]=0, data[52]=0, data[53]=0, data[54]=126, data[55]=127, data[56]=127, data[57]=127, data[58]=127, data[59]=127, data[60]=127, data[61]=127, data[62]=127, data[63]=127, data[64]=127, data[65]=127, data[66]=127, data[67]=127, data[68]=127, data[69]=126, data[70]=127, data[71]=127, data[72]=127, data[73]=126, data[74]=126, data[75]=127, data[76]=126, data[77]=126, data[78]=126, data[79]=126, data[80]=126, data[81]=126, data[82]=126, data[83]=126, data[84]=126, data[85]=127, data[86]=127, data[87]=126, data[88]=127, data[89]=126, data[90]=126, data[91]=127, data[92]=127, data[93]=127, data[94]=127, data[95]=127, data[96]=127, data[97]=127, data[98]=127, data[99]=127, data[100]=127, data[101]=127, data[102]=127, data[103]=127, data[104]=127, data[105]=127, data[106]=127, data[107]=127, data[108]=127, data[109]=127, data[110]=126, data[111]=127, data[112]=127, data[113]=127, data[114]=127, data[115]=127, data[116]=127, data[117]=127, data[118]=127, data[119]=127, data[120]=127, data[121]=127, data[122]=127, data[123]=127, data[124]=127, data[125]=127, data[126]=127, data[127]=127,

loop 9
data[28]=0, data[29]=0, data[30]=0, data[31]=0, data[32]=0, data[33]=0, data[34]=0, data[35]=0, data[36]=0, data[37]=0, data[38]=0, data[39]=0, data[40]=0, data[41]=0, data[42]=0, data[43]=0, data[44]=0, data[45]=0, data[46]=0, data[47]=0, data[48]=0, data[49]=0, data[50]=0, data[51]=0, data[52]=0, data[53]=0, data[54]=0, data[55]=0, data[56]=0, data[57]=0, data[58]=0, data[59]=0, data[60]=126, data[61]=127, data[62]=127, data[63]=127, data[64]=127, data[65]=127, data[66]=127, data[67]=127, data[68]=127, data[69]=127, data[70]=127, data[71]=127, data[72]=127, data[73]=127, data[74]=126, data[75]=126, data[76]=126, data[77]=126, data[78]=126, data[79]=126, data[80]=126, data[81]=126, data[82]=127, data[83]=126, data[84]=126, data[85]=126, data[86]=126, data[87]=127, data[88]=126, data[89]=126, data[90]=126, data[91]=127, data[92]=127, data[93]=126, data[94]=127, data[95]=126, data[96]=127, data[97]=126, data[98]=126, data[99]=127, data[100]=127, data[101]=127, data[102]=127, data[103]=127, data[104]=127, data[105]=127, data[106]=127, data[107]=127, data[108]=127, data[109]=127, data[110]=127, data[111]=127, data[112]=127, data[113]=126, data[114]=126, data[115]=127, data[116]=127, data[117]=127, data[118]=126, data[119]=127, data[120]=127, data[121]=127, data[122]=127, data[123]=127, data[124]=127, data[125]=127, data[126]=127, data[127]=127,
So the first buffers are now full, but since loop 4 I loose data from the left of the buffer...

Any idea?

Re: SPI receive in SPI master, byte shifting in the buffer

Posted: Sat Apr 27, 2019 3:12 pm
by fly135
I can't help much, but it seems to me that if you used incrementing numbers instead of random 126/127, then you might be able to determine more precisely what data is being lost, and therefore get closer to the solution.

John A

Re: SPI receive in SPI master, byte shifting in the buffer

Posted: Mon Apr 29, 2019 10:10 am
by GG23800
I have made more test, with some knowed data at the beginning of the SPI buffer and I can read it, the data lost are at the end of the buffer