完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
电子发烧友论坛|
我试图将USART1与stm8l连接起来。但是我遇到的问题是,无论我分配给USART1_DR的值是什么,它总是取值0xff而不是matte是什么。我的代码如下:
(我正在使用16 MHz内部时钟并已完成初始化) USART1_CR1 = 0x00; USART1_CR1 = 0x0C; USART1_CR3 = 0x0F; USART1_BRR2 = 0x0A; USART1_BRR1 = 0x08; USART1_DR ='HELLO'; (仍显示DR寄存器中的值0xff) 以上来自于谷歌翻译 以下为原文 I am trying to interface USART1 with the stm8l. However I am getting a problem that whatever the value I assign to the USART1_DR , it always takes the value of 0xff no matte what. my code is as follows: (I am working with a 16 MHz internal clock and have already done the initialisation) USART1_CR1 = 0x00; USART1_CR1 = 0x0C; USART1_CR3 = 0x0F; USART1_BRR2 = 0x0A; USART1_BRR1 = 0x08; USART1_DR = 'HELLO'; (still shows the value 0xff in the DR register) |
|
相关推荐
8个回答
|
|
|
你好Abhishek,
我没有对你的代码进行全面审查,但至少有一行看起来不对我。 USART1_DR寄存器只有一个字节,所以一次不能写入五个字节,就像你一样。在你的情况下,如果你试图写'HELLO'到这个寄存器,我希望你只发送最后一个字节('O',所以十六进制0x4F)。 发送五个字节的正确方法是逐字节发送它们,你需要确保在上一个字节已经发送之后开始发送下一个字节,例如像这样: 如果您想要完整的应用程序,您可以使用UART配置的最小代码,我在下面附加+数据传输代码。我检查了一下,它工作正常。引脚PC3在此用作UART_TX线。 最好的祝福 Szymon 以上来自于谷歌翻译 以下为原文 Hello Abhishek, I didn't make a full review of your code, but at least one line looks wrong to me. USART1_DR register has only one byte, so it is not possible to write to it five bytes in one time, like you did. In your case if you try to write 'HELLO' to this register, I would expect you will send just the last byte ('O', so hexadecimal 0x4F). Proper way to send five bytes is to send them byte by byte and you need to make sure, that you start sending next byte after previous one is already sent, so for example like this: If you would like to evalaute complete application, you can use the minimum code for UART configuration, which I attach below + the code for data transmission. I checked it on my side and it is working fine. Pin PC3 is used here as a UART_TX line. Best regards Szymon |
|
|
|
|
|
我尝试编译你的代码但不幸的是问题仍然存在
无论字符是什么,USART_DR寄存器只占用0xff值。 我正在附上截图。我也不明白的目的 line while(!(USART1-&gt; SR&amp; USART_SR_TC))。至于有什么不同 在我写的条件和你的条件之间。 问候, 阿布舍克 2017年6月21日星期三下午1:59,Szymon Panecki&lt; 以上来自于谷歌翻译 以下为原文 I tried compiling your code but unfortunately the problem still persists that the USART_DR register takes only 0xff value whatever the character. I'm attaching a screenshot. Also I didn't understand the purpose of the line while(!(USART1->SR & USART_SR_TC)) . As in what's the difference between the condition I had written and yours. Regards, Abhishek On Wed, Jun 21, 2017 at 1:59 PM, Szymon Panecki < |
|
|
|
|
|
上述代码的时钟配置(用于设置波特率)怎么样?
以上来自于谷歌翻译 以下为原文 What about the clock configuration(for setting the baud rate) for the above code ? |
|
|
|
|
|
你好Abhishek,
关于 :此行检查USART传输是否完成。建议使用它,因为在这种情况下你确定已发送了前一个字节,你可以写入新数据进行注册,这样你就不会遇到新数据在USART发送之前覆盖旧数据的情况。 关于我的应用程序中的时钟配置:如您所见,我没有配置时钟域,这意味着MCU使用默认设置:系统时钟等于HSI / 8 = 16 MHz / 8 = 2 MHz。 请在我的代码中找到附带的STVD项目。你能试试看吗?我在STM8L Discovery试剂盒(STM8L152C6T6)上进行了测试。 问候 Szymon 以上来自于谷歌翻译 以下为原文 Hello Abhishek, Regarding : this line checks if USART transfer is complete. It is recommended to use it, because with this condition you are sure, that previous byte was sent and you can write new data to register, so you will not face the situation that new data overwrites old one before it is sent by USART. Regarding clock configuration in my application: as you can see I don't configure the clock domain, which means that MCU uses default settings: system clock is equal to HSI / 8 = 16 MHz / 8 = 2 MHz. Please find attached a STVD project with my code. Could you plese try it? I tested it on STM8L Discovery kit (STM8L152C6T6). Regards Szymon |
|
|
|
|
|
好的,这是原因,但我仍然得到了错误的价值
USART_DR注册 2017年6月21日星期三下午3:55,Szymon Panecki&lt; 以上来自于谷歌翻译 以下为原文 Okay that's the reason but I'm still getting the wrong value in the USART_DR register On Wed, Jun 21, 2017 at 3:55 PM, Szymon Panecki < |
|
|
|
|
|
这是您自己的代码的调试。为什么它适合你而不适合我?
以上来自于谷歌翻译 以下为原文 This is debugging of your own code. Why is it working for you and not for me? |
|
|
|
|
|
你不能像那样检查DR,它不像存储单元那样。除非您在外部回输输出,否则RECEIVE寄存器不会反映您在TRANSMIT寄存器中的内容。
等待寄存器为空,发送'U'字符,循环执行此操作,将示波器探针连接到TX引脚并查看信号,检查位时序等。 以上来自于谷歌翻译 以下为原文 You can't inspect the DR like that, it doesn't act like a memory cell. Unless you loop-back the output externally, the RECEIVE register is not going to reflect what you put in the TRANSMIT register. Wait for the register to be empty, and send a 'U' character, do this in a loop, attach a scope probe to the TX pin and review the signalling, check bit timing, etc. |
|
|
|
|
|
你好克莱夫,我有点像业余爱好者,所以不能真正跟随最后一部分?你能详细说明吗?
以上来自于谷歌翻译 以下为原文 Hello Clive, I'm a bit of an amateur so couldn't really follow the last part? Could you please elaborate? |
|
|
|
|
只有小组成员才能发言,加入小组>>
stm32mp157的异核通信的rpmsg_sdb的m4固件和a7驱动该如何编写?
1453 浏览 0 评论
stm32f103用freertos对一个采样率为1kHz的传感器,进行采样,数据出差
1502 浏览 0 评论
请教:在使用UDE STK时,单片机使用SPC560D30L1,在配置文件怎么设置或选择?里面只有SPC560D40的选项
3649 浏览 1 评论
3842 浏览 1 评论
请问是否有通过UART连接的两个微处理器之间实现双向值交换的方法?
2461 浏览 1 评论
STM32H7打开DCache后,出现了串口接收信息为空的现象,是哪里出了问题?
727浏览 5评论
用NANO STM32F103RBT6的开发板烧录不了是哪里出了问题?
658浏览 5评论
710浏览 5评论
外部中断触发类型为双边沿触发,进入中断回调后有什么办法判断该边沿是上升沿还是下降沿?
940浏览 5评论
STM32L071CBT6低温环境下无法正常工作是什么原因引起的?
745浏览 5评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-1 20:58 , Processed in 1.041931 second(s), Total 86, Slave 69 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
1837