ST意法半导体
直播中

李龙

7年用户 186经验值
私信 关注
[问答]

STM8S001J3 UART重映射

你好
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)

冯瑾娜

2018-11-28 10:21:16
我没有测试你的代码,但是如果它适用于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!
举报

李龙

2018-11-28 10:32:33
谢谢您的回复。
 
选项位使用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.
举报

冯瑾娜

2018-11-28 10:51:04
坦率地说,我根本没有测试中断。我使用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.
举报

李荞

2018-11-28 11:07:32
我可以通过重新映射来确认问题。我还尝试使用轮询而不是中断从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.
举报

更多回帖

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