关于stm32f4 discovery USart1(PA9,PA10)正点原子不能正常通信的问题

1.如题所示使用正点原子的usart实验,烧录之后没有反应;使用usart2口可以很正常发收,排除了板子和串口之间的问题。

2.总结一下为什么不可以使用PA9,PA10作为usart1的原因。查看discovery板子原理图发现

两个引脚使用了usb otg功能(百度百科:USB OTG是USB On-The-Go的缩写,是近年发展起来的技术,2001年12月18日由USB Implementers Forum公布,主要应用于各种不同的设备或移动设备间的联接,进行数据交换,特别是PAD、移动电话、消费类设备。)。在板子最下方microUSB附近可以看到u8芯片。以及led7。USART1不仅仅适用PA9和PA10,也使用PB6,PB7口 尝试一下发现可用(可以搜索stm32f407datasheet)。

如果一定要使用PA9/PA10 需要更改几个阻容。具体链接。

http://www.micromouseonline.com/2013/05/05/using-usart1-on-the-stm32f4discovery/

3.自定义收发程序,看一下如果使用pa9/pa10到底会发生什么。




  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是基于STM32F4的串口1(PA9PA10)接MAX3490,实现RS422通信的示例程序: ```c #include "stm32f4xx.h" #include "stm32f4xx_conf.h" UART_HandleTypeDef UART_HandleStruct; void InitializeUART(void) { GPIO_InitTypeDef GPIO_InitStructure; // Enable GPIOA clock RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); // Enable USART1 clock RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); // Configure USART1 Tx (PA9) as alternate function push-pull GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(GPIOA, &GPIO_InitStructure); // Configure USART1 Rx (PA10) as input floating GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_OD; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOA, &GPIO_InitStructure); // Connect USART1 pins to AF7 GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_USART1); GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_USART1); // Configure USART1 UART_HandleStruct.Instance = USART1; UART_HandleStruct.Init.BaudRate = 115200; UART_HandleStruct.Init.WordLength = UART_WORDLENGTH_8B; UART_HandleStruct.Init.StopBits = UART_STOPBITS_1; UART_HandleStruct.Init.Parity = UART_PARITY_NONE; UART_HandleStruct.Init.HwFlowCtl = UART_HWCONTROL_NONE; UART_HandleStruct.Init.Mode = UART_MODE_TX_RX; HAL_UART_Init(&UART_HandleStruct); } void InitializeMAX3490(void) { GPIO_InitTypeDef GPIO_InitStructure; // Enable GPIOB clock RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE); // Configure MAX3490 /RE (PB12) as output push-pull GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(GPIOB, &GPIO_InitStructure); // Configure MAX3490 /DE (PB13) as output push-pull GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(GPIOB, &GPIO_InitStructure); // Enable MAX3490 transmit mode GPIO_ResetBits(GPIOB, GPIO_Pin_12); GPIO_SetBits(GPIOB, GPIO_Pin_13); } int main(void) { uint8_t txData[] = "Hello, world!\r\n"; uint8_t rxData[32]; // Initialize UART and MAX3490 InitializeUART(); InitializeMAX3490(); while(1) { // Send data HAL_UART_Transmit(&UART_HandleStruct, txData, sizeof(txData), HAL_MAX_DELAY); // Switch to receive mode GPIO_SetBits(GPIOB, GPIO_Pin_12); GPIO_ResetBits(GPIOB, GPIO_Pin_13); // Receive data HAL_UART_Receive(&UART_HandleStruct, rxData, sizeof(rxData), HAL_MAX_DELAY); // Switch back to transmit mode GPIO_ResetBits(GPIOB, GPIO_Pin_12); GPIO_SetBits(GPIOB, GPIO_Pin_13); } } ``` 在此示例程序中,我们首先初始化了UART和MAX3490的GPIO口。在主循环中,我们先使用UART发送了一个字符串,然后将MAX3490切换到接收模式,等待接收数据。当接收完成后,再将MAX3490切换回发送模式,继续发送数据。 需要注意的是,MAX3490的DE和RE引脚需要通过GPIO控制,用于切换发送和接收模式。在发送模式下,RE为高电平,DE为低电平;在接收模式下,RE为低电平,DE为高电平。在代码中,我们通过GPIO_SetBits和GPIO_ResetBits函数实现了引脚的电平控制。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值