完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
HII正在尝试在PIC16F15313上使用EUSAT,但是它好像在我传输1字节之后不断地传输。我不知道为什么。当我使用代码配置器时,它也是一样的。我知道设备和振荡器是正确的,因为LED每100ms闪烁一次。请帮助。//CONT1,PracMa配置FFEXOSC =关闭/ /外部振荡器模式选择位-GT;振荡器未启用的PLL,OSCFRQ=16 MHz和CdIV=1:1(FoCC=32兆赫),γ-PracMa配置,Clkutoun=O//Clut-Out-BIT & Gt;ClkOUT功能被禁用;OSC2上的I/O或振荡器功能CSWEN=ON//时钟开关允许位-GT;写入NOSC和NDIV是允许的。故障安全时钟监控器启用位-gt;fSCM定时器启用//CONT2ApRAD-PracMA配置=O//MARK清除允许位-gt;MCLR PIN功能是端口定义的函数γ-PracMa配置,PWRTE = OF//上电定时器允许位-GT;PWRT禁用的PracMA配置LPBORN=OF//低功耗Bor使能位& GOBPBOR停用的{ Primamatlab配置BRONE=//Brown out RESET使能位-GT;Brown Out-Read启用,SBRIN位被忽略,* PrimaMac配置,BOLV=Lo//Brown out重置电压选择-& Gt;Brown out重置电压(VBOR)在LF上设置为1.9V,而F设备上的2.45伏S检测禁用-GT;零交叉检测电路在POR禁用。低电平将导致Real//Stult3的PracMA配置WDTCPS=WdTCSPSY31//WDT周期选择比特-GT;除法器比1:65636;WDTPS软件的控制:Trac-Matlab配置WTDE=OF//WDT工作模式-GT;WDT禁用,SWDTEN被忽略。开放的方式(100%);软件控制;不需要密钥的访问;TraceMac配置,WDTTCS=SC//WDT输入时钟选择器-&软件控制//CONT4,PracMa配置BBSyth= BB512/ /引导块大小选择位-gt;512个字引导块大小α-PrAPMA配置BBEN=OF//引导块使能位-GT;引导块禁用,{ A/A/SAF } //SAF使能位-GT;SAF禁用的PyrAppliga配置文件WRAPAP=关闭/ /应用块写入保护位-&;应用块不写保护的{ PrimaMac配置符WRTB=关闭/ /引导块写保护位-GT;引导块未写保护的γ-PrimaMac配置WRTC=断开/ /配置寄存器写保护位-GT;配置寄存器不写保护,{ Trac-Mac配置,WTFTAF=OF//存储区FLASH写保护位-& GT;SAF不写保护SypPrima配置,LVP=OF//低电压编程允许位& GT;MCLR/VPP上的高电压必须是用于编程//Opj5的PraceMac配置,CP=OF//USENVM程序存储器代码保护位-GUT;USENVM代码保护禁用定义:XXTALOFRYQ 32000000α包含/lc;XC.H.G.;//y包含“McCyPrimeAddixFix/McC.H”空隙主(空隙){OSCCON1= 0x60;//NOSC HCFITOC,2X PLL;NDIV 1;OSCCON3=0x00;//CSWHOOD可继续;OSCEN=0x00;//MFEN禁用;ADON禁用;HFOEN禁用;OSCFRQ= 0x06;/HFFRQ 16MHz;OSCSTAT=0x00;/MOF未就绪;OSCTUNE=0x00;//HFTUN 0;LATA= 0x00;TrISA=0x00亿;ANSELA=0x37;WPUA=0x00;OdCONA;=0x00;GIE=0;PPSROCK=0x55;PPSROCKIT=0xAA;PPsLoClk=0x00;//解锁PPSRA4PPS= 0x0f;//RA4--Gt;EsARTAR1: 0x55;PPSLoCK=0xAA;PPSLoCKIT BPsLoCK=0x01;/ /锁定PPSBUD1CONC= 0x08;//ABDOVF NoA溢出;SCKP非倒;BRG16 16BITH生成器;WUE禁用;禁用;RC9 STA= 0x80;//SPEN启用;RAD9禁用;AdEN禁用;SX1STA= 0x24;//TX9 8位;TX9D完成;SDENB同步CyrBurx完成;TXEN启用;同步异步;BRGH HySub;CSRC slave;SP1BRGL= 0x40;/波特率=9600;SP1BRGL 64;SP1BRGH=0x03;/波特率=9600;SP1BRGH 3;而(1){Tx1Reg=0xAA;LATABIT.LATA2=!LATABITS。LATA2;//LEDα-DelayyMS(100);}
以上来自于百度翻译 以下为原文 Hi I am trying to use the EUSART on the PIC16F15313 but it seems to transmit constantly once I have transmitted 1 byte. I have no idea why. It does the same thing when I use Code Configurator. I know the device and oscilator are running correctly as the LED flashes every 100ms. Please help. // CONFIG1 #pragma config FEXTOSC = OFF // External Oscillator mode selection bits->Oscillator not enabled #pragma config RSTOSC = HFINTPLL // Power-up default value for COSC bits->HFINTOSC with 2x PLL, with OSCFRQ = 16 MHz and CDIV = 1:1 (FOSC = 32 MHz) #pragma config CLKOUTEN = OFF // Clock Out Enable bit->CLKOUT function is disabled; i/o or oscillator function on OSC2 #pragma config CSWEN = ON // Clock Switch Enable bit->Writing to NOSC and NDIV is allowed #pragma config FCMEN = ON // Fail-Safe Clock Monitor Enable bit->FSCM timer enabled // CONFIG2 #pragma config MCLRE = OFF // Master Clear Enable bit->MCLR pin function is port defined function #pragma config PWRTE = OFF // Power-up Timer Enable bit->PWRT disabled #pragma config LPBOREN = OFF // Low-Power BOR enable bit->ULPBOR disabled #pragma config BOREN = ON // Brown-out reset enable bits->Brown-out Reset Enabled, SBOREN bit is ignored #pragma config BORV = LO // Brown-out Reset Voltage Selection->Brown-out Reset Voltage (VBOR) set to 1.9V on LF, and 2.45V on F Devices #pragma config ZCD = OFF // Zero-cross detect disable->Zero-cross detect circuit is disabled at POR. #pragma config PPS1WAY = ON // Peripheral Pin Select one-way control->The PPSLOCK bit can be cleared and set only once in software #pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable bit->Stack Overflow or Underflow will cause a reset // CONFIG3 #pragma config WDTCPS = WDTCPS_31 // WDT Period Select bits->Divider ratio 1:65536; software control of WDTPS #pragma config WDTE = OFF // WDT operating mode->WDT Disabled, SWDTEN is ignored #pragma config WDTCWS = WDTCWS_7 // WDT Window Select bits->window always open (100%); software control; keyed access not required #pragma config WDTCCS = SC // WDT input clock selector->Software Control // CONFIG4 #pragma config BBSIZE = BB512 // Boot Block Size Selection bits->512 words boot block size #pragma config BBEN = OFF // Boot Block Enable bit->Boot Block disabled #pragma config SAFEN = OFF // SAF Enable bit->SAF disabled #pragma config WRTAPP = OFF // Application Block Write Protection bit->Application Block not write protected #pragma config WRTB = OFF // Boot Block Write Protection bit->Boot Block not write protected #pragma config WRTC = OFF // Configuration Register Write Protection bit->Configuration Register not write protected #pragma config WRTSAF = OFF // Storage Area Flash Write Protection bit->SAF not write protected #pragma config LVP = OFF // Low Voltage Programming Enable bit->High Voltage on MCLR/Vpp must be used for programming // CONFIG5 #pragma config CP = OFF // UserNVM Program memory code protection bit->UserNVM code protection disabled #define _XTAL_FREQ 32000000 #include //#include "mcc_generated_files/mcc.h" void main(void) { OSCCON1 = 0x60; // NOSC HFINTOSC with 2x PLL; NDIV 1; OSCCON3 = 0x00; // CSWHOLD may proceed; OSCEN = 0x00; // MFOEN disabled; LFOEN disabled; ADOEN disabled; EXTOEN disabled; HFOEN disabled; OSCFRQ = 0x06; // HFFRQ 16_MHz; OSCSTAT = 0x00; // MFOR not ready; OSCTUNE = 0x00; // HFTUN 0; LATA = 0x00; TRISA = 0x00000000; ANSELA = 0x37; WPUA = 0x00; ODCONA = 0x00; GIE = 0; PPSLOCK = 0x55; PPSLOCK = 0xAA; PPSLOCKbits.PPSLOCKED = 0x00; // unlock PPS RA4PPS = 0x0F; //RA4->EUSART1:TX1; PPSLOCK = 0x55; PPSLOCK = 0xAA; PPSLOCKbits.PPSLOCKED = 0x01; // lock PPS BAUD1CON = 0x08; // ABDOVF no_overflow; SCKP Non-Inverted; BRG16 16bit_generator; WUE disabled; ABDEN disabled; RC1STA = 0x80; // SPEN enabled; RX9 8-bit; CREN disabled; ADDEN disabled; SREN disabled; TX1STA = 0x24; // TX9 8-bit; TX9D 0; SENDB sync_break_complete; TXEN enabled; SYNC asynchronous; BRGH hi_speed; CSRC slave; SP1BRGL = 0x40; // Baud Rate = 9600; SP1BRGL 64; SP1BRGH = 0x03; // Baud Rate = 9600; SP1BRGH 3; while(1) { TX1REG = 0xAA; LATAbits.LATA2 = !LATAbits.LATA2;//LED __delay_ms(100); } } |
|
相关推荐
15个回答
|
|
“不断传播”意味着什么?背靠背0xAA字符?恒低值?每100毫秒的0xAA字符?在初始化代码中有一些古怪的东西。您只使用内部振荡器,但启用故障安全监视器OSCSTAT是只读寄存器,并且向OSCCON1写入注释0,OSCFRQ不匹配值WordNo.-您将所有端口A设置为数字输出(TrISA=0),然后将所有端口A设置为模拟输入(安塞尔=0)。X37)数据表部分33.1.1表示,这可能是一个问题。另外一件事——33.1.1.7表示在设置SPEN和TXEN之前初始化BRG寄存器。这可能不是必要的,但它不同于你正在做的事情。
以上来自于百度翻译 以下为原文 What does "transmit constantly" mean? back to back 0xaa characters? constant low value? 0xaa characters every 100ms? There's some funky stuff in your initialization code. You're using internal oscillator only, but enable the failsafe monitor OSCSTAT is a read only register, and you write 0 to it comments for OSCCON1 and OSCFRQ don't match the values written Also - you set all of port a to digital outputs (TRISA=0), and then set all of port a to analog inputs (ANSEL=0x37) Datasheet section 33.1.1 says so this might be a problem. Another thing - 33.1.1.7 says initialize BRG register before setting SPEN and TXEN. This probably isn't necessary, but it's different from what you are doing. |
|
|
|
是的,TXIF或类似的标志应该在发送后检查
以上来自于百度翻译 以下为原文 Yeah, and TXIF or alike flag should be checked after transmitting |
|
|
|
将EUSAT设置为异步模式。您有一段时间(1)循环不断加载0xAA到txReg中。只要你继续加载0xAA进入TXRG,它将继续传输0xAA。在异步模式中,开始传输的“触发器”是加载TxReg的行为。我怀疑,如果你移动你的“Tx1Reg=0xAA”线,它将发送1字节,进入循环,然后连续闪烁LED并停止发送。此外,在启用模块之前,需要初始化波特率寄存器,否则不可预测。行为可能发生。
以上来自于百度翻译 以下为原文 You set the eusart up into async mode. You have a while(1) loop constantly loading 0xAA into the TXREG. As long as you continue to load 0xAA into the TXREG it will continue to transmit 0xAA. In async mode the "trigger" to begin transmission is the act of loading the TXREG. I suspect that if you move your "TX1REG = 0xAA" line just above and outside of the loop, the part will transmit 1 byte, enter the loop, then just continuously blink the LED and stop transmitting. Also, you need to initialize the baud rate registers BEFORE enabling the module, otherwise unpredictable behavior could occur. |
|
|
|
我注意到TXIF测试缺席,但算出一个9600波特字符将在1ms发送,并且在while循环中有100ms延迟。没有超支的可能。显然是一个非常有限的测试代码,在学习的道路上迈出一小步。
以上来自于百度翻译 以下为原文 I noticed the TXIF test absence, but figured one 9600 baud character will transmit in 1ms and there's a 100ms delay in the while loop. No chance of overrun. Obviously a very limited test code for taking small steps in the path of learning. |
|
|
|
谢谢你的评论。我现在不在工作,所以我不能测试解决方案,但我会回答一些问题。背靠背0xAA字符?恒定低值?/100xAA字符每100MS?0xAA在没有时间停止和开始位的情况下发送回。它似乎将加载的字符发送到TX1RG,直到加载另一个字符之后,它不断地发送新字符。在我的初始化代码中的“时髦的东西”是用MCC生成的。我只是把它全部复制到这个例子中的一个文件中。我明天将测试这些变化。@ CinziaGWhat是检查TXIF标志的目的吗?据我所知,这应该只是用来防止超支。我在1ms的转换之间有一个100ms的延迟。@ ErMOSRei将在启用模块之前尝试初始化波特,再次是来自MCC。可能在MCC有bug,我以前发现过一些。谢谢大家的帮助,我在很多微芯片设备上使用了EuSART,从来没有遇到过这个问题。非常相似的设置在PIC16F1586.约翰上完美地运行。
以上来自于百度翻译 以下为原文 Thanks for the comments. I am not at work at the moment so I can't test the solutions but I will reply to some of the questions asked. @mbrowning "What does "transmit constantly" mean? / back to back 0xaa characters? / constant low value? / 0xaa characters every 100ms?" 0xAA is transmitting back to back with no time stop and start bits. It seems to transmit the character loaded into TX1REG until another character is loaded after-which it transmits the new character constantly. The "funky stuff" in my initialization code was generated using MCC. I have just copied it all into one file for this example. I will test these changes tomorrow. @CinziaG What is the purpose of checking the TXIF flag? As far as I understand this should just be used to prevent overrun. I have a 100ms delay between the 1ms transitions. @ermoser I will try initializing BAUD before enabling the module, again this was from MCC. Possibly there are bugs in MCC, I have found a few before. Thanks everyone for your help, I have used EUSART on many microchip devices and never had this problem. Very similar setup works perfectly on PIC16F15386. John |
|
|
|
没有启动或停止位????这里有些东西听起来很不对劲。你到底是如何测试这个的?你在观察范围内的别针吗?
以上来自于百度翻译 以下为原文 No start or stop bits??? Something sounds very wrong here. How exactly are you testing this? Are you observing the pins with a scope? |
|
|
|
如果你不等待TXIF,变速器可能会“混乱”-现在我不知道确切的行为(特别是在你的PIC上),但可能是前一个字节被中止,一个新的字节开始被序列化…当然,延迟可以工作,但它会降低效率,并绑定到给定波特率。
以上来自于百度翻译 以下为原文 Well, if you don't wait for TXIF the transmission will possibly get "scrambled" - now I don't know exactly the behaviour (on your PIC especially) but possibly the previous byte is aborted and a new one starts being serialized... Of course a delay can work all the same but it will be less efficient, and also bound to the given baud rate. |
|
|
|
如果100MS延迟工作正常(如LED闪速率所示),我怀疑没有等待TXIF事项。
以上来自于百度翻译 以下为原文 If the 100ms delay is working correctly (as indicated by the LED flash rate), I doubt the no wait for TXIF matters. |
|
|
|
是的,也许它不像预期的那样工作:它可能很好地解释“不启动/停止位问题”:
以上来自于百度翻译 以下为原文 Yeah, maybe it's not working as expected: it would possibly explain nicely the no start/stop bits issue :) |
|
|
|
HiSorry,我的意思是在开始和停止之间没有时间。位在那里,数据是正确的,检查范围和逻辑分析仪。它只是重复传送同一个字节。约翰
以上来自于百度翻译 以下为原文 Hi Sorry, I meant to say to no time between start and stop bits. The bits are there and the data is correct, checked on scope and Saleae logic analyser. It just transmits the same byte repetitively. John |
|
|
|
|
|
|
|
现在我迷路了。我早就怀疑延迟是不起作用的,但是你说LED是正确闪烁的。我想你可以看到波特率是正确的。你试过在调试模式下通过你的代码吗?
以上来自于百度翻译 以下为原文 Now I'm lost. I would have suspected the delay was not working, but you said the LED is flashing correctly. I assume you can see that the baud rate is correct. Have you tried stepping through your code in debug mode? |
|
|
|
这是奇怪和难以理解的行为。我想你可能已经做过了,但可以肯定的是,你用安塞尔和SP1BRGL/H解决了初始化问题吗?
以上来自于百度翻译 以下为原文 This is odd and difficult to understand behavior. I think you probably did, but just to be sure, did you fix the initialization issues with ANSEL and SP1BRGL/H ? |
|
|
|
嗨,我已经花了一整天的时间,终于解决了这个问题。所以我用另一个交换了IC,这个(令人惊讶地)修复了它。然后我把错误的一个放回,行为就回来了。这个IC焊接在一个简单的断路板上,只有PICTIT3连接(供电),所以它不是PCB。我唯一的结论是,在那个没有清除内部标志的特殊IC中,TX硬件出了问题。谢谢所有的帮助。约翰。
以上来自于百度翻译 以下为原文 Hi Everyone I have spent the whole day and finally fixed the problem. None of the above suggestions worked. So I swapped the IC with another one and this (surprisingly) fixed it. I then put the 'faulty' one back and the behavior returned. This IC is soldered on a simple break out board with only the PICkit3 connected (supplying power) so it's not the PCB. My only conclusion is that there was something wrong with the TX hardware in that particular IC that was not clearing some internal flag. Thanks for all the help. John |
|
|
|
谢谢你的回复。在我耗尽所有其他可能的问题之前,我总是不喜欢责怪硅,但时不时会有一个坏芯片。
以上来自于百度翻译 以下为原文 Thanks for reporting back. I am always loathe to blame the silicon before I've exhausted all other possible issues, but every now and then there's a bad chip. |
|
|
|
只有小组成员才能发言,加入小组>>
5137 浏览 9 评论
1987 浏览 8 评论
1917 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3157 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2215 浏览 5 评论
705浏览 1评论
595浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
479浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
609浏览 0评论
504浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-6 23:15 , Processed in 1.430380 second(s), Total 106, Slave 89 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号