现在在线调试能够main函数了。我在线调试单步运行发现停到disassemly窗口中,按照楼上几位的说法改了一下,又检查了我的硬件就好了。现在我的串口0配置到PB6、PB7后只能接收数据,不能发送数据,不知道你遇到过没?
我的串口0初始化如下:
void USART0_Init(u32 bound)
{
rcu_periph_clock_enable(RCU_AF); //Need!!!!
rcu_periph_clock_enable(RCU_GPIOB);
gpio_pin_remap_config(GPIO_USART0_REMAP,ENABLE);
rcu_periph_clock_enable(RCU_USART0);
//USART0_TX
/* connect port to USARTx_Tx */
gpio_init(GPIOB, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ,GPIO_PIN_6);
/* connect port to USARTx_Rx */
gpio_init(GPIOB, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, GPIO_PIN_7);
gpio_pin_remap_config(GPIO_USART0_REMAP,ENABLE);
usart_deinit (USART0);
/* ÅäÖÃGPIOµÄģʽºÍIO¿Ú */
// GPIO_InitStructure.GPIO_Pin=GPIO_Pin_9;//TX //´®¿ÚÊä³öPB6
// GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
// GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP; //¸´ÓÃÍÆÍìÊä³ö
//// GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP; //¸´ÓÃÍÆÍìÊä³ö
// GPIO_Init(GPIOA,&GPIO_InitStructure); /* ³õʼ»¯´®¿ÚÊäÈëIO */
// GPIO_InitStructure.GPIO_Pin=10;//RX //´®¿ÚÊäÈëPA10
// GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING; //Ä£ÄâÊäÈë
// GPIO_Init(GPIOA,&GPIO_InitStructure); /* ³õʼ»¯GPIO */
//
//USART1 ³õʼ»¯ÉèÖÃ
// USART_InitStructure.USART_BaudRate = bound;//²¨ÌØÂÊÉèÖÃ
// USART_InitStructure.USART_WordLength = USART_WordLength_8b;//×Ö³¤Îª8λÊý¾Ý¸ñʽ
// 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); //³õʼ»¯´®¿Ú1
usart_word_length_set(USART0, USART_WL_8BIT); //×Ö³¤Îª8λÊý¾Ý¸ñʽ
usart_stop_bit_set(USART0, USART_STB_1BIT); //Ò»¸öֹͣλ
usart_parity_config(USART0, USART_PM_NONE); //ÎÞÆæżУÑéλ
usart_baudrate_set(USART0, bound);
usart_receive_config(USART0, USART_RECEIVE_ENABLE);
usart_transmit_config(USART0, USART_TRANSMIT_ENABLE);
nvic_irq_enable(USART0_IRQn,0,0);
usart_interrupt_enable(USART0, USART_INT_RBNE); //read data buffer not empty interrupt and overrun error interrupt
// usart_interrupt_enable(USART0, USART_INT_TBE);
usart_enable(USART0);
// USART_Cmd(USART1, ENABLE); //ʹÄÜ´®¿Ú1
//
// USART_ClearFlag(USART1, USART_FLAG_TC);
//
// USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);//¿ªÆôÏà¹ØÖжÏ
// //Usart1 NVIC ÅäÖÃ
// NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;//´®¿Ú1ÖжÏͨµÀ
// NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3;//ÇÀÕ¼ÓÅÏȼ¶3
// NVIC_InitStructure.NVIC_IRQChannelSubPriority =3; //×ÓÓÅÏȼ¶3
// NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQͨµÀʹÄÜ
// NVIC_Init(&NVIC_InitStructure); //¸ù¾ÝÖ¸¶¨µÄ²ÎÊý³õʼ»¯VIC¼Ä´æÆ÷¡¢
} |