• AVR Freaks

pic32mz uart whitout harmony

Author
joset
Starting Member
  • Total Posts : 48
  • Reward points : 0
  • Joined: 2016/07/25 13:05:11
  • Location: 0
  • Status: offline
2019/11/12 12:41:00 (permalink)
0

pic32mz uart whitout harmony

hello, im tryng to receive data on uart5 on a 32mz efm (no isr ) just pull the data.
so far my code to init uart:
void UART_Init()
{
    int pbClk;

    pbClk = SYS_CLK_SystemFrequencyGet() / 2; // Our PBCLK2 divider was set to 1, so PBCLK2 is exactly half the speed of the system clock, or 100Mhz

    U5MODE = 0; // Set UART 5 off prior to setting it up
    U5MODEbits.BRGH = 0; // We want standard speed mode. Not necessary as we just set U5MODE to 0 so this is just for explanation's sake
    U5BRG = pbClk / (16 * 19200) - 1;// This is the formula straight from the datasheet
    U5STA = 0; // Disable the TX and RX pins, clear all flags
    U5STAbits.UTXEN = 1; // Enable the TX pin
    U5STAbits.URXEN = 1; // Enable the RX pin
    U5MODEbits.PDSEL = 0; // PDSEL controls how many data bits and how many parity bits we want, this is the default of 8-bit data, no parity bits that most terminals use
    U5MODEbits.STSEL = 0; // STSEL controls how many stop bits we use, let's use the default of 1
    U5MODEbits.ON = 1; // Turn on the UART 5 peripheral
}

 
and more:
void APP_Initialize ( void )
{
    RPB3R = 0b0011; // RB3 = U5TX-pin13
    U5RXR = 0b1000; // RPB5 = U5RX-pin11
    TRISBbits.TRISB5 = 1; // Make RB5 an input
    UART_Init();
     
    /* Place the App state machine in its initial state. */
    appData.state = APP_STATE_INIT;
   
}

 
and try to read:
if(U5STAbits.URXDA)
        {
        *buf++ = U5RXREG;
        }

 
but when i send character form the PC it just restart the pic32, anyone can help?
 
 
 
#1

5 Replies Related Threads

    ric
    Super Member
    • Total Posts : 24581
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: pic32mz uart whitout harmony 2019/11/12 12:47:11 (permalink)
    0
    You don't show any code initialising the "buf" pointer, or any declaration of the buffer that it is pointing at.
    You also make no attempt to NOT step past the end of the buffer.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #2
    joset
    Starting Member
    • Total Posts : 48
    • Reward points : 0
    • Joined: 2016/07/25 13:05:11
    • Location: 0
    • Status: offline
    Re: pic32mz uart whitout harmony 2019/11/12 12:52:05 (permalink)
    0
    i initialize buf whit "unsigned char *buf;" at begining, im also just trying small data 5 byte at this point no need limit end buffer i think!
    #3
    Mysil
    Super Member
    • Total Posts : 3473
    • Reward points : 0
    • Joined: 2012/07/01 04:19:50
    • Location: Norway
    • Status: offline
    Re: pic32mz uart whitout harmony 2019/11/12 13:22:35 (permalink)
    0
    Hi,
    "unsigned char *buf;" 
    is a pointer, not an area of storage,  and it is not initialized in that statement.
    If the pointer is not initialized to a valid memory address somewhere else,
    it will point to memory address 0 which is deliberately Not accessible,
    just to catch that kind of mistakes,
    so the memory access will take exception for trying to access a prohibited address in memory,
    and reset the processor.
     
        Mysil
     
    #4
    joset
    Starting Member
    • Total Posts : 48
    • Reward points : 0
    • Joined: 2016/07/25 13:05:11
    • Location: 0
    • Status: offline
    Re: pic32mz uart whitout harmony 2019/11/12 13:38:10 (permalink)
    0
    many thanks, you was right, now is working.
    #5
    ric
    Super Member
    • Total Posts : 24581
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: pic32mz uart whitout harmony 2019/11/12 14:04:48 (permalink)
    0
    joset
    ... im also just trying small data 5 byte at this point no need limit end buffer i think!

    You waste far more time trying to solve obscure bugs caused by this sort of shortcut than you ever saved in the first place.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #6
    Jump to:
    © 2019 APG vNext Commercial Version 4.5