完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
电子发烧友论坛|
大家好,因为我是嵌入式时代的新手,所以在尝试用PIC24FJ256GB110(使用浏览器16开发板)实现UART通信时,遇到了一些小问题。然后生成代码。在生成代码之后,我得在文件“uart2.c”和“main.c”中获取uart例程,在这里我必须实现这些代码。我的main.c文件代码如下所示:我能够闪存和运行代码。我将rs232端口与电缆连接,并将其转换为u***并检查该端口。在串行模拟器中。由于我运气不好,我没有得到输出。我试图调试,但没有运气。任何人可以帮我。预先感谢。
以上来自于百度翻译 以下为原文 Hello everyone as I am new in embedded era,So I am facing little bit problem while trying to implement code to achieve uart communication with PIC24FJ256GB110 (using explorer 16 development board). I am using MPLAB X IDE v.3.35.I am opening MCC(MPLAB CODE configurator) and selecting UART2 module and then generating code. After generating code I am getting uart routines in file "uart2.c" and "main.c" where I have to implement that code. My main.c file code is as shown below: #include "mcc_generated_files/mcc.h" #define MY_BUFFER_SIZE 10 /* Main application */ main(void) { // initialize the device SYSTEM_Initialize(); const uint8_t writeBuffer[35] = "1234567890ABCDEFGHIJKLMNOPn" ; unsigned int numBytes = 0; int writebufferLen = 26; // UART2_Initialize(); // It is already initialised inside SYSTEM_Initialize() method. while(numBytes < writebufferLen) { int bytesToWrite = UART2_TransmitBufferSizeGet(); numBytes += UART2_WriteBuffer ( writeBuffer+numBytes, bytesToWrite) ; } } I am able to flash and run the code. I am connecting rs232 port with cable which converts it into u*** and checking that port in an serial emulator. As my hard luck I am not getting output.I tried to debug but no luck. Can anyone assist me please. Thanks in advance. |
|
相关推荐
9个回答
|
|
|
嘿,谢谢你的建议,它工作了,我在我的串行模拟器中得到输出。正如你说的,我把Pin49(RF4)连接到U2RX,Pin50(RF5)连接到U2TX。但是我仍然没有得到完整的缓冲数据作为输出。缓冲区数据如前所述。我只得到“1234567890ABCDEF”数据。正如您所知道的,为了实现与其他设备的串行通信,我想实现一个UART代码。我无法附加MCC生成的uart2.c和pin_manager.c文件。所以我是张贴1。UART2.C2:PisiManger-C.C.请进一步协助我。
以上来自于百度翻译 以下为原文 Hey thanks for your suggestion it worked I am getting output in my serial emulator. As you said I connected Pin49(RF4) to U2RX and Pin50(RF5) to U2TX. But still I am not getting complete buffer data as an output. Buffer data is as follows which I mentioned in previous post. const uint8_t writeBuffer[35] = "1234567890ABCDEFGHIJKLMNOPn" ; I am getting only "1234567890ABCDEF" data.As you will be knowing that I want to implement a UART code in order to achieve serial communication with other device. I am not able to attach MCC generated uart2.c and pin_manager.c file. So I am posting below. 1: uart2.c /** UART2 Generated Driver File @Company Microchip Technology Inc. @File Name uart2.c @Summary This is the generated source file for the UART2 driver using MPLAB(c) Code Configurator @Description This source file provides APIs for driver for UART2. Generation Information : Product Revision : MPLAB(c) Code Configurator - 3.15.0 Device : PIC24FJ256GB110 Driver Version : 0.5 The generated drivers are tested against the following: Compiler : XC16 1.26 MPLAB : MPLAB X 3.20 */ /* (c) 2016 Microchip Technology Inc. and its subsidiaries. You may use this software and any derivatives exclusively with Microchip products. THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP PRODUCTS, COMBINATION WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION. IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE. MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE TERMS. */ /** Section: Included Files */ #include "uart2.h" /** Section: Data Type Definitions */ /** UART Driver Queue Status @Summary Defines the object required for the status of the queue. */ typedef union { struct { uint8_t full:1; uint8_t empty:1; uint8_t reserved:6; }s; uint8_t status; } UART_BYTEQ_STATUS; /** UART Driver Hardware Instance Object @Summary Defines the object required for the maintenance of the hardware instance. */ typedef struct { /* RX Byte Q */ uint8_t *rxTail ; uint8_t *rxHead ; /* TX Byte Q */ uint8_t *txTail ; uint8_t *txHead ; UART_BYTEQ_STATUS rxStatus ; UART_BYTEQ_STATUS txStatus ; } UART_OBJECT ; static UART_OBJECT uart2_obj ; /** UART Driver Queue Length @Summary Defines the length of the Transmit and Receive Buffers */ #define UART2_CONFIG_TX_BYTEQ_LENGTH 8 #define UART2_CONFIG_RX_BYTEQ_LENGTH 8 /** UART Driver Queue @Summary Defines the Transmit and Receive Buffers */ static uint8_t uart2_txByteQ[UART2_CONFIG_TX_BYTEQ_LENGTH] ; static uint8_t uart2_rxByteQ[UART2_CONFIG_RX_BYTEQ_LENGTH] ; /** UART Hardware FIFO Buffer Length @Summary Defines the length of the Transmit and Receive FIFOs */ #define UART2_TX_FIFO_LENGTH 1 #define UART2_RX_FIFO_LENGTH 1 /** Section: Driver Interface */ void UART2_Initialize (void) { // STSEL 1; IREN disabled; PDSEL 8N; UARTEN enabled; RTSMD disabled; USIDL disabled; WAKE disabled; ABAUD disabled; LPBACK disabled; BRGH enabled; RXINV disabled; UEN TX_RX; U2MODE = 0x8008; // OERR NO_ERROR_cleared; URXISEL RX_ONE_CHAR; UTXBRK COMPLETED; UTXEN disabled; ADDEN disabled; UTXISEL0 TX_ONE_CHAR; UTXINV disabled; U2STA = 0x0000; // U2TXREG 0; U2TXREG = 0x0000; // BaudRate = 115200; Frequency = 4000000 Hz; BRG 8; U2BRG = 0x0008; IEC1bits.U2RXIE = 1; 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; } /** Maintains the driver's transmitter state machine and implements its ISR */ void __attribute__ ( ( interrupt, no_auto_psv ) ) _U2TXInterrupt ( void ) { if(uart2_obj.txStatus.s.empty) { IEC1bits.U2TXIE = false; return; } IFS1bits.U2TXIF = false; int count = 0; while((count < UART2_TX_FIFO_LENGTH)&& !(U2STAbits.UTXBF == 1)) { count++; U2TXREG = *uart2_obj.txHead; uart2_obj.txHead++; if(uart2_obj.txHead == (uart2_txByteQ + UART2_CONFIG_TX_BYTEQ_LENGTH)) { uart2_obj.txHead = uart2_txByteQ; } uart2_obj.txStatus.s.full = false; if(uart2_obj.txHead == uart2_obj.txTail) { uart2_obj.txStatus.s.empty = true; break; } } } void __attribute__ ( ( interrupt, no_auto_psv ) ) _U2RXInterrupt( void ) { int count = 0; while((count < UART2_RX_FIFO_LENGTH) && (U2STAbits.URXDA == 1)) { count++; *uart2_obj.rxTail = U2RXREG; uart2_obj.rxTail++; if(uart2_obj.rxTail == (uart2_rxByteQ + UART2_CONFIG_RX_BYTEQ_LENGTH)) { uart2_obj.rxTail = uart2_rxByteQ; } uart2_obj.rxStatus.s.empty = false; if(uart2_obj.rxTail == uart2_obj.rxHead) { //Sets the flag RX full uart2_obj.rxStatus.s.full = true; break; } } IFS1bits.U2RXIF = false; } void __attribute__ ( ( interrupt, no_auto_psv ) ) _U2ErrInterrupt ( void ) { if ((U2STAbits.OERR == 1)) { U2STAbits.OERR = 0; } IFS4bits.U2ERIF = false; } /** Section: UART Driver Client Routines */ uint8_t UART2_Read( void) { uint8_t data = 0; data = *uart2_obj.rxHead; uart2_obj.rxHead++; if (uart2_obj.rxHead == (uart2_rxByteQ + UART2_CONFIG_RX_BYTEQ_LENGTH)) { uart2_obj.rxHead = uart2_rxByteQ; } if (uart2_obj.rxHead == uart2_obj.rxTail) { uart2_obj.rxStatus.s.empty = true; } uart2_obj.rxStatus.s.full = false; return data; } unsigned int UART2_ReadBuffer( uint8_t *buffer, const unsigned int bufLen) { unsigned int numBytesRead = 0 ; while ( numBytesRead < ( bufLen )) { if( uart2_obj.rxStatus.s.empty) { break; } else { buffer[numBytesRead++] = UART2_Read () ; } } return numBytesRead ; } void UART2_Write( const uint8_t byte) { IEC1bits.U2TXIE = false; *uart2_obj.txTail = byte; uart2_obj.txTail++; if (uart2_obj.txTail == (uart2_txByteQ + UART2_CONFIG_TX_BYTEQ_LENGTH)) { uart2_obj.txTail = uart2_txByteQ; } uart2_obj.txStatus.s.empty = false; if (uart2_obj.txHead == uart2_obj.txTail) { uart2_obj.txStatus.s.full = true; } IEC1bits.U2TXIE = true ; } unsigned int UART2_WriteBuffer( const uint8_t *buffer , const unsigned int bufLen ) { unsigned int numBytesWritten = 0 ; while ( numBytesWritten < ( bufLen )) { if((uart2_obj.txStatus.s.full)) { break; } else { UART2_Write (buffer[numBytesWritten++] ) ; } } return numBytesWritten ; } UART2_TRANSFER_STATUS UART2_TransferStatusGet (void ) { UART2_TRANSFER_STATUS status = 0; if(uart2_obj.txStatus.s.full) { status |= UART2_TRANSFER_STATUS_TX_FULL; } if(uart2_obj.txStatus.s.empty) { status |= UART2_TRANSFER_STATUS_TX_EMPTY; } if(uart2_obj.rxStatus.s.full) { status |= UART2_TRANSFER_STATUS_RX_FULL; } if(uart2_obj.rxStatus.s.empty) { status |= UART2_TRANSFER_STATUS_RX_EMPTY; } else { status |= UART2_TRANSFER_STATUS_RX_DATA_PRESENT; } return status; } uint8_t UART2_Peek(uint16_t offset) { if( (uart2_obj.rxHead + offset) > (uart2_rxByteQ + UART2_CONFIG_RX_BYTEQ_LENGTH)) { return uart2_rxByteQ[offset - (uart2_rxByteQ + UART2_CONFIG_RX_BYTEQ_LENGTH - uart2_obj.rxHead)]; } else { return *(uart2_obj.rxHead + offset); } } unsigned int UART2_ReceiveBufferSizeGet(void) { if(!uart2_obj.rxStatus.s.full) { if(uart2_obj.rxHead > uart2_obj.rxTail) { return(uart2_obj.rxHead - uart2_obj.rxTail); } else { return(UART2_CONFIG_RX_BYTEQ_LENGTH - (uart2_obj.rxTail - uart2_obj.rxHead)); } } return 0; } unsigned int UART2_TransmitBufferSizeGet(void) { if(!uart2_obj.txStatus.s.full) { if(uart2_obj.txHead > uart2_obj.txTail) { return(uart2_obj.txHead - uart2_obj.txTail); } else { return(UART2_CONFIG_TX_BYTEQ_LENGTH - (uart2_obj.txTail - uart2_obj.txHead)); } } return 0; } bool UART2_ReceiveBufferIsEmpty (void) { return(uart2_obj.rxStatus.s.empty); } bool UART2_TransmitBufferIsFull(void) { return(uart2_obj.txStatus.s.full); } UART2_STATUS UART2_StatusGet (void) { return U2STA; } /** End of File */ 2:pin_manager.c /** System Interrupts Generated Driver File @Company: Microchip Technology Inc. @File Name: pin_manager.c @Summary: This is the generated manager file for the MPLAB(c) Code Configurator device. This manager configures the pins direction, initial state, analog setting. The peripheral pin select, PPS, configuration is also handled by this manager. @Description: This source file provides implementations for MPLAB(c) Code Configurator interrupts. Generation Information : Product Revision : MPLAB(c) Code Configurator - 3.15.0 Device : PIC24FJ256GB110 Version : 1.02 The generated drivers are tested against the following: Compiler : XC16 1.26 MPLAB : MPLAB X 3.20 Copyright (c) 2013 - 2015 released Microchip Technology Inc. All rights reserved. Microchip licenses to you the right to use, modify, copy and distribute Software only when embedded on a Microchip microcontroller or digital signal controller that is integrated into your product or third party product (pursuant to the sublicense terms in the accompanying license agreement). You should refer to the license agreement accompanying this Software for additional information regarding your rights and obligations. SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROCHIP OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT, NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS. */ /** Section: Includes */ #include #include "pin_manager.h" /** void PIN_MANAGER_Initialize(void) */ void PIN_MANAGER_Initialize(void) { /**************************************************************************** * Setting the Output Latch SFR(s) ***************************************************************************/ LATA = 0x0000; LATB = 0x0000; LATC = 0x0000; LATD = 0x0000; LATE = 0x0000; LATF = 0x0000; LATG = 0x0000; /**************************************************************************** * Setting the GPIO Direction SFR(s) ***************************************************************************/ TRISA = 0xC6FF; TRISB = 0xFFFF; TRISC = 0xF01E; TRISD = 0xFFFF; TRISE = 0x03FF; TRISF = 0x311F; TRISG = 0xF3CF; /**************************************************************************** * Setting the Weak Pull Up and Weak Pull Down SFR(s) ***************************************************************************/ CNPD1 = 0x0000; CNPD2 = 0x0000; CNPD3 = 0x0000; CNPD4 = 0x0000; CNPD5 = 0x0000; CNPD6 = 0x0000; CNPU1 = 0x0000; CNPU2 = 0x0000; CNPU3 = 0x0000; CNPU4 = 0x0000; CNPU5 = 0x0000; CNPU6 = 0x0000; /**************************************************************************** * Setting the Open Drain SFR(s) ***************************************************************************/ ODCA = 0x0000; ODCB = 0x0000; ODCC = 0x0000; ODCD = 0x0000; ODCE = 0x0000; ODCF = 0x0000; ODCG = 0x0000; /**************************************************************************** * Setting the Analog/Digital Configuration SFR(s) ***************************************************************************/ AD1PCFGH = 0x0000; AD1PCFGL = 0x00C0; /**************************************************************************** * Set the PPS ***************************************************************************/ __builtin_write_OSCCONL(OSCCON & 0xbf); // unlock PPS RPOR8bits.RP17R = 0x0005; //RF5->UART2:U2TX; RPINR19bits.U2RXR = 0x000A; //RF4->UART2:U2RX; __builtin_write_OSCCONL(OSCCON | 0x40); // lock PPS } Please assist me further. |
|
|
|
|
|
因为它适用于一些(16)个字符,所以设置就可以了。
以上来自于百度翻译 以下为原文 Since it works for some (16) characters, the setup is ok. I do not know, what this MCC function does int bytesToWrite = UART2_TransmitBufferSizeGet(); but obviously this should have to do with your problem, and numBytes += does not just increment by 1 |
|
|
|
|
|
你好,开发人员,我对此一无所知,我从来没有尝试过。我仍然在努力实现图片和其他设备之间的串行通信代码。为了你的帮助,我搜索了一些链接,我和你分享。也许对你会有帮助。通过链接,亲爱的,帮助你自己。
以上来自于百度翻译 以下为原文 Hi Developer, I don't have an idea about this and I never tried this. I am still struggling to implement the code for serial communication between pic and other device. For your help I searched some links that I am sharing with you.May be will help you. Go through the link and help yourself dear. |
|
|
|
|
|
他很好。我有一个非常小的疑问。如果我们使用诸如E.g:UbsEnth.()的函数。我们需要添加任何标题或任何.LIB文件或任何这样的文件。谢谢。
以上来自于百度翻译 以下为原文 Hi That is fine. I have a very small doubt. If we are usng functions such as e.g:USBsend(). Do we need to add any headers or any .lib files or any such files. Thanks |
|
|
|
|
|
HiSbsEnter()是微芯片预定义函数。但我想知道是否需要在我的项目窗口中添加任何页眉或文件。谢谢你的帮助。
以上来自于百度翻译 以下为原文 Hi USBsend() is Microchip predefined function. But I want to know is it required to add any header or any files to my project window. Thanks for assisting me |
|
|
|
|
|
嗨,PalaveTew告诉我如何定义微芯片定义的函数,比如UbHoestIn(),请帮助。非常紧急。当我使用这些函数时,会出现一个错误,我将如何添加头文件?
以上来自于百度翻译 以下为原文 Hi pallav Tell me how the microchip defined functions such as USBhostint() can be understood Please help. Its very urgent. When I use these functions an error is coming How will I add header files |
|
|
|
|
|
@开发人员不太有礼貌地劫持其他开发人员线程。你甚至用相同但完全无关的问题劫持其他线程。你不会以这样的方式得到答案,但更糟糕的是,你在扼杀原创开发者的线索。
以上来自于百度翻译 以下为原文 @developer Its not very polite to hijack other developers threads. You are even hijacking other threads with your same, but completely unrelated question. You will not get answers this way, but even worse, you are killing the thread of the original developer. |
|
|
|
|
|
>>>这意味着它应该只运行while循环一次,但是它要运行无限循环。请检查循环中的C代码,它不行。与PIC无关
以上来自于百度翻译 以下为原文 >>> So it means it should run the while loop only once but its going for infinite loop. Please check your C code for the loop, it is not ok. Nothing related to the PIC |
|
|
|
|
|
尝试增加UART2YRXXFIFOH长度,并设置一个断点ATU2Stist.Orr并查看它是否引起问题。
以上来自于百度翻译 以下为原文 try Increasing the UART2_RX_FIFO_LENGTH and also put a breakpoint at U2STAbits.OERR and see if it is causing a problem. |
|
|
|
|
只有小组成员才能发言,加入小组>>
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
473 浏览 0 评论
5793 浏览 9 评论
2334 浏览 8 评论
2224 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3530 浏览 3 评论
1124浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
1095浏览 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 02:30 , Processed in 1.032364 second(s), Total 90, Slave 73 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
1688