完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
您好,我浏览了数据表并搜索了google,但仍然无法将它们组合在一起。我想为简单的轮询发送/接收配置一个uart,而不使用plib,因为plib似乎不起作用。除此之外,我想像在18F组装时那样直接理解和控制硬件,我只需要知道如何为TX/RX选择几个管脚以及如何配置控制寄存器,并且读/写uart的状态和数据寄存器。这是可能的,但是你知道如何让plib工作,那么我也会非常感谢这些信息!谢谢,祝你有美好的一天,杰西
以上来自于百度翻译 以下为原文 Good Day, I've looked over the data sheet and searched google and still can't pull it together. I'd like to configure a uart for simple polled send/receive, without using plib, because plib doesn't seem to be working. (plib.h is present but it includes a whole bunch of things in Besides, I want to understand and control the hardware directly like I did in the days of assembly on 18F, I just need to know how to select a couple of pins for TX/RX and how to configure the control registers, and read/write the status and data registers for the uart. If none of that is possible, but you know how to get plib working, then I would be most grateful for that information as well! Thanks & have a great day, Jesse |
|
相关推荐
5个回答
|
|
下面是我在PIC32MX250F128B(同一PIC系列内存较少的一个)中设置UART2的方法。我在接收机上使用了中断,对发射机和UART2.c(附加文件)使用DMA。++在调用UART2Init()之后必须添加“IEC1bits.U2RXIE=1;//enable RXIE”。
以上来自于百度翻译 以下为原文 Here is what I used to setup UART2 in PIC32MX250F128B (the one in the same PIC family with less memory). I used interrupt on receiver and use DMA for the transmitter. void ConfigurePinReMap() { //setup UART2 RX/TX pins SYSKEY = 0x00; SYSKEY = 0xAA996655; SYSKEY = 0x556699AA; CFGCONbits.IOLOCK=0; U2RXR= 0x04; // U2Rx:RPB8 RPB9Rbits.RPB9R= 0x02; // U2Tx:RPB9 CFGCONbits.IOLOCK=1; SYSKEY = 0x00; return; } void __ISR(_UART2_VECTOR, ipl6AUTO) _U2Interrupt(void) { unsigned char c; if (IFS1bits.U2RXIF) { LATBbits.LATB1 ^= 1; while (U2STAbits.URXDA) { c = U2RXREG; UB_ProcessCommand(c); } IFS1bits.U2RXIF = 0; } } // ------------ the setup of DMA for UART2 ------------- void APP_HostInitialize() { // init DMA // Iniialisation DMA UART TX IFS1bits.U2TXIF = 0; IEC1bits.U2TXIE = 0; IEC1CLR= _IEC1_DMA0IE_MASK; // disable DMA channel 0 interrupts IFS1CLR= _IFS1_DMA0IF_MASK; //0x00010000; // clear existing DMA channel 0 interrupt flag DMACONSET= _DMACON_ON_MASK; // enable the DMA controller // program the transfer DCH0SSA=KVA_TO_PA(rspBuffer); // transfer source physical address DCH0DSA=KVA_TO_PA(&U2TXREG); // transfer destination physical address DCH0ECONbits.CHSIRQ = _UART2_TX_IRQ; // IRQ UART2 TX DCH0ECONbits.SIRQEN = 1; // Activation de la commande via interruption DCH0SSIZ=BUFFER_SIZE; // source size 256 bytes DCH0DSIZ=1; // destination size 1 bytes DCH0CSIZ=1; // 1 bytes transferred per event } and the UART2.c (attached file). ++ you have to add "IEC1bits.U2RXIE= 1; //enable RXIE" after calling UART2Init(). Attachment(s) uart2.c (12.55 KB) - downloaded 128 times |
|
|
|
嗨,你可以使用MCC插件来生成这个PIC32的代码
以上来自于百度翻译 以下为原文 Hi, you can use MCC plugin to generate code for this PIC32 Regards |
|
|
|
或者你可以把外设文件夹加载到包含PLIB的目录中。我想如果你愿意的话,我可以想出如何复制一个副本。
以上来自于百度翻译 以下为原文 Or you can just load the peripherals folder into the directory containing plib. I imagine I can figure out how to post a copy if you wish. |
|
|
|
您已经在这个帖子中回答了问题,HTTP://www. McCHIP.COM/FUMMS/M82229ASPX
以上来自于百度翻译 以下为原文 You already have answer for your question in this post, http://www.microchip.com/forums/m882729.aspx |
|
|
|
谢谢提姆!虽然不完全是我所寻找的,你的答案提供了足够的线索,让我开始在正确的方向,我现在有我的测试程序工作!我将复制我的代码在这里为未来的探险家,如果他们有一个类似的初学者的问题!(我意识到这很简单,我应该使用中断,DMA,和所有这些,但这只是一个演示程序,以显示初学者如何基本的UART工作,而不混淆他们的所有其他奇妙的特征!)你应该能够把它烧成一个PIC32 MX27 0F256B 28针,它有正确的电容器连接,它应该运行没有晶体或任何东西。再次感谢,Jeesse
以上来自于百度翻译 以下为原文 Thanks Tim! While not exactly what I was looking for, your answer provided enough clues to get me started in the right direction and I now have my test program working! I'll reproduce my code here for future explorers in case they have a similar beginner's question! (I realize this is very simple and I should be using interrupts, DMA, and all that, but this is just a demo program to show beginners how the basics of the uart works without confusing them all of the other wonderful features!) You should be able to just burn this into an PIC32MX270F256B 28 pin that has the correct capacitors connected, and it should run without crystals or anything. Thanks again, Jeesse // PIC32MX270F256B Configuration Bit Settings // Set up to run at 48Mhz off of the built in 8Mhz RC osc, with peripherals running at same speed as core. // 'C' source line config statements // DEVCFG3 // USERID = No Setting #pragma config PMDL1WAY = ON // Peripheral Module Disable Configuration (Allow only one reconfiguration) #pragma config IOL1WAY = ON // Peripheral Pin Select Configuration (Allow only one reconfiguration) #pragma config FUSBIDIO = ON // USB USID Selection (Controlled by the USB Module) #pragma config FVBUSONIO = ON // USB VBUS ON Selection (Controlled by USB Module) // DEVCFG2 #pragma config FPLLIDIV = DIV_2 // PLL Input Divider (4x Divider) #pragma config FPLLMUL = MUL_24 // PLL Multiplier (24x Multiplier) #pragma config UPLLIDIV = DIV_12 // USB PLL Input Divider (12x Divider) #pragma config UPLLEN = OFF // USB PLL Enable (Disabled and Bypassed) #pragma config FPLLODIV = DIV_2 // System PLL Output Clock Divider (PLL Divide by 256) // DEVCFG1 #pragma config FNOSC = FRCPLL // Oscillator Selection Bits (Fast RC Osc with PLL) #pragma config FSOSCEN = ON // Secondary Oscillator Enable (Enabled) #pragma config IESO = ON // Internal/External Switch Over (Enabled) #pragma config POSCMOD = OFF // Primary Oscillator Configuration (Primary osc disabled) #pragma config OSCIOFNC = OFF // CLKO Output Signal Active on the OSCO Pin (Disabled) #pragma config FPBDIV = DIV_1 // Peripheral Clock Divisor (Pb_Clk is Sys_Clk/1) #pragma config FCKSM = CSDCMD // Clock Switching and Monitor Selection (Clock Switch Disable, FSCM Disabled) #pragma config WDTPS = PS1048576 // Watchdog Timer Postscaler (1:1048576) #pragma config WINDIS = OFF // Watchdog Timer Window Enable (Watchdog Timer is in Non-Window Mode) #pragma config FWDTEN = OFF // Watchdog Timer Enable (WDT Disabled (SWDTEN Bit Controls)) #pragma config FWDTWINSZ = WINSZ_25 // Watchdog Timer Window Size (Window Size is 25%) // DEVCFG0 #pragma config JTAGEN = OFF // JTAG Enable (JTAG Disabled) #pragma config ICESEL = ICS_PGx3 // ICE/ICD Comm Channel Select (Communicate on PGEC3/PGED3) #pragma config PWP = OFF // Program Flash Write Protect (Disable) #pragma config BWP = OFF // Boot Flash Write Protect bit (Protection Disabled) #pragma config CP = OFF // Code Protect (Protection Disabled) // #pragma config statements should precede project file includes. // Use project enums instead of #define for ON and OFF. #include #include #include #include #include int sendstring1(char *line) { static int i; i=0; while(line) { while(U1STAbits.UTXBF) { ; } U1TXREG=line; i++; } return(i); } int sendstring2(char *line) { static int i; i=0; while(line) { while(U2STAbits.UTXBF) { ; } U2TXREG=line; i++; } return(i); } void main(void) { static unsigned int i; static char ts[50]; i=0; SYSKEY = 0x0; //Magic sequence to allow hardware to be reconfigured. SYSKEY = 0xAA996655; // SYSKEY unlock SYSKEY = 0x556699AA; // rest of magic sequence. CFGCONbits.IOLOCK=0; // unlock configuration U1RXR=0x04; //Uart 1 RX on RPB2 RPB3R=0x01;//Uart 1 TX on RPB3 U2RXR=0x02; //Uart 2 RX on RPB1 RPB0R=0x02; //Uart 2 TX on RPB0 CFGCONbits.IOLOCK=1; // relock configuration SYSKEY = 0x0; //Clear out configuration mode. // TRISBbits.TRISB0=0; //This sets the TX pins as outputs, but I guess that's not actually needed for the uart. // TRISBbits.TRISB1=1; //But it can be handy in trouble shooting and does not hurt anything. // TRISBbits.TRISB2=1; // TRISBbits.TRISB3=0; ANSELBbits.ANSB0=0; //Disable Analog functionality on the pins used for the two uarts. ANSELBbits.ANSB1=0; //Required. ANSELBbits.ANSB2=0; ANSELBbits.ANSB3=0; #define BPS (115200.0) #define CPUSPEED (48000000.0)//actually its based off of PBCLK which can be diveded down from sysclk. static double actualbps,brgf;//Some temporary vars to make debugging easier. U1MODE = 0; U1MODEbits.BRGH = 0; //4x or 16x baud rate generator prescaler. 1 means less resolution, higher speeds brgf = (((double)CPUSPEED)/(4.0*(1.0+(3.0*(double)(1-U1MODEbits.BRGH)))*((double)BPS)))-1; U1BRG = brgf; actualbps=((double)CPUSPEED)/(4.0*(1.0+(3.0*(double)(1-U1MODEbits.BRGH)))*((double)(U1BRG+1))); U1STA = 0; //Status and Control //U1MODEbits.RXINV=1; //Only invert if you're using a 10k resistor instead of an inverting level shifter! U1MODEbits.UARTEN = 1; //Enable the uart. U1STAbits.UTXEN = 1; //Uart TX Enable IFS1bits.U1RXIF = 0; //Interrupt flag status / Uart 1 RX Interrupt Flag U1STAbits.URXEN = 1; //Uart RX Enable U2MODE = 0; U2MODEbits.BRGH = 0; //4x or 16x baud rate generator prescaler. 1 means less resolution, higher speeds brgf = (((double)CPUSPEED)/(4.0*(1.0+(3.0*(double)(1-U2MODEbits.BRGH)))*((double)BPS)))-1; U2BRG = brgf; actualbps=((double)CPUSPEED)/(4.0*(1.0+(3.0*(double)(1-U2MODEbits.BRGH)))*((double)(U2BRG+1))); U2STA = 0; //Status and Control //U2MODEbits.RXINV=1; //Only invert if you're using a 10k resistor instead of an inverting level shifter!!! U2MODEbits.UARTEN = 1; //Enable the uart. U2STAbits.UTXEN = 1; //Uart TX Enable. IFS1bits.U2RXIF = 0; //Interrupt flag status / Uart 2 RX Interrupt Flag (Clear it) U2STAbits.URXEN = 1; //Uart RX Enable while(1) { static char c; if (IFS1bits.U2RXIF) //If we have received a char, { c=U2RXREG; //read it U2TXREG=c; //echo it back if(c=='A') //If that char was "A" then send a bunch of long stuff. { sendstring2("Long long ago, far far away, there lived deep deep in the woodsrn"); } IFS1bits.U2RXIF=0; } if(c=='B') //If "B" was the last char, then stream the value of i as it counts up. { sprintf(ts,"we got %drn",i); sendstring2(ts); } i++; } } |
|
|
|
只有小组成员才能发言,加入小组>>
5136 浏览 9 评论
1987 浏览 8 评论
1917 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3155 浏览 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 10:37 , Processed in 1.470380 second(s), Total 85, Slave 68 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号