• AVR Freaks

Hot!Receive data from EUSART interrupt using MCC Code

Author
Sherif89
Starting Member
  • Total Posts : 33
  • Reward points : 0
  • Joined: 2020/02/10 09:24:36
  • Location: 0
  • Status: offline
2020/02/20 09:19:28 (permalink)
0

Receive data from EUSART interrupt using MCC Code

Hello, 
 
I am new using UART, I am looking to receive the data from RX using interrupt? 
MCC generated these functions in Eusart.c: 
uint8_t EUSART2_Read(void)
void EUSART2_Receive_ISR(void)
void EUSART2_RxDataHandler(void)
 
But I don't know how I can use them in my MAIN program to perform processing and display it on LCD!
BTW, I tried to directly use the data available in eusart2RxBuffer! it works but I think I don't use the interrupt well. Please, could you help me? 
I use MPLAB X V5.30, compiler 2.10, PIC18F45K80
 
Thanks
#1

4 Replies Related Threads

    PStechPaul
    Super Member
    • Total Posts : 2558
    • Reward points : 0
    • Joined: 2006/06/27 16:11:32
    • Location: Cockeysville, MD, USA
    • Status: offline
    Re: Receive data from EUSART interrupt using MCC Code 2020/02/20 09:45:48 (permalink)
    5 (2)
    You really need to post your code, with comments added to explain what is intended for each line. Here is a basic overview of the USART:
     
    http://ww1.microchip.com/downloads/en/DeviceDoc/usart.pdf
     
    Do some Googling:
     
    https://www.microchip.com/forums/m182736.aspx
     
    https://microchipdeveloper.com/mcu1101:project-12
     
    https://electronics.stackexchange.com/questions/182354/problem-with-xc8-rx-interrupt-pic18f4550
     

     
    #2
    katela
    Super Member
    • Total Posts : 1635
    • Reward points : 0
    • Joined: 2013/06/11 05:25:18
    • Location: South Africa
    • Status: online
    Re: Receive data from EUSART interrupt using MCC Code 2020/02/20 10:28:19 (permalink)
    0
    You will need to enable the Global Interrupt and Peripheral Interrupt in the main code:

    // Enable the Global Interrupts
    INTERRUPT_GlobalInterruptEnable();
    // Enable the Peripheral Interrupts
    INTERRUPT_PeripheralInterruptEnable();

    Then write your code in your ISR.
    Read more here:
    https://microchipdeveloper.com/mcu1101:project-12
     

    Free online Microcontroller Tutorials and Projects for Hobbyists and students. From beginners to advanced. Website: www.studentcompanion.co.za
    YouTube Tutorials: https://www.youtube.com/StudentCompanionSA
    #3
    davekw7x
    Entropy++
    • Total Posts : 1849
    • Reward points : 0
    • Joined: 2012/01/16 12:01:07
    • Location: Second star on the right, straight on till morning
    • Status: offline
    Re: Receive data from EUSART interrupt using MCC Code 2020/02/20 16:06:03 (permalink)
    0
    Sherif89
     
    MCC generated these functions in Eusart.c: 
    uint8_t EUSART2_Read(void)
    void EUSART2_Receive_ISR(void)
    void EUSART2_RxDataHandler(void)
    ...
    I use MPLAB X V5.30, compiler 2.10, PIC18F45K80

    There is also a function named EUSART1_is_rx_ready(), which you use to let you know that a character has been received.
     
    Here is part of an MCC-generated test program for my PIC18F26K80.  Note that I clicked Redirect STDIO to USART in the MCC  EUSART1 "Easy Setup" window so that I can use printf.  I made no changes to any of the MCC files.
    // Suppress those annoying MCC "function never called" messages
    #pragma warning disable 520

    #include "mcc_generated_files/mcc.h"
    #include <stdio.h>
    #include <ctype.h>

    void main()
    {
        SYSTEM_Initialize();
        INTERRUPT_GlobalInterruptHighEnable();
        INTERRUPT_GlobalInterruptLowEnable();
        __delay_ms(100); // Give things a little time to settle down
                         // before transmitting

        printf("\r\nCompiled on %s at %s by XC8 version %u",
                __DATE__, __TIME__, __XC8_VERSION);
    #   ifdef __CLANG__
            printf(" (C99)\r\n");
    #   else
            printf(" (C90)\r\n");
    #   endif
        
        char ch;
        while (1) { // Main loop
            while (EUSART1_is_rx_ready()) {
                LED_RA7_Toggle();
                ch = EUSART1_Read();
                // Not shown here, but for production, the following
                // is VERY IMPORTANT:
                //
                // Use EUSART1_get_last_status() tp handle errors!
                // If no error, then do something useful with ch

                // For this example, simply print out printable chars.
                // If they are not printable, show their hex value

                if (isprint(ch)) {
                    printf("ch = '%c'\r\n", ch);
                }
                else {
                    printf("ch = 0x%02X\r\n", ch);
                }
            } // End of received character test

            // For initial testing/evaluation:
            // Put in a delay to show that characters can be received
            // using interrupt routine.  Type a few chars while it is
            // delaying, and they will be echoed the next time through the
            // loop!
            __delay_ms(1000);
        } // End of Main loop
    } // End of main()

    Output:  Windows 10 PUTTY connection to USB-logic-level converter on my Curiosity board.
    (MPLABX version 5.30)
     
    Compiled on Feb 20 2020 at 14:50:13 by XC8 version 2100 (C99)
    ch = 't'
    ch = 'h'
    ch = 'i'
    ch = 's'
    ch = ' '
    ch = 'i'
    ch = 's'
    ch = ' '
    ch = 'a'
    ch = ' '
    ch = 't'
    ch = 'e'
    ch = 's'
    ch = 't'


     
    Regards,

    Dave
     
    post edited by davekw7x - 2020/02/20 16:11:53

    Attached Image(s)


    Sometimes I just can't help myself...
    #4
    Sherif89
    Starting Member
    • Total Posts : 33
    • Reward points : 0
    • Joined: 2020/02/10 09:24:36
    • Location: 0
    • Status: offline
    Re: Receive data from EUSART interrupt using MCC Code 2020/03/17 07:38:50 (permalink)
    0
    [image]file:///C:/Users/czizoua/Desktop/data%20RX2.PNG[/image]
    Hello,
     
    Thank you for your response and help! 
     
    In my application, I have to read (RECEIVE USART) the data in interrupt mode and display it on the LCD screen.
    My data contain 0x 0D and 0x0A (CRLF ) in the middle and in the last of message! so i need to detect the last 0x0a to reset the buffer!
     
    Example of my data received:
     
    12/34/56/78/90/0x0d/0x0A/98/76/54/32/0x0d/0x0A (received each 400 ms)
     
    So, I implemented this detection directly in the interruption detection file. ''interrupt_manager.c''
    I chave deleted the function EUSART1_RxDefaultInterruptHandler();  = I don't use USART.C file that contains the following functions:
     
    uint8_t EUSART2_Read(void)
    void EUSART2_Receive_ISR(void)
    void EUSART2_RxDataHandler(void)
     
    Really I don't know if is the good way but my USART interrupt works very well.
     
    Regards 

    Attached Image(s)


    Regards
    Sherif
    #5
    Jump to:
    © 2020 APG vNext Commercial Version 4.5