本帖最后由 p13692166934 于 2019-1-16 16:07 编辑 使用spi驱动oled,配置不知道哪里有问题,用模拟时序没问题,但一换寄存器屏直接亮不了,下面为代码 RCC->AHBENR |=0x01<<17; //SCK(PA5) MOSI(PA7)配置为普通功能推挽输出 //端口模式设置 //模式----通用输出模式(01) GPIOA->MODER &=~(0x03<<10 |0x03<<14); GPIOA->MODER |=0X02<<14 | 0X02<<10; //输出类型----推挽 GPIOA->OTYPER &= ~(0X01<<7 | 0X01<<5); //输出速度----100M GPIOA->OSPEEDR &=~(0x03<<14 |0x03<<10|0X03<<12); //上下拉-----无上拉或下拉 GPIOA->PUPDR &=~(0x03<<14 |0x03<<10|0X03<<12); //MISO(pA6) 配置为浮空输入 GPIOA->MODER &=~(0X03<<12); //pA6为输入模式 GPIOA->MODER |=0X02<<12; GPIOA->AFR[0] &=~(0x0fff<<20); //SPI1时钟使能 RCC->APB2ENR |=0X01<<12; SPI_InitTypeDef SPI_InitStructure; SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex ; SPI_InitStructure.SPI_Mode = SPI_Mode_Master; SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low; SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge; SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4; SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; SPI_InitStructure.SPI_CRCPolynomial = 7; SPI_Init(SPI1,&SPI_InitStructure); SPI_RxFIFOThresholdConfig (SPI1,SPI_RxFIFOThreshold_QF ); SPI_Cmd(SPI1,ENABLE); u8 SPI1_ReadWriteByte(u8 _data) { while(SPI_I2S_GetFlagStatus(SPI1 ,SPI_I2S_FLAG_TXE )==RESET ); SPI_SendData8 (SPI1 ,_data); while(SPI_I2S_GetFlagStatus(SPI1 ,SPI_I2S_FLAG_RXNE )==RESET ); return SPI_ReceiveData8 (SPI1 ); } |
GPIO_PinAFConfig(GPIOB, GPIO_PinSource13, GPIO_AF_0);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource15, GPIO_AF_0);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource14, GPIO_AF_0);
评分
查看全部评分
拉低了,这个是spi初始化的,oled的程序我没放出来,之前模拟时序没问题可以亮,换成控制器就不行了,那就说明spi的问题,控制器不清楚哪里配置有问题
配置了,gpio初始化就有了GPIOA->AFR[0] &=~(0x0fff<<20);