完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
你好
STM8S001J3 UART通信存在问题。 如果使用PIN8而不重新映射tx,则效果很好。 如果重新映射tx并将其用作PIN5,则以下代码将不起作用。 void UART1_init(void) {CLK-> CKDIVR = 0x00; CLK-> PCKENR1 | = 0x20; //为USART启用时钟 UART1-> BRR2 = 0x0B; // BaudRate 115200 UART1-> BRR1 = 0x08; UART1-> CR2 = 0x2C; // RIEN = ENABLE,TEN = ENABLE,REN = ENABLE } void main(void) { UART1_init(); enableInterrupts(); 而(1); } INTERRUPT_HANDLER(UART1_RX_IRQHandler,18) { if(UART1-> SR& 0x20) { char temp = UART1-> DR; while(!(UART1-> SR& 0x80)); UART1-> DR = temp; } } #STM8S 以上来自于谷歌翻译 以下为原文 Hi STM8S001J3 There is a problem with UART communication. If PIN8 is used without remapping tx, it works well. If tx is remapped and used as PIN5, the following code will not work. void UART1_init(void) { CLK->CKDIVR = 0x00; CLK->PCKENR1 |= 0x20; // enable clock for USART UART1->BRR2 = 0x0B; // BaudRate 115200 UART1->BRR1 = 0x08; UART1->CR2 = 0x2C; // RIEN = ENABLE, TEN = ENABLE, REN = ENABLE } void main(void) { UART1_init(); enableInterrupts(); while(1); } INTERRUPT_HANDLER(UART1_RX_IRQHandler, 18) { if(UART1->SR & 0x20) { char temp = UART1->DR; while(!(UART1->SR & 0x80)); UART1->DR = temp; } } #stm8s |
|
相关推荐
7个回答
|
|
我没有测试你的代码,但是如果它适用于PD5(引脚8)那么它也适用于PA3(引脚5)。但是,我不会在没有重新映射引脚的情况下使用你的代码,或者至少在端口初始化之前添加1s延迟(抛弃完美的芯片可能会令人沮丧)。
您是否忘记设置选项位(OPT2位0:1至0x11)? 我测试了用例 https://github.com/TG9541/stm8ef/releases/download/2.2.20/stm8ef-bin.zip 对我来说,重新映射到PA3(引脚5)的工作原理如数据表中所述。使用eForth控制台和e4thcom设置选项字节的工作方式如下: #require OPT! res MCU:STM8S103 res export OPT2 3 OPT2 OPT! 以上来自于谷歌翻译 以下为原文 I didn't test your code, but if it works with PD5 (pin 8) then it should also work with PA3 (pin 5). However, I wouldn't use your code without remapping the pin, or at least adding a 1s delay before the port initialization (throwing away perfectly good chips can be frustrating). Did you maybe forget to set the option bits (OPT2 bits 0:1 to 0x11)? I tested the use case with the https://github.com/TG9541/stm8ef/releases/download/2.2.20/stm8ef-bin.zip For me the remapping to PA3 (pin 5) works as described in the datasheet.Using the eForth console and e4thcom setting the option bytes works like this: #require OPT! res MCU: STM8S103 res export OPT2 3 OPT2 OPT! |
|
|
|
谢谢您的回复。
选项位使用STVP设置。 AFR1和AFR0已激活。 如果像这样重新映射,RX中断也不起作用。 以上来自于谷歌翻译 以下为原文 Thank you for your reply. The option bit was set using STVP. AFR1 and AFR0 have been activated. If remapping like this, RX interrupt does not work either. |
|
|
|
坦率地说,我根本没有测试中断。我使用2线(半双工),即RX和TX到PA3,进行轮询。
我对PD5上的RX和PA3上的TX进行了一些测试,由于某种原因,它没有接收到数据(TX工作)。如果需要,我可以在以后运行更多测试(我的芯片标记为'8S001 YK719')。 备注:基于STM8S001J3和STM8S003F3 *非常相似的假设,OPT2中的AFR0 = AFR1 = 1设置是我可以在数据表和erratas中发现的芯片之间唯一的功能差异。据我所知,设置AFR1和AFR0对STM8S003F3没有影响。 以上来自于谷歌翻译 以下为原文 Frankly, I didn't test interrupts at all. I used a 2-wire (half-duplex), that is RX and TX through PA3, with polling. I did some tests with RX on PD5 and TX on PA3 which for some reason didn't receive data (TX worked). I can run more tests later on, if required (my chip is marked '8S001 YK719'). Remark: based on the assumption that STM8S001J3 and STM8S003F3 are *very* similar, the AFR0=AFR1=1 setting in OPT2 is the only functional difference between the chips I could spot in the datasheet, and in the erratas. As far as I can tell, setting AFR1 and AFR0 has no effect in the STM8S003F3. |
|
|
|
我可以通过重新映射来确认问题。我还尝试使用轮询而不是中断从UART数据寄存器获取数据,行为是相同的。永远不会设置接收完成位。波特率正常,因为UART_TX正常工作。我还尝试使用引脚1(PD6 / PA1)作为通用输入,同时为RX和TX启用UART并且它工作正常!所以,我的观点是UART_TX的重新映射也重新映射(我不知道哪种方式)UART_RX引脚。有了这样的障碍,我无法将微观用于我的目的。我打算重新设置PCB或使用带有负边沿中断的引脚1和波特率定时器来创建软件UART,但这是一个肮脏的解决方案。如果有人在重新映射后有正常工作的UART证明,请将解决方案放在这里!非常感谢。
以上来自于谷歌翻译 以下为原文 I can confirm the troubles with remapping. I also tried to get data from the UART data register using polling, not interrupt, and the behaviour is the same. The receive complete bit is never set. The baud rate is OK, 'cause the UART_TX works correctly. I also tried using the Pin 1 (PD6 / PA1) as general input while UART was enabled for RX and TX and it worked! So, my opinion is that the remapping of UART_TX also remaps (I don't know which way) the UART_RX pin. With such obstacle I can't use the micro for my purposes. I'm planning to remaster the PCB or to create a software UART using Pin 1 with negative edge interrupt and a timer for baud rate, but is a dirty solution. If someone has the proof of good working UART after remapping, please put the solution here! Many thanks. |
|
|
|
我在文档中确认了这个错误 - 它将在新数据表(很快)中得到纠正。如果将UART_TX重新映射到引脚5,那么
引脚1上的UART_RX功能变为不可用(实际上是UART_RX重映射到内部未连接的引脚)。然后,UART只能用于单线半双工模式(或智能卡模式) - 其中只使用UART_TX信号。这不是理想的,但也是可用的配置 - 但需要在主机端进行一些调整(硬件:OR-ing Tx和Rx信号,以及软件:接收发送的数据)。 以上来自于谷歌翻译 以下为原文 I confirm this mistake in documentation - it will be corrected in new datasheet (very soon). If the UART_TX is remapped to pin 5 then the UART_RX function on pin 1 becomes unavailable(in fact is UART_RX remapped to internal not connected pin). Then the UART can be used only in sinle-wire half duplex mode (or in Smartcard mode) - where only the UART_TX signal is used. This is not ideal but also usable configuration - but needs some adjustment on the host side (either hardware: OR-ing Tx and Rx signals, and software: receive the sent data). |
|
|
|
未连接的GPIO端口是PF4,对吧?
在修改数据表时,如果Ain7的带隙参考和定时器同步功能(T5,T6)也可以找到提及,那将是很好的。 以上来自于谷歌翻译 以下为原文 The unconnected GPIO port would be PF4, right? When revising the datasheet, it would be nice if the bandgap reference at Ain7 and the timer synchronization feature (T5, T6) could find a mention as well. |
|
|
|
谢谢你,伊戈尔。信息非常有用。我试图在单线模式下使用重新映射的引脚,它工作正常。我在我的网站上发表了一篇文章
http://ficara.altervista.org/?p=4047 ,包括原理图和完整的项目文件夹,可免费下载。希望这可以帮助其他计划使用STM8S001JL3微控制器的人。 以上来自于谷歌翻译 以下为原文 Thank you Igor. The info was very useful. I tried to use the remapped pin in single wire mode and it worked. I published an article on my website http://ficara.altervista.org/?p=4047 , including schematics and full project folder, freely available for download. Hope that this can help other people that is planning to use the STM8S001JL3 microcontroller. |
|
|
|
只有小组成员才能发言,加入小组>>
请教:在使用UDE STK时,单片机使用SPC560D30L1,在配置文件怎么设置或选择?里面只有SPC560D40的选项
2671 浏览 1 评论
3224 浏览 1 评论
请问是否有通过UART连接的两个微处理器之间实现双向值交换的方法?
1796 浏览 1 评论
3625 浏览 6 评论
6007 浏览 21 评论
953浏览 4评论
1324浏览 4评论
在Linux上安装Atollic TRUEStudio的步骤有哪些呢?
599浏览 3评论
使用DMA激活某些外设会以导致外设无法工作的方式生成代码是怎么回事
1317浏览 3评论
1376浏览 3评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-4 01:23 , Processed in 1.261611 second(s), Total 92, Slave 73 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号