UART baudrate wrong

General discussion on mikroC PRO for dsPIC30/33 and PIC24.
Post Reply
Author
Message
Jo910
Posts: 2
Joined: 24 May 2022 20:30

UART baudrate wrong

#1 Post by Jo910 » 24 May 2022 20:55

Hi,

I am currently working on a UART terminal for a dsPIC33EP512MC502. UART1 should be on Pin 21 and 22 of a 28pin DIP package. Code looks like this:

void main () {

Unlock_IOLOCK();
PPS_Mapping_NoLock(42, _OUTPUT, _U1TX); --> Pin 21 --> RP42
PPS_Mapping_NoLock(43, _INPUT, _U1RX); --> Pin 22 --> RP43
Lock_IOLOCK();
UART1_Init(9600);
Delay_ms(1000);
UART1_Write_Text("Start");

}

The terminal should display "Start", but the are only some undefined signs displayed. This is a typical phenomenon for wrong baudrate, so I think that the project settings could be wrong or that clock could be wrong. I wanted to run the dsPIC with 50 MHz. Is there anything to care about in main () or is it enough to write 50 MHz in the frequency field of the project settings? See project settings attached. Do I have to make some configuration for PLL? Is there anything else missing in the code?

Thank you.

Best regards
Attachments
dspic33ep512mc502.zip
(817 Bytes) Downloaded 51 times

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: UART baudrate wrong

#2 Post by filip » 27 May 2022 08:56

Hi,

Please take a look at the datasheet of this MCU to see how to set the configuration bits correctly.

Also, there are many examples for the 33EP512MU810 that is very similar to your MCU, so check this also.

Regards,
Filip.

Jo910
Posts: 2
Joined: 24 May 2022 20:30

Re: UART baudrate wrong

#3 Post by Jo910 » 31 May 2022 16:53

Hi,

thank you for the reply. The code examples for the 33EP512MU810 helped me and now UART is working with FRC frequency 7,37 MHz.
But I want to use a faster frequency. In further code examples and the datasheet, I understood how to configure PLL. With my code, FRC frequency should be multiplied with 10, so I should have a frequency of 73.7 MHz:

void main() {

FRCDIV_0_bit = 0;
FRCDIV_1_bit = 0;
FRCDIV_2_bit = 0;
PLLPRE_0_bit = 0;
PLLPRE_1_bit = 0;
PLLPRE_2_bit = 0;
PLLPRE_3_bit = 0;
PLLPRE_4_bit = 0;
PLLFBD = 38;
PLLPOST_0_bit = 0;
PLLPOST_1_bit = 0;
ANSELA = 0x00;
ANSELB = 0x00;
PORTB = 0;
TRISB.RB10 = 0;
TRISB.RB11 = 1;
Unlock_IOLOCK();
PPS_Mapping_NoLock(42, _OUTPUT, _U1TX);
PPS_Mapping_NoLock(43, _INPUT, _U1RX);
Lock_IOLOCK();
UART1_Init(9600);
Delay_ms(1000);
UART1_Write_Text("Start");
Delay_ms(1000);
while(1)
{
}
}

But when changing project settings to use the FRCPLL and the frequency to 73.7 MHz, UART is not working.
Is there something missing in my code?

Thank you.

Best regards
Attachments
project settings.png
project settings.png (180.74 KiB) Viewed 1179 times

Post Reply

Return to “mikroC PRO for dsPIC30/33 and PIC24 General”