完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
电子发烧友论坛|
嗨,我们使用PIC18F8K21控制器在我们的自定义板。当我试图发送7字节的数据,那么一些时间12字节的数据或一些时间在另一端(Tela Prime/HPER终端)接收,但当我关掉电路板,然后打开板,那么只有4字节的数据被接收。知道你是否可以怀疑任何可能的错误,因为我不能找出根本原因。关于配置比特,我没有改变任何默认值除了“XNST= Off&SoSSELS=挖掘”。因为我使用内部默认的10MHz时钟,我已经配置了SPBRG1作为0xC.完整的应用程序(UART)。C)我已经在邮件中上传了服务器。
以上来自于百度翻译 以下为原文 Hi , We are using PIC18F85K21 Controller in our custom board. when i trying to send 7byte of data then some time 12 bytes of data or some time less is received on other end(Tera term /Hper terminal) But when i power OFF the board and then switch ON the board then only 4bytes of data is received. Let me know if you can suspect any probable wrong since i am not able to figure out the root cause. Regarding config bits i haven't changed any default values apart from "XINST=OFF & SOSCSEL = DIG".Since I am using internal default 10MHZ clock,i have configured SPBRG1 as 0xC. Complete application(uart.c) i have uploaded in the server in the mail. |
|
相关推荐
19个回答
|
|
|
我没有看你的代码,但是12字节而不是7看起来像波特率不匹配。你送什么,你收到什么?
以上来自于百度翻译 以下为原文 I didn't look at your code, but 12 bytes instead of 7 looks like baud rate mismatch. What do you send and what do you receive? |
|
|
|
|
|
完成????我不这么认为。如果这确实是你的“完整”源代码,你就丢失了& lt;xc.h & gt;和配置位。此外,您的代码不配置波特率,并且您的主()将运行到结束,并再次重置,一次又一次…
以上来自于百度翻译 以下为原文 Complete??? I don't think so. If that's really your "complete" source code, you're missing |
|
|
|
|
|
您好,对不起,我的错误的话。我的意思是,我提供了主要的UART相关配置和操作。关于配置比特,我没有改变任何默认值除了“XNST= Off&SoSSELS=挖掘”。因为我使用内部默认的10MHz时钟,我已经配置了SPBRG1作为0xC。在代码(UART.C)中,Yin发送了一个字符“B”七次。不管怎样,我已经更新了先前编写的邮件和UART.C,并进行了所有需要的更改。
以上来自于百度翻译 以下为原文 Hi , Sorry for my wrong words.I mean to say that i have provided major UART related configuration &operation. Regarding config bits i haven't changed any default values apart from "XINST=OFF & SOSCSEL = DIG".Since I am using internal default 10MHZ clock,i have configured SPBRG1 as 0xC. I am trying send a character "B" seven Times in the code(uart.c). Anyways i have updated the earlier composed mail and also uart.c with all required changes. Regards, Biswajit |
|
|
|
|
|
你没有在你的配置词中设置FoSC。FoSC空白将是0B1111,这不是一个有效的设置。如何不懒惰,并指定你的所有配置位,你的意思是……也可以替换。
以上来自于百度翻译 以下为原文 You have not set FOSC at all in your CONFIG words. FOSC blank would be 0b1111, which is not a valid setting. How about not being lazy, and specifying ALL your CONFIG bits they way you are meant to... also, replace #include"p18f85k22.h" with #include "xc.h" |
|
|
|
|
|
并且摆脱这两条线路,你没有中断服务例程,所以你不想允许中断。如果你设置了GIE位,你的代码会崩溃。这两个位不掩饰RC1IF和TX1IF。
以上来自于百度翻译 以下为原文 and get rid of these two lines PIE1bits.RC1IE=1; PIE1bits.TX1IE=1; You do not have an interrupt service routine, so you do not want to allow interrupts. Your code would crash if you had set the GIE bit. Those two bits do NOT mask RC1IF and TX1IF. |
|
|
|
|
|
嗨,非常感谢你的回复。这不是关于懒惰。因为我是新的PIC编程,我没有很多关于配置比特的信息。如果我使用XC.H而不是p18f8k22.h,那么它不会被编译为“不能定位”。问候,Biswajit。
以上来自于百度翻译 以下为原文 Hi , Thanks a lot for your reply. Its not about being lazy.Since i am new to PIC programming , i dont have much information about the CONFIG BITS. If i am using xc.h instead of p18f85k22.h then its not getting compiled saying "unable to locate". Regards, Biswajit |
|
|
|
|
|
MPLABX有一个特定的窗口来帮助您设置所有的配置位。使用MCPabx来编译源代码中的配置位的简单方法是什么?要么不是XC8,要么是XC8没有正确安装。
以上来自于百度翻译 以下为原文 MPLABX has a window specific to help you set all the config bits. The easy way to set CONFIG bits in your source using MPLABX Which C compiler are you using? Either it's not XC8, or XC8 is not installed correctly. |
|
|
|
|
|
目前我正在使用C18工具链。当我对属性进行交叉检查时,[GT:CONF:[默认] XC8没有找到。所以我需要使用XC8工具链而不是C18工具链吗?问候,Biswajit
以上来自于百度翻译 以下为原文 Currently I am using C18 Tool chain.when i cross checked on properties->conf:[default] XC8 shows None found. So do i need to use XC8 tool chain instead of C18 tool chain? Regards, Biswajit |
|
|
|
|
|
我建议你现在使用XC8C18已经过时了。XC8要好得多,大多数人都会认为这是你提问时使用的。这是一个免费下载的微芯片网站。
以上来自于百度翻译 以下为原文 I would recommend you that use XC8. C18 is obsolete now. XC8 is much better, and most people will assume that's what you're using when you ask questions. It's a free download from the Microchip website. |
|
|
|
|
|
嗨,我已经安装了XC8工具链。我在代码中添加了配置比特。我已经配置了FoCC作为InTixApPrimaAcFig=InTiOy。由于BI默认,内部振荡器将为8MHz。因此,配置9600 BaDeff:SPBRG1= 0xC.在发送任何数据之前,我在等待TrMT寄存器I。s(TxSTA1BIT.TrMT=0);TxReG1= CH;观察:1。当我发送第二个字节时,我接收到第一字节。2.如果我将完全关闭电路板,然后打开板,那么我将接收所需的7字节的数据。3.如果我将在不关闭电源的情况下加载和运行程序,那么我将接收21字节的数据。DATA.4如果我在UART.C的UART1PtuCHAR函数上设置一个断点,那么在到达断点之前,它已经在超级终端上打印了14字节的数据。请告诉我在BaDeRead或任何配置错误中是否有计算。请在UART.C中交叉检查配置比特。我已经修改和上传了。问候,Biswajit
以上来自于百度翻译 以下为原文 Hi, I have installed the XC8 Tool chain.I have added the CONFIG BITs in the code. I have configured FOSC as INTIO2 #pragma config FOSC = INTIO2 . As the Bi default the internal oscillator will be 8MHz .So to configure 9600 Baudrate: SPBRG1=0xC Before sending any data,I am waiting till the TRMT register is ZERO. while(TXSTA1bits.TRMT==0); TXREG1 = Ch; OBSERVATION: 1. when ever I am sending the second Byte ,I am receiving the 1st Byte. 2.If I will completely switch OFF the board and then switch ON the board then i will receive the required 7 Bytes of Data. 3.If i will load & Run the program without switching off the Power supply then i am receiving 21Bytes of Data. 4.If i will put a break point at the UART1PutChar Function of uart.c then before hitting the break point 14 Bytes of data its already printed on the Hyper Terminal. Please let me know if my calculation in Baudrate or any configuration mistake is there. Please cross Check the CONFIG BITS in uart.c which I have modified and uploaded also. Regards, Biswajit |
|
|
|
|
|
请停止编辑你的第一篇文章。当你有新的代码时,把它附加到这个线程中的一个新的帖子中。现在没有任何代码连接到你的第一个帖子。这是有效的,但是等到TXIF位被设置时更有效率。这听起来像是代码中的一个错误,或者是一个丢失的地线连接。我需要看看你当前的代码T。o了解正在发生的事情。是的,0x0C是正确的,只要没有设置BRGH和BRG16位。我不能检查,因为我看不见您的代码。
以上来自于百度翻译 以下为原文 Please stop editing your first post. When you have new code, attach it to a new post in this thread. There's no code at all attached to your first post now. That will work, but it is more efficient to wait until the TXIF bit is set. That sounds like a bug in your code, or a missing ground wire connection. I need to see your current code to understand what is going on. Yes, 0x0C is correct so long as the BRGH and BRG16 bits are not set. I cannot check because I cannot see your code. |
|
|
|
|
|
嗨,非常感谢你的宝贵的输入。最初我正在监视TXIF位。但是后来我改为TrMT。正如你建议的,我将回复到监控TXIF位传输完成。根据要求,请找到完整的UART。C更新代码。问候,Biswajit。
以上来自于百度翻译 以下为原文 Hi, Thanks a lot for your valuable input. Initially i was monitoring TXIF Bit only .But then i modified to TRMT . As you suggested i will revert back to monitoring TXIF bit for transfer completion. As requested,Please find the complete uart.c updated code. Regards, Biswajit Attachment(s) uart.c (4.53 KB) - downloaded 54 times |
|
|
|
|
|
我假设双“虽然”是一个打印前的测试。这个代码只在开机后发送一个字符。我建议作为一个初始测试,让它继续在主循环中发送字符,每个字符之间有一个500毫秒的延迟,这样你就可以看到它们分别到达。(注意,“PutChar”之后的空间是为了阻止论坛的防火墙阻塞这个帖子……)
以上来自于百度翻译 以下为原文 I assume the double "while" is a typo void UART1PutChar (UINT8 Ch) { TXREG1 = Ch; while(while(PIR1bits.TX1IF==0); } Move the test to BEFORE the write. void UART1PutChar (UINT8 Ch) { while (PIR1bits.TX1IF==0); // wait until the transmit buffer is available TXREG1 = Ch; } This code is only sending a single character after power on. I suggest as an initial test, get it to keep sending the character in your main loop, with a 500ms delay between each character, so you can see them arriving separately. (note, the space after "PutChar" is to stop the forum's firewall blocking this post...) |
|
|
|
|
|
如果你调用你的UART发送例程“PUCH()”,那么你可以使用Primff()、PuthSo()等来写它!这是在XC8用户指南中记录的。
以上来自于百度翻译 以下为原文 n.b. if you call your uart send routine "putch()", then you can use printf(), puts() etc. to write to it! This is documented in the XC8 User Guide. |
|
|
|
|
|
嗨,非常感谢你的即时回复。为了提供延迟的500毫秒,有任何预先定义的API可用,或者我需要多次使用NOP()来实现相同的。如果你交叉检查我先前发送的代码,它尝试发送B、C、D、E、F、G、H字符。从零开始,直到“i”值达到7。
以上来自于百度翻译 以下为原文 Hi , Thanks a lot for your immediate reply. To provide delay of 500ms is there any predefined API available or do i need to use Nop() multiple times to achieve the same. If you cross check the code which i have sent earlier ,its trying to send B,C,D,E,F,G,H characters one by one. there is a loop which starts from zero and goes till the "i" value reaches 7. |
|
|
|
|
|
是的,有一个内置的宏名为y-yDelaysMy(),它需要你添加一条线来告诉编译器你的时钟速度。(POP,在刚上线之后,包括XC.H),我会关闭WDT直到你有一个完全工作的程序。是的,我看到了,但是你最近发布的代码并没有这样做。
以上来自于百度翻译 以下为原文 Yes, there is a built in macro named __delay_ms() It requires you to add a line to tell the compiler your clock speed. #define _XTAL_FREQ 8000000 (pop that in just after the line including xc.h) I'd turn off the WDT until you have a fully working program. Yes I saw that, but the most recent code you posted wasn't doing that. |
|
|
|
|
|
您好,观察:在我遇到旧数据之前,如果遇到了断点,可能是什么原因。测试1:关闭电路板,然后接通程序:尝试在TrAtTrm上发送BCFDGHULL:BcDefGbcffgEngt修改代码并尝试在TyTalm:B上发送GHIJKLM输出。当我尝试运行代码时,当我看到MPLAB ID输出的“固件类型……PIC18F”的时候,那时14个字节的数据没有显示在TRA术语上显示的延迟的500毫秒,那么当前7字节的数据具有500毫秒的延迟,显示一个AF。其他的超级终端(TARA术语)。我已经对接地问题进行了交叉检查,但它很好(用硬件团队验证)。让我知道是否还有其他可能的问题。问候,Biswajit。
以上来自于百度翻译 以下为原文 Hi, Observation: Before hitting the break point if i am receiving the old data then what could be the reason. Test 1: Switch off the board and then Switch ON followed by the programming: Trying to send BCDEFGH OUTPUT on TERATERM:BCDEFGHBCDEFGH Modify the Code and Trying to send GHIJKLM OUTPUT on TERATERM:BCDEFGHBCDEFGH G H I J K L M When ever I am trying run the code ,the moment I see "Firmware type..............PIC18F" on output of MPLAB ID, at that time old 14 bytes of data without 500ms of delay getting displayed on the Tera Term. Then current 7 bytes of data with 500ms delay getting displayed one after other on the hyper terminal(TERA TERM). I have cross checked regarding the Grounding issue but its fine(verified with Hardware Team). Let me know if any other probable issue for the same. Regards, Biswajit |
|
|
|
|
|
在你做任何事情之前加上一秒的延迟到你的代码的开始。如果你没有在MPLAB工具栏上打开“保持重置”,你的PIC将在它完成编程的那一刻开始运行。一旦验证完成,它将再次运行。由于启动延迟,在再次重置之前,它不会有任何发送任何东西的机会。
以上来自于百度翻译 以下为原文 Add a one second delay to the start of your code before you do anything. If you don't have "hold in reset" turned on in the MPLAB toolbar, your PIC will start running the moment it has finished programming. It will then start running again as soon as it finishes verifying. With a startup delay, it won't get a chance to send anything before it is reset again. |
|
|
|
|
|
嗨,我按照你的建议做了,编译了代码,然后点击“保持复位”按钮,按钮的状态就改变了“从重置中释放”。然后在超级终端(Tya术语)上只有4字节的旧数据,第一字节的数据在TARA术语上显示出来。输出:CDCDThen WH。EN我改变状态从“释放从复位”到“保持在复位”点击按钮,然后只有我目前的数据与500毫秒的延迟正在显示在屏幕上。我完全困惑是它的硬件问题或任何软件配置问题。我不觉得有任何代码问题将在那里。我也知道你的观点和建议。Biswajit,
以上来自于百度翻译 以下为原文 Hi , I did what you have suggested, Compiled the code then click on "Hold in Reset" Button then the state of Button changes "Release from Reset". Then on the hyper terminal(Tera Term) only 4Bytes of old Data with 1st Two bytes of repetation of data getting displayed on the TERA TERM. Output:CDCD Then when i change the state from "Release from Reset" to "Hold in Reset" on clicking the button then only my current data with 500ms of delay is getting displayed on the screen. I am totally confused whether its hardware issue or any software configuration issue. I don't feel any code issue will be there . Let me know your views or suggestions on the same. Regards, Biswajit |
|
|
|
|
只有小组成员才能发言,加入小组>>
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
475 浏览 0 评论
5794 浏览 9 评论
2334 浏览 8 评论
2224 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3530 浏览 3 评论
1124浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
1098浏览 1评论
我是Microchip 的代理商,有PIC16F1829T-I/SS 技术问题可以咨询我,微信:A-chip-Ti
873浏览 1评论
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
475浏览 0评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-2 13:24 , Processed in 1.195130 second(s), Total 108, Slave 91 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
2382