历史上的今天
今天是:2024年09月09日(星期一)
2019年09月09日 | 关于STM32F407ZGT6的一些知识小结及串口1程序
2019-09-09 来源:eefocus
一、关于STM32F4在通过串口通信的时候乱码问题
1.刚开始弄得时候,以为和stm32一样配置完串口之后就可以用了,结果后面发现串口打印出来的东西全是乱码。后面发现是STM32F4的固件库中使用的频率是25Mhz,而板子上的外部晶振是8Mhz的。因此需要去固件库的stm32f4xx.h中把HSE_VALUE改成8Mhz就可以了。
2.还有一种问题是,如果使用的是电平转换的问题。要直接从芯片的引脚进行通信的话,可以直接用一个TTL下载器直接相连,如CH340;如果板子上带有MAX3232芯片的电平转换,要通过DB9插口线转RS232电平为TTL电平然后和电脑相连。
#include "stm32f4xx.h"
#include "stdio.h"
#include "uart.h"
void nvic_config(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
/* NVIC configuration */
/* Configure the Priority Group to 2 bits */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
/* Enable the USARTx Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
/**
* @brief Main program
* @param None
* @retval None
*/
int main(void)
{
nvic_config();
uart_init();
while(1)
{
printf("hello!welcome to F4..1H.rn ");
}
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t* file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %drn", file, line) */
/* Infinite loop */
while (1)
{
}
}
#endif
/**
* @}
*/
/**
* @}
*/
/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "uart.h"
#include "stdio.h"
void uart_init(void)
{
USART_InitTypeDef USART_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
/* 开启GPIO_B的时钟 */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
/* 开启串口1的时钟 */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
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_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_USART1);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_USART1);
USART_InitStructure.USART_BaudRate = 115200;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
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_Tx | USART_Mode_Rx;
USART_Init(USART1, &USART_InitStructure);
/* 使能串口1 */
USART_Cmd(USART1, ENABLE);
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
}
int fputc(int ch, FILE *f)
{
/* Place your implementation of fputc here */
/* e.g. write a character to the USART */
USART_SendData(USART1, (uint8_t) ch);
/* Loop until the end of transmission */
while (USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET)
{}
return ch;
}
史海拾趣
|
前段时间买了2440开发板也没怎么搞,惭愧:$ 最近没啥其它事情就好好啃啃吧,哎……没什么基础啊,先欣赏下别人的东西吧 【mini2440开发板实现国际象棋人机对弈 】 我在机子上跑了一下,好像不太能跟电脑对弈啊,不知道哪个地方还有问题 ...… 查看全部问答> |
|
VC如何发彩信,已经实现ATDT*99***1#这一步了,下一步应该是什么,内容打包?如果打包? VC如何发彩信,已经实现ATDT*99***1#这一步了,下一步应该是什么,内容打包?如果打包? ATE AT+CMGF=0 AT+CIMI AT+CIMI获得IMSI IMSI 国际移动用户识别码(IMSI) international mobile subscriber identity 国际上为唯一识别 ...… 查看全部问答> |
|
/*进行SAA7121H的初始化*/ GPIO_RSET(GPVAL,0x0); addrI2C = 0xB8 >>1; /*选择第0路的I2C的地址*/ /*将第0路的视频输入口的数据口设为高阻状态, 使能SCLK,将第27脚设为输入*/ _IIC_write(hSeeddm642i2 ...… 查看全部问答> |
|
问题是这样的:我用flash烧写了一个控制电机的程序,不能运行,就把代码改了一下,再进行烧程序的时候就烧不进去啦,我也没有动“lock”和密码(在flash烧写的时候一直很小心的),怎么会锁住呢?很是不解。请EEWORLD老师和各位高手解答一下,谢谢 ...… 查看全部问答> |
|
各位高手,小弟近日在学习关于修改BSP的内容,有一种想法,设置多个引导行,然后在系统启动时按照需要选择相应的引导顺序,然后将config.h中的引导行 #define DEFAULT_BOOT_LINE \\ \"fd=0,0(0,0)host:/fd0/vxWorks.st h=90.0.0.3 e=90.0.0.50 u=ta ...… 查看全部问答> |
|
我是一个只有初中毕业没有读过多少书的人从小就爱好无线电记得很小的时候当通讯兵的父亲带回来几本电子方面的书籍从此就迷上了无线电那种痴迷程度决不亚于现在的小孩迷恋游戏机至今仍然清楚的记得曾经因为装成功一台6管收音机而兴奋的几天几夜没睡 ...… 查看全部问答> |




