void MemoryRemapConfig(void)
{
uint32_t i = 0;
uint32_t Data,Address;
// VectorTable = (unsigned int *)0x20000000; //RAM
for(i = 0; i < 48; i++)
{
Data=*(__IO unsigned int*)(0x08000000+i*4);
Address=0x20000000+(i*4);
*(__IO unsigned int*)Address=(uint32_t)Data;
}
/* Enable the SYSCFG peripheral clock*/
// RCC_APB2PeriphResetCmd(RCC_APB2Periph_SYSCFG, ENABLE);
/* Remap SRAM at 0x00000000 */
SYSCFG_MemoryRemapConfig(SYSCFG_MemoryRemap_SRAM);//RAM映射到0x0000 0000
}
void I2C_Configuration(void)
{
I2C_InitTypeDef I2C_InitStruct;
GPIO_InitTypeDef GPIO_InitStruct;
NVIC_InitTypeDef NVIC_InitStructure;
/* Enable GPIOA clock */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
// /* Configure the I2C clock source. The clock is derived from the HSI */
// RCC_I2CCLKConfig(RCC_I2C1CLK_HSI);
/*!< sEE_I2C Periph clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C2 , ENABLE);
/* Connect PXx to I2C_SCL*/
GPIO_PinAFConfig( GPIOB , GPIO_PinSource10, GPIO_AF_1);
/* Connect PXx to I2C_SDA*/
GPIO_PinAFConfig( GPIOB ,GPIO_PinSource11, GPIO_AF_1);
/*!< GPIO configuration */
/*!< Configure sEE_I2C pins: SCL */
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_Level_3;
GPIO_Init(GPIOB , &GPIO_InitStruct);
/*!< Configure sEE_I2C pins: SDA */
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_11;
GPIO_Init(GPIOB , &GPIO_InitStruct);
NVIC_InitStructure.NVIC_IRQChannel = I2C2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPriority = 0;
// NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* I2C configuration */
I2C_InitStruct.I2C_Mode = I2C_Mode_I2C;
I2C_InitStruct.I2C_AnalogFilter = I2C_AnalogFilter_Enable;
I2C_InitStruct.I2C_DigitalFilter = 0x00;
I2C_InitStruct.I2C_OwnAddress1 =0x00;
I2C_InitStruct.I2C_Ack = I2C_Ack_Enable;
I2C_InitStruct.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
I2C_InitStruct.I2C_Timing = 0x60801B30;//0x10D05D84;100KHz
/* Apply I2C configuration after enabling it */
I2C_Init(I2C2, &I2C_InitStruct);
/* I2C Peripheral Enable */
I2C_Cmd(I2C2, ENABLE);
}
void Dmx_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC | RCC_AHBPeriph_GPIOB, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE );
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;//control
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_PinAFConfig(GPIOB,GPIO_PinSource6,GPIO_AF_0);
GPIO_PinAFConfig(GPIOB,GPIO_PinSource7,GPIO_AF_0);
/*
* USART1_TX -> PB6, USART1_RX -> PB7
*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; //发送引脚
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPriority = 1;
// NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
USART_InitStructure.USART_BaudRate = 250000;//设置串口波特率
USART_InitStructure.USART_WordLength = USART_WordLength_9b;//设置数据位
USART_InitStructure.USART_StopBits = USART_StopBits_1;//设置停止位
USART_InitStructure.USART_Parity = USART_Parity_No;//设置效验位
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//设置流控制
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;//设置工作模式
USART_Init(USART1, &USART_InitStructure); //配置入结构体
USART_Cmd(USART1, ENABLE);//使能串口1
USART_ClearITPendingBit(USART1, USART_IT_TC);
USART_ITConfig(USART1, USART_IT_TC, ENABLE);
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
}
void Panel16v8_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Enable the GPIO Clock */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
/* Configure the GPIO pin 输出*/
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
// GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Pin = (1 << DD_SCK);
GPIO_Init(GPIOpinCM006SCK, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = (1 << DD_MOSI);
GPIO_Init(GPIOpinCM006MOSI, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = (1 << PinCM006Hold0);
GPIO_Init(GPIOpinCM006Hold0, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = (1 << PinCM006Hold1);
GPIO_Init(GPIOpinCM006Hold1, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = (1 << PinCM006Hold2);
GPIO_Init(GPIOpinCM006Hold2, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = (1 << PinCM006Hold3);
GPIO_Init(GPIOpinCM006Hold3, &GPIO_InitStructure);
//输入
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
// GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//GPIO_PuPd_NOPULL;
// GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Pin = 1 << PinCM006KeyMenu;
GPIO_Init(GPIOpinCM006KeyMenu, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = 1 << PinCM006KeyIncrease;
GPIO_Init(GPIOpinCM006KeyIncrease, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = 1 << PinCM006KeyDecrease;
GPIO_Init(GPIOpinCM006KeyDecrease, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = 1 << PinCM006KeyEnter;
GPIO_Init(GPIOpinCM006KeyEnter, &GPIO_InitStructure);
}
void PFIO_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Enable the GPIO Clock */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA|RCC_AHBPeriph_GPIOB|RCC_AHBPeriph_GPIOC, ENABLE);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
// 电机驱动
GPIO_InitStructure.GPIO_Pin = (1 << PinMotorDriveEnable);
GPIO_Init(GPIOpinMotorDriveEnable, &GPIO_InitStructure);
MotorDriveDisable();
//输入
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Pin = (1 << PinPanHomeSense); // Pan
GPIO_Init(GPIO_PanHomeSense, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = (1 << PinTiltHomeSense); // Tilt
GPIO_Init(GPIO_TiltHomeSense, &GPIO_InitStructure);
// MIC AD
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN ;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Pin = (1 << PinAD);
GPIO_Init(GPIOpinAD, &GPIO_InitStructure);
}
void IoInitial(void)
{
/*--------系统时钟设置 20000 == 50us*/
if (SysTick_Config(SystemCoreClock / 20000))
{
while (1);
}
MemoryRemapConfig();//升级用的?
I2C_Configuration();
Dmx_Config();
AdcInitial();
PFIO_Config();
Panel16v8_Config();
}
我程序的初始化时这样的,一开始板子是刚焊好,没程序的,烧录进去之后,重新烧写就不行了。是不是我增加了