My rig is:
1. PIC32MX795F512L with 8MHz Xtal on the carrier.
2. Config bits set so that Fosc is DIV2 TIMES 20 = 80MHz.
3. Edit project set so that PB is Fosc/8 = 10MHz = 10,000kHz.
4. Board is EasyPIC Fusion v7
5. Compiler is the latest REv 4.0.0
Code below does work OK but the frequency should be 10000 - and that fails:
Code: Select all
////////////////////////////////////////////////////////////////////////////////
// Project: WVL_Fusion_Morse_PBTest //
// File: Main.c //
// Function: Check RS232 and PB //
// MCU: P32MX795F512L with 8MHz on-board Xtal //
// Board: EasyPIC_Fusion_v7_for_PIC32 //
// Power 7-12V input. 3.3V //
// Compiler: mikroC PRO for PIC32 V4.0 //
// Oscillator: 8Mhz Xtal, Div2. PLLX20 = 80MHz //
// Programmer: On-board Mikro using PGEC2 and PGED2 on RB6 and RB7 //
// Author: WVL //
// Date: Apr 2023 //
////////////////////////////////////////////////////////////////////////////////
// Edit Project sets peripheral clock division to div8 so PB = 80/8 = 10MHz
////////////////////////////////////////////////////////////////////////////////
// Timer1 with PB set to div8 = 80/8 = 10MHz. T = 0.1uS //
// Prescaler 1:1; PR1 Preload = 10000; Actual Interrupt Time = 1 ms //
void InitTimer1(){ //
T1CON = 0x8000; //
TCS_bit = 0; // use PB = 80/10 = 10MHz //
T1IP0_bit = 1; //
T1IP1_bit = 1; //
T1IP2_bit = 1; //
T1IF_bit = 0; //
T1IE_bit = 1; //
PR1 = 10000; //
TMR1 = 0; //
} //
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// TIMES1 interrupt every 1[mS] //
void Timer1Interrupt() iv IVT_TIMER_1 ilevel 7 ics ICS_SRS { //
T1IF_bit = 0; //
LATA0_bit = ~LATA0_bit; //
} //
////////////////////////////////////////////////////////////////////////////////
void main(){
// Init MCU
AD1PCFG = 0xFFFF; // configure all pins digital
JTAGEN_bit = 0; // disable JTAG
//UART2_Init(57600); // initialize UART module on RF4 and RF5, USB UART A
// Use advanced init for UART2 - frequency[kHz] should be 10,000 but that does not work???
UART2_Init_Advanced(57600,80000,_UART_HIGH_SPEED,_UART_8BIT_NOPARITY,_UART_ONE_STOPBIT);
Delay_ms(100); // wait for UART module to stabilize
UART2_Write_Text("\r\nWVL_Fusion_Morse_Rx\r\n");
// Init pins
TRISA0_bit = 0; // LED blink by TIMER 1
TRISA1_bit = 0; // LED blink by dalay_mS
// Init TIMER 1
InitTimer1(); // call function to set up timer1
EnableInterrupts();
while(1){
delay_ms(20);
LATA1_bit = ~LATA1_bit;
UART2_Write_Text("WVL_Fusion_Morse_Rx\r\n");
}
}
What am I doing wrong?
Regards Bill Legge in Australia