Hot!PIC32MZ EF INTERNAL CRYSTAL ENABLING?

Author
baby
Senior Member
  • Total Posts : 160
  • Reward points : 0
  • Joined: 2018/07/16 22:33:00
  • Location: 0
  • Status: offline
2019/01/10 03:06:07 (permalink)
0

PIC32MZ EF INTERNAL CRYSTAL ENABLING?

I use PIC32MZ UART program to have a transmission i need to set 9600 baud rate. i refer the datasheet to set exact 9600 baud rate the corresponding clock frequencies are 18.432MHz , 5.0688MHz , 1.8432MHz.
i use PIC32MZ EF stater kit. 
how can i set this frequency in program?

want to be a perfect embedded developer..,
#1

19 Replies Related Threads

    crosland
    Super Member
    • Total Posts : 1460
    • Reward points : 0
    • Joined: 2005/05/10 10:55:05
    • Location: Bucks, UK
    • Status: offline
    Re: PIC32MZ EF INTERNAL CRYSTAL ENABLING? 2019/01/10 04:06:14 (permalink)
    0
    I don't think there is an internal crystal. The internal oscillator will not give you those frequencies.
     
    If you *really* need exact baud rate (why?) then you will need to use an external crystal or oscillator.
     
    A few percent error in the baud rate is usually acceptable.
    #2
    Howard Long
    Super Member
    • Total Posts : 573
    • Reward points : 0
    • Joined: 2005/04/04 08:50:32
    • Status: offline
    Re: PIC32MZ EF INTERNAL CRYSTAL ENABLING? 2019/01/10 04:15:28 (permalink)
    0
    I agree with crosland, for UARTs, half a bit time over 10 bits, or +/-5% combined RX & TX accuracy is usually sufficient, easily achievable with the internal FRC/PLL and baud rate generator at common speeds.
    #3
    baby
    Senior Member
    • Total Posts : 160
    • Reward points : 0
    • Joined: 2018/07/16 22:33:00
    • Location: 0
    • Status: offline
    Re: PIC32MZ EF INTERNAL CRYSTAL ENABLING? 2019/01/11 00:23:14 (permalink)
    0
    I use the below code but there is no response ....
     
     

    #include<stdio.h>
    #include<stdlib.h>
    #include<xc.h>

    #define PERIPHERAL_BUS_F (80000000ul)
    #define BAUDRATE (115200ul)

    void UART_init()
    {
    U4STA = 0;
    U4MODE = 0;

    U4STAbits.URXEN = 1;
    U4STAbits.UTXEN = 1;
    U4BRG = (PERIPHERAL_BUS_F / (BAUDRATE << 4)) - 1;

    U4MODEbits.ON = 1;
    }



    main()
    {

    TRISBbits.TRISB14=1;
    U4RXR=0b0010;
    //
    TRISGbits.TRISG6=0;
    RPG6R=0b0010;
    //tx U4TX
    UART_init();
    while(1)
    {
    U4TXREG='A';
    //UART_txArray("hai baby", 30);
    }
    }

     
    what is the problem with this code?
    post edited by baby - 2019/01/30 04:50:54

    want to be a perfect embedded developer..,
    #4
    crosland
    Super Member
    • Total Posts : 1460
    • Reward points : 0
    • Joined: 2005/05/10 10:55:05
    • Location: Bucks, UK
    • Status: offline
    Re: PIC32MZ EF INTERNAL CRYSTAL ENABLING? 2019/01/11 02:08:15 (permalink)
    0
    What do you mean by "no response"?
     
    What do you expect to happen?
     
    What device is the PIC connected to?
     
    How is it connected to that device?
     
    After loading the tx reg you always need to wait for it to be empty before sending another character.
     
    Have you actually read the documentation for the UART?
    #5
    baby
    Senior Member
    • Total Posts : 160
    • Reward points : 0
    • Joined: 2018/07/16 22:33:00
    • Location: 0
    • Status: offline
    Re: PIC32MZ EF INTERNAL CRYSTAL ENABLING? 2019/01/11 02:47:09 (permalink)
    0
             1) I didn't get any values on receiver side
     
             2) I need to transmit data from PIC32MZ
     
    3 and 4) I connect PIC32MZ  tx      to    RS232 to TTL converter RX. 
                                PIC32MZ gnd     to   RS232 to TTL converter gnd.
                       i use putty software to check the communication.
              5) Related to Delay?
     

    want to be a perfect embedded developer..,
    #6
    sunilbarot
    Starting Member
    • Total Posts : 47
    • Reward points : 0
    • Joined: 2016/06/25 03:13:13
    • Location: 0
    • Status: offline
    Re: PIC32MZ EF INTERNAL CRYSTAL ENABLING? 2019/01/11 03:40:11 (permalink)
    0
    You seem to ask for 9600 baud and the code shows you are setting 115200. Did you try 9600 ?
    I am sure you have set putty right (hand shake and all ) but also do a sanity check there.
    #7
    baby
    Senior Member
    • Total Posts : 160
    • Reward points : 0
    • Joined: 2018/07/16 22:33:00
    • Location: 0
    • Status: offline
    Re: PIC32MZ EF INTERNAL CRYSTAL ENABLING? 2019/01/11 04:02:28 (permalink)
    0
    Now i receive the response in putty software but the received characters are irrelevant to my transmitter coding.
    yes i checked with 9600 also.

    want to be a perfect embedded developer..,
    #8
    crosland
    Super Member
    • Total Posts : 1460
    • Reward points : 0
    • Joined: 2005/05/10 10:55:05
    • Location: Bucks, UK
    • Status: offline
    Re: PIC32MZ EF INTERNAL CRYSTAL ENABLING? 2019/01/11 07:37:13 (permalink)
    0
    Parity? Stop bits?
    #9
    qhb
    Superb Member
    • Total Posts : 8760
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: PIC32MZ EF INTERNAL CRYSTAL ENABLING? 2019/01/11 14:10:37 (permalink)
    0
    Just get it to send character 0x55 over and over, and look at the output with a scope to check the baud rate.
     
    #10
    baby
    Senior Member
    • Total Posts : 160
    • Reward points : 0
    • Joined: 2018/07/16 22:33:00
    • Location: 0
    • Status: offline
    Re: PIC32MZ EF INTERNAL CRYSTAL ENABLING? 2019/01/11 21:33:36 (permalink)
    0
    https://www.youtube.com/watch?v=W0XMeSVEwwk
    I Follow this video and i got the output.
    i get the response in PUTTY SOFTWARE. 

    want to be a perfect embedded developer..,
    #11
    crosland
    Super Member
    • Total Posts : 1460
    • Reward points : 0
    • Joined: 2005/05/10 10:55:05
    • Location: Bucks, UK
    • Status: offline
    Re: PIC32MZ EF INTERNAL CRYSTAL ENABLING? 2019/01/12 02:46:55 (permalink)
    +2 (2)
    You: Thank you.
     
    Us: You're welcome.
    #12
    baby
    Senior Member
    • Total Posts : 160
    • Reward points : 0
    • Joined: 2018/07/16 22:33:00
    • Location: 0
    • Status: offline
    Re: PIC32MZ EF INTERNAL CRYSTAL ENABLING? 2019/01/17 04:33:41 (permalink)
    0
    i send a word through UART communication i get the response in PUTTY software.
    but i need to send ADC data through UART communication.
     
    1)How can i send the integer value through UART?
    i follow the below step but i didnot get the proper response.
     
    int i=0;
    for(i=0;i<10;i++)
    {
    U4TXREG='i';
    }
     
    2)ADC output is 12 bit but i want to transfer the 8 bit data through UART. how can i transfer 8 bit ADC data through UART?
    post edited by baby - 2019/01/17 04:37:23

    want to be a perfect embedded developer..,
    #13
    qhb
    Superb Member
    • Total Posts : 8760
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: PIC32MZ EF INTERNAL CRYSTAL ENABLING? 2019/01/17 04:38:28 (permalink)
    0
    baby
    ...
    i follow the below step but i didnot get the proper response.
     
    int i=0;
    for(i=0;i<10;i++)
    {
    U4TXREG='i';
    }

    Two problems here.
    One, it's just going to send the character 'i' ten times.
    Two, you don't wait for the register to be ready, so you will probably lose most of the characters.
    Write a function to wait for TXREG to be available, then send one character. Read the PIC datasheet to determine how to know it is available.
     

    2)ADC output is 12 bit but i transfer the 8 bit data through UART. how can transfer 8 bit ADC data through UART?

    What is receiving the data at the other end?
    It is rarely a good idea to just send raw data. Use the sprintf() function to convert it to an ASCII string, then send the characters of the string one by one. That means the number would then be redable on a terminal like PUTTY.
     
    #14
    baby
    Senior Member
    • Total Posts : 160
    • Reward points : 0
    • Joined: 2018/07/16 22:33:00
    • Location: 0
    • Status: offline
    Re: PIC32MZ EF INTERNAL CRYSTAL ENABLING? 2019/01/17 05:02:35 (permalink)
    0
    i use the below code,
    UART_txArray("Hai baby ", 20);
    int i=0;
    for(;i<3;i++)
    {
    while(U4STAbits.UTXBF);

    U4TXREG=(i+0x30);
    }
     
    response in putty

    ▒▒▒▒012 ▒▒▒▒▒<tZ@Hai baby
     
     
     

    want to be a perfect embedded developer..,
    #15
    qhb
    Superb Member
    • Total Posts : 8760
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: PIC32MZ EF INTERNAL CRYSTAL ENABLING? 2019/01/17 05:18:48 (permalink)
    0
    You are mixing up code which calls library functions, and code which accesses the UART peripheral directly.
    At a guess, the UART_txArray() function is using a buffer and interrupts to send, so it doesn't happen until after your direct access finishes.
    You should stick to one way or the other.
     
    #16
    baby
    Senior Member
    • Total Posts : 160
    • Reward points : 0
    • Joined: 2018/07/16 22:33:00
    • Location: 0
    • Status: offline
    Re: PIC32MZ EF INTERNAL CRYSTAL ENABLING? 2019/01/17 05:38:00 (permalink)
    0
     
    char  pData1[]={'0','1','2','3','4','5','6'};  
    unsigned int i;

    for(i = 0;i < 9;i++)
    {
    while(U4STAbits.UTXBF);

    U4TXREG = pData1;
    delay(50000);

    }
     
    Response in putty
    ▒0123456▒0123456▒0123456▒0123456▒0123456▒0123456▒0123456▒0123456▒0123456▒0123456
     
     

    want to be a perfect embedded developer..,
    #17
    qhb
    Superb Member
    • Total Posts : 8760
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: PIC32MZ EF INTERNAL CRYSTAL ENABLING? 2019/01/17 12:05:41 (permalink)
    0
    I suspect you have the WATCHDOG timer enabled, and you see a glitch every time it triggers.
    Turn it off in the config words.
     
    #18
    baby
    Senior Member
    • Total Posts : 160
    • Reward points : 0
    • Joined: 2018/07/16 22:33:00
    • Location: 0
    • Status: offline
    Re: PIC32MZ EF INTERNAL CRYSTAL ENABLING? 2019/01/31 04:47:16 (permalink)
    0
    i get "0 to 1123"  UART  serial output.
     for (p=0;p<1123;p++)
                    {
                          while(U4STAbits.UTXBF);
                        q=p/1000;//1
                        r=p%1000;//123
                        s=r/100;//1
                        t=r%100;//23
                        u=t/10;//2
                        v=t%10;//3
                        U4TXREG=q+0x30;
                        U4TXREG=s+0x30;
                        U4TXREG=u+0x30;
                        U4TXREG=v+0x30;
                        delay(50000);
                        UART_txArray(" ", 5);
                        
                    }

     
    How can i send the ADC data to UART terminal.
    i refer the ADC -PIC32 datasheet and i got the coding 
       while (1)
            {
                
            
            // Trigger a conversion
            ADCCON3bits.GSWTRG = 1;
            
            // Wait the conversions to complete
            while (ADCDSTAT1bits.ARDY0 == 0);
            // fetch the result
            result[0] = ADCDATA0;
            while (ADCDSTAT1bits.ARDY1 == 0);
            // fetch the result
            result[1] = ADCDATA1;
            
            
            while (ADCDSTAT1bits.ARDY2 == 0);
            // fetch the result
            result[2] = ADCDATA2;
           
            while (ADCDSTAT1bits.ARDY3 == 0);
            /* fetch the result */
            result[3] = ADCDATA3;
           

     
    i use AN3 -RB3  channel only.
    how can i transfer this analog data to UART.
    I use below function but i didnot get the output.
        unsigned int i;

                for(i = 0;i < 4;i++)
                {
                    while(U4STAbits.UTXBF);

                  // U4TXREG = result[i] ;
                    
                   p=result[0];
                   q=result[1];
                   r=result[2];
                   s=result[3];
                    U4TXREG=p+0x30;
                        U4TXREG=q+0x30;
                        U4TXREG=r+0x30;
                        U4TXREG=s+0x30;
                        delay(50000);
               

                

     

    want to be a perfect embedded developer..,
    #19
    crosland
    Super Member
    • Total Posts : 1460
    • Reward points : 0
    • Joined: 2005/05/10 10:55:05
    • Location: Bucks, UK
    • Status: offline
    Re: PIC32MZ EF INTERNAL CRYSTAL ENABLING? 2019/01/31 05:33:04 (permalink)
    +2 (2)
    I use below function but i didnot get the output.

     
    You didn't get what output? What were you expecting?
     
    How many times does it need to be repeated. Show ALL of your code?
     
    What data type are result[], p, q, r, s?
     
    What values do you think they contain?
     
    What data type and range of values can the UART TXREG hold?
     
    Why do you add 0x30 to p, q, r, s?
     
    You ignored the advice from post #14. You MUST wait for each character to be sent before writing to the transmit register again.
     
    Think about the answers to these questions and you will make some progress. Otherwise, go away, learn some basic coding skills and then come back to the problem.
     
    #20
    Jump to:
    © 2019 APG vNext Commercial Version 4.5