silicon Simplicity Studio中提供的SPI操作,扩展性差,不支持读写cmd变长操作,下面根据SPI控制器的基本原理,重新封装了SPI的驱动,并提供SPI NOR flash 驱动进行验证。
spi.c内容如下:
/******************************************************************************
* Copyright (c) 2015 by Silicon Laboratories Inc. All rights rerved.
*
* /legal/version/v11/Silicon_Labs_Software_
*****************************************************************************/
#include "efm8_config.h"
#include "SI_EFM8UB2_Register_Enums.h"
#include "spi_0.h"
// Runtime API
// Flag to indicate if driver should control Nss (chip lect)40用英语怎么读
static bool uNss = fal;
// flag to indicate we are in master mode (el slave)
static bool modeIsMaster = fal;
// flag to indicate that init vars (above) are valid. If they are
// not valid then a special one-time init will be called to t them
static bool initIsValid = fal;
uint8_t FlashWriteFlag=0;
uint8_t FlashReadFlag=0;
//All Gpio Init
void SPICsInit()
{
P1MDIN |= 2; //p1.1 out
P1MDOUT |= 2;
P1_B1=1;
P1MDIN |= 8; //p1.7 out
P1MDOUT |= 8;
P1_B7=1;
P2MDIN |= 0x3; //p2.0 p2.1out
P2MDOUT |= 0x3;
P2_B0=1;
P2_B1=0;
P2MDIN |= 0xF0; //p2.4 p2.5 p2.6 p2.7 out
P2MDOUT |= 0xF0;
P2 &=~0xF0;
P0MDIN |=0xFC; //p0.2 p0.3 p0.4 p0.5 out
P0MDOUT |=0xFC;
P0 &=~0xFC;
P0MDIN |=0x3; //p0.1 p0.0 in
注册会计 P0MDIN &= ~0x3;
P0 |=0x3;
P2MDIN |= 0xC; //p2.2 p2.3out
P2MDOUT &= ~0xC;
杨贵妃与安禄山
P2_B2=1;
P2_B3=1;
}
// ----------------------------------------------------------------------------
// Initialize internal state variables. This is ud if init API is怎么算标准体重女
// not called.
// ----------------------------------------------------------------------------
static void SPI0_internalInit(void)
{
// figure out if we are master mode, and using 4-wire or not
modeIsMaster = SPI0CFG & SPI0CFG_MSTEN__MASTER_ENABLED;
uNss = SPI0CN0 & SPI0CN0_NSSMD__FMASK;
// indicate that init has now been done
initIsValid = true;
}
// ----------------------------------------------------------------------------
// Write a byte if transmit buffer is not full.
// ----------------------------------------------------------------------------
bool SPI0_writeByte(uint8_t value)
{
bool ret = fal;
形容忙的成语
// check to e if transmit buffer is not full
if (SPI0CN0_TXBMT)
{
SPI0DAT = value;
ret = true;
}
return ret;
}
// ----------------------------------------------------------------------------
// Write a byte, waiting for transmit buffer to be empty
// ----------------------------------------------------------------------------
void SPI0_pollWriteByte(uint8_t value)
{
家常炖牛肉的做法 // wait for TX empty
while (!SPI0CN0_TXBMT)
{}
SPI0DAT = value;
}
#if 0
// ----------------------------------------------------------------------------
// Perform a multi-byte transfer, waiting for each byte to complete.
// ----------------------------------------------------------------------------
uint8_t
SPI0_pollTransfer(SI_VARIABLE_SEGMENT_POINTER(pTxBuffer, uint8_t,
EFM8PDL_SPI0_TX_SEGTYPE),
SI_VARIABLE_SEGMENT_POINTER(pRxBuffer, uint8_t,
EFM8PDL_SPI0_RX_SEGTYPE),
SPI0_TransferDirection_t dir,
uint8_t xferCount)
{
uint8_t txCount = xferCount;
bool checkNss = fal;
// This function is not interrupt driven and if SPI interrupts are
// enabled, it can cau interference.
SPI0_disableInt();
// make sure SPI is not already busy
while (SPI0CFG & SPI0CFG_SPIBSY__BMASK)
{}
// Check to e if run-time mode variables have been t up
if (!initIsValid)
{
SPI0_internalInit();
}
// Flush the RX buffer in ca something is in there
{
uint8_t dummy = SPI0DAT;
}
// Clear the interrupt flag that is ud to indicate transfer complete
SPI0CN0_SPIF = 0;
// asrt NSS (if ud)
if (modeIsMaster && uNss)
{
SPI0CN0_NSSMD0 = 0;
}
// Wait in loop until the requested number of transfers are complete
// Note: xferCount tracks the number of bytes received你对我的爱
while (xferCount)尖字组词
{
// If the transmit buffer is empty and there are still bytes to
// write, then write a byte out
if (SPI0CN0_TXBMT && txCount)
{
// If ur provided a write buffer then u that