This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC2538 SPI接口

Other Parts Discussed in Thread: CC2538

参照cc2538_foundation_firmware_1_0_1_0里的,配置如下

测试发送SPI一直卡在下面的while里,请帮忙分析一下原因

//
// Wait until there is data to be read.
//
while(!(HWREG(ui32Base + SSI_O_SR) & SSI_SR_RNE))
{
}

//SPI配置

uint32_t ui32Dummy;

//
// Enable SSI peripheral module
//
SysCtrlPeripheralEnable(BSP_SPI_SSI_ENABLE_BM);

//
// Disable SSI function before configuring module
//
SSIDisable(BSP_SPI_SSI_BASE);

//
// Set IO clock as SSI clock source
//
SSIClockSourceSet(BSP_SPI_SSI_BASE, SSI_CLOCK_PIOSC);

//
// Map SSI signals to the correct GPIO pins and configure them as HW ctrl'd
//
IOCPinConfigPeriphOutput(BSP_SPI_BUS_BASE, BSP_SPI_SCK,
IOC_MUX_OUT_SEL_SSI0_CLKOUT);
IOCPinConfigPeriphOutput(BSP_SPI_BUS_BASE, BSP_SPI_MOSI,
IOC_MUX_OUT_SEL_SSI0_TXD);
IOCPinConfigPeriphInput(BSP_SPI_BUS_BASE, BSP_SPI_MISO,
IOC_SSIRXD_SSI0);
GPIOPinTypeSSI(BSP_SPI_BUS_BASE, (BSP_SPI_MOSI | BSP_SPI_MISO | BSP_SPI_SCK));

//
// Set SPI mode and speed
//
bspSpiClockSpeedSet(SPI_CLOCK);

// Configure SSI module to Motorola/Freescale SPI mode 3:
// Polarity = 1, SCK steady state is high
// Phase = 1, Data changed on first and captured on second clock edge
// Word size = 8 bits
SSIConfigSetExpClk(SSI0_BASE, SysCtrlIOClockGet(), SSI_FRF_MOTO_MODE_3,
SSI_MODE_MASTER, SysCtrlClockGet()/2, 8);

//
// Enable the SSI function
//
SSIEnable(BSP_SPI_SSI_BASE);

//
// Flush the RX FIFO
//
while(SSIDataGetNonBlocking(BSP_SPI_SSI_BASE, &ui32Dummy))
{
}
////////////////////////////////////////////////////////////////////////////////
//
// Enable 3.3-V domain
//
bsp3V3DomainEnable();

//
// Configure CSn and MODE(A0) as output high
//
GPIOPinTypeGPIOOutput(GPIO_B_BASE, GPIO_PIN_5);//CS
GPIOPinWrite(GPIO_B_BASE, GPIO_PIN_5, GPIO_PIN_5);//1

//
// Configure LCD RST as output low
//
GPIOPinTypeGPIOOutput(GPIO_B_BASE, GPIO_PIN_3);//RESET
GPIOPinWrite(GPIO_B_BASE, GPIO_PIN_3, 0);//1

//
// Delay ~100ms for LCD to be powered up
//
SysCtrlDelay((SysCtrlClockGet() / 10) / 3);

//
// Clear reset (set high)
//
GPIOPinWrite(GPIO_B_BASE, GPIO_PIN_3, GPIO_PIN_3);//1

uint8_t SPI_ReadByte(void)
{
uint32_t tmp=0;
while(SSIBusy(SSI0_BASE));
GPIOPinWrite(GPIO_B_BASE, GPIO_PIN_5, 0);//CS
SSIDataGet(SSI0_BASE,&tmp);
while(SSIBusy(SSI0_BASE));
GPIOPinWrite(GPIO_B_BASE, GPIO_PIN_5, GPIO_PIN_5);//CS
return (uint8_t)tmp;
}

void SPI_WriteByte(uint8_t wb)
{
while(SSIBusy(SSI0_BASE));
GPIOPinWrite(GPIO_B_BASE, GPIO_PIN_5, 0);//CS
SSIDataPut(SSI0_BASE,wb);
while(SSIBusy(SSI0_BASE));
GPIOPinWrite(GPIO_B_BASE, GPIO_PIN_5, GPIO_PIN_5);//CS
}

  • // Wait until SSI0 is done transferring all the data in the transmit FIFO.
    //
    while(SSIBusy(SSI0_BASE))
    {
    }

    你用逻辑分析仪看一下是否有完整的数据包出来。