完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
嗨,伙计们。我正在研究一个项目,希望能立即改变UART驱动程序的波特率。但是,当我使用它时,我会遇到同步问题。事实上,使用示波器,我注意到用DrviUsARTHARBUSET()函数设置的BUDRAT是UXBRG值在纸上遇到的最坏的情况!所以我查看了DrviUsARTHARBUSET()函数,我得到了这个函数:在这个代码中,我不理解这个部分:事实上,如果我设置第一个条件总是正确的,那么Boad Read总是高的。我错了吗?
以上来自于百度翻译 以下为原文 Hi guys. I'm working on a project that expects to change baudrate of the UART driver on the fly. But when I use it I have syncronizzation problems. In fact, using an osciloscope I noticed that the boudrate set with the DRV_USART_BaudSet() function is the worst confronted with the UxBRG value calcolate on the paper! So I looked inside the DRV_USART_BaudSet() function and I reached this function: DRV_USART_BAUD_SET_RESULT DRV_USART0_BaudSet(uint32_t baud) { uint32_t clockSource; int32_t brgValueLow=0; int32_t brgValueHigh=0; DRV_USART_BAUD_SET_RESULT retVal = DRV_USART_BAUD_SET_SUCCESS; #if defined (PLIB_USART_ExistsModuleBusyStatus) bool isEnabled = false; #endif /* Get the USART clock source value*/ clockSource = SYS_CLK_PeripheralFrequencyGet ( CLK_BUS_PERIPHERAL_2 ); /* Calculate low and high baud values */ brgValueLow = ( (clockSource/baud) >> 4 ) - 1; brgValueHigh = ( (clockSource/baud) >> 2 ) - 1; #if defined (PLIB_USART_ExistsModuleBusyStatus) isEnabled = PLIB_USART_ModuleIsBusy (USART_ID_5); if (isEnabled) { PLIB_USART_Disable (USART_ID_5); while (PLIB_USART_ModuleIsBusy (USART_ID_5)); } #endif /* Check if the baud value can be set with high baud settings */ if ((brgValueHigh >= 0) && (brgValueHigh <= UINT16_MAX)) { PLIB_USART_BaudRateHighEnable(USART_ID_5); PLIB_USART_BaudRateHighSet(USART_ID_5,clockSource,baud); } /* Check if the baud value can be set with low baud settings */ else if ((brgValueLow >= 0) && (brgValueLow <= UINT16_MAX)) { PLIB_USART_BaudRateHighDisable(USART_ID_5); PLIB_USART_BaudRateSet(USART_ID_5, clockSource, baud); } else { retVal = DRV_USART_BAUD_SET_ERROR; } #if defined (PLIB_USART_ExistsModuleBusyStatus) if (isEnabled) { PLIB_USART_Enable (USART_ID_5); } #endif return retVal; } In this code I don't understand this part: /* Check if the baud value can be set with high baud settings */ if ((brgValueHigh >= 0) && (brgValueHigh <= UINT16_MAX)) { PLIB_USART_BaudRateHighEnable(USART_ID_5); PLIB_USART_BaudRateHighSet(USART_ID_5,clockSource,baud); } /* Check if the baud value can be set with low baud settings */ else if ((brgValueLow >= 0) && (brgValueLow <= UINT16_MAX)) { PLIB_USART_BaudRateHighDisable(USART_ID_5); PLIB_USART_BaudRateSet(USART_ID_5, clockSource, baud); } else { retVal = DRV_USART_BAUD_SET_ERROR; } In fact, if I set brgValueLow = ( (clockSource/baud) >> 4 ) - 1; brgValueHigh = ( (clockSource/baud) >> 2 ) - 1; the first condition if ((brgValueHigh >= 0) && (brgValueHigh <= UINT16_MAX)) is always true and than the Boud Rate High is always enabled. Am I wrong? |
|
相关推荐
9个回答
|
|
它检查以确保BrgValueHead不大于UTIN 16Max,否则使用BRGValeleOW,这将是值的四分之一。这只会发生在非常慢的波特率上。
以上来自于百度翻译 以下为原文 It's checking to make sure brgValueHigh does not end up larger than UINT16_MAX Otherwise is uses brgValueLow which will be a quarter of the value. That would only happen for extremely slow baud rates. |
|
|
|
因此,它的检查BrgValueHuIs小于Unt1616Max=0xFFFF=65535????我敢肯定(几乎)总是经过验证。如果我有一个20MHz的外围时钟,我只想要一个比77 BPS的BrdRET Grand!我还不清楚!
以上来自于百度翻译 以下为原文 So it's checking brgValueHigh brgValueHigh = ( (clockSource/baud) >> 2 ) - 1; is less than UINT16_MAX = 0xFFFF = 65535 ??? I'm pretty sure that is (almost) always verified. If I have a 20MHz peripheral clock, just I want a boudrate grater than 77bps! I haven't clear this! |
|
|
|
这是正确的。如果波速比20BPS快,波特率将超过这个测试,如果时钟是20MHz。我不明白你的意思。
以上来自于百度翻译 以下为原文 That is correct. Any baud rate faster than 77bps will pass that test if the clock is 20MHz. I don't understand what you mean. |
|
|
|
我敢肯定这个API必须工作。你能提供更多的细节吗?1。外围时钟2值2.2。动态波特率你正在设置3.计算的BRG值:USAT驱动程序尝试设置高波特率的大部分时间的准确性。请计算两个高和低BRG值为您的理解,您可以阅读UART FRM的PIC32的更多细节,关于高波特率设置优势。4。调用此APII后的UXBRG寄存器值可以帮助您从点3和点4的值不匹配。-如果两者都匹配,并且你看到同步问题,我建议你在UART上发生事务时不要调用这个API。是的,肯定会在切换时引入故障。
以上来自于百度翻译 以下为原文 I'm pretty sure this API must be working. Can you give more details? 1. Peripheral clock 2 value 2. Dynamic Baud rate you are setting 3. BRG value from the calculation: USART driver tries to set HIGH baud rate most of the time for the accuracy. Please do calculate both high and low BRG values for your understanding, you can read UART FRM of PIC32 for more details on HIGH baud rate setting advantages. 4. UxBRG register value after calling this API I can help you if the value from point 3 and point 4 are not matching. ;-) If both are matching and you see sync issues, I suggest you not to call this API when there is a transaction happening on UART. Yes, definitely that will introduce glitches while switching. |
|
|
|
我明白了!我绘制了一个图(http://iimgur.com /pZ2fWMC.jpg),它显示了在PIC32上设置波特率的错误(在图例中,UXBRG值的低和近均值舍入到低整数和最接近整数)。我工作的一个20MHz的外围时钟和我的模块与我想要沟通支持以下波德率:1200,2400,4800,9600,19200,38400,57600,115200,230400,460800,921600,所以我考虑了这些值。但是我注意到BGRH的最佳值总是1,即使是1200 BPS!因此,在这一点上,我不理解设置BGRH=0.0的功能。当这个设置方便时,你能给我举个例子吗?当DrviUsARTHARBAUSET()函数中的条件是真的来设置BGRH=0时?此外,由于UXBRG值的舍入,我在通信中有同步化问题。如果我想要230400个BUDRATE,UXBRG值应该是20.7,所以DRVVUESARTARBAUDSET()函数将UXBRG设置为20,给出一个3,3%的相对误差,这对我来说是不好的。但是如果我将uxBrg设置为21,则错误大约是1.3%,这是好的。我认为DrviUsARTARBAUDSETE()自动地尽量减小相对误差以达到最佳的行为,但不是这样。DRVIUS UARTARSUBADSET()正常工作是正常的吗?对不起,如果我不清楚,但我有一点时间写这篇文章。
以上来自于百度翻译 以下为原文 I get it! I plotted a graph ( http://i.imgur.com/PZ2fWmC.jpg ) wich shows the reletive error of setting the baud rate on the PIC32 (in the legend, the LOW and NEAR mean the rounding of the UxBRG value to the low integer and to the nearest integer). I work with a peripheral clock of 20MHz and my module with I want communicate supports the following baudrates: 1200 2400 4800 9600 19200 38400 57600 115200 230400 460800 921600 and so I considered these values. But I noticed that the best value of BGRH is always 1, even for the 1200bps! So at this point I don't understand the functionality of setting the BGRH=0. Can you show me an example when this setting is convenient and so when the condition in DRV_USART_BaudSet() function is true for setting BGRH=0? Furthermore, I have syncronization problem in the communicatuin due to the rounding of the UxBRG value. If I want a 230400 boudrate, the UxBRG value should be 20.7 so the DRV_USART_BaudSet() function sets the UxBRG to 20, give a relative error about 3,3% that is bad for me. But if I set the UxBRG to 21, the error is about 1.3%, that is good. I thought that the DRV_USART_BaudSet() automatically try to minimize the relative error to reach the best behaviour, but is not so. Is it normal for the DRV_USART_BaudSet() to work this way? Sorry if I'm not clear, but I had a little time to write this post. |
|
|
|
好的,我明白了。那- 1对你来说是不同的。它在老版本的和声中,我记得并用最新的版本固定。你使用的是和声版本?你能检查最新版本吗?
以上来自于百度翻译 以下为原文 Ok, I got it. That -1 is making the difference for you. It was there in older versions of Harmony as I remember and fixed by latest versions. Which version of Harmony are you using? Can you check with latest version? |
|
|
|
|
|
|
|
1.10并没有这个修复,而你可以利用它,我认为,导航ToMICROCHIPSOrthyV1Y10FraseEdART\模板UARTARSB BUDRATHIGHIGIN 16位寄存器。手工替换现有的“BRG”公式,用“BRG”的V2.X.V1.10:BRG =(时钟频率/(4×BaDeRead))-1;V2.xx:BRG=(((时钟频率& gt;gt;2)+(波德率& gt;1))/波特率- 1;
以上来自于百度翻译 以下为原文 1.10 doesn't have this fix whereas 2.xx has. You can make use of it I think, Navigate to microchipharmonyv1_10frameworkperipheralusarttemplatesusart_BaudRateHigh_In16BitRegister.h And replace existing "brg" formula with "brg" of v2.xx. v1.10 : brg = (clockFrequency/(4*baudRate))-1; v2.xx : brg = ( ((clockFrequency >> 2) + (baudRate >> 1)) / baudRate ) - 1; |
|
|
|
好图腾,谢谢。我将检查V2.00,我将替换“BRG”公式。实际上,我尝试了我的公式,把它转为最近的整数(=(Unt32)t()((浮点)时钟频率/((浮点)4(浮点)波特率”)-(浮点)1 +(浮点)0.5;而且效果很好,但也许最好用和声来代替我。最后一个问题:无论如何谢谢。
以上来自于百度翻译 以下为原文 Ok Totem, thanks. I'll check the v2.00 and I'll replace the "brg" formula. Actually I tried my formula to round to the nearest integer brg = (uint32_t) ( ( ( (float) clockFrequency / ( (float) 4 * (float) baudRate ) ) ) - (float) 1 + (float) 0.5 ); and works well, but maybe is better to replace mine with the harmony one. A last question: Thanks anyway. |
|
|
|
只有小组成员才能发言,加入小组>>
5178 浏览 9 评论
2003 浏览 8 评论
1931 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3177 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2228 浏览 5 评论
738浏览 1评论
622浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
509浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
636浏览 0评论
533浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-27 00:34 , Processed in 1.438887 second(s), Total 91, Slave 75 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号