完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
你好,
我昨天花了整整一天再次尝试编译示例代码(UM0884)。出于某种原因,我很难理解作为一个有用的例子编写的代码,似乎有太多的头文件和源文件只需打开RS232串行通信... 过去每次我都想在PIC,摩托罗拉,NEC,Atmel等处理器上使用串行通信,这个过程非常简单明了,经过一些波特率的调整后可以在一个小时左右的时间内完成工作。 ... 我是否需要使用所有头文件和源文件来启动和运行基本通信,或者我可以直接打开Uart 2吗? 基本上我要问的是我可以这样做吗? void UART2_Init(void) { UART2_CR1 = 0x02; // 1个起始位,8个数据,奇校验 UART2_CR3 = 0x20; // 2停止比特 UART2_BRR2 = 0x02; // 波特率 UART2_BRR1 = 0x68; // 波特率 UART2_CR2 = 0x80; //将TEN位置1以启用发送器模式 //设置一个标志,以便在UART_SR中将TC设置为1 } 由于这是我一直用来初始化串行通信的方式,我还能这样做吗? 我理解要说出其他命令是必需的,但我已经明白应该怎么做了...... 以上来自于谷歌翻译 以下为原文 Hi there, I spent the entire day yesterday trying yet again to get the sample code (UM0884) to compile. For some reason I am struggling to understand the code that has been written as a worked example, there seems to be way too many header files and source files required just to turn on the RS232 Serial Comms... In the past everytime I wanted to use the serial comms on processors such as the PIC, Motorola, NEC, Atmel the process was fairly simple and straightforward and could be made to work in an hour or so, after some tweaking of the baud rate etc... Do I need to use all the headerfiles and source files to get basic comms up and running or can I directly turn on the Uart 2 directly? Basically what I am asking is can I do it like this? void UART2_Init (void) { UART2_CR1 = 0x02; // 1 start bit, 8 data, odd parity UART2_CR3 = 0x20; // 2 Stop Bits UART2_BRR2 = 0x02; // Baud Rate UART2_BRR1 = 0x68; // Baud Rate UART2_CR2 = 0x80; // Set TEN bit to Enable Transmitter Mode // set a flag to watch for TC to be set to 1 in UART_SR } As this is how I always used to initialise the Serial Comms, can I still do it this way? I understand to talk out other commands are required, but I already understand how that should be done... |
|
相关推荐
4个回答
|
|
Hy Icarus,
对不起,这个迟到的回复。 是的,您可以使用这种方式设置UART 2而不是使用库函数。您只需在项目中包含“stm8s.h”文件并使用已定义的UART2结构 例子: ''UART2-> CR1 = 0x02;''// 1个起始位,8个数据,奇校验 如果您熟悉微控制器,那么最好使用这种编程方式而不是库。 顺便说一句,我们已经开发了一个使用Hyperterminal + temp传感器的示例(没有库;-))。此示例尚未发布,但我可以为您提供我们的来源。 RGDS 格罗姆 以上来自于谷歌翻译 以下为原文 Hy Icarus, Sorry for this late reply. Yes you can use this way to setup the UART 2 instead of using the library function. You just have to include ''stm8s.h'' file in your project and use the defined UART2 struct example : ''UART2->CR1 = 0x02;'' // 1 start bit, 8 data, odd parity If you are familiar with microcontrolers , It's for sure better to use this way of programing instead of Libraries . By the way , We have developed by our side one example (without libraries ;-) ) using Hyperterminal + temp sensor. this example is not yet published but I can provide you our sources. Rgds Grom |
|
|
|
你好Grom,
我想获得你的UART + A / D(温度传感器)示例,如果不介意与我分享。 我花了很多时间来努力让Cosmic / Raisonance工具集起作用;昨晚(我的时间凌晨3点),Cosmic的某个人对我说话很糟糕,告诉我们必须做些什么来让他们的链接器能够处理超过256字节的数据。我已经设法将STM示例编译(所有使用非常少的数据,因此仅当我创建一个数组以保存一些A / D样本时才显示数据大小限制),但可以使用您的示例(如果可用)。 还有一个问题;我使用STVD环境;如果我进入工具/选项/工具集,然后选择工具集(Cosmic或Raisonance),指向可执行文件的位置(在bin条目中),我总是收到警告''工具集根路径至少没有指定其中一个受支持的工具集。确认.....''。有了Cosmic,我点击确定上帝知道什么,编译/链接似乎工作正常。有了Raisonance,我打了同样的OK,它告诉了我很多次同样的事情(即警告不会消失),但最终确实如此。它似乎也编译/链接确定。 你能理解这一切吗? 我发现整个软件包(STVD +编译器/链接器)很糟糕。我在这个主板上花了这么多时间的唯一原因是因为低价格和主板上的后台调试器。但即便如此,当我将近100名学生被要求使用这些工具进行编程时,我担心会发生什么,我将成为他们挫败感的避雷针。 无论如何,如果你不介意分享你的代码,我想从中学习。我不知道您是否可以将其作为附件发布到此主板上,如果没有,请发送电子邮件至fischerd@idirect.ca。 谢谢 丹尼尔 以上来自于谷歌翻译 以下为原文 Hello Grom, I would like to get your UART + A/D (temp sensor) example, if would not mind sharing it with me. I have been spending tons of time fighting with trying to get the Cosmic / Raisonance toolsets to work; last night (3AM my time), someone at Cosmic took pitty on me and told us what must be done to get their linker to be able to handle more than 256 bytes of data. I have managed to get the STM examples to compile (all use very little data, so the data size limitation showed up only when I created an array to save some A/D samples into), but could use your example if available. One more question; I use the STVD environment; if I go into Tools/Options/Toolset, then select the toolset (Cosmic or Raisonance), point to where the executables are (in the bin entry), I always get a warning about ''Toolset rootpaths have not been specified for at least one of the supported toolsets. Confirm.....''. With Cosmic, I hit ok to confirm god knows what, and the compile/link seems to work ok. With Raisonance, I hit the same OK, it tells me many more times the same thing (ie the warning does not go away), but eventually it does. It also seems to compile / link ok. Can you make any sense of all this? I find the whole software package (STVD + compiler/linker) terrible. The only reason for my spending so much time on this board, is because of the low price + the background debugger which comes on the board. But even then, I dread what is going to happen when my almost 100 students will be asked to program using these tools, and I will become the lightning rod for their frustration. Anyway, if you do not mind sharing your code, I would like to learn from it. I do not know if you can post it as an attachment to this board, if not could you please email it to me at fischerd@idirect.ca. Thanks Daniel |
|
|
|
嗨格罗姆,
我读到了关于超高温温度代码的信息,并希望自己节省大量时间,所以如果你能让我知道如何找到副本,那将非常有帮助。 我在交换tx和rx线后运行Hyperterminal示例。 一个简单的开始示例是一个好主意只有9600 8N1并没有所有的装饰。 干杯 科尔克尔 以上来自于谷歌翻译 以下为原文 Hi Grom, I read about the hyperterminal temperature code and would like to save myself a lot of time working it all out, so if you could let me know how to find a copy it would be very helpfull. I have just got Hyperterminal example to run after swapping the tx and rx lines. A simple start example would be a good idea with just 9600 8N1 and without all the frills. Cheers Col Kerr |
|
|
|
伊卡洛斯,
我在Discovery上尝试了这些init代码。他们工作。但是,我过去只有汇编代码。你可以用C写它们。 MOV PD_DDR,#$ 1; LED,SWIM MOV PD_CR1,#$ 3;引体向上 MOV PD_CR2,#$ 1;速度 MOV UARTBD2,#$ 00; 9600波特 MOV UARTBD1,#$ 0d; 9600波特 MOV UARTCR1,#$ 06; 8个数据位,无奇偶校验 MOV UARTCR3,#$ 00; 1个停止位 MOV UARTCR2,#$ 0C;启用tx& RX 受到: QKEY: BTJF UARTSR,#5,QKEY;检查状态 LD A,UARTDR;在A中获取char 发送: 输出:BTJF UARTSR,#7,OUTPUT;循环直到tdre LD UARTDR,A;发送A. 祝你好运。 婷。 顺便说一句,我的FORTH翻译正在工作。如果您有兴趣,请发送电子邮件给我:ting@offete.com。 以上来自于谷歌翻译 以下为原文 Icarus, I tried these init code on Discovery. They worked. However, I past only assembly code. You can write them in C. MOV PD_DDR,#$1 ; LED, SWIM MOV PD_CR1,#$3 ; pullups MOV PD_CR2,#$1 ; speed MOV UARTBD2,#$00 ;9600 baud MOV UARTBD1,#$0d ;9600 baud MOV UARTCR1,#$06 ;8 data bits, no parity MOV UARTCR3,#$00 ;1 stop bit MOV UARTCR2,#$0C ;enable tx & rx To receive: QKEY: BTJF UARTSR,#5,QKEY ;check status LD A,UARTDR ;get char in A To transmit: OUTPUT: BTJF UARTSR,#7,OUTPUT ;loop until tdre LD UARTDR,A ;send A Good luck. Ting. By the way, my FORTH interpreter is working. If you are interested, send an email to me: ting@offete.com. |
|
|
|
只有小组成员才能发言,加入小组>>
请教:在使用UDE STK时,单片机使用SPC560D30L1,在配置文件怎么设置或选择?里面只有SPC560D40的选项
2720 浏览 1 评论
3236 浏览 1 评论
请问是否有通过UART连接的两个微处理器之间实现双向值交换的方法?
1807 浏览 1 评论
3645 浏览 6 评论
6033 浏览 21 评论
1334浏览 4评论
209浏览 3评论
196浏览 3评论
对H747I-DISCO写程序时将CN2的st-link复用为usart1,再次烧录时无法检测到stlink怎么解决?
350浏览 2评论
STM32G474RE芯片只是串口发个数据就发烫严重是怎么回事?
442浏览 2评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-21 09:37 , Processed in 1.266179 second(s), Total 82, Slave 66 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号