A
A
alxrv2015-03-13 17:51:42
Programming
alxrv, 2015-03-13 17:51:42

How to properly process a circular buffer in C (stm32)?

Good day everyone!
There is a device based on the stm32 microcontroller that polls the ADC and adds the results via DMA to the ring buffer:
__IO uint32_t buff[4096];
when half the buffer and the whole buffer are full, interrupts are called in which you need to overtake the corresponding half of this array to the SD card via SPI (8bit). How can you access half of an array and iterate over it byte by byte?
as long as it comes to mind

void SPI1_send(unsigned char cmd);
for (i=0;i<2048;i++) {
SPI1_send(buff[i]>>24);
SPI1_send(buff[i]>>16);
SPI1_send(buff[i]>>8);
SPI1_send(buff[i]);
}

But here, every time before sending, you will have to perform shift operations, and I myself do not like this approach.
thank!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Martyanov, 2015-03-13
@alxrv

unsigned char* ptr = (unsigned char*)&buff[2048]; - something like this. Get a pointer to half the buffer and it will be of type char, and you just need addressing by bytes.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question