完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
电子发烧友论坛|
你好。这些是我在电子学和微芯片上的第一步。所以有点帮助,我将使用XC16,PIC24FJ1024GB610,Explorer 16/32板,RS485点击它。程序将数据传输到步进电机。命令发送,步进电机反应并发送确认命令,通信使用UART进行。问题是UARTAR2RXBYTEQ[]从来没有(如我所理解的)从步进电机获得数据。原因何在?
UART.TXT(0.86 KB)-下载33次UART2C.TXT(9.44 KB)-下载23次 以上来自于百度翻译 以下为原文 Hello. These are my first steps at electronics and Microchip. So a little bit of help would be appreciated. I am using XC16, PIC24FJ1024GB610, Explorer 16/32 board, and RS485 click on it. Program is transmitting data to stepper motor. Command is sent, stepper motor reacts and sends back confirmation command. Communication happens using UART. The issue is that uart2_rxByteQ[] never (as I do understand) gets data from stepper motor. What could be the reason? Attachment(s) main.txt (1.80 KB) - downloaded 24 times UART.txt (0.86 KB) - downloaded 33 times uart2c.txt (9.44 KB) - downloaded 23 times |
|
相关推荐
13个回答
|
|
|
嗨,你把你收到的数据推到你的FIFO?
以上来自于百度翻译 以下为原文 Hi, Where do you push your recived data to your fifo? |
|
|
|
|
|
只是我自己使用的自动生成函数。
以上来自于百度翻译 以下为原文 Is just auto generated functions I am using. uart2c.txt Thank you |
|
|
|
|
|
只是浏览文件,我没有看到UART PPS(外围PIN选择,TX和RX)的初始化,但是当你写的时候,你的TX似乎工作得很好。你没有评论它,但是显然S3是你的RX,所以ANSELx至少被设置了。但是你确定你使用的是正确的PIN吗?在SypSyPrimalIZE()中做PPS吗?
以上来自于百度翻译 以下为原文 Just browsing the files, I don't see initalization for the UART PPS (peripheral pin select, TX and RX) But as you write, your TX seems to work perfectly. You did not comment on it, but apparently S3 is your RX, so ANSELx is set at least. But are you sure you are using the correct pin ? Did you do PPS in SYSTEM_Initialize(); ? |
|
|
|
|
|
这就是为什么StaseType初始化:ValueStaseSype初始化(Valuy){PixMaungRixIrimalIZE();StudioTrimaLealIZE();UART2x初始化();*************************************************************OSCCONL(OSCCon and 0xBF);和/或解锁PPRSRPO8BITS.RP16R= 0x00 05;//R3-和GUT;UART2: U2TX;RPAR11BITS。RP23 R= 0x00 08;//RD2--GT;SPI1:SCK1OUT;RPNR19BITS。U2RXR=0x00 1E;//R2--Gt;UART2: U2RX;******************************************************************************************************************************************************************根据数据表的PIN应该是正确的(我相信是这样)
以上来自于百度翻译 以下为原文 This is what comes whit System_Initialize: void SYSTEM_Initialize(void) { PIN_MANAGER_Initialize(); INTERRUPT_Initialize(); OSCILLATOR_Initialize(); UART2_Initialize(); LCD_Initialize(); } And PPS in PIN_MANAGER_Initialize(void) /**************************************************************************** * Set the PPS ***************************************************************************/ __builtin_write_OSCCONL(OSCCON & 0xbf); // unlock PPS RPOR8bits.RP16R = 0x0005; //RF3->UART2:U2TX; RPOR11bits.RP23R = 0x0008; //RD2->SPI1:SCK1OUT; RPINR19bits.U2RXR = 0x001E; //RF2->UART2:U2RX; __builtin_write_OSCCONL(OSCCON | 0x40); // lock PPS And yes according to data sheets PINS should be correct (I believe so) |
|
|
|
|
|
嗨,我没有看到你启用接收模式。
以上来自于百度翻译 以下为原文 Hi, I am not seeing that you enabled Receive mode. URXEN in UxSTA reg shoud be set. |
|
|
|
|
|
无效UART2X初始化(空隙){//STSEL 1;IDEN 8N;UARTEN启用;RTSMD禁用;唤醒禁用;ABAUD禁用;LPBACK禁用;BRGH启用;UXIN禁用;U2TXYRX;U2MODE =(0x800 8&~(1 & lt;&;15));/ /禁用UARTEN//UTXISEL0 TXONONEXCHAR;UTX;UTX;Urxel.RxOnOn.Char;UTXBRK已完成;UTXBRK;AddieBug;U2STA= 0x1400;/BaDeRead=9600;频率=4000000 Hz;U2BRG 103;U2BRG= 0x067;/AdMADR 0;ADMMADSE 0;U2ADMD=0xMUN;IEC1BIT.U2RXYE=1;/ /确保设置LAT位与UTART初始化U2MODEBIT对应的TXPIN高;U/ARTUN=1;/UTAR2Obj.TxHead=UART2O.TXBYTEQ;UART2OBO.TXTAIL= UART2YOTXBYTEQ;UART2YObj.RxHead=UART2YORXBYTEQ;UART2OBOR.RX尾随= UART2YORXBYTEQ;UART2OBOR.RXSTATESU.S.Value= TRUE;UARt2Obj.txStasu.sValue= TRUE;UART2OBO.TXSTATUS .SULL = FALSE;UART2OBOR.RXSTATUSS.SULL = FALSE;}
以上来自于百度翻译 以下为原文 void UART2_Initialize (void) { // STSEL 1; IREN disabled; PDSEL 8N; UARTEN enabled; RTSMD disabled; USIDL disabled; WAKE disabled; ABAUD disabled; LPBACK disabled; BRGH enabled; URXINV disabled; UEN TX_RX; U2MODE = (0x8008 & ~(1<<15)); // disabling UARTEN bit // UTXISEL0 TX_ONE_CHAR; UTXINV disabled; URXEN enabled; OERR NO_ERROR_cleared; URXISEL RX_ONE_CHAR; UTXBRK COMPLETED; UTXEN enabled; ADDEN disabled; U2STA = 0x1400; // BaudRate = 9600; Frequency = 4000000 Hz; U2BRG 103; U2BRG = 0x0067; // ADMADDR 0; ADMMASK 0; U2ADMD = 0x0000; IEC1bits.U2RXIE = 1; //Make sure to set LAT bit corresponding to TxPin as high before UART initialization U2MODEbits.UARTEN = 1; // enabling UART ON bit U2STAbits.UTXEN = 1; uart2_obj.txHead = uart2_txByteQ; uart2_obj.txTail = uart2_txByteQ; uart2_obj.rxHead = uart2_rxByteQ; uart2_obj.rxTail = uart2_rxByteQ; uart2_obj.rxStatus.s.empty = true; uart2_obj.txStatus.s.empty = true; uart2_obj.txStatus.s.full = false; uart2_obj.rxStatus.s.full = false; } |
|
|
|
|
|
所以PPS看起来不错,如果R3是TX,而R2是GB610的RXNO模拟功能ANSF,你能确保你的“智能”步进电机真的回答,RS485点击或RF2真的收到信号吗?(范围,逻辑分析器)你是否验证了你的U2RX中断从来没有被调用过?
以上来自于百度翻译 以下为原文 So PPS looks ok, if RF3 is TX and RF2 is RX no analog function ANSF for GB610 Did you / can you ensure that your "intelligent" motor stepper really answers and the RS485 click or RF2 really receive a signal ? (Scope, Logic Analyzer) Did you verify that your _U2RXInterrupt gets never called ? |
|
|
|
|
|
R3是TX和R2是RX -这是正确的。“智能”步进电机真的回答“-检查终端-发送/接收命令工作完美。RS45 5点击接收信号(测试范围)。不应该?GB610的模拟功能ANSF?
以上来自于百度翻译 以下为原文 RF3 is TX and RF2 is RX - that is correct. "intelligent" motor stepper really answers " - checked on terminal - transmit/receive commands works perfect. RS485 click does receive signal (tested on scope). _U2RXInterrupt is used. Should not be ? analog function ANSF for GB610? |
|
|
|
|
|
Rf2没有一个ANOLG函数,因此没有ANSF寄存器,所以您不必关心它。尝试设置Rf2作为输入。我不认为这是必要的,但它不会对测试造成伤害。为了确保问题位于软件,而不是硬件,您可以分离点击板,然后快捷方式R2和RF3。如果你仍然没有收到中断(你需要在U2RX中断中设置一个断点),那么你可以集中在固件上。你也可以检查IFS1BIT.U2RXIF,不管它是否被设置。(SFR寄存器IFS1)
以上来自于百度翻译 以下为原文 RF2 does not have an anolog function, therefore no ANSF register, so you don't have to care about it. Try setting RF2 as input. I don't think it is necessary, but it doesn't hurt for a test. To ensure that the problem is located in software, not hardware, you could detach the CLick-Board and then shortcut RF2 and RF3. If you still do not receive interrupts (you need to set a break point in _U2RXInterrupt) then you can concentrate on the firmware. You can also check the IFS1bits.U2RXIF, whether it gets set. (sfr register ifs1) |
|
|
|
|
|
这是你的真实密码吗?我根据我所看到的是你的缩进样式格式化了你的主要功能,并添加了一些注释。你在函数中定义了一个函数(可疑的样式---我不认为嵌套函数是C标准的一部分——而且在这里完全不合适),但是,也许,更多的IM。顺便说一句,你从来没打过电话!另一个评论:你以前的帖子似乎有一个传输没有显示在您的代码。当你改变你的代码中的任何东西时,保持助手的更新是很重要的。无论如何,步进电机在接收到它们时会发出回声吗?这就是接收缓冲区内容与发送缓冲区相同的原因吗?问候,戴夫
以上来自于百度翻译 以下为原文 Is this your real code? I have formatted your main function according to what I perceive is your indentation style and added a couple of comments. You defined a function inside a function (questionable style---I don't think nested functions are part of the C Standard---and totally inappropriate here), but, perhaps, more importantly, you never called it! int main(void) { // Begin main() SYSTEM_Initialize(); S3_TRIS = PIN_INPUT ; S3_ANSEL = DIGITAL ; printf( "f" ); printf( "S3 - (JA/ S4 - S" ); while (1) { // Begin main while() loop // What the heck? Defining a function inside main()?????????? void ButtonS3_Pressed() { // Begin function definition if(S3_PORT == BUTTON_PRESSED) { // Begin if() printf( "f" ); //lcd IO_RD0_SetHigh();//Transmit send_string ("#1(JAr"); IO_RD0_SetLow();//Receive do{ cRxDataS3= UART2_Read(); printf("%c", cRxDataS3); } while (cRxDataS3!='r'); __delay32(10000); }// End if() } // End function definition } // End main while() loop // Never gets here, right? return -1; } // End main() Another comment: One of your previous posts seems to have a transmission not shown in your code. It is kind of important to keep helpers up to date when you change anything in your code. Anyhow... Is the stepper motor echoing characters as it receives them? Is that why the receive buffer contents are the same as the transmit buffer? Regards, Dave |
|
|
|
|
|
+1i甚至没有意识到这一点。实际上编译器并不抱怨。由于OP表示发送作品,或者所显示的代码不是使用的代码,或者MCC被设置为将Prtf重定向到UART(最初的几个PrTNFS)。唯一的机会输出一些字符。由于他使用中断,所以即使调用完整的while循环也没有效果,仍然应该调用μu2rxBuffic。因此,接收缓冲器可能确实显示了来自步进器的回声,或者接线不正确。在任何情况下,OP都没有正确测试,否则他会看到这个问题。
以上来自于百度翻译 以下为原文 +1 I did not even realize that. Indeed the compiler does not complain. Since OP says that sending works, either the shown code is not the used one, or MCC was set to redirect Printf to UART (first few printfs). The only chance to output some characters. Since he is using interrupts, the _U2RXInterrupt still should be called, even if the complete while loop has no effect. So probably the receive buffer indeed shows the echo from the stepper,- or wiring is not correct. In any case OP did not test correctly, otherwise he would have seen this problem. |
|
|
|
|
|
这是你的真实密码吗?不,不是。主()中的新函数根本不应该是。IDO道歉混淆。正确-步进电机正在做回声只是没有。1Vr,期望答案是“1vr+序列号”char CRXDATS3;ValueSundSype字符串(conx char *x){(*x){uART2x写(*x++);而(u2Stest.TMTM==0){};}无效ButOns3PrsiEdst(){if(S3xPale==ButoNoPosich&& and;FLAG=0){PrtTf( f));//LCD标志=1;IOIORD0SSETHY();//T除了“是”RANSMIT SDENSY字符串(“α1VR”);//CHECK:1VR 68656576……IOIORD00SETLUVER();/ /接收DO {CRXDATS3= UART2AY读();PrimTf(“%C”,CRXDATS3);}(CRXDATAS3)!{′r′);γ-Delay32(10000);}否则(S3O端口=ButoNo.NothPoint and & and;and FLAG=1){Leq3StLoWo();Fig=0;} int main(空隙){StaseRealEngalIZILIZE();S3O-TrIs= PINI输入;S3YANSEL=数字;PrINTF(“f”);而(1){Butns3PaySead();}返回-1;}
以上来自于百度翻译 以下为原文 Is this your real code? - No, is not. New function in main() should not be at all. I do apologise for confusing. Correct - stepper motor is doing echo just with no #. Except "#1vr", expecting answer is "1vr +serial number" char cRxDataS3; void send_string (const char *x) { while (*x) { UART2_Write (*x++); while (U2STAbits.TRMT == 0) {}; } } void ButtonS3_Pressed() { if(S3_PORT == BUTTON_PRESSED&&flag==0) { printf( "f" ); //lcd flag=1; IO_RD0_SetHigh();//Transmit send_string ("#1vr"); //Echo: 1vr 68656576...something IO_RD0_SetLow();//Receive do{ cRxDataS3= UART2_Read(); printf("%c", cRxDataS3); } while (cRxDataS3!='r'); __delay32(10000); } else if (S3_PORT == BUTTON_NOT_PRESSED&&flag==1) { LED3_SetLow(); flag=0; } } int main(void) { SYSTEM_Initialize(); S3_TRIS = PIN_INPUT ; S3_ANSEL = DIGITAL ; printf( "f" ); while (1) { ButtonS3_Pressed(); } return -1; } Attachment(s) text.txt (0.80 KB) - downloaded 15 times |
|
|
|
|
只有小组成员才能发言,加入小组>>
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
475 浏览 0 评论
5794 浏览 9 评论
2334 浏览 8 评论
2224 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3530 浏览 3 评论
1125浏览 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 15:44 , Processed in 1.057394 second(s), Total 96, Slave 79 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
1733