stm32 的烧录及串口程序问题
首先,stm32分了ram和flash烧录程序,我刚入手,不知道到底我现在是烧录到ran中还是flash中,然后不使用调试方式的时候程序是不是要烧到flash中去?
另外我用了3.5的固件库来写串口程序,调试了很多天都没办法实现发送,接收,不知道哪里有出错,我检查了很久的。求大神指导啦!
以下是我串口的代码
void USART_CFG(void)
{
USART_InitTypeDef USART_InitStruct;
USART_ClockInitTypeDef USART_ClockInitStruct;
USART_ClockInitStruct.USART_Clock =USART_Clock_Disable;
USART_ClockInitStruct.USART_CPOL = USART_CPOL_Low;
USART_ClockInitStruct.USART_CPHA = USART_CPHA_2Edge;
USART_ClockInitStruct.USART_LastBit = USART_LastBit_Disable;
USART_ClockInit(USART1,&USART_ClockInitStruct);
USART_InitStruct.USART_BaudRate = 9600;
USART_InitStruct.USART_WordLength = USART_WordLength_8b;
USART_InitStruct.USART_StopBits = USART_StopBits_1;
USART_InitStruct.USART_Parity = USART_Parity_No ;//奇偶校验
USART_InitStruct.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_InitStruct.USART_HardwareFlowControl = USART_HardwareFlowControl_None; //硬件流控制模式使能还是失能(即使用RTS/CTS(请求发送/清除发送)流控制)
USART_Init(USART1, &USART_InitStruct);
USART_ITConfig(USART1,USART_IT_TXE,ENABLE);
GPIO_SetBits(GPIOF, GPIO_Pin_6);
//USART_ITConfig (USART1,USART_IT_RXNE,ENABLE);
// USART_ClearFlag(USART1,USART_FLAG_TC);
//USART_Cmd(USART1,ENABLE);
}
void RCC_CFG(void)
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1|RCC_APB2Periph_GPIOF, ENABLE);
}
void GPIO_CFG(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
//TX
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStruct);
//RX
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStruct);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOF, &GPIO_InitStruct);
}
void NVIC_CFG(void)
{
NVIC_InitTypeDef NVIC_InitStruct;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
NVIC_InitStruct.NVIC_IRQChannel=USART1_IRQn;
NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority=0;
NVIC_InitStruct.NVIC_IRQChannelSubPriority=0;
NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStruct);
}
int main(void)
{
RCC_CFG();
GPIO_CFG();
NVIC_CFG();
USART_CFG();
USART_Cmd(USART1,ENABLE);
GPIO_SetBits(GPIOF, GPIO_Pin_7);
//GPIO_SetBits(GPIOF, GPIO_Pin_8);
while(1)
{
USART_SendData(USART1, 0x11);
GPIO_SetBits(GPIOF, GPIO_Pin_8);
}
}