按照你说的改了,程序如下:
int32_t main(void)
{
/* LED initialization */
BSP_CLK_Init();
// BSP_GPIO_Init();
// DataProc_TaskInit();
Spi1_Config();
SPI_Cmd(SPI1_UNIT, Enable);
SPI_SendData8(SPI1_UNIT, 0xff);
/* Initialize I2C port*/
PORT_SetFunc(I2C_SCL_PORT, I2C_SCL_PIN, I2C_GPIO_SCL_FUNC, Disable);
PORT_SetFunc(I2C_SDA_PORT, I2C_SDA_PIN, I2C_GPIO_SDA_FUNC, Disable);
/* Enable I2C Peripheral*/
PWC_Fcg1PeriphClockCmd(I2C_FCG_USE, Enable);
/* Initialize I2C peripheral and enable function*/
E2_Initialize();
RF_Config();
// osKernelStart();
uint16_t sum = 0;
while (1)
{
if (SPI_GetFlag(SPI1_UNIT,SpiFlagReceiveBufferFull) == Set) //注释1
{
g_dataRecvBuf[CHANNEL_0][sum++] = SPI_ReceiveData8(SPI1_UNIT);
SPI_SendData8(SPI1_UNIT, 0xff);
}
if(sum == 200)
{
sum =0;
}
}
}
void Spi1_Config(void)
{
stc_spi_init_t stcSpiInit;
stc_irq_regi_conf_t stcIrqRegiConf;
stc_port_init_t pstcPortInit;
/* configuration structure initialization */
MEM_ZERO_STRUCT(stcSpiInit);
MEM_ZERO_STRUCT(stcIrqRegiConf);
/* Configuration peripheral clock */
PWC_Fcg1PeriphClockCmd(SPI1_UNIT_CLOCK, Enable);
/* Configuration SPI pin */
MEM_ZERO_STRUCT(pstcPortInit);
pstcPortInit.enPullUp = Enable;
PORT_Init(SPI1_SCK_PORT,SPI1_SCK_PIN,&pstcPortInit);
PORT_Init(SPI1_MOSI_PORT, SPI1_MOSI_PIN, &pstcPortInit);
MEM_ZERO_STRUCT(pstcPortInit);
pstcPortInit.enPinMode = 0;
PORT_Init(SPI1_NSS_PORT, SPI1_NSS_PIN, &pstcPortInit);
PORT_SetFunc(SPI1_SCK_PORT, SPI1_SCK_PIN, SPI1_SCK_FUNC, Disable);
PORT_SetFunc(SPI1_NSS_PORT, SPI1_NSS_PIN, SPI1_NSS_FUNC, Disable);
PORT_SetFunc(SPI1_MOSI_PORT, SPI1_MOSI_PIN, SPI1_MOSI_FUNC, Disable);
/* Configuration SPI structure */
stcSpiInit.enClkDiv = SpiClkDiv8;//SpiClkDiv8
stcSpiInit.enFrameNumber = SpiFrameNumber1;
stcSpiInit.enDataLength = SpiDataLengthBit8;
stcSpiInit.enFirstBitPosition = SpiFirstBitPositionMSB;
stcSpiInit.enSckPolarity = SpiSckIdleLevelLow;//Sck极性
stcSpiInit.enSckPhase = SpiSckOddSampleEvenChange;//相位SpiSckOddSampleEvenChange
stcSpiInit.enReadBufferObject = SpiReadReceiverBuffer;
stcSpiInit.enWorkMode = SpiWorkMode4Line;
stcSpiInit.enTransMode = SpiTransFullDuplex;
stcSpiInit.enCommAutoSuspendEn = Disable;
stcSpiInit.enModeFaultErrorDetectEn = Disable;
stcSpiInit.enParitySelfDetectEn = Disable;
stcSpiInit.enParityEn = Disable;//奇偶校验
stcSpiInit.enParity = SpiParityEven; //Select even parity send and receive
stcSpiInit.enMasterSlaveMode = SpiModeSlave;
stcSpiInit.stcSsConfig.enSsValidBit = SpiSsValidChannel0;
stcSpiInit.stcSsConfig.enSs0Polarity = SpiSsLowValid;//SS极性和信道结构
SPI_Init(SPI1_UNIT, &stcSpiInit);
}
结果:只能收到主机发送的第一个数,后面就进不去注释1满足的条件了。
而且我看了下SPI1的寄存器,如下所示:
|