UARTx_Init_Advanced() MikroC PRO for PIC32 V4.0.0 problem

mikroC, mikroBasic and mikroPascal PRO for Microchip’s 32-bit PIC MCUs
Post Reply
Author
Message
rrid
Posts: 3
Joined: 24 Oct 2017 22:39

UARTx_Init_Advanced() MikroC PRO for PIC32 V4.0.0 problem

#1 Post by rrid » 24 Oct 2017 23:00

Hello,

This instruction:
void UARTx_Init_Advanced(unsigned long baud_rate, unsigned long freq_Khz, unsigned short high_low, unsigned short parity, unsigned short stop_bits);

from MikroC Library was operating properly with the previous version of MikroC.

It does not work anymore with the new version 4.0.0 !
I am forced to use :
UARTx_Init(baudrate)

I can not specify parameters or even standard 8N1 parameters !

Thanks for your help.

Also: it was an syntax error : "_UART_HI_SPEED" in place of "_UART_HIGH_SPEED ;-)

User avatar
lana.arsic
mikroElektronika team
Posts: 1715
Joined: 15 Jan 2016 12:50

Re: UARTx_Init_Advanced() MikroC PRO for PIC32 V4.0.0 proble

#2 Post by lana.arsic » 25 Oct 2017 17:24

Hi,

Welcome to the MikroE forum.

Thank you for reporting the typo in Help file,
I have forwarded to our developers.

Can you tell me which MCU are you using?

Kind regards,
Lana

rrid
Posts: 3
Joined: 24 Oct 2017 22:39

Re: UARTx_Init_Advanced() MikroC PRO for PIC32 V4.0.0 proble

#3 Post by rrid » 10 Jan 2018 15:41

Hi,

i use PIC32MX695F512L and PIC32MX440F512H

it seems that , from Library:
void UARTx_Init_Advanced(unsigned long baud_rate, unsigned long freq_Khz, unsigned short high_low, unsigned short parity, unsigned short stop_bits);

work with SYS_CLK, not PB_CLK (since MikroC Pro PIC32 version 4.0.0)

SYS_CLK = 20000
PB_CLK = 10000

two ways:
1.
#define PB_CLK 10000 // peripheral = MCU_CLK / 2

UART2_Init_Advanced(115200, PB_CLK, _UART_HIGH_SPEED, _UART_8BIT_NOPARITY, _UART_ONE_STOPBIT);
which gives me this real baudrate 230400 bps

2.
if ((PBDIV1_bit == 1) && (PBDIV0_bit == 1)) pb_divisor = 8;
else if ((PBDIV1_bit == 1) && (PBDIV0_bit == 0)) pb_divisor = 4;
else if ((PBDIV1_bit == 0) && (PBDIV0_bit == 1)) pb_divisor = 2;
else pb_divisor = 1;
periph_clock = Get_Fosc_kHz()/pb_divisor; // 20000 / 2 = 10000

UART2_Init_Advanced(115200, periph_clock, _UART_HIGH_SPEED, _UART_8BIT_NOPARITY, _UART_ONE_STOPBIT);
which gives me this real baudrate 230400 bps


I have to set: 20000 for "PB_CLK":
UART2_Init_Advanced(115200, 20000, _UART_HIGH_SPEED, _UART_8BIT_NOPARITY, _UART_ONE_STOPBIT); // TEST
which gives me the expected baudrate !

I tested this with different baudrates, with the same erroneous behaviors.

I checked the configuration by reading the chips:
1FC02FF0 DEVCFG3 0 USERID
1FC02FF4 DEVCFG2 20151 FPLLIDIV DIV_2 PLL Input Divider 2x Divider
FPLLMUL MUL_20 PLL Multiplier 20x Multiplier
UPLLIDIV DIV_2 USB PLL Input Divider 2x Divider
UPLLEN ON USB PLL Enable Enabled
FPLLODIV DIV_4 System PLL Output Clock Divider PLL Divide by 4
1FC02FF8 DEVCFG1 DD183 FNOSC PRIPLL Oscillator Selection Bits Primary Osc w/PLL (XT+,HS+,EC+PLL)
FSOSCEN OFF Secondary Oscillator Enable Disabled
IESO ON Internal/External Switch Over Enabled
POSCMOD XT Primary Oscillator Configuration XT osc mode
OSCIOFNC OFF CLKO Output Signal Active on the OSCO Pin Disabled
FPBDIV DIV_2 Peripheral Clock Divisor Pb_Clk is Sys_Clk/2
FCKSM CSDCMD Clock Switching and Monitor Selection Clock Switch Disable, FSCM Disabled
WDTPS PS8192 Watchdog Timer Postscaler 1:8192
FWDTEN OFF Watchdog Timer Enable WDT Disabled (SWDTEN Bit Controls)
1FC02FFC DEVCFG0 110FF00B DEBUG OFF Background Debugger Enable Debugger is disabled
ICESEL ICS_PGx2 ICE/ICD Comm Channel Select ICE EMUC2/EMUD2 pins shared with PGC2/PGD2
PWP OFF Program Flash Write Protect Disable
BWP OFF Boot Flash Write Protect bit Protection Disabled
CP OFF Code Protect Protection Disabled

Obviously if "Pb_Clk is Sys_Clk/1", the problem does not appear.

Please, can you check if there's been a change in the library?

User avatar
lana.arsic
mikroElektronika team
Posts: 1715
Joined: 15 Jan 2016 12:50

Re: UARTx_Init_Advanced() MikroC PRO for PIC32 V4.0.0 proble

#4 Post by lana.arsic » 12 Jan 2018 17:44

Hi,

I'm sorry for the inconvenience.

Yes, library is changed, and now you
should put MCU frequency in parameter freq_Khz.

I have forwarded this issue to our developers,
either library either Help menu will be changed.

If you want to use on previous way, I'm sending libraries which are used in version 3.6.0.
When you unzip them, you can replace them with existing ones in Uses folder
in the installation folder of the compiler, which are located in for example in:

c:\Users\Public\Documents\Mikroelektronika\mikroC PRO for PIC32\Uses

Kind regards,
Lana
Attachments
Lib_360_UART.zip
(54.75 KiB) Downloaded 162 times

Post Reply

Return to “PIC32 PRO Compilers”