完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
大家好,我正在为UART-2编写代码,我正在尝试使用PPS绘制UART-2引脚。我附上我的密码,我不知道哪里出了问题。我尝试了1种可能性。解锁和锁定序列,2。在FRM和3中使用代码示例。进一步详细说明IDE:MPLAB xCompiler:XC16.:SnadPICuController:dsPICEP512mu810main()和UART-2代码如下。
以上来自于百度翻译 以下为原文 Hello to all, I am writing code for UART-2 and I am trying to map UART-2 pins using PPS. I am attaching my code i don't know where I am going wrong. I tried every possibility using 1. Unlock and lock sequence, 2. Using code example in FRM and 3. demo examples. Further details IDE: MPLAB x Compiler: XC 16 Board : SnadPIC uController: dsPICEP512mu810 main() and UART-2 code are as follows. /* * File: main.c * Author: root * * Created on October 26, 2016, 3:42 AM */ #include #include "RS232_header.h" #include "p33EP512MU810.h" #pragma config GWRP = OFF // General Segment Write-Protect bit (General Segment may be written) #pragma config GSS = OFF // General Segment Code-Protect bit (General Segment Code protect is disabled) #pragma config GSSK = OFF // General Segment Key bits (General Segment Write Protection and Code Protection is Disabled) // FOSCSEL #pragma config FNOSC = FRC // Initial Oscillator Source Selection Bits #pragma config IESO = ON // Two-speed Oscillator Start-up Enable bit (Start up with user-selected oscillator source) // FOSC //#pragma config POSCMD = EC // Primary Oscillator Mode Select bits (EC (External Clock) Mode) #pragma config POSCMD = XT // Primary Oscillator Mode Select bits (EC (External Clock) Mode) //#pragma config OSCIOFNC = ON // OSC2 Pin Function bit (OSC2 is general purpose digital I/O pin) #pragma config OSCIOFNC = OFF // OSC2 Pin Function bit (OSC2 is general purpose digital I/O pin) #pragma config IOL1WAY = OFF // Peripheral pin select configuration (Allow multiple reconfigurations) #pragma config FCKSM = CSECMD // Clock Switching Mode bits (Clock switching is enabled,Fail-safe Clock Monitor is disabled) // FWDT #pragma config WDTPOST = PS32768 // Watchdog Timer Postscaler Bits (1:16,384) #pragma config WDTPRE = PR128 // Watchdog Timer Prescaler bit (1:32) #pragma config PLLKEN = ON // PLL Lock Wait Enable bit (Clock switch to PLL source will wait until the PLL lock signal is valid.) #pragma config WINDIS = OFF // Watchdog Timer Window Enable bit (Watchdog Timer in Non-Window mode) #pragma config FWDTEN = OFF // Watchdog Timer Enable bit (Watchdog timer enabled/disabled by user software) // FPOR #pragma config FPWRT = PWR128 // Power-on Reset Timer Value Select bits (Disabled) #pragma config BOREN = ON // Brown-out Reset (BOR) Detection Enable bit (BOR is disabled) #pragma config ALTI2C1 = OFF // Alternate I2C pins for I2C1 (SDA1/SCK1 pins are selected as the I/O pins for I2C1) #pragma config ALTI2C2 = OFF // Alternate I2C pins for I2C2 (SDA2/SCK2 pins are selected as the I/O pins for I2C2) // FICD #pragma config ICS = PGD3 // ICD Communication Channel Select bits (Communicate on PGEC3 and PGED3) #pragma config RSTPRI = PF // Reset Target Vector Select bit (Device will obtain reset instruction from Primary flash) #pragma config JTAGEN = OFF // JTAG Enable bit (JTAG is disabled) // FAS -- need to read #pragma config AWRP = OFF // Auxiliary Segment Write-protect bit (Auxiliary program memory is not write-protected) #pragma config APL = OFF // Auxiliary Segment Code-protect bit (Aux Flash Code protect is disabled) #pragma config APLK = OFF // Auxiliary Segment Key bits (Aux Flash Write Protection and Code Protection is Disabled) void TDelayms( unsigned t); int main(void) { PLLFBD=38; // M=40 CLKDIVbits.PLLPOST= 0x0; // N1=2 CLKDIVbits.PLLPRE = 0x0; // N2=2 RCONbits.SWDTEN = 0; // Disable Watch Dog Timer __builtin_write_OSCCONH(0x03); // New Oscillator Select XT(external) __builtin_write_OSCCONL(0x01); // Enable Shift to External Oscillator while (OSCCONbits.COSC != 0b011); // Wait for Shifting to new Oscillator while(OSCCONbits.LOCK != 1) {}; // Wait for PLL to lock UART2Init(); ANSELA = 0; ANSELC = 0; ANSELD = 0; TRISBbits.TRISB5 = 0; while (1) { LATBbits.LATB5 = 0; UART2TxString("dsPIC33ep512MU810n"); // Rcv_byte = UART1RxByte(200); // if (Rcv_byte) // { // UART1TxByte(Rcv_byte+0x30); // } TDelayms( 500); LATBbits.LATB5 = 1; TDelayms( 500); } return 0; } void TDelayms( unsigned t) { T1CON = 0x8000; // enable tmr1, Tcy, 1:1 while (t--) { TMR1 = 0; while (TMR1<40000); } T1CON = 0x0000; } /* * File: RS232_Config.c * Author: root * * Created on October 6, 2016, 5:33 PM */ #include "xc.h" #include "RS232_header.h" /******************** UART Functions ********************/ // initializes UART1 at specified baud rate // FCY defined in Header file void UART2Init() { U2MODE = 0x0; U2BRG = 260; // set baud rate generator Baud Rate setting for 9600 U2STA = 0x0; IFS1bits.U2TXIF = 0; // Clear UART Tx interrupt flag IEC1bits.U2TXIE = 1; // Enable UART TX interrupt U2STAbits.UTXEN = 1; // Enable UART TX U2MODEbits.UARTEN = 1; // Enable UART // __builtin_write_OSCCONL(0x46); // unlock sequence - step 1 // __builtin_write_OSCCONH(0x57); // unlock sequence - step 2 _IOLOCK = 0; RPOR9bits.RP101R = 3; // RF5/RP101 as U2TX _U2RXR = 100; // RP100/RF4 as U2RX // __builtin_write_OSCCONL(0x46); // unlock sequence - step 1 // __builtin_write_OSCCONH(0x57); // unlock sequence - step 2 _IOLOCK = 1; // re-lock the ports } // writes a byte to UART1 void UART2TxByte(char byte) { if(U2STAbits.UTXBF) while(!U2STAbits.TRMT); U2TXREG = byte; } // reads a byte from UART 1 -> polling char UART2RxByte(unsigned int timeout) { if (U2STAbits.OERR == 1) { U2STAbits.OERR = 0; // Clear overrun error return -1; } // check here for appropriate bits while (!U2STAbits.URXDA && timeout > 0) // wait for data to be available timeout--; return U2RXREG; // read the character from the receive buffer // return data byte } // writes a string to UART1 void UART2TxString(char *str) { int i = 0; while(str != 0) { UART2TxByte(str[i++]); } } void EnableU2RxInterrupt() { IEC1bits.U2RXIE = 1; // Enable UART Rx interrupt } void DisableU2Rxinterrupt() { IEC1bits.U2RXIE = 0; // dsiable UART Rx interrupt } void __attribute__((__interrupt__,no_auto_psv)) _U2TXInterrupt(void) { IFS1bits.U2TXIF = 0; // Clear TX Interrupt flag } |
|
相关推荐
2个回答
|
|
首先,取出处理器特定的include——“xc.h”include为您提供。其次,PPS寄存器的默认设置是它们是解锁的,因此您可以忘记解锁序列(至少对于现在,您可能希望在开发周期中稍后锁定它们)。在缺省情况下,PPS寄存器锁定的设置方式也有(轻微的)麻烦,因此也不要锁定寄存器。请查看FRM UART部分4.1节中关于设置UARTEN和UTXEN位的顺序的说明。(我必须承认,数据表本身并不直接涉及这一点——许多其他类似设备的数据表也涉及这一点。)严格地说,没有必要为TX(尤其是)和RX引脚设置TRIS位,但是它不会造成伤害。
以上来自于百度翻译 以下为原文 Firstly, take out the processor specific include - the 'xc.h' include does that for you. Secondly, the default settings for the PPS registers is that they are unlocked and so you can forget about the unlock sequence (at least for now - you may want to lock them later in the development cycle). There is also a (slight) nasty in the way the PPS register locking is set up by default so don't lock the registers either. Check out the note in Section 4.1 of the FRM UART section about the order of setting the UARTEN and UTXEN bits. (I must admit that the data sheet itself does not directly refer to this - many of the other data sheets for similar devices do. However it is in the FRM.) Strictly speaking it is not necessary to set the TRIS bits for the TX (in particular) and RX pins, but it does not hurt. Susan |
|
|
|
UART代码是100%工作。我已经测试了超过100次在各种DSPIC30F和DSPIC3F设备上。但是,不管我用PPS如何工作,只需在启用UART之前初始化PPS(PIN)。
以上来自于百度翻译 以下为原文 Well the UART code is 100 percent working. I have tested that more than 100 times on various dsPIC30F and dsPIC33F devices. But any way I made it work with PPS as well, just have to initialize PPS (pins) before enabling the UART.Smile: |
|
|
|
只有小组成员才能发言,加入小组>>
5166 浏览 9 评论
2000 浏览 8 评论
1929 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3175 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2227 浏览 5 评论
736浏览 1评论
619浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
507浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
633浏览 0评论
530浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-25 10:17 , Processed in 1.621887 second(s), Total 81, Slave 64 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号