硬件接线是PB6接MOSI,PB7接CS,PB8接CLK,实现与bc7277的通信,驱动数码管显示,不考虑按键为什么一直没有点亮
- #include "stm32f10x.h"
- void GPIO_Configuration(void);
- void SPI_Send_Byte(uint8_t);
- int main(void)
- {
- GPIO_Configuration();
- __nop();
- GPIO_ResetBits(GPIOB, GPIO_Pin_7);//CS = 0;
- __nop();
- SPI_Send_Byte(0x1b);
- __nop();
- SPI_Send_Byte(0x11);
- GPIO_SetBits(GPIOB, GPIO_Pin_7);//CS = 1;
- __nop();
- __nop();
- __nop();
- while(1);
- }
- void GPIO_Configuration()
- {
-
- GPIO_InitTypeDef GPIO_InitStructure;
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
- /* MOSI-PB6,CS-PB7,CLK-PB8*/
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOB, &GPIO_InitStructure);
- GPIO_SetBits(GPIOB, GPIO_Pin_7); //CS=1
- GPIO_SetBits(GPIOB, GPIO_Pin_8); //CLK=1
- }
|