这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 综合技术 » 基础知识 » SPI 大家看看这个SPI程序为什么不能收

共2条 1/1 1 跳转至

SPI 大家看看这个SPI程序为什么不能收

院士
2006-09-17 18:14:16     打赏
SPI 大家看看这个SPI程序为什么不能收



关键词: 大家     看看     这个     程序     为什么     不能    

院士
2006-12-22 22:43:00     打赏
2楼
问 void AT91F_SPI_Cfg_spi(void)
{
    //* Reset the SPI
    AT91F_SPI_Reset(AT91C_BASE_SPI);

    //* Configure SPI in Master Mode with No CS selected !!!  
    AT91F_SPI_CfgMode(AT91C_BASE_SPI, AT91C_SPI_MSTR | AT91C_SPI_MODFDIS | AT91C_SPI_FDIV);

    //* Configure SPI CS0 for Serial DataFlash AT45DBxx
    AT91F_SPI_CfgCs(AT91C_BASE_SPI,0,spi_mode1);

    //* Configure SPI CS3 for DataFlash Card AT45DCBxx
    //AT91F_SPI_CfgCs(3, AT91C_SPI_CPOL | (AT91C_SPI_DLYBS & 0x100000) | ((MASTER_CLOCK / (2*DATAFLASH_CLK)) << 8));

    //* Enable the SPI
       AT91F_SPI_Enable(AT91C_BASE_SPI);
}


////////read spi to confirm if the data oxf5 witen in fm25l256
void read_spi(void)
{
    
    unsigned int readint;
    AT91F_SPI_Cfg_spi();
    AT91C_BASE_SPI->SPI_TDR = 0x000E0003;
    AT91C_BASE_SPI->SPI_TDR = 0x000E0000;
    AT91C_BASE_SPI->SPI_TDR = 0x000E0000;
    readint=AT91C_BASE_SPI->SPI_RDR;
    readint=AT91C_BASE_SPI->SPI_RDR;
    readint=AT91C_BASE_SPI->SPI_RDR;
    if(readint&0xff<5){
        AT91F_PIO_ClearOutput( AT91C_BASE_PIOA, LED4 );
        delay();
        delay();
        delay();
        delay();
        delay();
        delay();
        AT91F_PIO_SetOutput( AT91C_BASE_PIOA, LED4 );
        }
}


void WRITE_SPI(void)
{
    AT91C_BASE_SPI->SPI_TDR = 0X000EFFFF&SPI_D6;
    AT91C_BASE_SPI->SPI_TDR = ((unsigned int) 0x000E0002);
    AT91C_BASE_SPI->SPI_TDR = (unsigned int)0x000E0000;
    AT91C_BASE_SPI->SPI_TDR = (unsigned int)0x000E0000;
    AT91C_BASE_SPI->SPI_TDR = (unsigned int)0x000E0002;
    AT91C_BASE_SPI->SPI_TDR = (unsigned int)0x000E0003;
    AT91C_BASE_SPI->SPI_TDR = (unsigned int)0x010E0004;
    
    
    //write oxf5 in the address of 0x0;
    read_spi();
}


void spi_init(void)
{
    AT91F_PIO_CfgPeriph(AT91C_BASE_PIOA, AT91C_PIO_PA11|AT91C_PIO_PA12|AT91C_PIO_PA13|AT91C_PIO_PA14, 0);
    
    AT91F_PMC_EnablePeriphClock ( AT91C_BASE_PMC, (unsigned int) 1<<AT91C_ID_SPI );
    
    AT91F_SPI_Cfg_spi();
    //AT91PS_SPI SPI_PT;
    //SPI_PT = AT91C_BASE_SPI;
    
    //AT91C_SPI_MR = AT91C_SPI_MSTR|AT91C_SPI_FDIV|AT91C_SPI_MODFDIS;
    //AT91F_SPI_CfgMode(AT91C_BASE_SPI,AT91C_SPI_MSTR|AT91C_SPI_FDIV|AT91C_SPI_MODFDIS);
    //AT91C_BASE_SPI->SPI_IDR = (unsigned int)0X000003FF;
    //AT91C_BASE_SPI->SPI_CSR[0] = (unsigned int) 0X0307FF00;
    
    //OPEN SPI
    //AT91C_BASE_SPI->SPI_CR=AT91C_SPI_SPIEN;
    
    WRITE_SPI( );
    
}


用的时at91sam7s64,在AXD下调试,调试的时候发现通过示波器可以看到输出的波形,但是在读取的时候MISO引脚上没有反应,此时PCS和SPCK引脚也没有波形, 有做过的高手指点一下,究竟是什么问题。不胜感激!!!!!!!!!!!!!!!! 1: 请教高手 2: 帮你顶rt

共2条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]