[ 3 / a / adv / an / asp / cgl / ck / co / diy / fa / g / gd / int / jp / k / lit / m / mlp / mu / n / o / out / p / po / sci / sp / tg / toy / trv / tv / v / vg / vp / vr / w / wsg / x]

/diy/ - Do-It-Yourself - STM32

<< back to board
[Delete this thread]

File: 13491087983868.jpg-(50 KB, 418x467)
STM32
STM32 Anonymous 05/10/14(Sat)00:01 UTC+1 No.636259 Report

Are there STM32 guru on this board? I have a problem with STM32F407.

I try to run DMA for SPI reading. But when "transfer complete" interrupt has occurred I get "transfer error" flag in interrupt status register and than DMA doesn't work.

There is part of my code:

static void DmaInit()
{
DMA_InitTypeDef dma;

RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE);

// DMA for Rx
dma.DMA_Channel = DMA_Channel_3;
dma.DMA_PeripheralBaseAddr = (uint32_t)&SPI1->DR;
dma.DMA_Memory0BaseAddr = 0; // will be set later
dma.DMA_DIR = DMA_DIR_PeripheralToMemory;
dma.DMA_BufferSize = 1; // will be set later
dma.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
dma.DMA_MemoryInc = DMA_MemoryInc_Enable;
dma.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
dma.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
dma.DMA_Mode = DMA_Mode_Normal;
dma.DMA_Priority = DMA_Priority_High;
dma.DMA_FIFOMode = DMA_FIFOMode_Disable;
dma.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull;
dma.DMA_MemoryBurst = DMA_MemoryBurst_Single;
dma.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
DMA_DeInit(DMA2_Stream2);
DMA_Init(DMA2_Stream2, &dma);

// Enable DMA Interrupt on complete transfer
NVIC_EnableIRQ(DMA2_Stream2_IRQn);
DMA_ITConfig(DMA2_Stream2, DMA_IT_TC, ENABLE);
}

// It run on external interrupt
static void DmaStart(uint32_t bufferSize, uint32_t* rxBuffer)
{
// Start DMA for reading
DMA2_Stream2->NDTR = bufferSize;
DMA2_Stream2->M0AR = (uint32_t)rxBuffer;
DMA_Cmd(DMA2_Stream2, ENABLE);
}

What do I do wrong?
>>
Anonymous 05/10/14(Sat)00:14 UTC+1 No.636260 Report

>>636259

Not saying we don't have STM32 gurus here but you'd be better off at >>>/g/

Also in /g/ you may use [code] tags to highlight syntax and preserve whitespace. To use them, just wrap your code snippets [code]like this[/code].
>>
Anonymous 05/10/14(Sat)00:23 UTC+1 No.636264 Report

>>636260
Thank you, bro. This girl for you.
>>
Anonymous 05/10/14(Sat)03:24 UTC+1 No.636326 Report

Bump
>>
Anonymous 05/10/14(Sat)10:06 UTC+1 No.636431 Report

>>636259
Dunno about that chip in particular, but since SPI is synchronous, as a master you usually have to transmit in order to receive. Also make sure you've enabled and configured the peripheral correctly.
>>
Anonymous 05/10/14(Sat)10:10 UTC+1 No.636433 Report

>>636431
Should add that get SPI working without DMA first, it's just an additional layer of complexity.
All the content on this website comes from 4chan.org. All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster. 4chanArchive is not affiliated with 4chan.