野火电子论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9317|回复: 1

spi读取模块失败RT1050

[复制链接]
发表于 2018-11-26 09:54:06 | 显示全部楼层 |阅读模式
麻烦大家帮忙看看哪里出问题了啊?
int main(void)
{
        gpio_pin_config_t gpio_config = {kGPIO_DigitalOutput, 0, kGPIO_NoIntmode};
        BOARD_ConfigMPU();
        BOARD_InitPins();
        BOARD_BootClockRUN();
        BOARD_InitDebugConsole();

        /*Set clock source for LPSPI*/
        CLOCK_SetMux(kCLOCK_LpspiMux, EXAMPLE_LPSPI_CLOCK_SOURCE_SELECT);
        CLOCK_SetDiv(kCLOCK_LpspiDiv, EXAMPLE_LPSPI_CLOCK_SOURCE_DIVIDER);

        PRINTF("lpspi_functional_interrupt_board_2_board_master start.\r\n");
        PRINTF("This example use one board as master and another as slave.\r\n");
        PRINTF("Master and slave uses interrupt way. Slave should start first. \r\n");
        PRINTF("Please make sure you make the correct line connection. Basically, the connection is: \r\n");
        PRINTF("LPSPI_master -- LPSPI_slave   \r\n");
        PRINTF("   CLK      --    CLK  \r\n");
        PRINTF("   PCS      --    PCS \r\n");
        PRINTF("   SOUT     --    SIN  \r\n");
        PRINTF("   SIN      --    SOUT \r\n");
        PRINTF("   GND      --    GND \r\n");
       
        GPIO_PinInit(GPIO1, 2U, &gpio_config);
        GPIO_PinWrite(GPIO1, 2U, 1U);
        uint32_t srcClock_Hz;
        uint32_t errorCount;
        uint32_t i;
        uint32_t whichPcs;
        uint8_t txWatermark;
        lpspi_master_config_t masterConfig;

        /*Master config*/
        masterConfig.baudRate = TRANSFER_BAUDRATE;
        masterConfig.bitsPerFrame = 8;
        masterConfig.cpol = kLPSPI_ClockPolarityActiveHigh;
        masterConfig.cpha = kLPSPI_ClockPhaseFirstEdge;
        masterConfig.direction = kLPSPI_MsbFirst;

        masterConfig.pcsToSckDelayInNanoSec = 1000000000 / masterConfig.baudRate;
        masterConfig.lastSckToPcsDelayInNanoSec = 1000000000 / masterConfig.baudRate;
        masterConfig.betweenTransferDelayInNanoSec = 1000000000 / masterConfig.baudRate;

        masterConfig.whichPcs = EXAMPLE_LPSPI_MASTER_PCS_FOR_INIT;
        masterConfig.pcsActiveHighOrLow = kLPSPI_PcsActiveLow;

        masterConfig.pinCfg = kLPSPI_SdiInSdoOut;
        masterConfig.dataOutConfig = kLpspiDataOutRetained;

        srcClock_Hz = LPSPI_MASTER_CLK_FREQ;
        LPSPI_MasterInit(EXAMPLE_LPSPI_MASTER_BASEADDR, &masterConfig, srcClock_Hz);
        unsigned char wData = 0;
        uint32_t byte = 0;
        unsigned char c = 0;
//        c =((0x26 << 1) & ~(0x80));
        c = (0x03 << 1) & 0x7E;
        wData = (((0x03 << 1) & 0x7E ) | 0x80);
//        wData = ((0x26 << 1)  | 0x80);
    while (1)
    {
#if 1               
                LPSPI_WriteData(EXAMPLE_LPSPI_MASTER_BASEADDR, c);
                LPSPI_WriteData(EXAMPLE_LPSPI_MASTER_BASEADDR, 0xFE);
                LPSPI_WriteData(EXAMPLE_LPSPI_MASTER_BASEADDR, wData);
                byte = LPSPI_ReadData(EXAMPLE_LPSPI_MASTER_BASEADDR);
                //        debug_printf("addr is 0x%x, spi data is 0x%x, return byte is 0x%x", addr, wData, byte);
                       
                PRINTF("byte = %d \r\n",byte);
#endif
    }
}


回复

使用道具 举报

 楼主| 发表于 2018-11-26 09:56:50 | 显示全部楼层
本帖最后由 ftq5201314 于 2018-11-26 10:00 编辑

#define LPSPI1                                   ((LPSPI_Type *)LPSPI1_BASE)
#define EXAMPLE_LPSPI_MASTER_BASEADDR (LPSPI1)#define EXAMPLE_LPSPI_CLOCK_SOURCE_SELECT (1U)
#define EXAMPLE_LPSPI_CLOCK_SOURCE_DIVIDER (7U)
#define EXAMPLE_LPSPI_MASTER_IRQN LPSPI1_IRQn
#define EXAMPLE_LPSPI_MASTER_IRQHandler LPSPI1_IRQHandler

#define EXAMPLE_LPSPI_MASTER_PCS_FOR_INIT (kLPSPI_Pcs0)
#define EXAMPLE_LPSPI_MASTER_PCS_FOR_TRANSFER (kLPSPI_MasterPcs0)

/* Select USB1 PLL PFD0 (720 MHz) as lpspi clock source */
#define EXAMPLE_LPSPI_CLOCK_SOURCE_SELECT (1U)
/* Clock divider for master lpspi clock source */
#define EXAMPLE_LPSPI_CLOCK_SOURCE_DIVIDER (7U)

#define LPSPI_MASTER_CLK_FREQ (CLOCK_GetFreq(kCLOCK_Usb1PllPfd0Clk) / (EXAMPLE_LPSPI_CLOCK_SOURCE_DIVIDER + 1U))
#define TRANSFER_SIZE 64U         /*! Transfer dataSize */
#define TRANSFER_BAUDRATE 500000U /*! Transfer baudrate - 500k */

typedef enum _gpio_pin_direction
{
    kGPIO_DigitalInput = 0U,  /*!< Set current pin as digital input.*/
    kGPIO_DigitalOutput = 1U, /*!< Set current pin as digital output.*/
} gpio_pin_direction_t;

typedef enum _lpspi_which_pcs_config
{
    kLPSPI_Pcs0 = 0U, /*!< PCS[0] */
    kLPSPI_Pcs1 = 1U, /*!< PCS[1] */
    kLPSPI_Pcs2 = 2U, /*!< PCS[2] */
    kLPSPI_Pcs3 = 3U  /*!< PCS[3] */
} lpspi_which_pcs_t;

回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

联系站长|手机版|野火电子官网|野火淘宝店铺|野火电子论坛 ( 粤ICP备14069197号 ) 大学生ARM嵌入式2群

GMT+8, 2024-11-23 11:06 , Processed in 0.034743 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表