金牌会员
- 积分
- 1547
- 金钱
- 1547
- 注册时间
- 2014-7-11
- 在线时间
- 256 小时
|
3金钱
本人现在用STM32F407寄存器版本进行串口通讯,从串口1-6通讯都失败,请问怎么回事
//------------------------------------------------------------------------------------------------------------------
#define UART5_TX_GPIO_PORT GPIOC
#define UART5_TX_GPIO_PIN SYS_GPIO_PIN12
#define UART5_TX_GPIO_AF 7 /* AF1|ÄüÑ¡Ôñ */
#define UART5_TX_GPIO_CLK_ENABLE() do{ RCC->AHB1ENR |= 1 << 2; }while(0) /* PA¿úê±Öóê1Äü */
#define UART5_RX_GPIO_PORT GPIOD
#define UART5_RX_GPIO_PIN SYS_GPIO_PIN2
#define UART5_RX_GPIO_AF 7 /* AF1|ÄüÑ¡Ôñ */
#define UART5_RX_GPIO_CLK_ENABLE() do{ RCC->AHB1ENR |= 1 << 3; }while(0) /* PA¿úê±Öóê1Äü */
#define UART5_UX UART5
#define UART5_UX_IRQn UART5_IRQn
#define UART5_UX_IRQHandler UART5_IRQHandler
#define UART5_UX_CLK_ENABLE() do{ RCC->APB1ENR |= 1 << 20; }while(0) /* USART1 ê±Öóê1Äü */
void uart5_init(uint32_t sclk, uint32_t baudrate)
{
uint32_t temp;
/* IO ¼° ê±ÖóÅäÖÃ */
UART5_TX_GPIO_CLK_ENABLE(); /* ê1Äü′®¿úTX½Åê±Öó */
UART5_RX_GPIO_CLK_ENABLE(); /* ê1Äü′®¿úRX½Åê±Öó */
UART5_UX_CLK_ENABLE(); /* ê1Äü′®¿úê±Öó */
sys_gpio_set(UART5_TX_GPIO_PORT, UART5_TX_GPIO_PIN,
SYS_GPIO_MODE_AF, SYS_GPIO_OTYPE_PP, SYS_GPIO_SPEED_MID, SYS_GPIO_PUPD_PU); /* ′®¿úTX½Å Ä£ê½éèÖà */
sys_gpio_set(UART5_RX_GPIO_PORT, UART5_RX_GPIO_PIN,
SYS_GPIO_MODE_AF, SYS_GPIO_OTYPE_PP, SYS_GPIO_SPEED_MID, SYS_GPIO_PUPD_PU); /* ′®¿úRX½Å Ä£ê½éèÖà */
sys_gpio_af_set(GPIOC, UART5_TX_GPIO_PIN, UART5_TX_GPIO_AF); /* TX½Å ¸′óÃ1|ÄüÑ¡Ôñ, ±ØDëéèÖÃÕyè· */
sys_gpio_af_set(GPIOD, UART5_RX_GPIO_PIN, UART5_RX_GPIO_AF); /* RX½Å ¸′óÃ1|ÄüÑ¡Ôñ, ±ØDëéèÖÃÕyè· */
temp = (sclk * 1000000 + baudrate / 2) / baudrate; /* μÃμ½USARTDIV@OVER8 = 0, 2éóÃËÄéáÎåèë¼ÆËã */
/* 2¨ìØÂêéèÖà */
UART5_UX->BRR = temp; /* 2¨ìØÂêéèÖÃ@OVER8 = 0 */
UART5_UX->CR1 = 0; /* ÇåáãCR1¼Ä′æÆ÷ */
UART5_UX->CR1 |= 0 << 12; /* éèÖÃM = 0, Ñ¡Ôñ8λ×Ö3¤ */
UART5_UX->CR1 |= 0 << 15; /* éèÖÃOVER8 = 0, 16±¶1y2éÑù */
UART5_UX->CR1 |= 1 << 3; /* ′®¿ú·¢Ëíê1Äü */
/* ê1Äü½óêÕÖD¶Ï */
UART5_UX->CR1 |= 1 << 2; /* ′®¿ú½óêÕê1Äü */
UART5_UX->CR1 |= 1 << 5; /* ½óêÕ»o3åÇø·Ç¿ÕÖD¶Ïê1Äü */
sys_nvic_init(3, 3, UART5_UX_IRQn, 2); /* ×é2£¬×îμíóÅÏ輶 */
UART5_UX->CR1 |= 1 << 13; /* ′®¿úê1Äü */
}
void UART5_UX_IRQHandler(void)
{
uint8_t rxdata;
if (UART5_UX->SR & (1 << 5)) /* ½óêÕμ½êy¾Y */
{
rxdata = UART5_UX->DR;
uart5_rx_buf[uart5_rx_counter] = rxdata; /* ′æ′¢êy¾Yμ½ g_usart_rx_buf */
uart5_rx_counter++;
}
}
|
|