SPI程序 void spi_init(void) { SPI_InitTypeDef SPI_InitStructure; GPIO_InitTypeDef GPIO_InitStructure; /*ʱÖÓÉèÖà */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOC, ENABLE);//Ç°ÃæGPIOÉèÖÃʱʱÖÓÒÑ¿ªÆô ´Ë´¦²»ÔÙÉèÖà /*SCK ʱÖӹܽÅÉèÖÃ*/ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(GPIOA, &GPIO_InitStructure); /*MOSI ¹Ü½ÅÉèÖà */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; GPIO_Init(GPIOA, &GPIO_InitStructure); /* MISO ¹Ü½ÅÉèÖÃ*/ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD; GPIO_Init(GPIOA, &GPIO_InitStructure); /*NSS Ƭѡ¹Ü½ÅÉèÖÃ*/ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(GPIOC, &GPIO_InitStructure); /*RC522复位管脚*/ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(GPIOC, &GPIO_InitStructure); /*À¸ß NSS¹Ü½Å*/ SET_SPI_CS; /* */ SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;//SPI ÉèÖÃΪ˫ÏßË«ÏòÈ«Ë«¹¤ SPI_InitStructure.SPI_Mode = SPI_Mode_Master; //ÉèÖÃΪÖ÷SPI SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; //ÉèÖÃΪ·¢ËͽÓÊÕ8λ֡½á¹¹ SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low; //ʱÖÓÐü¿ÕµÍ SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge; //Êý¾Ý²¶»ñÓëµÚ1¸öʱÖÓÑØ SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; //ÄÚ²¿NSSÐźÅÓÉSSIλ¿ØÖÆ SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8; //²¨ÌØÂÊ·ÖƵֵΪ4 ²¨ÌØÂÊΪ9M SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; //Êý¾Ý´«Êä´Ó¸ßλ¿ªÊ¼ SPI_InitStructure.SPI_CRCPolynomial = 7; //CRCУÑé SPI_Init(SPI1, &SPI_InitStructure); /*ʹÄÜSPI1 */ SPI_Cmd(SPI1, ENABLE); } u8 SPIWriteByte(u8 Byte) { while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);//µÈ´ý·¢ËÍΪ¿Õ SPI_I2S_SendData(SPI1, Byte);//·¢ËÍÒ»¸ö×Ö½Ú while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET);//µÈ´ý·¢ËÍÍê³É return SPI_I2S_ReceiveData(SPI1);//½ÓÊÕÒ»¸ö×Ö½Ú } RC522读寄存器程序 u8 ReadRawRC(unsigned char Address) { u8 ucAddr; u8 ucResult=0; CLR_SPI_CS; ucAddr = ((Address<<1)&0x7E)|0x80; SPIWriteByte(ucAddr); ucResult=SPIWriteByte(0); SET_SPI_CS; return ucResult; } 读寄存器时无法读到 |
我之前有个关于SPI MISO管脚配置的帖子 跟FLASH芯片通信的时候 MISO 管脚配置成3种输出 通信都可以成功 但是 为什么 跟RC522的时候 只能配置复用推挽呢??????
还有具体是什么问题?