紧接着配置SPI通信数据的格式,采样模式只能选择“CPOL = 0,CPHA = 0”或者“CPOL = 1,CPHA = 1”两种模式(配合MX25L04006E芯片)
配置完成后就可以写MX25L04006E的驱动函数了,例如MX25L4006E读取芯片ID的操作时发送0x9F指令,则代码如下
/*
* Read identification
* MID -- Manufacture Identification
* DID -- Device Identification
*/
void mx25_RDID(uint8_t *MID,uint16_t *DID)
{
uint8_t cmd;
uint8_t ID[2];
cmd=0x9f;
clr_cs();
HAL_SPI_Transmit(&hspi1, &cmd, 1, 10);
HAL_SPI_Receive(&hspi1,MID,1,10);
HAL_SPI_Receive(&hspi1,ID,2,10);
set_cs();
DID[0]=ID[0];
DID[0]=DID[0]<<8;
DID[0]+=ID[1];
}
|