中级会员
- 积分
- 268
- 金钱
- 268
- 注册时间
- 2017-12-12
- 在线时间
- 103 小时
|
楼主 |
发表于 2018-1-23 14:02:19
|
显示全部楼层
SPI初始化里面的啊,这个是我那里面完整的,用的标准库
SPI_InitTypeDef SPI_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
/* SCK, MISO and MOSI SCK=PA5,MISO=PA6,MOSI=PA7*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
//CS
// GPIO_SetBits(GPIOA, GPIO_Pin_4);//Ƭѡ
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_SetBits(GPIOA, GPIO_Pin_4);//ƬѡÀ­¸ß
/* SPI1 configuration */
SPI_Cmd(SPI1, DISABLE); //±ØÐëÏÈDISABLE£¬²ÅÄܸıäMODE
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; //Á½ÏßÈ«Ë«¹¤Ä£Ê½
SPI_InitStructure.SPI_Mode = SPI_Mode_Master; //Ö÷»ú
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; //8bits
SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;
SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; //Èí¼þNSS
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; //¸ßλÏÈÐÐ
SPI_InitStructure.SPI_CRCPolynomial = 7; //CRC7
SPI_Init(SPI1, &SPI_InitStructure);
//SPI_SSOutputCmd(SPI1, ENABLE); //ʹÄÜNSS
SPI_Cmd(SPI1, ENABLE); |
|