STM32F767板子,这是我的spi2的dma 代码,配置为slave 接收模式,测试时发现,配置为8bit、16bit数据时,前面32bit的数据都接收不到,数据从接收buffer的第33bit位置开始填充,后续的接收数据正确。请问怎么回事?
请大神们指点。。。
#include "sys.h"
#include "misc.h"
SPI_HandleTypeDef SPI2_Handler;
DMA_HandleTypeDef DMA1_Handler;
#define LENGTH 128
uint8_t dma_rx[LENGTH] = {0xff};
void DMA1_Stream3_IRQHandler(void)
{
int i = 0;
if( HAL_DMA_GetState(&DMA1_Handler) != RESET)
{
if(DMA1->LISR & (1 << 27))
{
__HAL_DMA_DISABLE(&DMA1_Handler);
DMA1->LIFCR |= (1 << 27);
DMA1->LIFCR |= (1 << 26);
for(i = 0; i < LENGTH/2; i++)
{
printf("dma rx[%d] = %x
",i, dma_rx);
}
__HAL_DMA_ENABLE(&DMA1_Handler);
}
}
}
void myDMA_Init(void)
{
int i = 0;
NVIC_InitTypeDef NVIC_InitStructure;
SPI2_Handler.Instance = SPI2;
SPI2_Handler.Init.Mode = SPI_MODE_SLAVE;
SPI2_Handler.Init.Direction = SPI_DIRECTION_2LINES_RXONLY;
SPI2_Handler.Init.DataSize = SPI_DATASIZE_8BIT;
SPI2_Handler.Init.CLKPolarity = SPI_POLARITY_LOW;
SPI2_Handler.Init.CLKPhase = SPI_PHASE_1EDGE;
SPI2_Handler.Init.NSS = SPI_NSS_HARD_INPUT;
SPI2_Handler.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16; //256O?u
SPI2_Handler.Init.FirstBit = SPI_FIRSTBIT_MSB;
SPI2_Handler.Init.TIMode = SPI_TIMODE_DISABLE;
SPI2_Handler.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
SPI2_Handler.Init.CRCPolynomial = 7;
HAL_SPI_Init(&SPI2_Handler);
SPI2->CR2 |= 1 << 7;
SPI2->CR2 |= 1 << 6;
__HAL_RCC_DMA1_CLK_ENABLE();
__HAL_LINKDMA(&SPI2_Handler, hdmarx, DMA1_Handler);
DMA1_Handler.Instance = DMA1_Stream3;
DMA1_Handler.Init.Channel = DMA_CHANNEL_0;
DMA1_Handler.Init.Direction = DMA_PERIPH_TO_MEMORY;
DMA1_Handler.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
DMA1_Handler.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;
DMA1_Handler.Init.MemBurst = DMA_MBURST_SINGLE;
DMA1_Handler.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
DMA1_Handler.Init.MemInc = DMA_MINC_ENABLE;
DMA1_Handler.Init.Mode = DMA_NORMAL;//DMA_CIRCULAR;//
DMA1_Handler.Init.PeriphBurst = DMA_PBURST_SINGLE;
DMA1_Handler.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
DMA1_Handler.Init.PeriphInc = DMA_PINC_DISABLE;
DMA1_Handler.Init.Priority = DMA_PRIORITY_VERY_HIGH;
HAL_DMA_DeInit(&DMA1_Handler);
HAL_DMA_Init(&DMA1_Handler);
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
NVIC_InitStructure.NVIC_IRQChannel = DMA1_Stream3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
HAL_SPI_Receive_DMA(&SPI2_Handler, (uint8_t *)&dma_rx[0], LENGTH);
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>