学前班
最后登录1970-1-1
在线时间 小时
注册时间2019-12-5
|
我在配置好SPI 参数后,读取设备ID,一共有4个变量,示波器上看到的波形数据 顺序是 00 C2 20 16,但是寄存器里面的顺序是16 00 C2 20
我在读取设备ID函数 每句话都打断点 慢慢跑的话 数据顺序 就正确 是 00 C2 20 16
下面是我的配置和发送接收函数 还有读取设备ID 函数 求大佬帮忙看看 哪里有问题
//SPI2 读设备ID
uint32_t SPI2_Read_ID(void)
{
uint8_t test=0,Factory_Number=0,Storage_type=0,Capacity=0;
uint32_t Device_ID=0;
SPI2_CS_0;
test = SPI2_Send_Byte(0X9F);//读取指令
Factory_Number=SPI2_Read_Byte();//编号
Storage_type=SPI2_Read_Byte();//类型
Capacity=SPI2_Read_Byte();// 容量
Device_ID=((Factory_Number<<16)|(Storage_type<<8)|(Capacity));
SPI2_CS_1;
return Device_ID;
}
void SPI_FLASH_GPIO_Init(void)
{
lpspi_master_config_t FLASH_config;
gpio_pin_config_t GPIO_InitStructure;
//CS
IOMUXC_SetPinMux(IOMUXC_GPIO_EMC_11_GPIO2_IO11,0U);
IOMUXC_SetPinConfig(IOMUXC_GPIO_EMC_11_GPIO2_IO11,0x10B0u);
GPIO_InitStructure.direction=kGPIO_DigitalOutput;
GPIO_InitStructure.interruptMode=kGPIO_NoIntmode;
GPIO_InitStructure.outputLogic=1;
GPIO_PinInit(CS_SPI_GPIO_BASE,CS_SPI_GPIO_PIN,&GPIO_InitStructure);//SCL
//CLK MOSI MISO
IOMUXC_SetPinMux(IOMUXC_GPIO_EMC_10_LPSPI2_SCK, 0U);
IOMUXC_SetPinMux(IOMUXC_GPIO_EMC_12_LPSPI2_SDO, 0U);
IOMUXC_SetPinMux(IOMUXC_GPIO_EMC_13_LPSPI2_SDI, 0U);
IOMUXC_SetPinConfig(IOMUXC_GPIO_EMC_10_LPSPI2_SCK,0x10B0u);
IOMUXC_SetPinConfig(IOMUXC_GPIO_EMC_12_LPSPI2_SDO,0x10B0u);
IOMUXC_SetPinConfig(IOMUXC_GPIO_EMC_13_LPSPI2_SDI,0x10B0u);
/* LPSPI 默认配置
masterConfig->baudRate = 500000;
masterConfig->bitsPerFrame = 8;
masterConfig->cpol = kLPSPI_ClockPolarityActiveHigh; CPOL=0
masterConfig->cpha = kLPSPI_ClockPhaseFirstEdge; CPHA=0
masterConfig->direction = kLPSPI_MsbFirst;
masterConfig->pcsToSckDelayInNanoSec = 1000000000 / masterConfig->baudRate * 2;
masterConfig->lastSckToPcsDelayInNanoSec = 1000000000 / masterConfig->baudRate * 2;
masterConfig->betweenTransferDelayInNanoSec = 1000000000 / masterConfig->baudRate * 2;
masterConfig->whichPcs = kLPSPI_Pcs0;
masterConfig->pcsActiveHighOrLow = kLPSPI_PcsActiveLow;
masterConfig->pinCfg = kLPSPI_SdiInSdoOut;
masterConfig->dataOutConfig = kLpspiDataOutRetained;
*/
LPSPI_MasterGetDefaultConfig(&FLASH_config);
LPSPI_MasterInit(LPSPI2,&FLASH_config,132000000);
LPSPI_Enable(LPSPI2,true);
}
//发数据
uint8_t SPI2_Send_Byte(uint8_t TXData)
{
uint8_t TXDummy;
uint16_t retry=0;
LPSPI_WriteData(LPSPI2,TXData);
while ((LPSPI_GetStatusFlags(LPSPI2)>>24)&0x01 == 1)
{
retry++;
if(retry>=1000)
return 0;
}
TXDummy=LPSPI_ReadData(LPSPI2);//¶áè¡êy¾Y Çå¿ÕFIFO
return TXDummy;
}
//读数据
uint8_t SPI2_Read_Byte(void)
{
uint8_t RXDummy;
uint16_t retry=0;
LPSPI2->TDR=0XFF;
while ((LPSPI_GetStatusFlags(LPSPI2)>>24)&0x01 == 1)
{
retry++;
if(retry>=1000)
return 0;
}
RXDummy=LPSPI_ReadData(LPSPI2);
return RXDummy;
}
|
|