void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc) {
// HAL_ADC_Stop_DMA(&hadc1);
for (int i = 0; i < ADC_BUF_LEN; i++) {
fres = f_printf(&fil, "%d\n", adc_buf[i]);
if (fres < 0) {
myprintf("f_printf error (%i)\r\n", fres);
while(1);
}
}
f_close(&fil);
f_mount(NULL, "", 0);
}
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc) {
for (int i = 0; i < ADC_BUF_LEN; ) {
myprintf("%i\r\n", adc_buf[i]);
i++;
}
}
void HAL_ADC_ConvHalfCpltCallback(ADC_HandleTypeDef* hadc) {
for (int i = 0; i < ADC_BUF_LEN/2; ) {
myprintf("%i\r\n", adc_buf[i]);
i++;
}
}
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc) {
for (int i = ADC_BUF_LEN/2; i < ADC_BUF_LEN; ) {
myprintf("%i\r\n", adc_buf[i]);
i++;
}
}
Hi Klaus,Hi,
The math is really simple ... and indeed should be expected to be solved by anybody.
Per sample you get a 16 bit number ....
So with 1 million samples you get 16 million bits per second. (Just raw bits)
But now you translate this into an ASCII string:
The range of each sample is 0...4095 (assuming a 12 bit ADC), thus up to 4 digits
Now you form this into an ASCII string (mysprintf) you get up to 4 ASCII bytes (digits) plus CR plus LF (your \r \n).
This makes up to 6 bytes per sample.
Each byte is transferred by 10 bits (1 START, 8 data , 1 STOP).
So 60 bits per sample.
Multiplied with 1 MSPS this gives a (UART) data rate of 60 Million bits per second. 60Mbits/s, 60MBaud (in optimal case)
But you use 256,000 Baud = 256 kBaud = 0.256MBaud
*****
Even if you are not able to do the math without or with a calculator..
Just guessing that 1,000,000 = 1 million "informations per second" (1MSPS)
transferred with a speed of 256,000 informations per second (ignoring the size of information)
could cause trouble ... was the least you could do.
Klaus
Hi FvM,Sending decimal formatted 10 or 12 bit data with \n terminator, 5 characters or 50 bits. Maximal 5.1 k samples per second with 256 kBaud.
--- Updated ---
In a short, STM32F303 doesn't provide a peripheral interface that can continuously stream 1 or 2 MSPS ADC data to a PC or a storage device. I would go for a faster F4xx device with 100 MBit ethernet.
Really? 250,000 (baud) x 240 (factor) = 60,000,000 (baud)May I ask about "You are a factor of 240 too slow!", do you mean the factors of 240 are the numbers that are multiplied in pairs resulting in the original number 240?
You can't transmit 8 but data via UART (at least not with standard interfaces)The "Data Size" in STM32CubeIDE can be minimum of 4 bits. 6 bytes per sample * 6 bits (1 START, 4 data, 1 STOP) = 36MBits/s, which is still not fast enough. Is this calculation correct for saving to an sd card?
#define ADC_BUFFER_SIZE 1024
// do not forget to place these buffers in DMA-accesible RAM
uint16_t adcBuffer[ADC_BUFFER_SIZE] ; // for ADC circular buffer
uint16_t adcBuffer2[ADC_BUFFER_SIZE]; // copied from adcBuffer using mem2mem
volatile uint8_t idx=255;
void m2mCallback(DMA_HandleTypeDef *_hdma)
{
// you can track mem2mem complete here, something like
if (idx==2) {idx=3;}
}
// ...
HAL_DMA_RegisterCallback(&hdma_memtomem_dma2_stream0, HAL_DMA_XFER_CPLT_CB_ID, m2mCallback);
while (1)
{
idx=0; // allow mem2mem
while(idx!=3){asm("nop");
// process data here
// if processing fast enough, idx will be set to 0 before
// HAL_ADC_ConvHalfCpltCallback
// will be called again
// idx=0 - need to copy, 1 - first half copy initiated,
// 2 - second half copy initiated,
// 3 - second half copy mem2mem completed
}
void HAL_ADC_ConvHalfCpltCallback(ADC_HandleTypeDef* hadc)
{
if (idx==0) {
// memmove( (void *)&adcBuffer2[0],
// (void *)&adcBuffer[0],
// sizeof(adcBuffer)/2);
HAL_DMA_Start_IT(&hdma_memtomem_dma2_stream0,
(uint32_t)&adcBuffer[0],
(uint32_t)&adcBuffer2[0],
sizeof(adcBuffer)/2/4);
idx=1;
}
}
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)
{
if (idx==1) {
//memmove( (void *)&adcBuffer2[ADC_BUFFER_SIZE/2],
// (void *)&adcBuffer[ADC_BUFFER_SIZE/2],
// sizeof(adcBuffer)/2);
HAL_DMA_Start_IT(&hdma_memtomem_dma2_stream0,
(uint32_t)&adcBuffer[ADC_BUFFER_SIZE/2],
(uint32_t)&adcBuffer2[ADC_BUFFER_SIZE/2],
sizeof(adcBuffer)/2/4);
idx=2;
}
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?