ST意法半导体
直播中

廖阿朋

9年用户 1369经验值
私信 关注
[问答]

USART与stm8l连接总是取值0xff

我试图将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)

李振云

2018-9-13 17:28:26
你好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
举报

廖阿朋

2018-9-13 17:36:19
我尝试编译你的代码但不幸的是问题仍然存在
无论字符是什么,USART_DR寄存器只占用0xff值。
我正在附上截图。我也不明白的目的
line while(!(USART1-> SR& USART_SR_TC))。至于有什么不同
在我写的条件和你的条件之间。
问候,
阿布舍克
2017年6月21日星期三下午1:59,Szymon Panecki<

以上来自于谷歌翻译


以下为原文





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 <
举报

廖阿朋

2018-9-13 17:45:02
上述代码的时钟配置(用于设置波特率)怎么样?

以上来自于谷歌翻译


以下为原文




What about the clock configuration(for setting the baud rate) for the above code ?
举报

李振云

2018-9-13 18:02:52
你好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
举报

更多回帖

发帖
×
20
完善资料,
赚取积分