AnsweredAssumed Answered

how to send 4096 int32_t by USB CDC

Question asked by elgarbe on Aug 28, 2015
Latest reply on Sep 5, 2015 by elgarbe
Hi, I'm working on a project that use an audiocodec, connected to a stm32f411 uC by I2S and I2C. I use 
HAL_I2SEx_TransmitReceive_DMA(&hi2s2, (uint16_t *)OutputBuffer, (uint16_t *)InputBuffer, 2*SAMPLES);

to send 2 tone sound and receive the "echo" on the microfone. SAMPLES=4096.
Then I process the incoming data to transform on 32 bit int:
for(i=0;i<2*SAMPLES;i+=2)
{
    tmp= InputBuffer[i];
    tmp = ((tmp&0x0000FFFF)<<16) | ((tmp&0xFFFF0000)>>16);
    tmp >>= 8;
    InputBuffer2[i/2] = tmp;
}
and obtain a 4096 array of int32. I would like to send that by USB to my terminal program.
I've never work with USB before, I've just could send a string by USB CDC and receive it on my terminal.
Now I write this:
while(1)
{
    if (u8_cdc_initialized)
    {
        CDC_Transmit_FS(&InputBuffer2[i], 512);
        i+=512;
        if(i==4608){
            CDC_Transmit_FS((uint8_t *)"start", 5);
            i=0;
        }
    }
    HAL_Delay(100);
}

I receive the data on my terminal, but I can't synchronize and recover 4096 * 4 bytes becouse if I configure the terminal to receive ASCII I can see "start", but data is unreadable and if I configure the terminal for HEX I can't finde "start".
I know that the correct way is wait on the uC for a character sending by the terminal, and, as an answer to that incoming character, send 4096*4 bytes. But, I don't know how to do that..... where do I can detect character send by the terminal program?
waht is the best way to send all of the data? I'm not sure how many bytes should I send on each CDC_Transmit_FS
can some one point me on the right direction?

Thank!

Outcomes