共2条
1/1 1 跳转至页
SPI 大家看看这个SPI程序为什么不能收
问
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
{
//* 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 跳转至页
回复
有奖活动 | |
---|---|
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |
打赏帖 | |
---|---|
与电子爱好者谈读图四被打赏50分 | |
与电子爱好者谈读图二被打赏50分 | |
【FRDM-MCXN947评测】Core1适配运行FreeRtos被打赏50分 | |
【FRDM-MCXN947评测】双核调试被打赏50分 | |
【CPKCORRA8D1B评测】---移植CoreMark被打赏50分 | |
【CPKCORRA8D1B评测】---打开硬件定时器被打赏50分 | |
【FRDM-MCXA156评测】4、CAN loopback模式测试被打赏50分 | |
【CPKcorRA8D1评测】--搭建初始环境被打赏50分 | |
【FRDM-MCXA156评测】3、使用FlexIO模拟UART被打赏50分 | |
【FRDM-MCXA156评测】2、rt-thread MCXA156 BSP制作被打赏50分 |