STM32 F4/F7/H7开发板,使用SPI2做自收发实验,将PB14、PB15(MISO和MOSI)两个引脚连接,进行数据传输。
传输时发现,当数据总长度不超过16个字节时收发正常,超过16个字节接收到的数据全是0,请问是什么情况。。
附代码如下:
#define DATA_NUM 9
void SPI_Init(void)
{
int i = 0;
uint16_t tx[DATA_NUM] = {0x1234, 0x2234, 0x3234, 0x4234, 0x5234, 0x6234, 0x7234, 0x8234, 0x9234};//, 0xa234};
uint16_t rx[DATA_NUM] = {0};
SPI_HandleTypeDef SPI_Handler;
SPI_Handler.Instance = SPI2;
SPI_Handler.Init.Mode = SPI_MODE_MASTER;
SPI_Handler.Init.Direction = SPI_DIRECTION_2LINES;
SPI_Handler.Init.DataSize = SPI_DATASIZE_16BIT;
SPI_Handler.Init.CLKPolarity = SPI_POLARITY_HIGH;
SPI_Handler.Init.CLKPhase = SPI_PHASE_1EDGE;
SPI_Handler.Init.NSS = SPI_NSS_SOFT;
SPI_Handler.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_256;
SPI_Handler.Init.FirstBit = SPI_FIRSTBIT_MSB;
SPI_Handler.Init.TIMode = SPI_TIMODE_DISABLE;
SPI_Handler.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
SPI_Handler.Init.CRCPolynomial = 7;
HAL_SPI_Init(&SPI_Handler);
__HAL_SPI_ENABLE(&SPI_Handler);
HAL_SPI_TransmitReceive(&SPI_Handler, (uint8_t *)tx, (uint8_t *)rx, sizeof(uint16_t) * DATA_NUM, 1000);
for(i = 0; i < DATA_NUM; i++)
printf("rx[%d] = %x
",i, rx[i]);
}
一周热门 更多>