2017-11-12 10:59 AM
HI
I have stm32f407 evaluation boardI use SPI with DMA to read/send the valuesin the
evaluation board have accelarometer(spi-connect)
this is the data i want to send and i shuold be get acc(x,y,z)
TX_Buffer[0] = 0xA9;//0x80 |0x29;
TX_Buffer[1] = 0xAB;//0x80 |0x2B; TX_Buffer[2] = 0xAD;//0x80 |0x2D;i didn't understand how i send and receive data ?
config DMA and SPI
/////////////////////////////////////
extern volatile uint8_t tempbuff_TX;
extern volatile uint8_t tempbuff_RX;void CTRLSPI_DMA_init()
{ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE); DMA_InitTypeDef DMA_InitStructure;DMA_DeInit(DMA2_Stream2);
DMA_DeInit(DMA2_Stream3);DMA_StructInit(&DMA_InitStructure);
// Configure the Rx part
DMA_InitStructure.DMA_Channel = DMA_Channel_3; DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&(SPI1->DR); DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)tempbuff_RX; DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory; DMA_InitStructure.DMA_BufferSize = NS; DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord; DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; DMA_InitStructure.DMA_Mode = DMA_Mode_Normal; DMA_InitStructure.DMA_Priority = DMA_Priority_Medium; DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable; DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull; DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single; DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single; DMA_Init(DMA2_Stream2, &DMA_InitStructure); DMA_ITConfig(DMA2_Stream2, DMA_IT_TC, ENABLE); DMA_Cmd(DMA2_Stream2, DISABLE); //DMA TX.. just modify the relevant parts... DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&(SPI2->DR); DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)tempbuff_TX; DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral; DMA_InitStructure.DMA_BufferSize = NS; DMA_Init(DMA2_Stream3, &DMA_InitStructure); DMA_ITConfig(DMA2_Stream3, DMA_IT_TC, ENABLE); DMA_Cmd(DMA2_Stream3, DISABLE);}void initSpi(void) {
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE);GPIO_InitTypeDef GPIO_InitStruct;
GPIO_StructInit(&GPIO_InitStruct); GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStruct.GPIO_OType = GPIO_OType_PP; GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_DOWN; GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStruct.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7; GPIO_Init(GPIOA, &GPIO_InitStruct);GPIO_PinAFConfig(GPIOA, GPIO_PinSource5, GPIO_AF_SPI1);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource6, GPIO_AF_SPI1); GPIO_PinAFConfig(GPIOA, GPIO_PinSource7, GPIO_AF_SPI1);GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_3; GPIO_Init(GPIOE, &GPIO_InitStruct); GPIO_SetBits(GPIOE, GPIO_Pin_3);/*
* configure SPI1 in Mode 0 * CPOL = 0 --> clock is low when idle * CPHA = 0 --> data is sampled at the first edge */SPI_InitTypeDef SPI_InitStructure;
SPI_I2S_DeInit(SPI1); SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low; SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge; SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;//| SPI_NSSInternalSoft_Set; SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_64;// SCLK_freq = APB2_freq / (BaudRatePrescaler + 1) SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;// SPI_InitStructure.SPI_CRCPolynomial = 0;//7; SPI_InitStructure.SPI_Mode = SPI_Mode_Master; SPI_Init(SPI1, &SPI_InitStructure);// SPI_SSOutputCmd(SPI1, ENABLE);
SPI_Cmd(SPI1, ENABLE);}#dma #dma-spi #spi2017-11-13 01:08 PM
Is this answered, or was did you mark it so only by mistake?
i didn't understand how i send and receive data ?By enabling the DMA streams?
JW
2017-11-15 11:50 AM
can you give me example how to do that?
thanks2017-11-15 12:07 PM
Well, I don't use SPL, but you have
DMA_Cmd(DMA2_Stream2, DISABLE);
DMA_Cmd(DMA2_Stream3, DISABLE);
So I'd expect you to have ENABLE somewhere too.
Also, is there no example around in the various EVAL board bundles?
JW