OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 3553|回复: 4

求个STM32F207的串口的测试程序啊

[复制链接]

1

主题

2

帖子

0

精华

新手入门

积分
9
金钱
9
注册时间
2016-7-27
在线时间
0 小时
发表于 2016-7-27 08:34:52 | 显示全部楼层 |阅读模式
1金钱
如题 求个实测能用的串口发送接收程序~~~~~~~~~~~~~~~~~~~~~~~

最佳答案

查看完整内容[请看2#楼]

这是以前用F205做的产品,串口初始化部分。 F207没用过,但可以断定是一样的。 [mw_shl_code=applescript,true]/*--------------------------------------------*/ //Configure USART1, 9600baud, 1-bit start, 8-bit data, 1-bit stop, no parity. RCC -> AHB1ENR |= 0x00000001; //Enable clock of GPIOA. RCC -> APB2ENR |= 0x00000010; //Enable clock of USART1. GPIOA -> MODER |= 0x00280000; //PA10 ...
正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

58

主题

6294

帖子

1

精华

资深版主

Rank: 8Rank: 8

积分
11564
金钱
11564
注册时间
2014-4-1
在线时间
1319 小时
发表于 2016-7-27 08:34:53 | 显示全部楼层


这是以前用F205做的产品,串口初始化部分。
F207没用过,但可以断定是一样的。



[mw_shl_code=applescript,true]/*--------------------------------------------*/
//Configure USART1, 9600baud, 1-bit start, 8-bit data, 1-bit stop, no parity.
RCC -> AHB1ENR |= 0x00000001;                        //Enable clock of GPIOA.
RCC -> APB2ENR |= 0x00000010;                        //Enable clock of USART1.
GPIOA -> MODER |= 0x00280000;                        //PA10, PA9 as AF.
GPIOA -> AFR[1] |= 0x00000770;                //PA10, PA9 as AF7.

USART1 -> BRR = 0x0000186A;                        // BRR = 60MHz / (2*8*9600).
                                                        //        NOTE: the clock frequency of APB2 is different from APB1!
USART1 -> CR1 |= 0x0000200C;                        //oversampling by 16; Enable USART.
                                                        // enable Tx; enable Rx.

i=USART1 -> SR;                                        //Software sequence to clear hardware flags, then avoid the 1st interrupt.
i=USART1 -> DR;
USART1 -> DR = i;

for        ( i=0; i<5; i++ )
        {                                                //waiting until the USART is ready.
        if        ( USART1 -> SR & 0x00000040 )
                { i=5; }
        else
                { i=0; }
        }
USART1 -> SR &= 0xFFFFFFBF;

USART1 -> CR1 |= 0x00000060;                        //Enable TCIE and RXNEIE.
/*--------------------------------------------*/
//Configure USART2, 9600baud, 1-bit start, 8-bit data, 1-bit stop, no parity.
RCC -> AHB1ENR |= 0x00000001;                        //Enable clock of GPIOA.
RCC -> APB1ENR |= 0x00020000;                        //Enable clock of USART2.
GPIOA -> MODER |= 0x000000A0;                        //PA3, PA2 as AF.
GPIOA -> AFR[0] |= 0x00007700;                //PA3, PA2 as AF7.

USART2 -> BRR = 0x00000C35;                        // BRR = 30MHz / (2*8*9600).
USART2 -> CR1 |= 0x0000200C;                        //oversampling by 16; Enable USART.
                                                        // enable Tx; enable Rx.

i=USART2 -> SR;                                        //Software sequence to clear hardware flags, then avoid the 1st interrupt.
i=USART2 -> DR;
USART2 -> DR = i;

for        ( i=0; i<5; i++ )
        {                                                //waiting until the USART is ready.
        if        ( USART2 -> SR & 0x00000040 )
                { i=5; }
        else
                { i=0; }
        }
USART2 -> SR &= 0xFFFFFFBF;

USART2 -> CR1 |= 0x00000060;                        //Enable TCIE and RXNEIE.
/*--------------------------------------------*/
//Configure USART3, 9600baud, 1-bit start, 8-bit data, 1-bit stop, no parity.
RCC -> AHB1ENR |= 0x00000002;                        //Enable clock of GPIOB.
RCC -> APB1ENR |= 0x00040000;                        //Enable clock of USART3.
GPIOB -> MODER |= 0x00A00000;                        //PB11, PB10 as AF.
GPIOB -> AFR[1] |= 0x00007700;                //PB11, PB10 as AF7.

USART3 -> BRR = 0x00000C35;                        // BRR = 30MHz / (2*8*9600).
USART3 -> CR1 |= 0x0000200C;                        //oversampling by 16; Enable USART.
                                                        // enable Tx; enable Rx.

i=USART3 -> SR;                                        //Software sequence to clear hardware flags, then avoid the 1st interrupt.
i=USART3 -> DR;
USART3 -> DR = i;

for        ( i=0; i<5; i++ )
        {                                                //waiting until the USART is ready.
        if        ( USART3 -> SR & 0x00000040 )
                { i=5; }
        else
                { i=0; }
        }
USART3 -> SR &= 0xFFFFFFBF;

USART3 -> CR1 |= 0x00000060;                        //Enable TCIE and RXNEIE.
/*--------------------------------------------*/
//Configure UART4, 9600baud, 1-bit start, 8-bit data, 1-bit stop, no parity.
RCC -> AHB1ENR |= 0x00000001;                        //Enable clock of GPIOA.
RCC -> APB1ENR |= 0x00080000;                        //Enable clock of USART4.
GPIOA -> MODER |= 0x00000002;                        //PA0 as AF.
GPIOA -> AFR[0] |= 0x00000008;                //PA0 as AF8.

UART4 -> BRR = 0x00000C35;                        // BRR = 30MHz / (2*8*9600).
UART4 -> CR1 |= 0x00002008;                        //oversampling by 16; Enable USART.
                                                        // enable Tx only.

i=UART4 -> SR;                                        //Software sequence to clear hardware flags, then avoid the 1st interrupt.
i=UART4 -> DR;
UART4 -> DR = i;

for        ( i=0; i<5; i++ )
        {                                                //waiting until the USART is ready.
        if        ( UART4 -> SR & 0x00000040 )
                { i=5; }
        else
                { i=0; }
        }
UART4 -> SR &= 0xFFFFFFBF;

UART4 -> CR1 |= 0x00000040;                        //Enable TCIE only.
/*--------------------------------------------*/
[/mw_shl_code]




回复

使用道具 举报

58

主题

6294

帖子

1

精华

资深版主

Rank: 8Rank: 8

积分
11564
金钱
11564
注册时间
2014-4-1
在线时间
1319 小时
发表于 2016-7-27 09:04:08 | 显示全部楼层

贴上去的格式全乱了,
原来的注释都是对齐的,很漂亮。

我开发F407也是用这代码,完全复制过去。


回复

使用道具 举报

1

主题

2

帖子

0

精华

新手入门

积分
9
金钱
9
注册时间
2016-7-27
在线时间
0 小时
 楼主| 发表于 2016-7-27 09:22:01 | 显示全部楼层
xuande 发表于 2016-7-27 09:04
贴上去的格式全乱了,
原来的注释都是对齐的,很漂亮。

3Q   能用=-=
回复

使用道具 举报

58

主题

6294

帖子

1

精华

资深版主

Rank: 8Rank: 8

积分
11564
金钱
11564
注册时间
2014-4-1
在线时间
1319 小时
发表于 2016-7-27 09:25:57 | 显示全部楼层


这么快就测试了?


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-7-2 12:01

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表